no message

This commit is contained in:
2024-10-09 22:21:57 +03:00
parent 54c80c516b
commit 6252af944e
699 changed files with 2634 additions and 1997 deletions

View File

@@ -0,0 +1,73 @@
package _VisualDVM.TestingSystem.Common.Configuration;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import Common.Utils.CommonUtils;
import Common.Utils.TextLog;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Group.Json.GroupsJson;
import _VisualDVM.TestingSystem.Common.Settings.Json.SettingsArrayJson;
import _VisualDVM.TestingSystem.Common.Settings.Settings;
import _VisualDVM.TestingSystem.Common.Test.Json.TestsJson;
import _VisualDVM.TestingSystem.Common.Test.Test;
import com.sun.org.glassfish.gmbal.Description;
import javax.swing.*;
import java.util.Vector;
public class Configuration extends riDBObject {
//конфигурация = данные для пакета.
//группы
//тесты
//настройки тестируемого объекта
//пакет = запуск конфигурация + тестируемый объект
//---
public int maxtime = 300;
@Description("DEFAULT 0")
public int autoTesting = 0;
@Description("DEFAULT 1")
public int kernels = 1; //ядра
//----
public String printAuto() {
return autoTesting > 0 ? "Да" : "Нет";
}
public void SwitchAuto() {
autoTesting = (autoTesting == 0) ? 1 : 0;
}
public ImageIcon GetAutoIcon() {
return CommonUtils.getIcon("/Common/icons/" + (autoTesting == 1 ? "RedPick" : "NotPick") + ".png");
}
//--
@Description("DEFAULT ''")
public String packedGroupsJson = "";
@Description("DEFAULT ''")
public String packedTestsJson = "";
@Description("DEFAULT ''")
public String packedSettingsJson = "";
//--
public void saveGroupsAsJson(Vector<Group> groups) {
packedGroupsJson = CommonUtils.gson.toJson(new GroupsJson(groups));
}
public void saveTestsAsJson(Vector<Test> tests) {
packedTestsJson = CommonUtils.gson.toJson(new TestsJson(tests));
}
public void saveSettingsAsJson(Vector<Settings> settings) {
packedSettingsJson = CommonUtils.gson.toJson(new SettingsArrayJson(settings));
}
//--
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Configuration c = (Configuration) src;
//--
maxtime = c.maxtime;
autoTesting = c.autoTesting;
kernels = c.kernels;
//-
packedGroupsJson = c.packedGroupsJson;
packedTestsJson = c.packedTestsJson;
packedSettingsJson = c.packedSettingsJson;
}
//- для автоматического тестирования главным образом.
public boolean validate(TextLog log) {
return true;
}
}

View File

@@ -0,0 +1,16 @@
package _VisualDVM.TestingSystem.Common.Configuration.Json;
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
public class ConfigurationJson implements Serializable {
@Expose
public int id;
@Expose
public String description;
public ConfigurationJson(Configuration configuration){
id=configuration.id;
description= configuration.description;
}
public ConfigurationJson(){}
}

View File

@@ -0,0 +1,19 @@
package _VisualDVM.TestingSystem.Common.Configuration.Json;
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
public class ConfigurationsJson implements Serializable {
@Expose
public List<ConfigurationJson> array =new Vector<>();
public ConfigurationsJson(){
}
//при создании пакета.
public ConfigurationsJson(Vector<? extends Configuration> configurations){
array =new Vector<>();
for (Configuration configuration:configurations)
array.add(new ConfigurationJson(configuration));
}
}

View File

@@ -0,0 +1,117 @@
package _VisualDVM.TestingSystem.Common.Group;
import Common.Utils.CommonUtils;
import Common.Visual.CommonUI;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import _VisualDVM.Global;
import _VisualDVM.Visual.UI;
import _VisualDVM.Utils;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import com.sun.org.glassfish.gmbal.Description;
import java.util.LinkedHashMap;
import java.util.Vector;
public class Group extends riDBObject {
@Description("DEFAULT 'Default'")
public TestType type = TestType.Default;
@Description("DEFAULT 'fortran'")
public LanguageName language = LanguageName.fortran;
//--
@Override
public boolean isVisible() {
return (!GroupsDBTable.filterMyOnly || Current.getAccount().email.equals(sender_address)) &&
Global.testingServer.db.groups.applyFilters(this);
}
public String getSummary() {
return description + " " + language.getDescription();
}
//-
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Group g = (Group) src;
type = g.type;
language = g.language;
}
public Group(Group group) {
this.SynchronizeFields(group);
}
public Group() {
}
@Override
public void select(boolean flag) {
super.select(flag);
if (CommonUI.isActive())
UI.getMainWindow().ShowCheckedTestsCount();
}
//--
//-
public static void generateForLanguage(
String dvm_drv,
LinkedHashMap<LanguageName, Vector<ProjectFile>> programs,
LanguageName language,
Vector<String> titles,
Vector<String> objects,
Vector<String> bodies,
String flags_in
) {
if (!programs.get(language).isEmpty()) {
String LANG_ = language.toString().toUpperCase() + "_";
Vector<String> module_objects = new Vector<>();
String module_body = "";
int i = 1;
for (ProjectFile program : programs.get(language)) {
//--
String object = CommonUtils.DQuotes(language + "_" + i + ".o");
module_objects.add(object);
module_body +=
object + ":\n" +
"\t" +
String.join(" ",
Utils.MFVar(LANG_ + "COMMAND"),
Utils.MFVar(LANG_ + "FLAGS"),
program.getStyleOptions(),
"-c",
program.getQSourceName(),
"-o",
object + "\n\n"
);
++i;
}
titles.add(String.join("\n",
LANG_ + "COMMAND=" + CommonUtils.DQuotes(dvm_drv) + " " +
language.getDVMCompile(),
LANG_ + "FLAGS=" + flags_in,
LANG_ + "OBJECTS=" + String.join(" ", module_objects),
""
));
objects.add(Utils.MFVar(LANG_ + "OBJECTS"));
bodies.add(module_body);
}
}
public String GenerateMakefile(Test test, String dvm_drv, String flags_in) {
//----->>
LinkedHashMap<LanguageName, Vector<ProjectFile>> programs = test.getPrograms();
Vector<String> titles = new Vector<>();
Vector<String> objects = new Vector<>();
Vector<String> bodies = new Vector<>();
String binary = CommonUtils.DQuotes("0");
//----->>
generateForLanguage(dvm_drv, programs, language, titles, objects, bodies, flags_in);
//----->>
return String.join("\n",
"LINK_COMMAND=" + CommonUtils.DQuotes(dvm_drv) + " " +
language.getDVMLink(),
"LINK_FLAGS=" + flags_in + "\n",
String.join("\n", titles),
"all: " + binary,
binary + " : " + String.join(" ", objects),
"\t" + Utils.MFVar("LINK_COMMAND") + " " + Utils.MFVar("LINK_FLAGS") + " " + String.join(" ", objects) + " -o " + binary,
String.join(" ", bodies));
}
}

View File

@@ -0,0 +1,149 @@
package _VisualDVM.TestingSystem.Common.Group;
import Common.Visual.CommonUI;
import _VisualDVM.Current;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.FKBehaviour;
import Common.Database.Tables.FKCurrentObjectBehaviuor;
import Common.Database.Tables.FKDataBehaviour;
import Common.Database.Tables.iDBTable;
import Common.Visual.DBObjectFilter;
import Common.Visual.DataSetFilter;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Group.UI.GroupFields;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import java.util.LinkedHashMap;
//-
public class GroupsDBTable extends iDBTable<Group> {
public static boolean filterMyOnly = false;
public GroupsDBTable() {
super(Group.class);
}
//------------------------------------------------>>>
@Override
protected void createFilters() {
filters.add(new Common.Visual.DataSetFilter<Group>("Тип", this) {
@Override
public void fill() {
for (TestType type : TestType.values())
field_filters.add(new Common.Visual.DBObjectFilter<Group>(dataSet, type.getDescription()) {
@Override
protected boolean validate(Group object) {
return object.type.equals(type);
}
});
}
});
filters.add(new DataSetFilter<Group>("Язык", this) {
@Override
public void fill() {
for (LanguageName languageName : LanguageName.values()) {
field_filters.add(new DBObjectFilter<Group>(dataSet, languageName.getDescription()) {
@Override
protected boolean validate(Group object) {
return object.language.equals(languageName);
}
});
}
}
});
}
@Override
public String getSingleDescription() {
return "группа тестов";
}
@Override
public String getPluralDescription() {
return "группы";
}
@Override
public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
res.put(Test.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
return res;
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"тип",
"язык"
};
}
@Override
public Object getFieldAt(Group object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return object.type.getDescription();
case 5:
return object.language.getDescription();
default:
return null;
}
}
@Override
public Current CurrentName() {
return Current.Group;
}
@Override
public DBObjectDialog<Group, GroupFields> getDialog() {
return new DBObjectDialog<Group, GroupFields>(GroupFields.class) {
@Override
public int getDefaultHeight() {
return 250;
}
@Override
public int getDefaultWidth() {
return 400;
}
@Override
public void validateFields() {
}
@Override
public void fillFields() {
fields.tfName.setText(Result.description);
CommonUI.TrySelect(fields.cbType, Result.type);
CommonUI.TrySelect(fields.cbLanguage, Result.language);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.type = (TestType) fields.cbType.getSelectedItem();
Result.language = (LanguageName) fields.cbLanguage.getSelectedItem();
}
};
}
public boolean containsGroupWithDescription(String description_in) {
for (Group group : Data.values()) {
if (group.description.equalsIgnoreCase(description_in))
return true;
}
return false;
}
public Group getGroupByDescription(LanguageName language_in,String description_in) {
for (Group group : Data.values()) {
if (group.sender_address.equals("vmk-post@yandex.ru")&&
group.language.equals(language_in)&&group.description.equalsIgnoreCase(description_in))
return group;
}
return null;
}
}

View File

@@ -0,0 +1,36 @@
package _VisualDVM.TestingSystem.Common.Group;
import Common.Utils.CommonUtils;
import _VisualDVM.Global;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Controls.MenuBarButton;
import _VisualDVM.TestingSystem.Common.Group.UI.AddGroupMenu;
import _VisualDVM.TestingSystem.Common.Group.UI.EditGroupMenu;
import Visual_DVM_2021.Passes.PassCode_2021;
import javax.swing.*;
public class GroupsMenuBar extends DataMenuBar {
public GroupsMenuBar() {
super("группы",
PassCode_2021.SynchronizeTests,
PassCode_2021.ConvertCorrectnessTests
);
addMenus(new AddGroupMenu(), new EditGroupMenu());
addPasses(PassCode_2021.DeleteGroup);
add(new JSeparator());
add(new MenuBarButton() {
{
setText("Свои");
setToolTipText("Отображать только группы тестов авторства пользователя");
Mark();
addActionListener(e -> {
GroupsDBTable.filterMyOnly = !GroupsDBTable.filterMyOnly;
Mark();
Global.testingServer.db.groups.ShowUI();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(GroupsDBTable.filterMyOnly ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
}
}

View File

@@ -0,0 +1,18 @@
package _VisualDVM.TestingSystem.Common.Group.Json;
import _VisualDVM.TestingSystem.Common.Group.Group;
import com.google.gson.annotations.Expose;
public class GroupJson {
@Expose
public int id;
@Expose
public String description;
@Expose
public String language;
public GroupJson(Group group) {
id = group.id;
language = group.language.toString();
description = group.description;
}
public GroupJson() {
}
}

View File

@@ -0,0 +1,19 @@
package _VisualDVM.TestingSystem.Common.Group.Json;
import _VisualDVM.TestingSystem.Common.Group.Group;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
public class GroupsJson implements Serializable {
@Expose
public List<GroupJson> array = new Vector<>();
public GroupsJson() {
}
//при создании пакета.
public GroupsJson(Vector<Group> groups) {
array = new Vector<>();
for (Group group : groups)
array.add(new GroupJson(group));
}
}

View File

@@ -0,0 +1,9 @@
package _VisualDVM.TestingSystem.Common.Group.UI;
import _VisualDVM.Visual.Menus.VisualiserMenu;
import Visual_DVM_2021.Passes.PassCode_2021;
public class AddGroupMenu extends VisualiserMenu {
public AddGroupMenu() {
super("", "/icons/RedAdd.png");
addPasses(PassCode_2021.PublishGroup,PassCode_2021.CreateGroupFromDirectory,PassCode_2021.CreateGroupFromFiles);
}
}

View File

@@ -0,0 +1,9 @@
package _VisualDVM.TestingSystem.Common.Group.UI;
import _VisualDVM.Visual.Menus.VisualiserMenu;
import Visual_DVM_2021.Passes.PassCode_2021;
public class EditGroupMenu extends VisualiserMenu {
public EditGroupMenu() {
super("", "/icons/Edit.png" );
addPasses(PassCode_2021.EditGroup, PassCode_2021.ReplaceTestsFromFiles);
}
}

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.Common.Group.UI.GroupFields">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="385" height="181"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="a979" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d80" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<component id="f2392" class="javax.swing.JTextField" binding="tfName" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="238" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="c5591" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="тип"/>
</properties>
</component>
<component id="a5bbe" class="javax.swing.JComboBox" binding="cbType" custom-create="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="238" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="8a5e9" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="язык сборки"/>
</properties>
</component>
<component id="c8d4e" class="javax.swing.JComboBox" binding="cbLanguage" custom-create="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="238" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,32 @@
package _VisualDVM.TestingSystem.Common.Group.UI;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import javax.swing.*;
import java.awt.*;
public class GroupFields implements DialogFields {
public JPanel content;
public JTextField tfName;
public JComboBox<TestType> cbType;
public JComboBox<LanguageName> cbLanguage;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
//-
cbType = new JComboBox<>();
cbType.addItem(TestType.Default);
cbType.addItem(TestType.Performance);
cbType.addItem(TestType.Correctness);
cbType.addItem(TestType.SAPFOR);
//-
cbLanguage = new JComboBox<>();
cbLanguage.addItem(LanguageName.fortran);
cbLanguage.addItem(LanguageName.c);
}
}

View File

@@ -0,0 +1,124 @@
package _VisualDVM.TestingSystem.Common.MachineProcess;
import Common.CommonConstants;
import Common.Database.Objects.DBObject;
import Common.Mode;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.GlobalProperties;
import _VisualDVM.Utils;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import _VisualDVM.Global;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.net.InetAddress;
import java.util.Vector;
public class MachineProcess extends DBObject {
public String id = "";
public String machineAddress = "";
public int machinePort = CommonConstants.Nan;
public String userName = "";
public String userPassword = "";
public String userWorkspace = "";
public String testingSystemRoot = "";
public String serverName = "";
public MachineProcess() {
}
public MachineProcess(MachineProcess p) {
SynchronizeFields(p);
}
public MachineProcess(DVMPackage p) {
machineAddress = p.machine_address;
machinePort = p.machine_port;
userName = p.user_name;
userPassword = p.user_password;
userWorkspace = p.user_workspace;
testingSystemRoot =CommonUtils.getHomePath();
serverName = Global.testingServer.name;
id = CommonUtils.getDateName(machineAddress + "_" + machinePort + "_" + userName);
}
@Override
public Object getPK() {
return id;
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
MachineProcess p = (MachineProcess) src;
machineAddress = p.machineAddress;
machinePort = p.machinePort;
userName = p.userName;
userPassword = p.userPassword;
userWorkspace = p.userWorkspace;
testingSystemRoot = p.testingSystemRoot;
serverName = p.serverName;
}
public String getUniqueKey() {
Vector<String> res = new Vector<>();
res.add(machineAddress);
res.add(String.valueOf(machinePort));
res.add(userName);
res.add(userWorkspace);
return String.join("_", res);
}
public File getWorkspace() {
return new File(Global.MachinesDirectory, id);
}
public File getStartedFile() {
return new File(getWorkspace(), Constants.STARTED);
}
public File getAbortedFile() {
return new File(getWorkspace(), Constants.ABORTED);
}
//---
public boolean isAborted() {
File aborted = getAbortedFile();
return aborted.exists();
}
public boolean isStarted() {
File started = getStartedFile();
return started.exists();
}
public boolean isLocal() {
boolean local = false;
try {
InetAddress address = InetAddress.getByName(machineAddress);
InetAddress localAddress = InetAddress.getByName(Global.properties.ServerAddress);
local = localAddress.getHostAddress().equals(address.getHostAddress());
} catch (Exception ex) {
CommonUtils.MainLog.PrintException(ex);
}
return local;
}
//--
public void Start() {
try {
File workspace = getWorkspace();
Utils.CheckAndCleanDirectory(workspace);
//копирование визуализатора
File src = new File(CommonUtils.getHomeDirectory(), "_VisualDVM.TestingSystem.jar");
File supervisor = new File(workspace, "VisualSapfor.jar");
FileUtils.copyFile(src, supervisor);
//создание настроек
GlobalProperties properties = new GlobalProperties(Global.properties);
properties.Mode = Mode.MachineQueue;
CommonUtils.jsonToFile(properties, new File(workspace, "properties"));
Vector<String> args = new Vector<>();
args.add(CommonUtils.DQuotes(machineAddress));
args.add(CommonUtils.DQuotes(machinePort));
args.add(CommonUtils.DQuotes(userName));
args.add(CommonUtils.DQuotes(userPassword));
args.add(CommonUtils.DQuotes(userWorkspace));
args.add(CommonUtils.DQuotes(testingSystemRoot));
args.add(CommonUtils.DQuotes(Global.testingServer.name));
//--
Utils.startScript(workspace, workspace,
"start",
"java -jar VisualSapfor.jar " +
String.join(" ", args) + " 1>out.txt 2>err.txt");
//---
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,29 @@
package _VisualDVM.TestingSystem.Common.MachineProcess;
import Common.Database.Tables.DataSet;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import java.util.LinkedHashMap;
public class MachineProcessSet extends DataSet<String, MachineProcess> {
public MachineProcessSet() {
super(String.class, MachineProcess.class);
}
public LinkedHashMap<String, MachineProcess> getSortedByKeys() {
LinkedHashMap<String, MachineProcess> res = new LinkedHashMap<>();
for (MachineProcess process : Data.values())
res.put(process.getUniqueKey(), process);
return res;
}
public boolean hasProcessForPackage(DVMPackage package_in) {
for (MachineProcess process : Data.values()) {
if (
process.machineAddress.equals(package_in.machine_address) &&
process.machinePort == package_in.machine_port &&
process.userName.equals(package_in.user_name) &&
process.userWorkspace.equals(package_in.user_workspace)
) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,6 @@
package _VisualDVM.TestingSystem.Common.MachineProcess;
public enum MachineProcessState {
Inactive,
Active,
Aborted
}

View File

@@ -0,0 +1,19 @@
package _VisualDVM.TestingSystem.Common.Settings.Json;
import _VisualDVM.TestingSystem.Common.Settings.Settings;
import com.google.gson.annotations.Expose;
import java.util.List;
import java.util.Vector;
public class SettingsArrayJson {
@Expose
public List<SettingsJson> array =new Vector<>();
public SettingsArrayJson(){
}
//при создании пакета.
public SettingsArrayJson(Vector<? extends Settings> settings_in){
array =new Vector<>();
for (Settings settings: settings_in)
array.add(new SettingsJson(settings));
}
}

View File

@@ -0,0 +1,15 @@
package _VisualDVM.TestingSystem.Common.Settings.Json;
import _VisualDVM.TestingSystem.Common.Settings.Settings;
import com.google.gson.annotations.Expose;
public class SettingsJson {
@Expose
public int id;
@Expose
public String description;
public SettingsJson(Settings settings) {
id = settings.id;
description = settings.description;
}
public SettingsJson() {
}
}

View File

@@ -0,0 +1,15 @@
package _VisualDVM.TestingSystem.Common.Settings;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import Common.Utils.TextLog;
//предопределенный набор настроек тестируемой системы. сохраняется для упрощения.
public abstract class Settings extends riDBObject {
public String flags="";
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Settings s = (Settings) src;
flags=s.flags;
}
public boolean validate(TextLog Log){return true;}
}

View File

@@ -0,0 +1,17 @@
package _VisualDVM.TestingSystem.Common;
import _VisualDVM.TestingSystem.SAPFOR.PerformSapforTask;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import java.io.File;
public class TaskThread extends Thread {
public SapforTask task = null;
public TaskThread(SapforTask task_, File sapfor_drv) {
super(() -> {
while (!task_.state.isComplete()) {
task_.Reset();
new PerformSapforTask().Do(task_,sapfor_drv);
}
});
task = task_;
}
}

View File

@@ -0,0 +1,123 @@
package _VisualDVM.TestingSystem.Common;
import Common.Visual.StatusEnum;
import Common.Visual.Fonts.VisualiserFonts;
import java.util.Arrays;
import java.util.Vector;
import java.util.stream.Collectors;
public enum TasksPackageState implements StatusEnum {
Draft,
//--
Inactive, //пакет просто есть. не запущен.
Queued,
//--
TestsSynchronize, //оставить.
PackageWorkspaceCreation,
PackageStart,
//
CompilationWorkspacesCreation,
CompilationPreparation,
CompilationExecution,
//-
RunningWorkspacesCreation,
RunningPreparation,
RunningExecution,
//--
RunningEnd, //скачка архива
Analysis,
//-
Done,
Aborted,
ConnectionError,
DoneWithErrors
;
public boolean isActive() {
switch (this) {
case Inactive:
case Done:
case DoneWithErrors:
case Aborted:
case Draft:
case ConnectionError:
return false;
default:
return true;
}
}
public boolean isDone() {
switch (this) {
case Done:
case DoneWithErrors:
return true;
default:
return false;
}
}
@Override
public VisualiserFonts getFont() {
switch (this) {
case TestsSynchronize:
case Analysis:
case Draft:
return VisualiserFonts.BlueState;
case CompilationExecution:
case RunningExecution:
return VisualiserFonts.ProgressState;
case Done:
return VisualiserFonts.GoodState;
case DoneWithErrors:
return VisualiserFonts.BadState;
default:
return StatusEnum.super.getFont();
}
}
//-
public String getDescription() {
switch (this) {
case Inactive:
return "неактивен";
case Draft:
return "Подготовка к публикации";
case Aborted:
return "прерван";
case Queued:
return "в очереди";
case TestsSynchronize:
return "синхронизация тестов";
case PackageWorkspaceCreation:
return "создание рабочей папки пакета";
case PackageStart:
return "старт пакета";
case CompilationWorkspacesCreation:
return "создание рабочих папок компиляции";
case CompilationPreparation:
return "подготовка к компиляции";
case CompilationExecution:
return "компиляция";
case RunningWorkspacesCreation:
return "создание рабочих папок для запуска";
case RunningPreparation:
return "подготовка к запуску";
case RunningExecution:
return "запуск";
case RunningEnd:
return "загрузка результатов";
case Analysis:
return "анализ результатов";
case Done:
return "завершен";
case ConnectionError:
return "сбой связи";
case DoneWithErrors:
return "завершен с ошибками";
default:
return StatusEnum.super.getDescription();
}
}
public Vector<TasksPackageState> getHigherStates(){
return Arrays.stream(values()).filter(state -> state.ordinal() > this.ordinal()).collect(Collectors.toCollection(Vector::new));
}
}

View File

@@ -0,0 +1,13 @@
package _VisualDVM.TestingSystem.Common.Test.Json;
import _VisualDVM.TestingSystem.Common.Test.Test;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
public class TestJson implements Serializable {
@Expose
public int id;
public TestJson(Test test){
id=test.id;
}
public TestJson(){}
}

View File

@@ -0,0 +1,19 @@
package _VisualDVM.TestingSystem.Common.Test.Json;
import _VisualDVM.TestingSystem.Common.Test.Test;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
public class TestsJson implements Serializable {
@Expose
public List<TestJson> array = new Vector<>();
public TestsJson() {
}
//при создании пакета.
public TestsJson(Vector<Test> tests) {
array = new Vector<>();
for (Test test : tests)
array.add(new TestJson(test));
}
}

View File

@@ -0,0 +1,10 @@
package _VisualDVM.TestingSystem.Common.Test;
import _VisualDVM.ProjectData.Files.DBProjectFile;
import com.google.gson.annotations.Expose;
import java.util.List;
import java.util.Vector;
public class ProjectFiles_json {
@Expose
public List<DBProjectFile> files = new Vector<>();
}

View File

@@ -0,0 +1,135 @@
package _VisualDVM.TestingSystem.Common.Test;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import Common.Visual.CommonUI;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import _VisualDVM.Global;
import _VisualDVM.Visual.UI;
import _VisualDVM.ProjectData.Files.FileState;
import _VisualDVM.ProjectData.Files.FileType;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.Repository.RepositoryRefuseException;
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
import Visual_DVM_2021.Passes.All.ZipFolderPass;
import com.sun.org.glassfish.gmbal.Description;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Vector;
public class Test extends riDBObject {
@Description("DEFAULT 0")
public int min_dim = 0; //мин размерность теста.
@Description("DEFAULT 0")
public int max_dim = 0; //макс размерность теста.
@Description("DEFAULT ''")
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
@Description("DEFAULT -1")
public int group_id = CommonConstants.Nan;
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Test t = (Test) src;
min_dim = t.min_dim;
max_dim = t.max_dim;
args = t.args;
group_id = t.group_id;
}
@Description("DEFAULT ''")
public String files = ""; //файлы теста
//--------------------------------------------->>>
@Description("IGNORE")
public String temp_project_name = "";
@Description("IGNORE")
public byte[] project_archive_bytes = null;
//--------------------------------------------->>>
public Test(Test test) {
this.SynchronizeFields(test);
}
public Test() {
}
@Override
public void select(boolean flag) {
super.select(flag);
if (CommonUI.isActive())
UI.getMainWindow().ShowCheckedTestsCount();
}
//---
@Override
public boolean isVisible() {
return Current.HasGroup() && (Current.getGroup().id == group_id);
}
//-
public File getArchive() {
return new File(Global.TestsDirectory, id + ".zip");
}
//-
public File getServerPath() {
return new File(Global.TestsDirectory, String.valueOf(id));
}
public File getHomePath() {
return new File(Global.visualiser.getWorkspace(), String.valueOf(id));
}
//--
public File getTempArchive() {
return new File(Global.TempDirectory, temp_project_name + ".zip");
}
public File getTempProject() {
return new File(Global.TempDirectory, temp_project_name);
}
public boolean unpackProjectOnServer() throws Exception {
File tmpArchive = new File(Global.TempDirectory, temp_project_name + ".zip");
File tmpProject = new File(Global.TempDirectory, temp_project_name);
File testProject = new File(Global.TestsDirectory, String.valueOf(id));
File testArchive = new File(Global.TestsDirectory, id + ".zip");
//--
if (tmpArchive.exists())
FileUtils.forceDelete(tmpArchive);
if (tmpProject.exists())
FileUtils.forceDelete(tmpProject);
if (testProject.exists())
FileUtils.forceDelete(testProject);
if (testArchive.exists())
FileUtils.forceDelete(testArchive);
//--
CommonUtils.bytesToFile(project_archive_bytes, tmpArchive); // распаковка байтов.
//--
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
if (!unzipFolderPass.Do(
tmpArchive.getAbsolutePath(),
Global.TempDirectory.getAbsolutePath())) {
return false;
}
//--
FileUtils.moveDirectory(tmpProject, testProject);
//--
ZipFolderPass zip = new ZipFolderPass();
if (!zip.Do(testProject.getAbsolutePath(), testArchive.getAbsolutePath()))
throw new RepositoryRefuseException("Не удалось переписать архив проекта");
return true;
}
public String getFilesForTable() {
return files.replace("\n", ";");
}
public LinkedHashMap<LanguageName, Vector<ProjectFile>> getPrograms() {
LinkedHashMap<LanguageName, Vector<ProjectFile>> res = new LinkedHashMap<>();
//--
res.put(LanguageName.fortran, new Vector<>());
res.put(LanguageName.c, new Vector<>());
res.put(LanguageName.cpp, new Vector<>());
//--
String[] files_names = files.split("\n");
for (String file_name : files_names) {
ProjectFile file = new ProjectFile(new File(file_name));
//--
if (!file.state.equals(FileState.Excluded) &&
file.fileType.equals(FileType.program) &&
(!file.languageName.equals(LanguageName.n)))
res.get(file.languageName).add(file);
}
return res;
}
}

View File

@@ -0,0 +1,126 @@
package _VisualDVM.TestingSystem.Common.Test;
import _VisualDVM.Current;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Test.UI.TestFields;
import java.util.Vector;
public class TestDBTable extends iDBTable<Test> {
public TestDBTable() {
super(Test.class);
}
@Override
public String getSingleDescription() {
return "тест DVM";
}
@Override
public String getPluralDescription() {
return "тесты";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
protected void AdditionalInitColumns() {
//columns.get(0).setVisible(false);
}
@Override
public boolean hasCheckBox() {
return true;
}
};
}
@Override
public Object getFieldAt(Test object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.min_dim;
case 4:
return object.max_dim;
case 5:
return object.getFilesForTable();
default:
return null;
}
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"min_dim",
"max_dim",
"файлы"
};
}
@Override
public Current CurrentName() {
return Current.Test;
}
@Override
public DBObjectDialog<Test, TestFields> getDialog() {
return new DBObjectDialog<Test, TestFields>(TestFields.class) {
@Override
public int getDefaultHeight() {
return 200;
}
@Override
public int getDefaultWidth() {
return 400;
}
@Override
public void validateFields() {
if (!edit) {
if (!Current.getGroup().language.equals(Current.getProject().languageName))
Log.Writeln_("В текущую группу могут войти только тесты на языке " + Current.getGroup().language);
}
}
@Override
public void fillFields() {
fields.tfName.setText(Result.description);
fields.sMinDim.setValue(Result.min_dim);
fields.sMaxDim.setValue(Result.max_dim);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.min_dim = (int) fields.sMinDim.getValue();
Result.max_dim = (int) fields.sMaxDim.getValue();
if (!edit) {
Result.sender_name = Current.getAccount().name;
Result.sender_address = Current.getAccount().email;
}
}
};
}
public boolean containsTestWithDescription(String description_in) {
for (Test test : Data.values()) {
if (test.description.equalsIgnoreCase(description_in))
return true;
}
return false;
}
public Test getTestByDescription(int group_id_in, String description_in) {
for (Test test : Data.values()) {
if (test.sender_address.equals("vmk-post@yandex.ru")&&
(test.group_id==group_id_in)&&(test.description.equalsIgnoreCase(description_in)))
return test;
}
return null;
}
public Vector<Test> getSelectedGroupTests(Group group) {
Vector<Test> allTests = new Vector<>();
Vector<Test> selectedTests = new Vector<>();
//--
for (Test test : Data.values()) {
if (test.group_id == group.id) {
allTests.add(test);
if (test.isSelected()) selectedTests.add(test);
}
}
return selectedTests.isEmpty()?allTests:selectedTests;
}
}

View File

@@ -0,0 +1,22 @@
package _VisualDVM.TestingSystem.Common.Test;
public enum TestType {
Default,
Correctness,
Performance,
SAPFOR,
;
public String getDescription(){
switch (this){
case Correctness:
return "Корректность";
case Performance:
return "Производительность";
case Default:
return "Без типа";
case SAPFOR:
return "SAPFOR";
default:
return "?";
}
}
}

View File

@@ -0,0 +1,12 @@
package _VisualDVM.TestingSystem.Common.Test;
import Common.Visual.Menus.DataMenuBar;
import _VisualDVM.TestingSystem.Common.Test.UI.AddTestMenu;
import _VisualDVM.TestingSystem.Common.Test.UI.EditTestMenu;
import Visual_DVM_2021.Passes.PassCode_2021;
public class TestsMenuBar extends DataMenuBar {
public TestsMenuBar() {
super("тесты");
addMenus(new AddTestMenu(), new EditTestMenu());
addPasses(PassCode_2021.DownloadTest,PassCode_2021.DeleteTest);
}
}

View File

@@ -0,0 +1,13 @@
package _VisualDVM.TestingSystem.Common.Test.UI;
import _VisualDVM.Visual.Menus.VisualiserMenu;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
public class AddTestMenu extends VisualiserMenu {
public AddTestMenu() {
super("Добавление теста", "/icons/RedAdd.png", false);
add(Pass_2021.passes.get(PassCode_2021.CreateTestFromProject).createMenuItem());
add(Pass_2021.passes.get(PassCode_2021.CreateTestFromDirectory).createMenuItem());
add(Pass_2021.passes.get(PassCode_2021.CreateTestsFromFiles).createMenuItem());
add(Pass_2021.passes.get(PassCode_2021.CreateTestFromSelectedFiles).createMenuItem());
}
}

View File

@@ -0,0 +1,11 @@
package _VisualDVM.TestingSystem.Common.Test.UI;
import _VisualDVM.Visual.Menus.VisualiserMenu;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
public class EditTestMenu extends VisualiserMenu {
public EditTestMenu() {
super("Редактирование теста", "/icons/Edit.png", false);
add(Pass_2021.passes.get(PassCode_2021.EditTest).createMenuItem());
add(Pass_2021.passes.get(PassCode_2021.ReplaceTestProject).createMenuItem());
}
}

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.Common.Test.UI.TestFields">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e9479" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<vspacer id="9a439">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="ddf02" class="javax.swing.JTextField" binding="tfName" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<enabled value="true"/>
</properties>
</component>
<component id="fbef6" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="максимальная размерность"/>
</properties>
</component>
<component id="2b54" class="javax.swing.JSpinner" binding="sMaxDim">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/>
<maximum-size width="50" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="82807" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="минимальная размерность"/>
</properties>
</component>
<component id="c59e6" class="javax.swing.JSpinner" binding="sMinDim">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/>
<maximum-size width="50" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>

View File

@@ -0,0 +1,24 @@
package _VisualDVM.TestingSystem.Common.Test.UI;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import javax.swing.*;
import java.awt.*;
public class TestFields implements DialogFields {
public JTextField tfName;
private JPanel content;
public JSpinner sMinDim;
public JSpinner sMaxDim;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
}
public TestFields(){
sMinDim.setModel(new SpinnerNumberModel(1, 0, 16,1));
sMaxDim.setModel(new SpinnerNumberModel(1, 0, 16,1));
}
}

View File

@@ -0,0 +1,97 @@
package _VisualDVM.TestingSystem.Common;
import Common.Utils.CommonUtils;
import Common.Visual.CommonUI;
import _VisualDVM.Global;
import Common.Visual.Controls.MenuBarButton;
import _VisualDVM.Visual.Menus.VisualiserMenuBar;
import Common.Visual.Fonts.VisualiserFonts;
import Visual_DVM_2021.Passes.PassCode_2021;
import javax.swing.*;
import java.awt.*;
public class TestingBar extends VisualiserMenuBar {
// public JLabel KernelsLabel;
public JButton autorefreshButton;
JSpinner sCheckTime;
// JSpinner sKernels;
JLabel serverAdminLabel;
public TestingBar() {
//-
// KernelsLabel = addLabel("", "/icons/Kernels.png");
// KernelsLabel.setHorizontalTextPosition(JLabel.LEFT);
// KernelsLabel.setToolTipText("количество ядер, задействованное при тестировании");
/*
add(sKernels = new JSpinner());
sKernels.setPreferredSize(new Dimension(60, 26));
sKernels.setMaximumSize(new Dimension(60, 26));
sKernels.setModel(new SpinnerNumberModel(Global.properties.TestingKernels, 1,
Utils.getTestingMaxKernels(),
1));
sKernels.setValue(Global.properties.TestingKernels);
UI.MakeSpinnerRapid(sKernels, e -> {
Global.properties.updateField("TestingKernels", sKernels.getValue());
});
*/
addLabel(" ");
//--
add(new MenuBarButton() {
{
setText("оповещение по email");
setToolTipText("Оповещение о прогрессе выполнения пакета тестов");
Mark();
addActionListener(e -> {
Global.properties.switchAndUpdateFlag("EmailOnTestingProgress");
Mark();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(Global.properties.EmailOnTestingProgress ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
//--
add(autorefreshButton = new MenuBarButton() {
{
setText("проверка раз в");
setToolTipText("автоматическое обновление состояния пакета задач");
Mark();
addActionListener(e -> {
Global.properties.switchAndUpdateFlag("AutoCheckTesting");
//-
if (Global.properties.AutoCheckTesting)
TestingServer.TimerOn();
else
TestingServer.TimerOff();
//-
Mark();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(Global.properties.AutoCheckTesting ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
//--
add(sCheckTime = new JSpinner());
sCheckTime.setPreferredSize(new Dimension(60, 26));
sCheckTime.setMaximumSize(new Dimension(60, 26));
sCheckTime.setModel(new SpinnerNumberModel(Global.properties.CheckTestingIntervalSeconds, 10, 3600, 1));
sCheckTime.setValue(Global.properties.CheckTestingIntervalSeconds);
CommonUI.MakeSpinnerRapid(sCheckTime, e -> {
Global.properties.updateField("CheckTestingIntervalSeconds", sCheckTime.getValue());
if (Global.properties.AutoCheckTesting) TestingServer.ResetTimer();
});
add(new JLabel(" сек ") {
{
setFont(CommonUI.getTheme().Fonts.get(VisualiserFonts.TreeItalic));
}
});
addSeparator();
serverAdminLabel = addLabel(" управление сервером ");
addPasses(PassCode_2021.StartTestingServer, PassCode_2021.ShutdownTestingServer, PassCode_2021.PublishTestingServer);
}
public void ShowAutoCheckTesting() {
autorefreshButton.setIcon(CommonUtils.getIcon(Global.properties.AutoCheckTesting ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
public void showServerAdminLabel(boolean flag) {
serverAdminLabel.setVisible(flag);
}
}

View File

@@ -0,0 +1,90 @@
package _VisualDVM.TestingSystem.Common.TestingPackage;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
import _VisualDVM.TestingSystem.Common.Configuration.Json.ConfigurationsJson;
import _VisualDVM.TestingSystem.Common.TasksPackageState;
import com.sun.org.glassfish.gmbal.Description;
import java.io.File;
import java.util.Vector;
public abstract class TestingPackage<J> extends riDBObject {
public String PID = "";
public int tasksCount = 0; //Общее число задач
//--
public int kernels = 1;
public int needsEmail = 0;
//---
public String version = ""; //версия тестируемого объекта
public String drv = ""; //пусть к исполняемому файлы тестируемого объекта
//--
public int progress = 0; //прогресс выполнения
public long StartDate = 0;
public long ChangeDate = 0;
@Description("DEFAULT 0")
public int connectionErrosCount = 0;
public TasksPackageState state = TasksPackageState.Draft;
@Description("DEFAULT ''")
public String packedConfigurationsJson = "";
//--
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
TestingPackage tp = (TestingPackage) src;
//--
tasksCount = tp.tasksCount;
needsEmail = tp.needsEmail;
version = tp.version;
drv = tp.drv;
PID = tp.PID;
kernels = tp.kernels;
progress = tp.progress;
StartDate = tp.StartDate;
ChangeDate = tp.ChangeDate;
connectionErrosCount = tp.connectionErrosCount;
state = tp.state;
//--
packedConfigurationsJson= tp.packedConfigurationsJson;
}
public TestingPackage(TestingPackage p) {
SynchronizeFields(p);
}
public TestingPackage() {
}
public File getLocalWorkspace() {
return new File(getHomeDirectory(), String.valueOf(id));
}
public boolean isLoaded() {
return new File(getLocalWorkspace(), Constants.LOADED).exists();
}
//json где хранятся задачи----------------------------------
@Description("IGNORE")
public J package_json = null;
public abstract Class getJsonClass();
public abstract File getHomeDirectory();
public File getJsonFile() {
return new File(getLocalWorkspace(), "package_json");
}
public File getLoadedFile() {
return new File(getLocalWorkspace(), Constants.LOADED);
}
public void saveJson() throws Exception {
CommonUtils.jsonToFile(package_json, getJsonFile());
}
public void readJson() throws Exception {
package_json = (J) CommonUtils.jsonFromFile(getJsonFile(), getJsonClass());
}
public void destructor() {
package_json = null;
}
//----------------------------------------------------------
public void saveConfigurationsAsJson(Vector<? extends Configuration> configurations) {
packedConfigurationsJson = CommonUtils.gson.toJson(new ConfigurationsJson(configurations));
}
//определить завершен пакет с ошибками или нет.
public void checkFinishState() throws Exception{
}
}

View File

@@ -0,0 +1,9 @@
package _VisualDVM.TestingSystem.Common.TestingPackageToKill;
import Common.CommonConstants;
import Common.Database.Objects.iDBObject;
public class TestingPackageToKill extends iDBObject {
public int packageId = CommonConstants.Nan;
public int type = 0; // 0 - dvm /1 - sapfor
public TestingPackageToKill() {
}
}

View File

@@ -0,0 +1,7 @@
package _VisualDVM.TestingSystem.Common.TestingPackageToKill;
import Common.Database.Tables.iDBTable;
public class TestingPackagesToKillDBTable extends iDBTable<TestingPackageToKill> {
public TestingPackagesToKillDBTable() {
super(TestingPackageToKill.class);
}
}

View File

@@ -0,0 +1,244 @@
package _VisualDVM.TestingSystem.Common;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.GlobalData.Machine.MachineType;
import _VisualDVM.GlobalData.User.User;
import _VisualDVM.Repository.EmailMessage;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.TestingSystem.Common.TestingPackage.TestingPackage;
import _VisualDVM.TestingSystem.Common.TestingPackageToKill.TestingPackageToKill;
import _VisualDVM.Repository.RepositoryClient;
import Common.Utils.Loggable;
import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.Date;
import java.util.Vector;
public abstract class TestingPlanner<P extends TestingPackage> extends RepositoryClient {
protected P testingPackage;
protected File packageLocalWorkspace = null;
protected String serverName = "";
protected File supervisorHome = null;
protected Machine machine = null;
protected User user = null;
//----
protected void UpdatePackageState(TasksPackageState state_in) throws Exception {
testingPackage.state = state_in;
testingPackage.ChangeDate = new Date().getTime();
ServerCommand(ServerCode.EditObject, testingPackage);
switch (testingPackage.state) {
case Done:
case DoneWithErrors:
case Aborted:
case CompilationExecution:
case RunningExecution:
EmailPackage();
break;
}
}
protected void UpdatePackageState() throws Exception {
testingPackage.ChangeDate = new Date().getTime();
ServerCommand(ServerCode.EditObject, testingPackage);
switch (testingPackage.state) {
case Done:
case DoneWithErrors:
case Aborted:
case CompilationExecution:
case RunningExecution:
EmailPackage();
break;
}
}
void UpdatePackage() throws Exception {
testingPackage.ChangeDate = new Date().getTime();
ServerCommand(ServerCode.EditObject, testingPackage);
}
public abstract String packageDescription();
void EmailPackage() throws Exception {
if (testingPackage.needsEmail == 1) {
EmailMessage message = new EmailMessage();
message.subject = "Состояние пакета тестирования "+packageDescription()+ " "+
CommonUtils.Brackets(testingPackage.id) + " изменилось на " + CommonUtils.Brackets(testingPackage.state.getDescription());
message.text = testingPackage.description;
message.targets.add(testingPackage.sender_address);
ServerCommand(ServerCode.Email, message);
}
}
//---
protected abstract ServerCode getActivePackagesCode();
protected abstract ServerCode getCheckIfNeedsKillCode();
protected abstract TasksPackageState getStateAfterStart();
protected void InitSessionCredentials() {
}
protected abstract void TestsSynchronize() throws Exception;
protected abstract void PackageWorkspaceCreation() throws Exception;
protected void AnalyseResults() throws Exception {
UpdatePackageState(TasksPackageState.Done);
};
protected abstract void PackageStart() throws Exception;
protected abstract boolean CheckNextState() throws Exception;
protected abstract void DownloadResults() throws Exception;
protected abstract void Kill() throws Exception;
protected boolean Connect() {
return true;
}
protected void Disconnect() {
}
protected void MachineConnectionError() {
}
protected void PerformPackage(TestingPackage package_in) throws Exception {
testingPackage = (P) package_in;
//--
Print(testingPackage.id + ":" + testingPackage.state.getDescription());
//--
if (testingPackage.connectionErrosCount >= 10) {
Print(testingPackage.id + " had 10 connection errors. stop");
UpdatePackageState(TasksPackageState.ConnectionError);
MachineConnectionError();
} else {
//--
InitSessionCredentials();
if (testingPackage.state.equals(TasksPackageState.Analysis)) {
AnalyseResults(); //todo ввести состояние DoneWithErrors
} else {
try {
if (Connect()) {
int ptk_id = (int) ServerCommand(getCheckIfNeedsKillCode(), testingPackage.id);
if (ptk_id != CommonConstants.Nan) {
Print("package " + testingPackage.id + " NEEDS TO KILL");
Kill();
UpdatePackageState(TasksPackageState.Aborted);
ServerCommand(ServerCode.DeleteObjectByPK, new Pair(TestingPackageToKill.class, ptk_id));
} else {
//--
System.out.println(testingPackage.id+":"+testingPackage.state.getDescription());
switch (testingPackage.state) {
case TestsSynchronize:
TestsSynchronize();
UpdatePackageState(TasksPackageState.PackageWorkspaceCreation);
break;
case PackageWorkspaceCreation:
PackageWorkspaceCreation();
UpdatePackageState(TasksPackageState.PackageStart);
break;
case PackageStart:
PackageStart();
testingPackage.StartDate = new Date().getTime();
UpdatePackageState(getStateAfterStart());
break;
case RunningEnd:
DownloadResults();
UpdatePackageState(TasksPackageState.Analysis);
break;
default:
if (CheckNextState()) UpdatePackage();
break;
}
//--
}
} else {
testingPackage.connectionErrosCount++;
UpdatePackage();
}
} catch (Exception ex) {
Print("Ошибка сеанса. Соединение будет разорвано.");
ex.printStackTrace();
Print(ex.getMessage());
//
testingPackage.connectionErrosCount++;
UpdatePackage();
} finally {
Disconnect();
}
}
}
//--
testingPackage.destructor();
testingPackage = null;
System.gc();
//--
}
@Override
public void perform() throws Exception {
testingPackage = null;
Vector<P> activePackages = (Vector<P>) ServerCommand(getActivePackagesCode());
for (P activePackage : activePackages)
PerformPackage(activePackage);
}
protected void Finalize(String reason) {
Print(reason);
File stateFile = new File(supervisorHome, Constants.ABORTED);
try {
FileUtils.writeStringToFile(stateFile, reason);
} catch (Exception ex) {
ex.printStackTrace();
}
System.exit(0);
}
//---------------------------------------------
public String getPlanner() {
return String.join("/", user.workspace, "modules", "planner");
}
//---
public TestingPlanner(){}
public TestingPlanner(String... args) {
//---
String machineAddress = args[0];
int machinePort = Integer.parseInt(args[1]);
String userName = args[2];
String userPassword = args[3];
String userWorkspace = args[4];
String testingSystemRoot = args[5];
serverName = args[6];
supervisorHome = CommonUtils.getHomeDirectory(); //при инициализации это текущая папка.
//---
CommonUtils.MainLog = new Loggable() {
@Override
public String getLogHomePath() {
return supervisorHome.getAbsolutePath();
}
@Override
public String getLogName() {
return Global.mode.toString();
}
};
CommonUtils.MainLog.ClearLog();
//--
CommonUtils.setHomePath(testingSystemRoot);
Global.CheckTestingSystemDirectories();
//---
machine = new Machine(machineAddress, machineAddress, machinePort, MachineType.Server);
user = new User(userName, userPassword, userWorkspace);
//---
Print("machineAddress=" + CommonUtils.Brackets(machineAddress));
Print("machinePort=" + CommonUtils.Brackets(String.valueOf(machinePort)));
Print("userName=" + CommonUtils.Brackets(userName));
Print("userPassword=" + CommonUtils.Brackets(userPassword));
Print("userWorkspace=" + CommonUtils.Brackets(userWorkspace));
Print("root=" + CommonUtils.Brackets(CommonUtils.getHomePath()));
Print("serverName=" + serverName);
Print("=====");
//----
Utils.createEmptyFile(Constants.STARTED);
}
/*
void CheckLocal() {
local = false;
try {
InetAddress address = InetAddress.getByName(machine.address);
InetAddress localAddress = InetAddress.getByName("alex-freenas.ddns.net");
Print("machine ip=" + Utils.Brackets(address.getHostAddress()));
Print("server ip=" + Utils.Brackets(localAddress.getHostAddress()));
local = localAddress.getHostAddress().equals(address.getHostAddress());
//todo в этом случае отдельный режим без ssh
} catch (Exception ex) {
Global.Log.PrintException(ex);
}
}
*/
}

View File

@@ -0,0 +1,652 @@
package _VisualDVM.TestingSystem.Common;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import Common.Database.Objects.DBObject;
import _VisualDVM.Global;
import Common.Utils.TextLog;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Account.Account;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
import _VisualDVM.Repository.EmailMessage;
import _VisualDVM.Repository.RepositoryRefuseException;
import _VisualDVM.Repository.RepositoryServer;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.MachineProcess.MachineProcess;
import _VisualDVM.TestingSystem.Common.MachineProcess.MachineProcessSet;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import _VisualDVM.TestingSystem.Common.TestingPackageToKill.TestingPackageToKill;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage_json;
import _VisualDVM.TestingSystem.DVM.DVMTestingChecker;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforPackage_json;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommand;
import _VisualDVM.TestingSystem.SAPFOR.SapforTestingPlanner;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
import Visual_DVM_2021.Passes.All.DownloadRepository;
import Visual_DVM_2021.Passes.All.ZipFolderPass;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import javax.swing.*;
import java.io.File;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Vector;
public class TestingServer extends RepositoryServer<TestsDatabase> {
public String name = "?";
public static MachineProcessSet machinesProcesses = new MachineProcessSet();
@Override
public void afterPublishAction(DBObject object) throws Exception {
if (object instanceof Test) {
Test test = (Test) object;
if (!test.unpackProjectOnServer()) {
db.Delete(test);
throw new RepositoryRefuseException(
"Не удалось прикрепить проект к тесту с id " + test.id
+ "\nТест будет удален"
);
}
} else if (object instanceof DVMPackage) {
DVMPackage dvmPackage = (DVMPackage) object;
//--
Utils.CheckAndCleanDirectory(dvmPackage.getLocalWorkspace());
//--
dvmPackage.saveJson();
dvmPackage.package_json = null; // объект больше не нужен.
//--
} else if (object instanceof SapforPackage) {
((SapforPackage) object).init();
}
}
@Override
public void afterDeleteAction(DBObject object) throws Exception {
if (object instanceof Test) {
Test test = (Test) object;
Utils.forceDeleteWithCheck(test.getArchive());
Utils.forceDeleteWithCheck(test.getServerPath());
} else if (object instanceof Group) {
Group group = (Group) object;
Vector<Test> tests = new Vector<>();
for (Test group_test : db.tests.Data.values()) {
if (group_test.group_id == group.id)
tests.add(group_test);
}
for (Test group_test : tests) {
db.Delete(group_test);
Utils.forceDeleteWithCheck(group_test.getArchive());
Utils.forceDeleteWithCheck(group_test.getServerPath());
}
} else if (object instanceof ServerSapfor) {
Utils.forceDeleteWithCheck(
new File(
((ServerSapfor) object).home_path
)
);
} else if (object instanceof DVMPackage) {
DVMPackage dvmPackage = (DVMPackage) object;
File workspace = dvmPackage.getLocalWorkspace();
Utils.forceDeleteWithCheck(workspace);
} else if (object instanceof SapforPackage) {
SapforPackage sapforPackage = (SapforPackage) object;
File workspace = sapforPackage.getLocalWorkspace();
Utils.forceDeleteWithCheck(workspace);
} else if (object instanceof SapforSettings) {
SapforSettings sapforSettings = (SapforSettings) object;
Vector<SapforSettingsCommand> commands = new Vector<>();
for (SapforSettingsCommand command : db.sapforSettingsCommands.Data.values()) {
if (command.sapforsettings_id== sapforSettings.id)
commands.add(command);
}
for (SapforSettingsCommand command : commands) {
db.Delete(command);
}
}
}
//-->>>
@Override
protected void beforePublishAction(DBObject object) throws Exception {
if (object instanceof ServerSapfor) {
int current_version = getSapforActualVersion();
int max_installed_version = db.getInstalledSapforMaxVersion();
if (max_installed_version == current_version)
throw new RepositoryRefuseException("Актуальная версия SAPFOR " + max_installed_version + " уже установлена");
}
}
public TestingServer() {
super(TestsDatabase.class);
name = CommonUtils.getDateName("testingServer");
System.out.println("ServerName=" + CommonUtils.Brackets(name));
}
//основа
@Override
public int getPort() {
return Global.properties.TestingServerPort;
}
//---
@Override
protected void startAdditionalThreads() {
testingThread.start();
}
DVMTestingChecker dvmTestingChecker = new DVMTestingChecker();
SapforTestingPlanner sapforTestingPlanner = new SapforTestingPlanner();
//--
protected Thread testingThread = new Thread(() -> {
while (true) {
dvmTestingChecker.Perform();
sapforTestingPlanner.Perform();
CommonUtils.sleep(5000);
}
});
//------>>>
public static Timer checkTimer = null;
public static void TimerOn() {
checkTimer = new Timer(Global.properties.CheckTestingIntervalSeconds * 1000, e -> {
Pass_2021.passes.get(PassCode_2021.ActualizePackages).Do();
});
checkTimer.start();
}
public static void TimerOff() {
if (checkTimer != null)
checkTimer.stop();
}
public static void ResetTimer() {
TimerOff();
TimerOn();
}
@Override
protected void Session() throws Exception {
Test test;
int test_id;
switch (code) {
case PerformAutoSapforTesting:
Print("Запустить автоматическое тестирование SAPFOR");
TextLog Log = new TextLog();
SapforPackage autoPackage = tryAutoSapforTesting(Log);
response = new ServerExchangeUnit_2021(ServerCode.OK);
EmailMessage message = Log.isEmpty() ?
new EmailMessage(
"Запущено автоматическое тестирование версии " + request.arg + " системы SAPFOR",
"Пакет "+ CommonUtils.Brackets(autoPackage.id), new Vector<>()) :
new EmailMessage(
"Не удалось запустить автоматическое тестирование версии " + request.arg + " системы SAPFOR",
Log.toString(),
new Vector<>()
);
Email(message);
break;
case DownloadTest:
Print("Отправить клиенту тест " + request.arg);
test_id = Integer.parseInt(request.arg);
if (db.tests.containsKey(test_id)) {
test = db.tests.get(test_id);
response = new ServerExchangeUnit_2021(ServerCode.OK, "", CommonUtils.fileToBytes(test.getArchive()));
} else
throw new RepositoryRefuseException("Теста с именем " + request.arg + " не существует");
break;
case ReceiveTestsDatabase:
Print("Получить базу данных тестов");
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = CommonUtils.fileToBytes(db.getFile());
break;
//---
case RefreshDVMTests:
Print("Синхронизировать репозиторий тестов ");
response = new ServerExchangeUnit_2021(ServerCode.OK);
RefreshDVMTests((Account) request.object, Integer.parseInt(request.arg));
break;
case DVMPackageNeedsKill:
Print("Проверить нуждается ли пакет DVM в убийстве");
DVMPackageNeedsKill();
break;
case UpdateActiveDVMPackages:
Print("Получить данные по пакетам DVM");
UpdateActiveDVMPackages();
break;
case GetFirstActiveSapforPackages:
Print("Получить первый активный пакет задач SAPFOR");
GetFirstActiveSapforPackages();
break;
case SapforPackageNeedsKill:
Print("Проверить нуждает ли пакет SAPFOR в убийстве");
SapforPackageNeedsKill();
break;
case UpdateActiveSapforPackages:
Print("Получить данные по пакетам Sapfor");
UpdateActiveSapforPackages();
break;
case DownloadDVMPackage:
Print("Загрузить пакет DVM");
DownloadDVMPackage();
break;
case DownloadDVMPackages:
Print("Загрузить пакеты DVM");
DownloadDVMPackages();
break;
case DownloadSapforPackage:
Print("Загрузить пакет SAPFOR");
DownloadSapforPackage();
break;
case ReplaceTestCode:
Print("Заменить код теста");
ReplaceTestCode();
break;
case ReplaceTestsCodes:
Print("Заменить код тестов");
ReplaceTestsCodes();
break;
case GetSapforPackagesJson:
Print("Получить информацию о задачах пакетов SAPFOR");
GetSapforPackagesJson();
break;
case GetDVMPackagesJson:
Print("Получить информацию о задачах пакетов DVM");
GetDVMPackagesJson();
break;
case GetFirstActiveDVMPackageForMachineURL:
Print("Получить первый активный пакет задач DVM на машине с адресом");
GetFirstActiveDVMPackageForMachineURL();
break;
case GetServerName:
Print("Получить имя сервера");
GetServerName();
break;
case StartNecessaryMachines:
Print("Проверка процессов машин");
response = new ServerExchangeUnit_2021(ServerCode.OK);
StartNecessaryMachines();
break;
case GetSapforForCompilation:
Print("Получить первую активную версию Sapfor для сборки");
GetSapforForCompilation();
break;
case GetMaxSapforVersion:
Print("Получить максимальную установленную версию Sapfor");
GetSapforMaxVersion();
break;
default:
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
}
}
//->>
Pair<Group, Vector<File>> ConvertDirectoryToGroup(File src, LanguageName languageName, TestType
testType, Account account) throws Exception {
Group object = new Group();
Vector<File> groupFiles = null; //транспорт.
//->>
object.description = src.getName();
object.language = languageName;
object.type = testType;
object.sender_name = account.name;
object.sender_address = account.email;
//-->>
File[] files = src.listFiles(pathname ->
pathname.isFile()
&& !pathname.getName().equals("settings")
&& !pathname.getName().equals("test-analyzer.sh")
&& CommonUtils.getExtension(pathname).startsWith(languageName.getDVMCompile()));
;
if (files != null) {
groupFiles = new Vector<>(Arrays.asList(files));
groupFiles.sort(Comparator.comparing(File::getName));
}
//->>
return new Pair<>(object, groupFiles);
}
public void RefreshDVMTests(Account account, int sapfor_id) throws Exception {
ServerSapfor sapfor = null;
if (!db.serverSapfors.containsKey(sapfor_id))
throw new RepositoryRefuseException("Версия SAPFOR с ключом " + sapfor_id + " не найдена.");
sapfor = db.serverSapfors.get(sapfor_id);
DownloadRepository downloadRepository = new DownloadRepository();
if (!downloadRepository.Do())
throw new RepositoryRefuseException("Не удалось обновить репозиторий");
//-->>
Vector<Pair<Group, Vector<File>>> groups = new Vector<>();
File testsSrc = Paths.get(
Global.RepoDirectory.getAbsolutePath(),
"dvm", "tools", "tester", "trunk", "test-suite").toFile();
LanguageName[] supportedLanguages = new LanguageName[]{LanguageName.fortran, LanguageName.c};
for (LanguageName languageName : supportedLanguages) {
for (TestType testType : TestType.values()) {
File groupsSrc = null;
switch (testType) {
case Correctness:
String languageSrcName = null;
switch (languageName) {
case fortran:
languageSrcName = "Fortran";
break;
case c:
languageSrcName = "C";
break;
}
if (languageSrcName != null) {
groupsSrc = Paths.get(testsSrc.getAbsolutePath(), "Correctness", languageSrcName).toFile();
File[] groupsDirs = groupsSrc.listFiles(File::isDirectory);
if (groupsDirs != null) {
for (File groupDir : groupsDirs)
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType, account));
}
}
break;
case Performance:
File groupDir = Paths.get(testsSrc.getAbsolutePath(), "Performance").toFile();
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType, account));
break;
}
}
}
groups.sort(Comparator.comparing(o -> o.getKey().description));
//-теперь создать тесты.
//--
for (Pair<Group, Vector<File>> p : groups)
db.RefreshGroup(account, sapfor, p);
}
private void GetFirstActiveSapforPackages() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = db.getFirstActiveSapforPackagesCopies();
}
void GetSapforMaxVersion() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = db.getInstalledSapforMaxVersion();
}
void UpdateActiveDVMPackages() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
Vector<Pair<Integer, Long>> keys_pairs = (Vector<Pair<Integer, Long>>) request.object;
Vector<DVMPackage> res = new Vector<>();
//--
for (Pair<Integer, Long> p : keys_pairs) {
if (db.dvmPackages.containsKey(p.getKey())) {
DVMPackage actual = db.dvmPackages.get(p.getKey());
if (actual.ChangeDate != p.getValue())
res.add(new DVMPackage(actual));
}
}
response.object = res;
}
private void UpdateActiveSapforPackages() {
response = new ServerExchangeUnit_2021(ServerCode.OK);
Vector<Pair<Integer, Long>> keys_pairs = (Vector<Pair<Integer, Long>>) request.object;
Vector<SapforPackage> res = new Vector<>();
//--
for (Pair<Integer, Long> p : keys_pairs) {
if (db.sapforPackages.containsKey(p.getKey())) {
SapforPackage actual = db.sapforPackages.get(p.getKey());
if (actual.ChangeDate != p.getValue())
res.add(new SapforPackage(actual));
}
}
response.object = res;
}
private void DVMPackageNeedsKill() {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = CommonConstants.Nan;
int packageId = (int) request.object;
for (TestingPackageToKill packageToKill : db.testingPackagesToKill.Data.values()) {
if ((packageToKill.packageId == packageId) && (packageToKill.type == 0)) {
response.object = packageToKill.id;
break;
}
}
}
private void SapforPackageNeedsKill() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = CommonConstants.Nan;
int packageId = (int) request.object;
for (TestingPackageToKill packageToKill : db.testingPackagesToKill.Data.values()) {
if ((packageToKill.packageId == packageId) && (packageToKill.type == 1)) {
response.object = packageToKill.id;
break;
}
}
}
private void DownloadDVMPackage() throws Exception {
int dvmPackage_id = (int) request.object;
if (!db.dvmPackages.containsKey(dvmPackage_id))
throw new RepositoryRefuseException("Не найдено пакета тестирования DVM с ключом " + dvmPackage_id);
response = new ServerExchangeUnit_2021(ServerCode.OK);
DVMPackage dvmPackage = db.dvmPackages.get(dvmPackage_id);
File workspace = dvmPackage.getLocalWorkspace();
File results_zip = new File(workspace, "results.zip");
File package_json = dvmPackage.getJsonFile();
response.object = new Pair(CommonUtils.fileToBytes(results_zip), CommonUtils.fileToBytes(package_json));
}
private void DownloadDVMPackages() throws Exception {
Vector<Integer> ids = (Vector<Integer>) request.object;
Vector<Pair<Integer, Pair<byte[], byte[]>>> res = new Vector<>();
for (int dvmPackage_id : ids) {
if (!db.dvmPackages.containsKey(dvmPackage_id))
throw new RepositoryRefuseException("Не найдено пакета тестирования DVM с ключом " + dvmPackage_id);
DVMPackage dvmPackage = db.dvmPackages.get(dvmPackage_id);
File workspace = dvmPackage.getLocalWorkspace();
File results_zip = new File(workspace, "results.zip");
File package_json = dvmPackage.getJsonFile();
res.add(new Pair<>(dvmPackage_id, new Pair(CommonUtils.fileToBytes(results_zip), CommonUtils.fileToBytes(package_json))));
}
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = res;
}
private void DownloadSapforPackage() throws Exception {
int sapforPackage_id = (int) request.object;
if (!db.sapforPackages.containsKey(sapforPackage_id))
throw new RepositoryRefuseException("Не найдено пакета тестирования SAPFOR с ключом " + sapforPackage_id);
response = new ServerExchangeUnit_2021(ServerCode.OK);
SapforPackage sapforPackage = db.sapforPackages.get(sapforPackage_id);
File workspace = sapforPackage.getLocalWorkspace();
File results_zip = Utils.getTempFileName("results");
ZipFolderPass zipFolderPass = new ZipFolderPass();
zipFolderPass.Do(workspace.getAbsolutePath(), results_zip.getAbsolutePath());
if (results_zip.exists())
response.object = CommonUtils.fileToBytes(results_zip);
else
throw new RepositoryRefuseException("Не удалось заархивировать пакет тестирования SAPFOR с ключом " + sapforPackage_id);
}
private void ReplaceTestCode() throws Exception {
Test test = (Test) request.object;
response = new ServerExchangeUnit_2021(ServerCode.OK);
//---
if (!test.unpackProjectOnServer()) {
db.Delete(test);
throw new RepositoryRefuseException(
"Не удалось прикрепить проект к тесту с id " + test.id
+ "\nТест будет удален"
);
} else db.Update(test); //обновить список файлов и размерность.
}
private void ReplaceTestsCodes() throws Exception {
Vector<Test> tests = (Vector<Test>) request.object;
response = new ServerExchangeUnit_2021(ServerCode.OK);
for (Test test : tests) {
if (!test.unpackProjectOnServer()) {
db.Delete(test);
throw new RepositoryRefuseException(
"Не удалось прикрепить проект к тесту с id " + test.id
+ "\nТест будет удален"
);
} else db.Update(test); //обновить список файлов и размерность.
}
}
private void GetDVMPackagesJson() throws Exception {
Vector<Integer> packages_ids = (Vector<Integer>) request.object;
Vector<DVMPackage_json> jsons = new Vector<>();
for (int package_id : packages_ids) {
if (!db.dvmPackages.containsKey(package_id))
throw new RepositoryRefuseException("Пакета задач DVM " + CommonUtils.Brackets(package_id) + " не существует.");
DVMPackage dvmPackage = db.dvmPackages.get(package_id);
File json = dvmPackage.getJsonFile();
if (!json.exists())
throw new RepositoryRefuseException("Не найден JSON файл для пакета задач DVM " + CommonUtils.Brackets(package_id));
jsons.add((DVMPackage_json) CommonUtils.jsonFromFile(json, DVMPackage_json.class));
}
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = jsons;
}
private void GetSapforPackagesJson() throws Exception {
Vector<Integer> packages_ids = (Vector<Integer>) request.object;
Vector<SapforPackage_json> jsons = new Vector<>();
for (int package_id : packages_ids) {
if (!db.sapforPackages.containsKey(package_id))
throw new RepositoryRefuseException("Пакета задач SAPFOR " + CommonUtils.Brackets(package_id) + " не существует.");
SapforPackage sapforPackage = db.sapforPackages.get(package_id);
File json = sapforPackage.getJsonFile();
if (!json.exists())
throw new RepositoryRefuseException("Не найден JSON файл для пакета задач SAPFOR " + CommonUtils.Brackets(package_id));
jsons.add((SapforPackage_json) CommonUtils.jsonFromFile(json, SapforPackage_json.class));
}
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = jsons;
}
private void GetServerName() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = name;
}
//--
private void GetFirstActiveDVMPackageForMachineURL() {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = db.getFirstActiveDVMPackageCopyForMachineURL(request.arg);
}
void StartNecessaryMachines() {
try {
Vector<String> aborted = new Vector<>();
for (MachineProcess process : machinesProcesses.Data.values()) {
if (process.isAborted()) {
aborted.add(process.id);
}
}
//---
for (String key : aborted) {
machinesProcesses.Data.remove(key);
}
//---
LinkedHashMap<String, MachineProcess> processes_to_start = new LinkedHashMap<>();
//1. Получить список всех пакетов, которые активны, и взять из них машины.
for (DVMPackage dvmPackage : db.dvmPackages.Data.values()) {
if (dvmPackage.state.isActive()) {
//-
if (!machinesProcesses.hasProcessForPackage(dvmPackage)) {
MachineProcess new_process = new MachineProcess(dvmPackage);
processes_to_start.put(new_process.getUniqueKey(), new_process);
}
}
}
//запуск.
for (MachineProcess process : processes_to_start.values()) {
process.Start();
if (Utils.checkFileCreation(process.getStartedFile())) {
machinesProcesses.Data.put(process.id, process);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
void GetSapforActualVersion() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
File versionFile = new File(Global.TempDirectory, "version.h");
if (versionFile.exists())
FileUtils.forceDelete(versionFile);
//1. Получить версию из репозитория.
Utils.startScript(Global.TempDirectory,
Global.TempDirectory,
"get_version",
"wget --user dvmhuser --password dvmh2013 -P " +
CommonUtils.DQuotes(Global.TempDirectory.getAbsolutePath()) +
" http://svn.dvm-system.org/svn/dvmhrepo/sapfor/experts/Sapfor_2017/_src/Utils/version.h"
).waitFor();
if (!versionFile.exists())
throw new RepositoryRefuseException("Не удалось загрузить текущую версию SAPFOR из репозитория!");
int current_version = Sapfor.readVersionFromCode(versionFile);
int max_installed_version = db.getInstalledSapforMaxVersion();
if (max_installed_version == current_version)
throw new RepositoryRefuseException("Версия " + max_installed_version + " уже установлена");
}
//---
int getSapforActualVersion() throws Exception {
File versionFile = new File(Global.TempDirectory, "version.h");
if (versionFile.exists())
FileUtils.forceDelete(versionFile);
//1. Получить версию из репозитория.
Utils.startScript(Global.TempDirectory,
Global.TempDirectory,
"get_version",
"wget --user dvmhuser --password dvmh2013 -P " +
CommonUtils.DQuotes(Global.TempDirectory.getAbsolutePath()) +
" http://svn.dvm-system.org/svn/dvmhrepo/sapfor/experts/Sapfor_2017/_src/Utils/version.h"
).waitFor();
if (!versionFile.exists())
throw new RepositoryRefuseException("Не удалось загрузить текущую версию SAPFOR из репозитория!");
return Sapfor.readVersionFromCode(versionFile);
}
void GetSapforForCompilation() throws Exception {
//1. Проверить наличие заказов от пользователя
ServerSapfor serverSapfor = db.getSapforCopyForCompilation();
if (serverSapfor == null) {
//2 если нет. проверить есть ли свежие версии.
int max_version = db.getInstalledSapforMaxVersion();
int current_version = getSapforActualVersion();
if (current_version > max_version) {
serverSapfor = new ServerSapfor();
serverSapfor.sender_name = "server";
serverSapfor.sender_address = Constants.MailAddress;
serverSapfor.state = ServerSapforState.Queued;
db.Insert(serverSapfor);
}
}
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = serverSapfor;
}
SapforPackage tryAutoSapforTesting(TextLog Log) throws Exception {
//--
Account account = new Account();
account.name = "server";
account.email = Constants.MailAddress;
//-
int sapforId = Integer.parseInt(request.arg);
System.out.println("Sapfor_id = "+request.arg);
if (!db.serverSapfors.containsKey(sapforId)) {
Log.Writeln_("Версия SAPFOR " + sapforId + " не существует.");
return null;
}
ServerSapfor sapfor = db.serverSapfors.get(sapforId);
if (!sapfor.state.equals(ServerSapforState.Done)) {
Log.Writeln_("Выбранная версия SAPFOR " + sapforId + " не собрана!");
return null;
}
Vector<SapforConfiguration> configurations = db.sapforConfigurations.getAutoConfigurations();
if (configurations.isEmpty()) {
Log.Writeln_("Не найдено конфигураций для автоматического тестирования!");
return null;
}
SapforPackage target = new SapforPackage(account,
sapfor,
configurations,
1,
Log);
//-
if (target.tasksCount == 0) {
Log.Writeln_("Не сформировано ни одной новой задачи.");
return null;
}
beforePublishAction(target);
db.InsertS(target);
afterPublishAction(target);
//--
return target;
}
}

View File

@@ -0,0 +1,332 @@
package _VisualDVM.TestingSystem.Common;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import Common.Database.SQLITE.SQLiteDatabase;
import _VisualDVM.Global;
import Common.Utils.TextLog;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Account.Account;
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
import _VisualDVM.Repository.RepositoryRefuseException;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Group.GroupsDBTable;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestDBTable;
import _VisualDVM.TestingSystem.Common.TestingPackageToKill.TestingPackagesToKillDBTable;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfigurationDBTable;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackageDBTable;
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettingsDBTable;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMRunTasksSet;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfigurationDBTable;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackageDBTable;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettingsDBTable;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommandsDBTable;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforsDBTable;
import Visual_DVM_2021.Passes.All.ZipFolderPass;
import Visual_DVM_2021.Passes.PassCode_2021;
import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Vector;
public class TestsDatabase extends SQLiteDatabase {
public DVMConfigurationDBTable dvm_configurations;
public TestDBTable tests;
public GroupsDBTable groups;
public DVMPackageDBTable dvmPackages;
public SapforPackageDBTable sapforPackages;
//--
public TestingPackagesToKillDBTable testingPackagesToKill;
//--
public SapforConfigurationDBTable sapforConfigurations;
//----
public ServerSapforsDBTable serverSapfors;
//---
public DVMRunTasksSet dvmRunTasks = new DVMRunTasksSet(); //задачи текущего пакета тестирования DVM
public SapforSettingsDBTable sapforSettings;
public SapforSettingsCommandsDBTable sapforSettingsCommands;
//--
public DVMSettingsDBTable dvmSettings;
public TestsDatabase() {
super(Paths.get(System.getProperty("user.dir"), "Data", Constants.tests_db_name + ".sqlite").toFile());
}
@Override
protected void initAllTables() throws Exception {
addTable(dvm_configurations = new DVMConfigurationDBTable());
addTable(groups = new GroupsDBTable());
addTable(tests = new TestDBTable());
addTable(dvmPackages = new DVMPackageDBTable());
addTable(sapforPackages = new SapforPackageDBTable());
addTable(testingPackagesToKill = new TestingPackagesToKillDBTable());
//-
addTable(sapforConfigurations = new SapforConfigurationDBTable());
addTable(serverSapfors = new ServerSapforsDBTable());
addTable(sapforSettings = new SapforSettingsDBTable());
addTable(sapforSettingsCommands = new SapforSettingsCommandsDBTable());
addTable(dvmSettings=new DVMSettingsDBTable());
}
@Override
public PassCode_2021 getSynchronizePassCode() {
return PassCode_2021.SynchronizeTests;
}
public Vector<SapforPackage> getFirstActiveSapforPackagesCopies() {
Vector<SapforPackage> res = new Vector<>();
Vector<SapforPackage> packages = new Vector<>();
SapforPackage activePackage = null;
//1. получить активные пакеты.
for (SapforPackage p : sapforPackages.Data.values()) {
switch (p.state) {
case Done:
case Aborted:
case Draft:
case ConnectionError:
case DoneWithErrors:
break;
default:
packages.add(p);
break;
}
}
//2. отсортировать по приоритету.
packages.sort(new Comparator<SapforPackage>() {
@Override
public int compare(SapforPackage o1, SapforPackage o2) {
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
}
});
if (!packages.isEmpty()) {
activePackage = packages.lastElement();
if (activePackage.state.equals(TasksPackageState.Queued)) {
activePackage.state = TasksPackageState.TestsSynchronize;
try {
Update(activePackage);
} catch (Exception ex) {
ex.printStackTrace();
}
}
res.add(new SapforPackage(activePackage));
; //копия чтобы не было конфликта доступа с нитью планировщика.
}
return res;
}
public Vector<DVMPackage> getFirstActiveDVMPackagesCopies() {
Vector<DVMPackage> res = new Vector<>();
//--
LinkedHashMap<String, Vector<DVMPackage>> packagesByMachines = new LinkedHashMap<>();
//----
//1. Получить список активных пакетов по машинам.
for (DVMPackage dvmPackage : dvmPackages.Data.values()) {
switch (dvmPackage.state) {
case Done:
case DoneWithErrors:
case Aborted:
case Draft:
case ConnectionError:
break;
default:
//активен.
Vector<DVMPackage> packages = null;
//--
if (packagesByMachines.containsKey(dvmPackage.machine_address)) {
packages = packagesByMachines.get(dvmPackage.machine_address);
} else {
packages = new Vector<>();
packagesByMachines.put(dvmPackage.machine_address, packages);
}
packages.add(dvmPackage);
break;
}
}
//2. Выбрать для каждой машины наиболее приоритетный пакет.
for (String machine : packagesByMachines.keySet()) {
Vector<DVMPackage> packages = packagesByMachines.get(machine);
if (!packages.isEmpty()) {
packages.sort(new Comparator<DVMPackage>() {
@Override
public int compare(DVMPackage o1, DVMPackage o2) {
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
}
});
//-
DVMPackage activePackage = packages.lastElement();
if (activePackage.state.equals(TasksPackageState.Queued)) {
activePackage.state = TasksPackageState.TestsSynchronize;
try {
Update(activePackage);
} catch (Exception ex) {
ex.printStackTrace();
}
}
res.add(new DVMPackage(activePackage)); //копия чтобы не было конфликта доступа с нитью планировщика.
}
}
return res;
}
//--
public void SaveTestFromSingleFile(ServerSapfor sapfor, Group group, Test test, File file) throws Exception {
File testDirectory = new File(Global.TestsDirectory, String.valueOf(test.id));
Utils.CheckAndCleanDirectory(testDirectory);
File testFile = Paths.get(testDirectory.getAbsolutePath(), file.getName()).toFile();
FileUtils.copyFile(file, testFile);
//----
//архивация.
File archive = test.getArchive();
if (archive.exists())
FileUtils.forceDelete(archive);
//----------->>
ZipFolderPass zip = new ZipFolderPass();
zip.Do(testDirectory.getAbsolutePath(), archive.getAbsolutePath());
//---
//Определение размерности
switch (group.language) {
case fortran:
// временная папка для анализа. чтобы не засорять нормальную.
File tempProject = Utils.getTempFileName("test");
FileUtils.forceMkdir(tempProject);
FileUtils.copyDirectory(testDirectory, tempProject);
//--
if (Sapfor.getMinMaxDim(Sapfor.getTempCopy(new File(sapfor.call_command)), tempProject, test)) {
Update(test);
} else
throw new RepositoryRefuseException("Не удалось определить размерность теста " + CommonUtils.Brackets(test.description));
break;
case c:
test.max_dim = Utils.getCTestMaxDim(testFile);
Update(test);
break;
}
}
//---
public void CreateTestFromSingleFile(Account account, ServerSapfor sapfor, Group group, File file, String testDescription) throws Exception {
Test test = new Test();
test.description = testDescription;
test.sender_name = account.name;
test.sender_address = account.email;
test.group_id = group.id;
test.files = file.getName();
Insert(test);
//->>
SaveTestFromSingleFile(sapfor, group, test, file);
}
public void RefreshGroup(Account account, ServerSapfor sapfor, Pair<Group, Vector<File>> groupData) throws Exception {
Group group = groupData.getKey();
Vector<File> files = groupData.getValue();
//--
Group oldGroup = groups.getGroupByDescription(group.language, group.description);
if (oldGroup == null) {
Insert(group);
for (File file : files) {
String testDescription = CommonUtils.getNameWithoutExtension(file.getName()) + "_" + group.language.getDVMCompile();
CreateTestFromSingleFile(account, sapfor, group, file, testDescription);
}
} else {
for (File file : files) {
String testDescription = CommonUtils.getNameWithoutExtension(file.getName()) + "_" + group.language.getDVMCompile();
Test oldTest = tests.getTestByDescription(oldGroup.id, testDescription);
if (oldTest == null) {
CreateTestFromSingleFile(account, sapfor, oldGroup, file, testDescription);
} else {
SaveTestFromSingleFile(sapfor, group, oldTest, file);
}
}
}
}
public Vector<DVMPackage> getFirstActiveDVMPackageCopyForMachineURL(String arg) {
Vector<DVMPackage> res = new Vector<>();
Vector<DVMPackage> machinePackages = new Vector<>();
//--
//1. Получить список активных пакетов для машины.
for (DVMPackage dvmPackage : dvmPackages.Data.values()) {
switch (dvmPackage.state) {
case Done:
case DoneWithErrors:
case Aborted:
case Draft:
case ConnectionError:
break;
default:
if (dvmPackage.getMachine().getURL().equals(arg))
machinePackages.add(dvmPackage);
break;
}
}
if (!machinePackages.isEmpty()) {
machinePackages.sort(new Comparator<DVMPackage>() {
@Override
public int compare(DVMPackage o1, DVMPackage o2) {
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
}
});
//-
DVMPackage activePackage = machinePackages.lastElement();
if (activePackage.state.equals(TasksPackageState.Queued)) {
activePackage.state = TasksPackageState.TestsSynchronize;
try {
Update(activePackage);
} catch (Exception ex) {
ex.printStackTrace();
}
}
res.add(new DVMPackage(activePackage));
}
return res;
}
public ServerSapfor getSapforCopyForCompilation() {
for (ServerSapfor serverSapfor : serverSapfors.Data.values()) {
if (serverSapfor.state.equals(ServerSapforState.Queued)) {
return new ServerSapfor(serverSapfor);
}
}
return null;
}
public Integer getInstalledSapforMaxVersion() {
int max_version = CommonConstants.Nan;
for (ServerSapfor sapfor : serverSapfors.Data.values()) {
if (sapfor.state.equals(ServerSapforState.Done)) {
int version = CommonConstants.Nan;
try {
version = Integer.parseInt(sapfor.version);
} catch (Exception ex) {
ex.printStackTrace();
}
if (version > max_version) max_version = version;
}
}
return max_version;
}
public boolean hasActiveSapfors() {
for (ServerSapfor serverSapfor : serverSapfors.Data.values()) {
if (serverSapfor.state.isActive())
return true;
}
return false;
}
public void UnselectAllGTC() {
groups.CheckAll(false);
tests.CheckAll(false);
dvm_configurations.CheckAll(false);
}
public void CheckTestsPackagesDependencies(Vector<Integer> testsIds, TextLog Log){
//определить есть ли активные пакеты в которые входят упомянутые тесты
//если есть выписать группа/тест причина - находится в активном пакете
}
public void RefreshTestNameInConfigurations(Integer testId){
//обновить имя теста во всех конфигурация
}
public void DeleteTestFromConfigurations(Integer testId){
//обновить имя теста во всех конфигурация
}
//todo возможно рассмотреть вариант с синхроннизацией тестов для пакетов через команду серверу а не в нити
//во избежание конфликта доступа,или удалением тестов во время копирования(?)
}

View File

@@ -0,0 +1,117 @@
package _VisualDVM.TestingSystem.Common.ThreadsPlanner;
import Common.Utils.CommonUtils;
import Common.Utils.InterruptThread;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Vector;
public abstract class ThreadsPlanner {
//-->
protected Thread interruptThread = new InterruptThread(5000, () -> {
try {
Interrupt();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
System.exit(0);
return null;
});
protected int maxKernels;
protected int kernels;
//---
protected int threadMaxId = 0;
protected int wait_ms;
protected int done_threads = 0;
protected int progress = 0;
protected LinkedHashMap<Integer, Thread> threads = new LinkedHashMap<>();
protected Vector<Integer> activeThreads = new Vector<>();
protected Vector<Integer> waitingThreads = new Vector<>();
//--
public ThreadsPlanner(int wait_ms_in) {
wait_ms = wait_ms_in;
}
public void setMaxKernels(int maxKernels_in) {
maxKernels = maxKernels_in;
kernels = maxKernels;
}
public String printThread(Integer id) {
return "thread id = "+id;
}
public String getThreadsSummary() {
Vector<String> lines = new Vector<>();
lines.add("Planner summary:");
lines.add("Waiting: " + waitingThreads.size());
lines.add("Running: " + activeThreads.size());
for (Integer id : activeThreads) {
lines.add(printThread(id));
}
lines.add("");
return String.join("\n", lines);
}
//--
public void Start() {
CommonUtils.MainLog.Print("Planner started");
try {
//--
while (!waitingThreads.isEmpty() || !activeThreads.isEmpty()) {
CommonUtils.MainLog.Print(getThreadsSummary());
checkActiveThreads();
tryStartThreads();
Thread.sleep(wait_ms);
}
//--
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
} finally {
CommonUtils.MainLog.Print("Planner finished");
finalize();
}
}
public void Interrupt() throws Exception {
}
protected void checkActiveThreads() throws Exception {
Vector<Integer> toExclude = new Vector<>();
//--
for (int i : activeThreads) {
Thread thread = threads.get(i);
if (!thread.isAlive()) {
toExclude.add(i);
kernels++;
done_threads++;
}
}
activeThreads.removeAll(toExclude);
//--
double progress = ((double)done_threads/threads.size())*100.0;
CommonUtils.MainLog.Print("done_threads="+done_threads+";all_threads="+threads.size()+";progress="+progress);
File progress_file = new File("progress");
try {
FileUtils.writeStringToFile(progress_file, String.valueOf(((int)progress)));
}
catch (Exception exception){
exception.printStackTrace();
}
}
protected void tryStartThreads() throws Exception {
Vector<Integer> toExclude = new Vector<>();
//-
for (int i : waitingThreads) {
if (kernels > 0) {
Thread thread = threads.get(i);
thread.start();
activeThreads.add(i);
kernels--;
toExclude.add(i);
} else break;
}
waitingThreads.removeAll(toExclude);
}
protected void finalize() {
}
protected void addThread(Thread thread) {
threads.put(threadMaxId, thread);
waitingThreads.add(threadMaxId);
threadMaxId++;
}
}

View File

@@ -0,0 +1,17 @@
package _VisualDVM.TestingSystem.DVM.DVMConfiguration;
import Common.Database.Objects.DBObject;
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
//конфгурация тестирования ДВМ
public class DVMConfiguration extends Configuration {
public int c_maxtime = 40;
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
DVMConfiguration c = (DVMConfiguration) src;
c_maxtime=c.c_maxtime;
}
public DVMConfiguration(DVMConfiguration src){
this.SynchronizeFields(src);
}
public DVMConfiguration(){}
}

View File

@@ -0,0 +1,116 @@
package _VisualDVM.TestingSystem.DVM.DVMConfiguration;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Tables.TableRenderers;
import _VisualDVM.ServerObjectsCache.ConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.UI.ConfigurationFields;
public class DVMConfigurationDBTable extends iDBTable<DVMConfiguration> {
public DVMConfigurationDBTable() {
super(DVMConfiguration.class);
}
@Override
public Current CurrentName() {
return Current.DVMConfiguration;
}
@Override
public String getSingleDescription() {
return "конфигурация тестирования DVM системы";
}
@Override
public String getPluralDescription() {
return "конфигурации тестирования DVM системы";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
columns.get(6).setRenderer(TableRenderers.RendererMultiline);
columns.get(6).setMaxWidth(500);
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"ядра",
"параметры",
"группы",
"тестов",
"компиляция(с)",
"запуск(с)"
};
}
@Override
public Object getFieldAt(DVMConfiguration object, int columnIndex) {
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(object);
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return object.kernels;
case 5:
return cache.settingsSummary;
case 6:
return cache.groupsSummary;
case 7:
return cache.getTestsCount();
case 8:
return object.c_maxtime;
case 9:
return object.maxtime;
default:
return null;
}
}
@Override
public DBObjectDialog<DVMConfiguration, ConfigurationFields> getDialog() {
return new DBObjectDialog<DVMConfiguration, ConfigurationFields>(ConfigurationFields.class) {
@Override
public int getDefaultHeight() {
return 300;
}
@Override
public int getDefaultWidth() {
return 500;
}
@Override
public void fillFields() {
fields.tfName.setText(Result.description);
//------->>>>
fields.sCompilationMaxtime.setValue(Result.c_maxtime);
fields.sRunMaxtime.setValue(Result.maxtime);
fields.sKernels.setValue(Result.kernels);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.c_maxtime = (int) fields.sCompilationMaxtime.getValue();
Result.maxtime = (int) fields.sRunMaxtime.getValue();
Result.kernels = (int) fields.sKernels.getValue();
}
@Override
public void SetReadonly() {
fields.tfName.setEnabled(false);
fields.sCompilationMaxtime.setEnabled(false);
fields.sRunMaxtime.setEnabled(false);
}
};
}
@Override
public boolean ShowEditObjectDialog(DBObject object) {
return (Current.getAccount().CheckAccessRights(((DVMConfiguration) object).sender_address, null)) ? super.ShowEditObjectDialog(object) : ViewObject(object);
}
}

View File

@@ -0,0 +1,18 @@
package _VisualDVM.TestingSystem.DVM.DVMConfiguration;
import Common.Visual.Menus.DataMenuBar;
import Visual_DVM_2021.Passes.PassCode_2021;
public class DVMConfigurationsMenuBar extends DataMenuBar {
public DVMConfigurationsMenuBar() {
super("конфигурации");
addPasses(
PassCode_2021.PublishConfiguration,
PassCode_2021.EditConfiguration,
PassCode_2021.ShowCurrentDVMConfigurationTests,
PassCode_2021.SaveCurrentDVMConfiguration,
PassCode_2021.DeleteConfiguration,
PassCode_2021.StartSelectedDVMConfigurations
);
}
}

View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.DVM.DVMConfiguration.UI.ConfigurationFields">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="467" height="163"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="5bf8c" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="18f5c" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<vspacer id="68a9">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="fdaa3" class="javax.swing.JTextField" binding="tfName" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="238" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="1a85a" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="макс. время компиляции, сек"/>
</properties>
</component>
<component id="fbc6d" class="javax.swing.JSpinner" binding="sCompilationMaxtime">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="238" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="30c43" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="макс. время выполнения, сек"/>
</properties>
</component>
<component id="69368" class="javax.swing.JSpinner" binding="sRunMaxtime">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="15871" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="ядра"/>
<toolTipText value="количество ядер, задействованное при тестировани"/>
</properties>
</component>
<component id="bd4cb" class="javax.swing.JSpinner" binding="sKernels">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,34 @@
package _VisualDVM.TestingSystem.DVM.DVMConfiguration.UI;
import _VisualDVM.Constants;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import javax.swing.*;
import java.awt.*;
public class ConfigurationFields implements DialogFields {
public JTextField tfName;
public JSpinner sCompilationMaxtime;
public JSpinner sRunMaxtime;
//-
private JPanel content;
public JSpinner sKernels;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
}
public ConfigurationFields(){
sCompilationMaxtime.setModel(new SpinnerNumberModel(40,
5, 3600, 1
));
sRunMaxtime.setModel(new SpinnerNumberModel(40,
5, 3600, 1
));
sKernels.setModel(new SpinnerNumberModel(1, 1,
Constants.testingMaxKernels,
1));
}
}

View File

@@ -0,0 +1,121 @@
package _VisualDVM.TestingSystem.DVM.DVMPackage;
import Common.CommonConstants;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import _VisualDVM.Global;
import _VisualDVM.ServerObjectsCache.DVMConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import _VisualDVM.GlobalData.Account.Account;
import _VisualDVM.GlobalData.Compiler.Compiler;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.GlobalData.Machine.MachineType;
import _VisualDVM.GlobalData.User.User;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.TasksPackageState;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.TestingPackage.TestingPackage;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettings;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMCompilationTask;
import java.io.File;
import java.util.Vector;
public class DVMPackage extends TestingPackage<DVMPackage_json> {
//---
public String machine_name = "";
public String machine_address = "";
public int machine_port = 22;
//---
public String user_name = "";
public String user_password;
public String user_workspace;
//---
public DVMPackage() {
}
public DVMPackage(Account account,
Machine machine,
User user,
Compiler compiler,
Vector<DVMConfiguration> configurations,
int neeedsEmail_in) {
id = CommonConstants.Nan;
//-
sender_name = account.name;
sender_address = account.email;
//-
machine_name = machine.name;
machine_address = machine.address;
machine_port = machine.port;
//-
user_name = user.login;
user_password = user.password;
user_workspace = user.workspace;
//-
drv = compiler.call_command;
version = compiler.getVersionInfo();
//-
needsEmail = neeedsEmail_in;
//--
state = TasksPackageState.Queued;
//--
for (DVMConfiguration configuration : configurations)
kernels = Math.max(configuration.kernels, kernels);
//-
tasksCount = 0;
Vector<DVMCompilationTask> compilationTasks = new Vector<DVMCompilationTask>();
for (DVMConfiguration configuration : configurations) {
DVMConfigurationCache cache = (DVMConfigurationCache) VisualCaches.GetCache(configuration);
for (Group group : cache.getGroups()) {
for (Test test : cache.getGroupTests(group)) {
for (DVMSettings dvmSettings : cache.getSettings()) {
DVMCompilationTask compilationTask = new DVMCompilationTask(configuration, dvmSettings, group, test, kernels);
compilationTasks.add(compilationTask);
tasksCount += compilationTask.runTasks.size();
}
}
}
}
package_json = new DVMPackage_json(compilationTasks);
saveConfigurationsAsJson(configurations);
}
@Override
public Class getJsonClass() {
return DVMPackage_json.class;
}
@Override
public File getHomeDirectory() {
return Global.DVMPackagesDirectory;
}
public DVMPackage(DVMPackage p) {
super(p);
this.SynchronizeFields(p);
}
//---
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
DVMPackage tasksPackage = (DVMPackage) src;
machine_name = tasksPackage.machine_name;
machine_address = tasksPackage.machine_address;
machine_port = tasksPackage.machine_port;
user_name = tasksPackage.user_name;
user_workspace = tasksPackage.user_workspace;
user_password = tasksPackage.user_password;
}
public Machine getMachine() {
return new Machine(machine_name, machine_address, machine_port, MachineType.Server);
}
public User getUser() {
return new User(user_name, user_password, user_workspace);
}
@Override
public boolean isVisible() {
return (!DVMPackageDBTable.filterMyOnly || Current.getAccount().email.equals(sender_address)) &&
(!DVMPackageDBTable.filterActive || state.isActive());
}
@Override
public void checkFinishState() throws Exception {
}
}

View File

@@ -0,0 +1,127 @@
package _VisualDVM.TestingSystem.DVM.DVMPackage;
import _VisualDVM.Current;
import Common.Database.Tables.iDBTable;
import _VisualDVM.Global;
import Common.Visual.DataSetControlForm;
import _VisualDVM.Visual.UI;
import _VisualDVM.ServerObjectsCache.PackageCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import java.util.Comparator;
import java.util.Date;
import static Common.Visual.Tables.TableRenderers.*;
public class DVMPackageDBTable extends iDBTable<DVMPackage> {
public static boolean filterMyOnly = false;
public static boolean filterActive = false;
public DVMPackageDBTable() {
super(DVMPackage.class);
}
@Override
public Current CurrentName() {
return Current.DVMPackage;
}
@Override
public String getSingleDescription() {
return "пакет задач DVM";
}
@Override
public String getPluralDescription() {
return "пакеты задач DVM";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
columns.get(6).setRenderer(RendererMultiline);
// columns.get(7).setRenderer(RendererMultiline);
columns.get(9).setRenderer(RendererProgress);
columns.get(10).setRenderer(RendererDate);
columns.get(11).setRenderer(RendererDate);
columns.get(12).setRenderer(RendererStatusEnum);
}
@Override
public void ShowCurrentObject() throws Exception {
super.ShowCurrentObject();
//--
Global.testingServer.db.dvmRunTasks.ShowDVMPackage(getCurrent());
UI.getMainWindow().getTestingWindow().DropTestRunTasksComparison();
//--
}
@Override
public void ShowNoCurrentObject() throws Exception {
super.ShowNoCurrentObject();
Global.testingServer.db.dvmRunTasks.ShowNoPackage();
UI.getMainWindow().getTestingWindow().DropTestRunTasksComparison();
}
@Override
public void MouseAction2() throws Exception {
Pass_2021.passes.get(PassCode_2021.DownloadDVMPackage).Do();
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Автор",
"Машина",
"Пользователь",
"DVM",
"Конфигурации",
"Задач",
"Ядер",
"Прогресс",
"Начало",
"Изменено",
"Статус"
};
}
@Override
public Object getFieldAt(DVMPackage object, int columnIndex) {
PackageCache cache = (PackageCache) VisualCaches.GetCache(object);
switch (columnIndex) {
case 2:
return object.sender_name;
case 3:
return object.machine_address + ":" + object.machine_port;
case 4:
return object.user_name;
case 5:
return object.version;
case 6:
return cache.getConfigurationsDescriptions();
case 7:
return object.tasksCount;
case 8:
return object.kernels;
case 9:
return object.progress;
case 10:
return new Date(object.StartDate);
case 11:
return new Date(object.ChangeDate);
case 12:
return object.state;
default:
return null;
}
}
@Override
public Comparator<DVMPackage> getComparator() {
return new Comparator<DVMPackage>() {
@Override
public int compare(DVMPackage o1, DVMPackage o2) {
return o2.id - o1.id;
}
};
// return Comparator.comparingInt(o -> o.).reversed();
}
}

View File

@@ -0,0 +1,29 @@
package _VisualDVM.TestingSystem.DVM.DVMPackage;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMCompilationTask;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMRunTask;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
public class DVMPackage_json implements Serializable {
@Expose
public int max_task_id = 0;
@Expose
public List<DVMCompilationTask> compilationTasks = new Vector<>();
public int getMaxTaskId() {
return max_task_id++;
}
public DVMPackage_json(){}
public DVMPackage_json(List<DVMCompilationTask> tasks){
for (DVMCompilationTask compilationTask : tasks) {
compilationTask.id = getMaxTaskId();
//-
for (DVMRunTask runTask : compilationTask.runTasks) {
runTask.id = getMaxTaskId();
runTask.dvmcompilationtask_id = compilationTask.id;
}
}
compilationTasks.addAll(tasks);
}
}

View File

@@ -0,0 +1,51 @@
package _VisualDVM.TestingSystem.DVM.DVMPackage;
import Common.Utils.CommonUtils;
import _VisualDVM.Global;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Controls.MenuBarButton;
import Visual_DVM_2021.Passes.PassCode_2021;
import javax.swing.*;
public class DVMPackagesBar extends DataMenuBar {
public DVMPackagesBar() {
super("пакеты задач DVM");
addPasses(PassCode_2021.SynchronizeTests);
addSeparator();
addPasses(PassCode_2021.AbortDVMPackage );
addSeparator();
addPasses(PassCode_2021.DownloadDVMPackage,
PassCode_2021.ExportDVMPackageToExcel,
PassCode_2021.DeleteDVMPackage);
add(new JSeparator());
add(new MenuBarButton() {
{
setText("Свои");
setToolTipText("Отображать только пакеты тестов авторства пользователя");
Mark();
addActionListener(e -> {
DVMPackageDBTable.filterMyOnly = !DVMPackageDBTable.filterMyOnly;
Mark();
Global.testingServer.db.dvmPackages.ShowUI();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(DVMPackageDBTable.filterMyOnly ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
add(new MenuBarButton() {
{
setText("Активные");
setToolTipText("Отображать только активные пакеты тестов");
Mark();
addActionListener(e -> {
DVMPackageDBTable.filterActive = !DVMPackageDBTable.filterActive;
Mark();
Global.testingServer.db.dvmPackages.ShowUI();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(DVMPackageDBTable.filterActive ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
}
}

View File

@@ -0,0 +1,87 @@
package _VisualDVM.TestingSystem.DVM.DVMSettings;
import Common.Database.Objects.DBObject;
import _VisualDVM.GlobalData.RunConfiguration.RunConfiguration;
import _VisualDVM.TestingSystem.Common.Settings.Settings;
import com.sun.org.glassfish.gmbal.Description;
import java.util.Vector;
public class DVMSettings extends Settings {
//todo.хранить флаги и окружение в json чтобы можно было в форме их видеть.
public String environments="";
@Description("DEFAULT 0")
public int Is_DVM_STAT= 0; //флаг вмест usr par, которые не использовались.
// public String usr_par = "";
//---
public int cube = 0; //
public int max_proc_count = 4;
public int min_dim_proc_count = 1;
public int max_dim_proc_count = 4;
//
public DVMSettings(){}
public DVMSettings(DVMSettings src){
this.SynchronizeFields(src);
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
DVMSettings c = (DVMSettings) src;
environments=c.environments;
Is_DVM_STAT = c.Is_DVM_STAT;
// usr_par=c.usr_par;
//-
cube= c.cube;
max_proc_count=c.max_proc_count;
min_dim_proc_count=c.min_dim_proc_count;
max_dim_proc_count=c.max_dim_proc_count;
}
public String printUsrPar(){
return "Is_DVM_STAT="+Is_DVM_STAT;
}
public Vector<String> getMatrixes(int testDim) {
Vector<Vector<Integer>> res_ = new Vector<>();
Vector<String> res = new Vector<>();
if ((max_proc_count==0) || (min_dim_proc_count == 0 && max_dim_proc_count == 0)) {
res.add("");
} else {
if (testDim > 0) {
Vector<String> min_border = new Vector<>();
Vector<String> max_border = new Vector<>();
for (int i = 1; i <= testDim; ++i) {
min_border.add(String.valueOf(min_dim_proc_count));
max_border.add(String.valueOf(max_dim_proc_count));
}
Vector<Integer> from = RunConfiguration.getBounds(String.join(" ", min_border));
Vector<Integer> to = RunConfiguration.getBounds(String.join(" ", max_border));
if (from.size() != to.size()) {
return res;
}
if (from.size() != testDim) {
return res;
}
//1 стадия. заполнение.
for (int j = from.get(0); j <= to.get(0); ++j) {
Vector<Integer> m = new Vector<>();
res_.add(m);
m.add(j);
}
//---
if (testDim > 1) RunConfiguration.gen_rec(from, to, res_, 1, testDim, cube == 1);
for (Vector<Integer> m : res_) {
Vector<String> ms = new Vector<>();
int proc = 1;
for (int i : m) {
ms.add(String.valueOf(i));
proc *= i;
}
if (proc <= max_proc_count)
res.add(String.join(" ", ms));
}
} else res.add("");
}
return res;
}
public String getParamsText() {
return "Is_DVM_STAT="+Is_DVM_STAT;
}
}

View File

@@ -0,0 +1,146 @@
package _VisualDVM.TestingSystem.DVM.DVMSettings;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.TestingSystem.DVM.DVMSettings.UI.DVMSettingsFields;
public class DVMSettingsDBTable extends iDBTable<DVMSettings> {
public DVMSettingsDBTable() {
super(DVMSettings.class);
}
@Override
public Current CurrentName() {
return Current.DVMSettings;
}
@Override
public String getSingleDescription() {
return "параметры тестирования DVM системы";
}
@Override
public String getPluralDescription() {
return "параметры тестирования DVM системы";
}
//--
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"флаги",
"окружение",
"usr.par",
"куб",
"max",
"min dim",
"max dim"
};
}
//--
@Override
public Object getFieldAt(DVMSettings object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return object.flags;
case 5:
return object.environments;
case 6:
return object.printUsrPar();
case 7:
return object.cube;
case 8:
return object.max_proc_count;
case 9:
return object.min_dim_proc_count;
case 10:
return object.max_dim_proc_count;
default:
return null;
}
}
//-
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
/*
columns.get(5).setRenderer(TableRenderers.RendererMultiline);
columns.get(5).setMaxWidth(500);
columns.get(7).setRenderer(TableRenderers.RendererMultiline);
columns.get(8).setRenderer(TableRenderers.RendererMultiline);
columns.get(15).setRenderer(TableRenderers.RendererMultiline);
*/
}
};
}
@Override
public DBObjectDialog<DVMSettings, DVMSettingsFields> getDialog() {
return new DBObjectDialog<DVMSettings, DVMSettingsFields>(DVMSettingsFields.class) {
@Override
public int getDefaultHeight() {
return 400;
}
@Override
public int getDefaultWidth() {
return 800;
}
@Override
public void validateFields() {
int min = (int) fields.sMinDimProc.getValue();
int max = (int) fields.sMaxDimProc.getValue();
if (max < min)
Log.Writeln_("Некорректный диапазон размерностей: максимум меньше минимума");
if ((min == 0) && (max != 0) || (min != 0) && (max == 0))
Log.Writeln_("Некорректный диапазон размерностей. " +
"'0' допускается только одновременно на обеих границах,\n" +
"и подразумевает единственный запуск без решётки");
}
@Override
public void fillFields() {
fields.tfName.setText(Result.description);
//------->>>
fields.tfFlags.setText(Result.flags);
fields.tfEnvironments.setText(Result.environments);
//------->>>
fields.sMinDimProc.setValue(Result.min_dim_proc_count);
fields.sMaxDimProc.setValue(Result.max_dim_proc_count);
fields.cbCube.setSelected(Result.cube == 1);
//-
fields.sMaxProc.setValue(Result.max_proc_count);
fields.cbDvmStat.setSelected(Result.Is_DVM_STAT!=0);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.min_dim_proc_count = (int) fields.sMinDimProc.getValue();
Result.max_dim_proc_count = (int) fields.sMaxDimProc.getValue();
Result.cube = fields.cbCube.isSelected() ? 1 : 0;
Result.max_proc_count = (int) fields.sMaxProc.getValue();
Result.flags = fields.tfFlags.getText();
Result.environments = fields.tfEnvironments.getText();
Result.Is_DVM_STAT = fields.cbDvmStat.isSelected()?1:0;
}
@Override
public void SetReadonly() {
fields.tfName.setEnabled(false);
fields.sMinDimProc.setEnabled(false);
fields.sMaxDimProc.setEnabled(false);
fields.cbCube.setEnabled(false);
fields.sMaxProc.setEnabled(false);
}
};
}
@Override
public boolean ShowEditObjectDialog(DBObject object) {
return (Current.getAccount().CheckAccessRights(((DVMSettings) object).sender_address, null)) ? super.ShowEditObjectDialog(object) : ViewObject(object);
}
}

View File

@@ -0,0 +1,13 @@
package _VisualDVM.TestingSystem.DVM.DVMSettings.UI;
import Common.Visual.Menus.DataMenuBar;
import Visual_DVM_2021.Passes.PassCode_2021;
public class DVMSettingsBar extends DataMenuBar {
public DVMSettingsBar() {
super("параметры тестированя",
PassCode_2021.PublishDVMSettings,
PassCode_2021.CloneDVMSettings,
PassCode_2021.EditDVMSettings,
PassCode_2021.DeleteDVMSettings
);
}
}

View File

@@ -0,0 +1,227 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.DVM.DVMSettings.UI.DVMSettingsFields">
<grid id="27dc6" binding="content" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="777" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e9baf" layout-manager="GridLayoutManager" row-count="9" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="8f4d9" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<vspacer id="2176d">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c61a7" class="javax.swing.JTextField" binding="tfName" custom-create="true">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="238" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="a1d86" class="javax.swing.JSpinner" binding="sMinDimProc">
<constraints>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="deae5" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="мин. число процессоров по измерению"/>
</properties>
</component>
<component id="61ffc" class="javax.swing.JLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="макс. число процессоров по измерению"/>
</properties>
</component>
<component id="380de" class="javax.swing.JSpinner" binding="sMaxDimProc">
<constraints>
<grid row="6" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="9b010" class="javax.swing.JCheckBox" binding="cbCube">
<constraints>
<grid row="7" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<horizontalAlignment value="0"/>
<icon value="icons/NotPick.png"/>
<selectedIcon value="icons/Pick.png"/>
<text value="кубические решётки"/>
<toolTipText value="матрица с одинаковым размером измерений"/>
</properties>
</component>
<component id="bd5c7" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="макс. число процессоров"/>
</properties>
</component>
<component id="ad38a" class="javax.swing.JSpinner" binding="sMaxProc">
<constraints>
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="4d47b" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="флаги"/>
</properties>
</component>
<component id="45943" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="окружение"/>
</properties>
</component>
<component id="decc3" class="javax.swing.JTextField" binding="tfFlags">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="400" height="30"/>
<preferred-size width="400" height="30"/>
<maximum-size width="400" height="30"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
<font size="10"/>
</properties>
</component>
<component id="f6927" class="javax.swing.JTextField" binding="tfEnvironments">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="400" height="30"/>
<preferred-size width="400" height="30"/>
<maximum-size width="400" height="30"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
<font size="10"/>
</properties>
</component>
<component id="265bb" class="javax.swing.JButton" binding="bAddFlags">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<borderPainted value="false"/>
<icon value="icons/Menu/Regions.png"/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<preferredSize width="30" height="30"/>
<text value=""/>
<toolTipText value="Редактировать флаги"/>
</properties>
</component>
<component id="77de1" class="javax.swing.JButton" binding="bAddEnvironments">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<borderPainted value="false"/>
<icon value="icons/Menu/Regions.png"/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<preferredSize width="30" height="30"/>
<text value=""/>
<toolTipText value="Добавить набор переменных окружения"/>
</properties>
</component>
<component id="7682" class="javax.swing.JButton" binding="bDeleteFlags">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<borderPainted value="false"/>
<icon value="icons/Delete.png"/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<preferredSize width="30" height="30"/>
<text value=""/>
<toolTipText value="Удалить флаги"/>
</properties>
</component>
<component id="6c384" class="javax.swing.JButton" binding="bDeleteEnvironment">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<borderPainted value="false"/>
<icon value="icons/Delete.png"/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<preferredSize width="30" height="30"/>
<text value=""/>
<toolTipText value="Удалить переменную окружения"/>
</properties>
</component>
<component id="3f04c" class="javax.swing.JCheckBox" binding="cbDvmStat">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<horizontalAlignment value="0"/>
<icon value="icons/NotPick.png"/>
<selectedIcon value="icons/Pick.png"/>
<text value="Is_DVM_STAT"/>
<toolTipText value="сбор статистики DVM после запуска"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,68 @@
package _VisualDVM.TestingSystem.DVM.DVMSettings.UI;
import _VisualDVM.Current;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DVMSettingsFields implements DialogFields {
private JPanel content;
public JTextField tfName;
public JSpinner sMinDimProc;
public JSpinner sMaxDimProc;
public JSpinner sMaxProc;
public JCheckBox cbCube;
public JTextField tfFlags;
public JTextField tfEnvironments;
private JButton bAddFlags;
private JButton bAddEnvironments;
private JButton bDeleteFlags;
private JButton bDeleteEnvironment;
public JCheckBox cbDvmStat;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
}
public DVMSettingsFields(){
sMinDimProc.setModel(new SpinnerNumberModel(1, 0, 128, 1));
sMaxDimProc.setModel(new SpinnerNumberModel(1, 0, 128, 1));
sMaxProc.setModel(new SpinnerNumberModel(0, 0, 128, 1));
bAddFlags.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Pass_2021 pass = Pass_2021.passes.get(PassCode_2021.PickCompilerOptions);
if (pass.Do(Current.getCompiler())) {
tfFlags.setText((String)pass.target);
}
}
});
bAddEnvironments.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Pass_2021 pass = Pass_2021.passes.get(PassCode_2021.PickCompilerEnvironmentsForTesting);
if (pass.Do(Current.getCompiler()))
tfEnvironments.setText((String)pass.target);
}
});
bDeleteFlags.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tfFlags.setText("");
}
});
bDeleteEnvironment.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tfEnvironments.setText("");
}
});
}
}

View File

@@ -0,0 +1,74 @@
package _VisualDVM.TestingSystem.DVM.DVMTasks;
import Common.Utils.CommonUtils;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettings;
import com.google.gson.annotations.Expose;
import java.util.List;
import java.util.Vector;
public class DVMCompilationTask extends DVMTask {
@Expose
public List<DVMRunTask> runTasks = new Vector<>();
//-
public DVMCompilationTask() {
}
@Override
public Vector<String> pack(Object arg) {
Vector<String> res = new Vector<>();
res.add(String.valueOf(id)); //1
res.add(String.valueOf(maxtime)); //2
res.add(String.valueOf(test_id)); //3
res.add(arg.toString().replace("\n", "|")); //4
return res;
}
//--
public static String checkFlags(String flags_in) {
if (!flags_in.contains("-shared-dvm")) {
if (flags_in.isEmpty())
return "-shared-dvm";
else return flags_in + " -shared-dvm";
} else
return flags_in;
}
public static String checkEnvironments(String environmentsSet_in) {
if (!environmentsSet_in.contains("DVMH_NO_DIRECT_COPY")) {
if (environmentsSet_in.isEmpty())
return "DVMH_NO_DIRECT_COPY=" + CommonUtils.DQuotes("1");
else
return environmentsSet_in + " " + "DVMH_NO_DIRECT_COPY=" + CommonUtils.DQuotes("1");
} else
return environmentsSet_in;
}
//--
public DVMCompilationTask(DVMConfiguration configuration, DVMSettings dvmSettings, Group group, Test test, int kernels_in){
super (configuration, group, test,checkFlags(dvmSettings.flags));
Vector<String> matrixes = dvmSettings.getMatrixes(test.max_dim);
String checkedEnvironments = checkEnvironments(dvmSettings.environments);
if (dvmSettings.flags.trim().equalsIgnoreCase("-s")) {
runTasks.add(new DVMRunTask(
configuration,
dvmSettings,
group,
test,
"",
flags,
checkedEnvironments,
kernels_in
));
} else
for (String matrix : matrixes) {
runTasks.add(new DVMRunTask(
configuration,
dvmSettings,
group,
test,
matrix,
flags,
checkedEnvironments,
kernels_in));
}
}
}

View File

@@ -0,0 +1,136 @@
package _VisualDVM.TestingSystem.DVM.DVMTasks;
import Common.CommonConstants;
import _VisualDVM.Constants;
import Common.Database.Objects.DBObject;
import _VisualDVM.Global;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettings;
import com.google.gson.annotations.Expose;
import java.io.File;
import java.nio.file.Paths;
import java.util.Vector;
public class DVMRunTask extends DVMTask {
@Expose
public int dvmcompilationtask_id = CommonConstants.Nan;
@Expose
public String matrix = "";
@Expose
public String args = "";
@Expose
public double CleanTime = 0.0;
@Expose
public int progress = 0;
@Expose
public int cube = 1;
@Expose
public int min_dim = 1;
@Expose
public int max_dim = 1;
@Expose
public String environments = "";
@Expose
public String usr_par = "";
@Expose
public int compilation_maxtime = 40;
@Expose
public TaskState compilation_state = TaskState.Waiting;
@Expose
public double compilation_time = 0.0;
public DVMRunTask(DVMConfiguration configuration, DVMSettings settings,
Group group, Test test,
String matrix_in, String flags_in,
String environments_in,
int kernels_in
) {
super(configuration, group, test, flags_in);
//--------------------------
//инфа о компиляции.
compilation_maxtime = configuration.c_maxtime;
compilation_state = TaskState.Waiting;
//инфа о запуске
cube = settings.cube;
min_dim = settings.max_dim_proc_count;
max_dim = settings.max_dim_proc_count;
maxtime = configuration.maxtime;
environments = environments_in;
usr_par = settings.getParamsText();
args = test.args;
//---------
matrix = matrix_in;
kernels = (test_type == TestType.Performance) ? kernels_in :
Math.min(Utils.getMatrixProcessors(matrix), kernels_in);
}
public DVMRunTask() {
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
DVMRunTask rt = (DVMRunTask) src;
dvmcompilationtask_id = rt.dvmcompilationtask_id;
matrix = rt.matrix;
CleanTime = rt.CleanTime;
progress = rt.progress;
language = rt.language;
cube = rt.cube;
min_dim = rt.min_dim;
max_dim = rt.max_dim;
maxtime = rt.maxtime;
environments = rt.environments;
usr_par = rt.usr_par;
compilation_maxtime = rt.compilation_maxtime;
compilation_state = rt.compilation_state;
compilation_time = rt.compilation_time;
args = rt.args;
}
public DVMRunTask(DVMRunTask src) {
this.SynchronizeFields(src);
}
//-
@Override
public Vector<String> pack(Object arg) {
Vector<String> res = new Vector<>();
res.add(String.valueOf(id)); //1
res.add(String.valueOf(maxtime)); //2
res.add(String.valueOf(dvmcompilationtask_id)); //3
res.add(matrix); //4
res.add(environments); //5
res.add(usr_par.replace("\n", "|")); //6
res.add(args); //7
res.add(String.valueOf(kernels)); //8
return res;
}
public String getEnvironments() {
return environments.replace("\n", ";");
}
public String getUsrPar() {
return usr_par.replace("\n", ";");
}
@Override
public boolean isVisible() {
return Global.testingServer.db.dvmRunTasks.applyFilters(this);
}
public File getCompilationTaskWorkspace() {
return Paths.get(
Global.DVMPackagesDirectory.getAbsolutePath(),
String.valueOf(dvm_package_id),
"results",
String.valueOf(dvmcompilationtask_id)
).toFile();
}
public String getCompilationOutput() {
return getResultFile(new File(getCompilationTaskWorkspace(),Constants.out_file));
}
public String getCompilationErrors() {
return getResultFile(new File(getCompilationTaskWorkspace(),Constants.err_file));
}
public String getStatistic() {
return getResultFile(new File(getLocalWorkspace(), Constants.statistic + ".txt"));
}
}
//--

View File

@@ -0,0 +1,9 @@
package _VisualDVM.TestingSystem.DVM.DVMTasks;
import Common.Visual.Menus.DataMenuBar;
import Visual_DVM_2021.Passes.PassCode_2021;
public class DVMRunTasksBar extends DataMenuBar {
public DVMRunTasksBar() {
super("задачи",
PassCode_2021.CompareDVMRunTasks, PassCode_2021.DownloadTaskTest);
}
}

View File

@@ -0,0 +1,165 @@
package _VisualDVM.TestingSystem.DVM.DVMTasks;
import _VisualDVM.Current;
import Common.Visual.DBObjectFilter;
import Common.Database.Tables.DataSet;
import Common.Visual.DataSetFilter;
import Common.Visual.DataSetControlForm;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import java.util.Comparator;
import static Common.Visual.Tables.TableRenderers.RendererProgress;
import static Common.Visual.Tables.TableRenderers.RendererStatusEnum;
public class DVMRunTasksSet extends DataSet<Integer, DVMRunTask> {
//todo обобщить бы наличие фильтров для всех таблиц.
DVMPackage target;
@Override
protected void createFilters() {
filters.add(new DataSetFilter<DVMRunTask>("Компиляция", this) {
@Override
public void fill() {
for (TaskState state : TaskState.values()) {
if (state.isVisible()) {
field_filters.add(new DBObjectFilter<DVMRunTask>(dataSet, state.getDescription()) {
@Override
protected boolean validate(DVMRunTask object) {
return object.compilation_state.equals(state);
}
});
}
}
}
});
filters.add(new DataSetFilter<DVMRunTask>("Запуск", this) {
@Override
public void fill() {
for (TaskState state : TaskState.values()) {
if (state.isVisible()) {
field_filters.add(new DBObjectFilter<DVMRunTask>(dataSet, state.getDescription()) {
@Override
protected boolean validate(DVMRunTask object) {
return object.state.equals(state);
}
});
}
}
}
});
}
public DVMRunTasksSet() {
super(Integer.class, DVMRunTask.class);
}
@Override
public String getSingleDescription() {
return "задача";
}
@Override
public String getPluralDescription() {
return "задачи";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
columns.get(5).setRenderer(RendererStatusEnum);
columns.get(6).setRenderer(RendererStatusEnum);
columns.get(13).setRenderer(RendererProgress);
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Тест",
"Язык",
"Флаги",
"Компиляция",
"Запуск",
"Матрица",
"Окружение",
"usr.par",
"Время компиляции (с)",
"Время запуска (с)",
"Чистое время (с)",
"Прогресс",
};
}
@Override
public Object getFieldAt(DVMRunTask object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.test_description;
case 3:
return object.language;
case 4:
return object.flags;
case 5:
return object.compilation_state;
case 6:
return object.state;
case 7:
return object.matrix;
case 8:
return object.getEnvironments();
case 9:
return object.getUsrPar();
case 10:
return object.compilation_time;
case 11:
return object.Time;
case 12:
return object.CleanTime;
case 13:
return object.progress;
default:
return null;
}
}
@Override
public Current CurrentName() {
return Current.DVMRunTask;
}
public void ShowDVMPackage(DVMPackage dvmPackage) {
target = dvmPackage;
ClearUI();
Data.clear();
if (dvmPackage.package_json == null) {
if (dvmPackage.getJsonFile().exists()) {
try {
dvmPackage.readJson();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
if (dvmPackage.package_json != null) {
for (DVMCompilationTask compilationTask : dvmPackage.package_json.compilationTasks) {
for (DVMRunTask runTask : compilationTask.runTasks) {
Data.put(runTask.id, runTask);
}
}
ShowUI();
}
}
public void ShowNoPackage() {
ClearUI();
Data.clear();
target = null;
}
@Override
public Comparator<DVMRunTask> getComparator() {
return new Comparator<DVMRunTask>() {
@Override
public int compare(DVMRunTask o1, DVMRunTask o2) {
return o1.state.ordinal() - o2.state.ordinal();
}
};
// return Comparator.comparingInt(o -> o.).reversed();
}
}

View File

@@ -0,0 +1,107 @@
package _VisualDVM.TestingSystem.DVM.DVMTasks;
import Common.CommonConstants;
import _VisualDVM.Constants;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.iDBObject;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.Test.TestType;
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import com.google.gson.annotations.Expose;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
import java.util.Vector;
public class DVMTask extends iDBObject {
@Expose
public int dvm_package_id = CommonConstants.Nan;
@Expose
public int group_id = CommonConstants.Nan;
@Expose
public String group_description = "";
@Expose
public int test_id = CommonConstants.Nan;
@Expose
public String test_description = "";
@Expose
public LanguageName language = LanguageName.fortran;
@Expose
public String flags = "";
@Expose
public int kernels = 1;
@Expose
public TaskState state = TaskState.Inactive;
@Expose
public int maxtime = 40;
@Expose
public TestType test_type = TestType.Default;
//результаты-------------------------------
@Expose
public double Time; //время выполнения.
//------------------------------------------------------
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
DVMTask t = (DVMTask) src;
group_id = t.group_id;
group_description = t.group_description;
test_id = t.test_id;
test_description = t.test_description;
language = t.language;
flags = t.flags;
kernels = t.kernels;
state = t.state;
maxtime = t.maxtime;
test_type = t.test_type;
Time = t.Time;
}
public DVMTask(DVMTask src) {
this.SynchronizeFields(src);
}
public DVMTask() {
}
public DVMTask(DVMConfiguration configuration,
Group group, Test test, String flags_in) {
group_id = group.id;
test_id = test.id;
group_description = group.description;
test_description = test.description;
test_type = group.type;
language = group.language;
flags = flags_in;
}
public File getLocalWorkspace() {
return
Paths.get(Global.DVMPackagesDirectory.getAbsolutePath(),
String.valueOf(dvm_package_id),
"results",
String.valueOf(id)).toFile();
}
public Vector<String> pack(Object arg) {
return null;
}
public String getResultFile(File resultFile) {
String res = "";
if (dvm_package_id == CommonConstants.Nan) res = "задача ещё не выполнялась";
else {
if (resultFile.exists()) {
try {
res = FileUtils.readFileToString(resultFile);
} catch (Exception ex) {
ex.printStackTrace();
}
} else res = "не существует";
}
return res;
}
public String getOutput() {
return getResultFile(new File(getLocalWorkspace(), Constants.out_file));
}
public String getErrors() {
return getResultFile(new File(getLocalWorkspace(), Constants.err_file));
}
}

View File

@@ -0,0 +1,9 @@
package _VisualDVM.TestingSystem.DVM;
import _VisualDVM.Repository.RepositoryClient;
import _VisualDVM.Repository.Server.ServerCode;
public class DVMTestingChecker extends RepositoryClient {
@Override
public void perform() throws Exception {
ServerCommand(ServerCode.StartNecessaryMachines);
}
}

View File

@@ -0,0 +1,154 @@
package _VisualDVM.TestingSystem.DVM;
import Common.Utils.CommonUtils;
import _VisualDVM.Global;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.TestingSystem.Common.TasksPackageState;
import _VisualDVM.TestingSystem.Common.TestingPlanner;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMCompilationTask;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMTask;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.FileFilter;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Vector;
public abstract class DVMTestingPlanner extends TestingPlanner<DVMPackage> {
public DVMTestingPlanner(String[] args) {
super(args);
}
LinkedHashMap<Integer, File> getTestsFromJson() {
LinkedHashMap<Integer, File> res = new LinkedHashMap<>();
for (DVMCompilationTask task : testingPackage.package_json.compilationTasks) {
if (!res.containsKey(task.test_id)) {
res.put(task.test_id, Paths.get(Global.TestsDirectory.getAbsolutePath(), String.valueOf(task.test_id)).toFile());
}
}
return res;
}
static LinkedHashMap<LanguageName, Vector<ProjectFile>> getTestPrograms(File test) {
LinkedHashMap<LanguageName, Vector<ProjectFile>> res = new LinkedHashMap<>();
//--
res.put(LanguageName.fortran, new Vector<>());
res.put(LanguageName.c, new Vector<>());
res.put(LanguageName.cpp, new Vector<>());
//--
File[] files = test.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile();
}
});
if (files != null) {
for (File file : files) {
ProjectFile projectFile = new ProjectFile(new File(file.getName()));
if (projectFile.isNotExcludedProgram()) res.get(projectFile.languageName).add(projectFile);
}
}
return res;
}
static void generateForLanguage(String dvm_drv, LanguageName language, Vector<ProjectFile> language_programs, Vector<String> titles, Vector<String> objects, Vector<String> bodies, String flags) {
if (!language_programs.isEmpty()) {
String LANG_ = language.toString().toUpperCase() + "_";
Vector<String> module_objects = new Vector<>();
String module_body = "";
int i = 1;
for (ProjectFile program : language_programs) {
//--
String object = CommonUtils.DQuotes(language + "_" + i + ".o");
module_objects.add(object);
module_body += object + ":\n" + "\t" + String.join(" ", Utils.MFVar(LANG_ + "COMMAND"), Utils.MFVar(LANG_ + "FLAGS"), program.getStyleOptions(), "-c", program.getQSourceName(), "-o", object + "\n\n");
++i;
}
titles.add(String.join("\n", LANG_ + "COMMAND=" + CommonUtils.DQuotes(dvm_drv) + " " + language.getDVMCompile(), LANG_ + "FLAGS=" + flags, LANG_ + "OBJECTS=" + String.join(" ", module_objects), ""));
objects.add(Utils.MFVar(LANG_ + "OBJECTS"));
bodies.add(module_body);
}
}
static String generateMakefile(File test, LanguageName test_language, String dvm_drv, String flags) {
//----->>
LinkedHashMap<LanguageName, Vector<ProjectFile>> programs = getTestPrograms(test);
Vector<String> titles = new Vector<>();
Vector<String> objects = new Vector<>();
Vector<String> bodies = new Vector<>();
String binary = CommonUtils.DQuotes("0");
//----->>
for (LanguageName languageName : programs.keySet()) {
generateForLanguage(dvm_drv, languageName, programs.get(languageName), titles, objects, bodies, flags);
}
//----->>
return String.join("\n", "LINK_COMMAND=" + CommonUtils.DQuotes(dvm_drv) + " " + test_language.getDVMLink(), "LINK_FLAGS=" + flags + "\n", String.join("\n", titles), "all: " + binary, binary + " : " + String.join(" ", objects), "\t" + Utils.MFVar("LINK_COMMAND") + " " + Utils.MFVar("LINK_FLAGS") + " " + String.join(" ", objects) + " -o " + binary, String.join(" ", bodies));
}
public void getTasksInfo(List<? extends DVMTask> tasks, String file_name) throws Exception {
LinkedHashMap<Integer, DVMTask> sorted_tasks = new LinkedHashMap<>();
for (DVMTask task : tasks)
sorted_tasks.put(task.id, task);
//--
File info_file = Paths.get(packageLocalWorkspace.getAbsolutePath(), "results", file_name).toFile();
List<String> lines = FileUtils.readLines(info_file, Charset.defaultCharset());
for (String packed : lines) {
if (!packed.isEmpty()) {
String[] data = packed.split(" ");
int id = Integer.parseInt(data[0]);
TaskState state = TaskState.valueOf(data[1]);
double time = Double.parseDouble(data[2]);
//--
DVMTask task = sorted_tasks.get(id);
task.state = state;
task.Time = state.equals(TaskState.AbortedByTimeout) ? (task.maxtime + 1) : time;
}
}
}
@Override
protected void Print(String message) {
try {
if (isPrintOn()) {
System.out.println(message);
CommonUtils.MainLog.Print(message);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
protected ServerCode getActivePackagesCode() {
return ServerCode.GetFirstActiveDVMPackageForMachineURL;
}
@Override
protected ServerCode getCheckIfNeedsKillCode() {
return ServerCode.DVMPackageNeedsKill;
}
@Override
protected TasksPackageState getStateAfterStart() {
return TasksPackageState.CompilationWorkspacesCreation;
}
@Override
protected void ServerConnectionError(ServerCode code_in, String logText) throws Exception {
Finalize("Не удалось выполнить команду " + code_in + " на сервере тестирования\n" + logText);
}
protected abstract boolean CheckModules() throws Exception;
@Override
public void perform() throws Exception {
Print("Проверка сервера...");
String currentServerName = (String) ServerCommand(ServerCode.GetServerName);
Print("имя текущего сервера " + CommonUtils.Brackets(currentServerName));
Print("имя сервера, создавшего нить " + CommonUtils.Brackets(serverName));
if (!serverName.equals(currentServerName)) {
Finalize("Несоответствующий сервер");
}
Print("Запрос активных пакетов для машины " + CommonUtils.Brackets(machine.getURL()));
testingPackage = null;
Vector<DVMPackage> activePackages = (Vector<DVMPackage>) ServerCommand(getActivePackagesCode(), machine.getURL(), null);
if (activePackages.isEmpty())
Finalize("Не найдено активных пакетов для машины " + CommonUtils.Brackets(machine.getURL()));
for (DVMPackage activePackage : activePackages)
PerformPackage(activePackage);
}
}

View File

@@ -0,0 +1,85 @@
package _VisualDVM.TestingSystem.DVM;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
public class LocalDVMTestingPlanner extends DVMTestingPlanner {
public LocalDVMTestingPlanner(String[] args) {
super(args);
}
@Override
protected boolean CheckModules() throws Exception {
/*
File modulesDirectory = Paths.get(user.workspace, "modules").toFile();
File version = new File(modulesDirectory,"version.h");
int current_version = Constants.Nan;
int actual_version = Constants.planner_version;
///--
if (version.exists()) {
try {
current_version = Integer.parseInt(FileUtils.readFileToString(version));
} catch (Exception ex) {
ex.printStackTrace();
}
}
else {
}
if (current_version < actual_version) {
Print("Закачка кода модулей...");
for (String resource_name : Constants.resourses_names) {
Print(resource_name);
File src = Utils.CreateTempResourceFile(resource_name);
File dst = new File(modulesDirectory, resource_name);
FileUtils.copyFile(src, dst);
}
//--
Print("Сборка модулей...");
String modules_log = user.connection.compileModules(modulesDirectory);
if (!modules_log.isEmpty()) {
testingPackage.description = modules_log;
testingPackage.state = TasksPackageState.Aborted;
return false;
}
}
*/
return true;
}
@Override
public String packageDescription() {
return "DVM";
}
@Override
protected void TestsSynchronize() throws Exception {
testingPackage.readJson();
LinkedHashMap<Integer, File> tests = getTestsFromJson();
//синхронизировать их.
for (int test_id : tests.keySet()) {
File test = tests.get(test_id);
File testDst = Paths.get(testingPackage.user_workspace,"projects", String.valueOf(test_id)).toFile();
Print(testDst.getAbsolutePath());
FileUtils.copyDirectory(test,testDst);
}
Finalize("+");
}
@Override
protected void PackageWorkspaceCreation() throws Exception {
}
@Override
protected void AnalyseResults() throws Exception {
}
@Override
protected void PackageStart() throws Exception {
}
@Override
protected boolean CheckNextState() throws Exception {
return false;
}
@Override
protected void DownloadResults() throws Exception {
}
@Override
protected void Kill() throws Exception {
}
}

View File

@@ -0,0 +1,277 @@
package _VisualDVM.TestingSystem.DVM;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.TestingSystem.Common.TasksPackageState;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMCompilationTask;
import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMRunTask;
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
import java.util.*;
public class RemoteDVMTestingPlanner extends DVMTestingPlanner {
RemoteFile packageRemoteWorkspace = null;
public RemoteDVMTestingPlanner(String... args) {
super(args);
}
@Override
protected boolean Connect() {
if (user.connection == null) {
try {
user.connection = new UserConnection(machine, user);
Print("Соединение c " + machine.getURL() + " " + user.login + " успешно установлено.");
Print("Проверка инициализации..");
user.connection.CheckUserInitialization(testingPackage.sender_address);
} catch (Exception ex) {
Print(ex.toString());
user.connection = null;
Print("Не удалось установить соединение.");
}
}
return user.connection != null;
}
@Override
protected void Disconnect() {
if (user.connection != null) {
user.connection.Disconnect();
user.connection = null;
Print("Соединение c " + machine.getURL() + " " + user.login + " сброшено.");
}
}
//----
@Override
protected void TestsSynchronize() throws Exception {
System.out.println("--");
testingPackage.readJson();
System.out.println("+");
LinkedHashMap<Integer, File> tests = getTestsFromJson();
//синхронизировать их.
for (int test_id : tests.keySet()) {
System.out.println("test=" + test_id);
File test = tests.get(test_id);
RemoteFile test_dst = new RemoteFile(testingPackage.user_workspace + "/projects/" + test_id, true);
user.connection.MKDIR(test_dst);
user.connection.SynchronizeSubDirsR(test, test_dst);
}
System.out.println("++");
}
@Override
protected void PackageWorkspaceCreation() throws Exception {
System.out.println("package workspace creation");
if (!CheckModules()) {
return;
}
System.out.println("modules checked");
//--
testingPackage.readJson();
//--
LinkedHashMap<Integer, File> tests = getTestsFromJson();
//создать папку для пакета.
user.connection.RMDIR(packageRemoteWorkspace.full_name);
user.connection.sftpChannel.mkdir(packageRemoteWorkspace.full_name);
//положить туда запакованные тексты задач.
Vector<String> compilationLines = new Vector<>();
Vector<String> runLines = new Vector<>();
for (DVMCompilationTask compilationTask : testingPackage.package_json.compilationTasks) {
String makefileText = generateMakefile(tests.get(compilationTask.test_id), compilationTask.language, testingPackage.drv, compilationTask.flags);
compilationLines.addAll(compilationTask.pack(makefileText));
for (DVMRunTask runTask : compilationTask.runTasks)
runLines.addAll(runTask.pack(null));
}
RemoteFile compilationPackage = new RemoteFile(packageRemoteWorkspace, "compilationTasks");
RemoteFile runPackage = new RemoteFile(packageRemoteWorkspace, "runTasks");
user.connection.writeToFile(String.join("\n", compilationLines) + "\n", compilationPackage);
user.connection.writeToFile(String.join("\n", runLines) + "\n", runPackage);
// --
user.connection.MKDIR(new RemoteFile(packageRemoteWorkspace, "state"));
}
@Override
protected void AnalyseResults() throws Exception {
boolean hasErrors = false;
testingPackage.readJson();
Print("analysing results");
Vector<DVMRunTask> runTasks = new Vector<>();
for (DVMCompilationTask compilationTask : testingPackage.package_json.compilationTasks)
runTasks.addAll(compilationTask.runTasks);
//----
getTasksInfo(testingPackage.package_json.compilationTasks, "CompilationInfo.txt");
getTasksInfo(runTasks, "RunningInfo.txt");
//--
int ct_count = 0;
int rt_count = 0;
int good=0;
//--
for (DVMCompilationTask compilationTask : testingPackage.package_json.compilationTasks) {
compilationTask.dvm_package_id = testingPackage.id;
if (!compilationTask.state.equals(TaskState.Done))
hasErrors = true;
ct_count++;
File ct_workspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), "results", String.valueOf(compilationTask.id)).toFile();
if (ct_workspace.exists()) {
for (DVMRunTask runTask : compilationTask.runTasks) {
runTask.dvm_package_id = testingPackage.id;
rt_count++;
runTask.compilation_state = compilationTask.state;
runTask.compilation_time = compilationTask.Time;
if (compilationTask.state == TaskState.DoneWithErrors) {
runTask.state = TaskState.Canceled;
} else {
File rt_workspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), "results", String.valueOf(runTask.id)).toFile();
if (rt_workspace.exists() && runTask.state.equals(TaskState.Finished)) {
//анализ задачи на запуск.
File outFile = new File(rt_workspace, Constants.out_file);
File errFile = new File(rt_workspace.getAbsolutePath(), Constants.err_file);
//--
String output = FileUtils.readFileToString(outFile);
String errors = FileUtils.readFileToString(errFile);
//--
List<String> output_lines = Arrays.asList(output.split("\n"));
List<String> errors_lines = Arrays.asList(errors.split("\n"));
//---
if (Utils.isCrushed(output_lines, errors_lines)) {
runTask.state = TaskState.Crushed;
} else {
Pair<TaskState, Integer> results = new Pair<>(TaskState.Done, 100);
switch (runTask.test_type) {
case Correctness:
results = Utils.analyzeCorrectness(output_lines);
break;
case Performance:
results = Utils.analyzePerformance(output_lines);
break;
default:
break;
}
runTask.state = results.getKey();
runTask.progress = results.getValue();
runTask.CleanTime = Utils.parseCleanTime(output);
}
}
}
if (!runTask.state.equals(TaskState.Done))
hasErrors = true;
else good++;
}
}
}
testingPackage.progress = 100;
testingPackage.saveJson(); //запись обновленных результатов пакета в json!
Print("analysis done, ct_count=" + ct_count + " rt count=" + rt_count);
testingPackage.state = hasErrors ? TasksPackageState.DoneWithErrors : TasksPackageState.Done;
double percent = ( ((double)(good))/testingPackage.tasksCount)*100.0;
testingPackage.description = "Выполнено на "+((int)percent)+"%\n"+
"Всего задач: "+testingPackage.tasksCount+", из них с ошибками "+(testingPackage.tasksCount-good);
UpdatePackageState();
}
@Override
protected void PackageStart() throws Exception {
String plannerStartCommand = String.join(" ",
CommonUtils.DQuotes(getPlanner()),
CommonUtils.DQuotes(user.workspace),
CommonUtils.DQuotes(packageRemoteWorkspace.full_name),
CommonUtils.DQuotes(testingPackage.kernels),
CommonUtils.DQuotes(testingPackage.drv));
user.connection.startShellProcess(packageRemoteWorkspace, "planner_output",
"ulimit -s unlimited", plannerStartCommand);
//---
RemoteFile PID = new RemoteFile(packageRemoteWorkspace, "PID");
while (!user.connection.Exists(PID)) {
Print("PID not found");
CommonUtils.sleep(1000);
}
testingPackage.PID = user.connection.readFromFile(PID).replace("\n", "").replace("\r", "");
//---
System.out.println("PID=" + CommonUtils.Brackets(testingPackage.PID));
RemoteFile STARTED = new RemoteFile(packageRemoteWorkspace, "STARTED");
while (!user.connection.Exists(STARTED)) {
Print("waiting for package start...");
CommonUtils.sleep(1000);
}
}
@Override
protected boolean CheckNextState() throws Exception {
boolean progress_changed = false;
boolean state_changed = false;
RemoteFile progress = new RemoteFile(packageRemoteWorkspace, "progress");
if (user.connection.Exists(progress)) {
String s = user.connection.readFromFile(progress);
int current_progress = Integer.parseInt(s);
if (current_progress != testingPackage.progress) {
Print("progress changed: " + current_progress);
testingPackage.progress = current_progress;
progress_changed = true;
}
}
RemoteFile stateDir = new RemoteFile(packageRemoteWorkspace, "state");
//состояния пакета могут меняться только по возрастанию. ищем, появилось ли такое.
Vector<TasksPackageState> higherStates = testingPackage.state.getHigherStates();
Collections.reverse(higherStates); //берем в обратном порядке, чтобы быстрее найти высшее.
for (TasksPackageState state : higherStates) {
RemoteFile file = new RemoteFile(stateDir, state.toString());
if (user.connection.Exists(file)) {
Print("found new state: " + file.name);
testingPackage.state = state;
state_changed = true;
break;
}
}
//--
user.connection.iterations++;
if (user.connection.iterations == 100) {
Disconnect();
}
//--
return progress_changed || state_changed;
}
@Override
protected void DownloadResults() throws Exception {
Utils.CheckDirectory(packageLocalWorkspace);
RemoteFile remote_results_archive = new RemoteFile(packageRemoteWorkspace, "results.zip");
File results_archive = new File(packageLocalWorkspace, "results.zip");
user.connection.performScript(packageRemoteWorkspace, "zip -r " + CommonUtils.DQuotes("results.zip") + " " + CommonUtils.DQuotes("results"));
//---
if (user.connection.Exists(remote_results_archive)) {
user.connection.getSingleFile(remote_results_archive.full_name, results_archive.getAbsolutePath());
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
unzipFolderPass.Do(results_archive.getAbsolutePath(), packageLocalWorkspace.getAbsolutePath(), false);
}
//---
if (Global.properties.eraseTestingWorkspaces && user.connection.Exists(packageRemoteWorkspace))
user.connection.RMDIR(packageRemoteWorkspace.full_name);
}
@Override
protected void MachineConnectionError() {
Finalize("Количество безуспешных попыток соединения с машиной " + machine.getURL() + " превысило 10");
}
@Override
protected void Kill() throws Exception {
if (!testingPackage.PID.isEmpty()) {
user.connection.Command("kill -9 " + testingPackage.PID);
}
}
@Override
protected void InitSessionCredentials() {
packageRemoteWorkspace = new RemoteFile(user.workspace + "/tests", String.valueOf(testingPackage.id), true);
packageLocalWorkspace = new File(Global.DVMPackagesDirectory, String.valueOf(testingPackage.id));
}
@Override
protected boolean CheckModules() throws Exception {
String log = user.connection.CheckModulesVersion();
if (!log.isEmpty()) {
testingPackage.description = log;
testingPackage.state = TasksPackageState.Aborted;
return false;
}
return true;
}
@Override
public String packageDescription() {
return "DVM";
}
}

View File

@@ -0,0 +1,570 @@
package _VisualDVM.TestingSystem.DVM;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
import _VisualDVM.GlobalData.User.User;
import _VisualDVM.ProjectData.Project.db_project_info;
import Visual_DVM_2021.Passes.PassException;
import com.jcraft.jsch.*;
import javafx.util.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Vector;
public class UserConnection {
//http://www.jcraft.com/jsch/
public int iterations = 0; //для тестирования
//--
public ChannelSftp sftpChannel = null;
public ChannelShell shellChannel = null;
public ChannelExec execChannel = null;
//--
JSch jsch = null;
Session session = null;
//---
PipedInputStream in = null;
PipedOutputStream out = null;
//---
PipedOutputStream pin = null;
PipedInputStream pout = null;
InputStreamReader fromServer = null;
//---
Machine machine = null;
User user = null;
//---
public UserConnection(Machine machine_in, User user_in) throws Exception {
machine = machine_in;
user = user_in;
//--
session = (jsch = new JSch()).getSession(user.login, machine.address, machine.port);
session.setPassword(user.password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect(0);
//-->
//создать канал для файлов
sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
//-->
//создать канал для команд
}
public void Disconnect() {
if (in != null) {
try {
in.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (out != null) {
try {
out.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (pin != null) {
try {
pin.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (pout != null) {
try {
pout.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (fromServer != null) {
try {
fromServer.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (sftpChannel != null) sftpChannel.disconnect();
if (shellChannel != null) shellChannel.disconnect();
if (execChannel != null) execChannel.disconnect();
if (session != null) {
session.disconnect();
}
//----------------------
sftpChannel = null;
shellChannel = null;
execChannel = null;
session = null;
//---
in = null;
out = null;
//---
pin = null;
pout = null;
fromServer = null;
jsch = null;
System.gc();
}
public void getSingleFile(String src, String dst) throws Exception {
sftpChannel.get(src, dst);
}
public long getFileKBSize(String path) throws Exception {
long size = sftpChannel.lstat(path).getSize();
return size / 1024;
}
public void getSingleFileWithMaxSize(RemoteFile src, File dst, int maxSize) throws Exception {
if ((maxSize == 0) || getFileKBSize(src.full_name) <= maxSize) {
getSingleFile(src.full_name, dst.getAbsolutePath());
} else {
Utils.WriteToFile(dst, "Размер файла превышает " + maxSize + " KB.\n" + "Файл не загружен. Его можно просмотреть на машине по адресу\n" + CommonUtils.Brackets(src.full_name));
}
}
public void putSingleFile(File src, RemoteFile dst) throws Exception {
sftpChannel.put(src.getAbsolutePath(), dst.full_name);
}
//-
public void MKDIR(RemoteFile dir) throws Exception {
if (!Exists(dir)) sftpChannel.mkdir(dir.full_name);
}
//-
public void RMDIR(String dir) throws Exception {
if (!dir.isEmpty() && !dir.equals("/") && !dir.equals("\\") && !dir.equals("*")) {
Command("rm -rf " + CommonUtils.DQuotes(dir));
} else throw new PassException("Недопустимый путь для удаления папки " + CommonUtils.DQuotes(dir));
}
//-
public void SynchronizeSubDirsR(File local_dir, RemoteFile remote_dir) throws Exception {
File[] local_subdirs = local_dir.listFiles(File::isDirectory);
File[] local_files = local_dir.listFiles(File::isFile);
//------------------------------------------------------------------------
LinkedHashMap<String, RemoteFile> remote_subdirs = new LinkedHashMap<>();
LinkedHashMap<String, RemoteFile> remote_files = new LinkedHashMap<>();
Vector<ChannelSftp.LsEntry> files = sftpChannel.ls(remote_dir.full_name);
for (ChannelSftp.LsEntry file : files) {
if (file.getAttrs().isDir()) {
if (!file.getFilename().equals(".") && !file.getFilename().equals(".."))
remote_subdirs.put(file.getFilename(), new RemoteFile(remote_dir.full_name, file.getFilename(), true));
} else {
RemoteFile rf = new RemoteFile(remote_dir.full_name, file.getFilename());
rf.updateTime = RemoteFile.convertUpdateTime(file.getAttrs().getMTime());
remote_files.put(file.getFilename(), rf);
}
}
if (local_subdirs != null) {
for (File lsd : local_subdirs) {
if (!lsd.getName().equals(Constants.data)) {
RemoteFile rsd = null;
if (!remote_subdirs.containsKey(lsd.getName()))
sftpChannel.mkdir((rsd = new RemoteFile(remote_dir.full_name, lsd.getName(), true)).full_name);
else rsd = remote_subdirs.get(lsd.getName());
SynchronizeSubDirsR(lsd, rsd);
}
}
}
if (local_files != null) {
for (File lf : local_files) {
RemoteFile rf = null;
if (!remote_files.containsKey(lf.getName())) {
rf = new RemoteFile(remote_dir.full_name, lf.getName());
putSingleFile(lf, rf);
} else {
rf = remote_files.get(lf.getName());
if (lf.lastModified() > rf.updateTime) {
putSingleFile(lf, rf);
}
}
}
}
}
public void writeToFile(String text, RemoteFile dst) throws Exception {
sftpChannel.put(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)), dst.full_name);
sftpChannel.chmod(0777, dst.full_name);
}
public String readFromFile(RemoteFile src) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
sftpChannel.get(src.full_name, outputStream);
return outputStream.toString(StandardCharsets.UTF_8.name());
}
//--
public boolean Exists(String file_full_name) throws Exception {
try {
sftpChannel.lstat(file_full_name);
return true;
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
// file doesn't exist
return false;
} else {
// something else went wrong
throw e;
}
}
}
public boolean Busy(String file_full_name) throws Exception {
try {
sftpChannel.lstat(file_full_name);
return true;
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_PERMISSION_DENIED) {
// file busy
return false;
} else {
// something else went wrong
throw e;
}
}
}
public boolean Busy(RemoteFile file) throws Exception {
return Busy(file.full_name);
}
public boolean Exists(RemoteFile file) throws Exception {
return Exists(file.full_name);
}
//--
public Pair<RemoteFile, RemoteFile> performScript(RemoteFile directory, String... commands) throws Exception {
RemoteFile script_file = new RemoteFile(directory, Constants.script);
RemoteFile out = new RemoteFile(directory, Constants.out_file);
RemoteFile err = new RemoteFile(directory, Constants.err_file);
//
Vector<RemoteFile> files = new Vector<>();
files.add(script_file);
files.add(out);
files.add(err);
for (RemoteFile file : files) {
if (Exists(file))
sftpChannel.rm(file.full_name);
}
//--
writeToFile("cd " + CommonUtils.DQuotes(directory.full_name) + "\n" + String.join("\n", commands), script_file);
//--
Command(CommonUtils.DQuotes(script_file.full_name) + " 1>" + CommonUtils.DQuotes(out.full_name) + " 2>" + CommonUtils.DQuotes(err.full_name));
return new Pair<>(out, err);
}
public void putResource(RemoteFile dstDirectory, String resource_name) throws Exception {
File src = Utils.CreateTempResourceFile(resource_name);
RemoteFile dst = new RemoteFile(dstDirectory, resource_name);
putSingleFile(src, dst);
}
boolean compileModule(RemoteFile modulesDirectory, String module_name) throws Exception {
String flags = module_name.equals("planner") ? getAvailibleCPPStandard(modulesDirectory) : "";
String command = "g++ -O3 " + flags + " " + CommonUtils.DQuotes(module_name + ".cpp") + " -o " + CommonUtils.DQuotes(module_name);
RemoteFile binary = new RemoteFile(modulesDirectory, module_name);
//--
if (Exists(binary))
sftpChannel.rm(binary.full_name);
//--
performScript(modulesDirectory, command);
//--
if (Exists(binary)) {
sftpChannel.chmod(0777, binary.full_name);
return true;
}
return false;
}
String getAvailibleCPPStandard(RemoteFile scriptDirectory) throws Exception {
String res = "";
String command = "g++ -v --help 2> /dev/null | sed -n '/^ *-std=\\([^<][^ ]\\+\\).*/ {s//\\1/p}' | grep c++";
Pair<RemoteFile, RemoteFile> oe = performScript(scriptDirectory, command);
RemoteFile outFile = oe.getKey();
String out = readFromFile(outFile);
//--
RemoteFile cppVersionsInfo = new RemoteFile(scriptDirectory, "cpp_versions.txt");
sftpChannel.rename(outFile.full_name, cppVersionsInfo.full_name);
//--
String[] data = out.split("\n");
boolean cpp_17 = false;
boolean cpp_11 = false;
//определить какие есть версии.
for (String version : data) {
switch (version) {
case "c++17":
cpp_17 = true;
break;
case "c++11":
cpp_11 = true;
break;
}
}
if (cpp_17)
res = "-std=c++17";
else if (cpp_11)
res = "-std=c++11";
RemoteFile cppFlag = new RemoteFile(scriptDirectory, "current_ccp_version");
writeToFile(res, cppFlag);
return res;
}
public String compileModules(RemoteFile modulesDirectory) throws Exception {
if (!compileModule(modulesDirectory, "launcher")) {
return "Не удалось собрать модуль [launcher]";
}
if (!compileModule(modulesDirectory, "starter")) {
return "Не удалось собрать модуль [starter]";
}
if (!compileModule(modulesDirectory, "planner")) {
return "Не удалось собрать модуль [planner]";
}
return "";
}
//--
public void tryRM(RemoteFile file) throws Exception {
if (Exists(file))
sftpChannel.rm(file.full_name);
}
//с проверкой.
public boolean tryGetSingleFileWithMaxSize(RemoteFile src, File dst, int maxSize) throws Exception {
if (Exists(src)) {
if ((maxSize == 0) || (getFileKBSize(src.full_name) <= maxSize)) {
getSingleFile(src.full_name, dst.getAbsolutePath());
return true;
} else {
Utils.WriteToFile(dst, "Размер файла превышает " + maxSize + " KB.\n" + "Файл не загружен. Его можно просмотреть на машине по адресу\n" + CommonUtils.Brackets(src.full_name));
}
}
return false;
}
//--
public void SynchronizeProjectSubDirsR(db_project_info project, File local_dir, RemoteFile remote_dir, boolean data) throws Exception {
// ShowMessage2("синхронизация: " + local_dir.getName());
Vector<File> local_subdirs = project.getSubdirectoriesSimple(local_dir);
Vector<File> local_files = project.getActiveFilesForSynchronization(local_dir, data);
//------------------------------------------------------------------------
LinkedHashMap<String, RemoteFile> remote_subdirs = new LinkedHashMap<>();
LinkedHashMap<String, RemoteFile> remote_files = new LinkedHashMap<>();
Vector<ChannelSftp.LsEntry> files = sftpChannel.ls(remote_dir.full_name);
for (ChannelSftp.LsEntry file : files) {
if (file.getAttrs().isDir()) {
if (!file.getFilename().equals(".") && !file.getFilename().equals(".."))
remote_subdirs.put(file.getFilename(), new RemoteFile(remote_dir.full_name, file.getFilename(), true));
} else {
RemoteFile rf = new RemoteFile(remote_dir.full_name, file.getFilename());
rf.updateTime = RemoteFile.convertUpdateTime(file.getAttrs().getMTime());
remote_files.put(file.getFilename(), rf);
}
}
for (File lsd : local_subdirs) {
RemoteFile rsd = null;
if (!remote_subdirs.containsKey(lsd.getName()))
sftpChannel.mkdir((rsd = new RemoteFile(remote_dir.full_name, lsd.getName(), true)).full_name);
else rsd = remote_subdirs.get(lsd.getName());
SynchronizeProjectSubDirsR(project, lsd, rsd, data);
}
for (File lf : local_files) {
RemoteFile rf = null;
if (!remote_files.containsKey(lf.getName())) {
rf = new RemoteFile(remote_dir.full_name, lf.getName());
// ShowMessage2(lf.getName());
putSingleFile(lf, rf);
} else {
rf = remote_files.get(lf.getName());
if (lf.lastModified() > rf.updateTime) {
// ShowMessage2(lf.getName());
putSingleFile(lf, rf);
}
}
}
}
//--
public Vector<RemoteFile> getFilesByExtensions(RemoteFile dir, String... extensions) throws Exception {
Vector<RemoteFile> res = new Vector<>();
Vector<ChannelSftp.LsEntry> files = sftpChannel.ls(dir.full_name);
for (ChannelSftp.LsEntry file : files) {
String[] data = file.getFilename().split("\\.");
if (data.length > 1) {
String file_extension = data[data.length - 1];
for (String extension : extensions) {
if (file_extension.equalsIgnoreCase(extension))
res.add(new RemoteFile(dir.full_name, file.getFilename()));
}
}
}
return res;
}
public void deleteFilesByExtensions(RemoteFile dir, String... extensions) throws Exception {
Vector<RemoteFile> to_delete = getFilesByExtensions(dir, extensions);
for (RemoteFile file : to_delete)
sftpChannel.rm(file.full_name);
}
public void Command(String... commands) throws Exception {
if (commands.length > 0) {
String command = String.join("\n", commands);
execChannel = (ChannelExec) session.openChannel("exec");
execChannel.setErrStream(System.err);
execChannel.setCommand(command);
execChannel.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(execChannel.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(CommonUtils.Brackets(line));
}
}
execChannel.disconnect();
}
public void CommandNoWait(String... commands) throws Exception {
if (commands.length > 0) {
String command = String.join("\n", commands);
execChannel = (ChannelExec) session.openChannel("exec");
execChannel.setErrStream(System.err);
execChannel.setCommand(command);
execChannel.connect();
execChannel.disconnect();
}
}
//-----
public void ShellConnect() throws Exception {
shellChannel = (ChannelShell) session.openChannel("shell");
in = new PipedInputStream();
out = new PipedOutputStream();
//--
shellChannel.setInputStream(in);
shellChannel.setOutputStream(out);
pin = new PipedOutputStream(in);
pout = new PipedInputStream(out);
shellChannel.connect();
//-
fromServer = new InputStreamReader(pout);
/*
ShellParser.setUserName(user.login);
ShellParser.ReadInvitation(fromServer); //прочитать первое приглашение от машины.
*/
}
public void ShellDisconnect() throws Exception {
if (in != null) {
try {
in.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (out != null) {
try {
out.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (pin != null) {
try {
pin.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (pout != null) {
try {
pout.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (fromServer != null) {
try {
fromServer.close();
} catch (Exception exception) {
CommonUtils.MainLog.PrintException(exception);
}
}
if (shellChannel != null) shellChannel.disconnect();
//--
in = null;
out = null;
pin = null;
pout = null;
fromServer = null;
shellChannel = null;
System.gc();
}
public void waitForFileCreation(RemoteFile file) throws Exception {
while (!Exists(file)) {
System.out.println(file.full_name + " NOT FOUND");
CommonUtils.sleep(1000);
}
}
public void waitForFileFree(RemoteFile file) throws Exception {
while (!Busy(file)) {
System.out.println(file.full_name + " PERMISSION DENIED");
CommonUtils.sleep(1000);
}
}
public String startShellProcess(RemoteFile directory, String outFileName, String... commands) throws Exception {
Vector<String> commands_ = new Vector<>();
commands_.add("cd " + CommonUtils.DQuotes(directory.full_name));
for (int i = 0; i < commands.length; ++i) {
if (i == commands.length - 1) {
commands_.add(commands[i] + " 1>" + CommonUtils.DQuotes(outFileName));
} else {
commands_.add(commands[i]);
}
}
RemoteFile script_file = new RemoteFile(directory, Constants.script);
if (Exists(script_file))
sftpChannel.rm(script_file.full_name);
writeToFile(String.join("\n", commands_), script_file);
String start_command = CommonUtils.DQuotes(script_file.full_name);
//--
RemoteFile outFile = new RemoteFile(directory, outFileName);
if (Exists(outFile))
sftpChannel.rm(outFile.full_name);
ShellConnect();
pin.write(("nohup " + start_command + " &\r\n").getBytes());
waitForFileCreation(outFile);
waitForFileFree(outFile);
ShellDisconnect();
return readFromFile(outFile).replace("\n", "").replace("\r", "");
}
//-- проверка существования рабочего пространства.
public void CheckUserInitialization(String email) throws Exception {
RemoteFile userWorkspace = new RemoteFile(user.workspace, true);
if (!Exists(userWorkspace)) {
sftpChannel.mkdir(userWorkspace.full_name);
//--
RemoteFile modulesDirectory = new RemoteFile(userWorkspace, "modules");
RemoteFile projectsDirectory = new RemoteFile(userWorkspace, "projects");
RemoteFile testsDirectory = new RemoteFile(userWorkspace, "tests");
//--
Vector<RemoteFile> subdirectories = new Vector<>();
subdirectories.add(modulesDirectory);
subdirectories.add(projectsDirectory);
subdirectories.add(testsDirectory);
for (RemoteFile remoteFile : subdirectories)
sftpChannel.mkdir(remoteFile.full_name);
//--
for (String resource_name : Constants.resourses_names) {
putResource(modulesDirectory, resource_name);
}
//-
String modules_log = compileModules(modulesDirectory);
if (!modules_log.isEmpty())
throw new PassException(modules_log);
//--
RemoteFile info = new RemoteFile(userWorkspace, email);
user.connection.writeToFile("", info);
}
}
//--
public String CheckModulesVersion() throws Exception {
RemoteFile modulesDirectory = new RemoteFile(user.workspace, "modules");
RemoteFile version = new RemoteFile(modulesDirectory, "version.h");
int current_version = CommonConstants.Nan;
int actual_version = Constants.planner_version;
if (Exists(version)) {
try {
current_version = Integer.parseInt(readFromFile(version));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (current_version < actual_version) {
for (String resource_name : Constants.resourses_names) {
putResource(modulesDirectory, resource_name);
}
//--
return compileModules(modulesDirectory);
}
return "";
}
}

View File

@@ -0,0 +1,29 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
import Common.CommonConstants;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import Visual_DVM_2021.Passes.PassCode_2021;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.List;
import java.util.Vector;
//на самом деле уже settings. конфиграция = группы + параметры
public class SapforConfiguration_json implements Serializable {
@Expose
public int id = CommonConstants.Nan;
@Expose
public String name = "";
@Expose
public String flags = "";
@Expose
public List<PassCode_2021> codes = new Vector<>();
//--
public SapforConfiguration_json() {
}
public SapforConfiguration_json(SapforSettings sapforSettings) {
id = sapforSettings.id;
name = sapforSettings.description;
flags = sapforSettings.flags;
codes = sapforSettings.getCheckedCodes();
}
}

View File

@@ -0,0 +1,204 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.ComparisonState;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI.PackageComparisonSummary;
import _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI.PackageSummary;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import com.google.gson.annotations.Expose;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
import java.io.Serializable;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Vector;
public class SapforPackage_json implements Serializable {
@Expose
public int kernels = 1;
@Expose
public String sapfor_drv = ""; //файл с сапфором. Имя уникально для сценария.
//--
@Expose
public int max_set_id = 0;
public int getMaxSetId() {
return max_set_id++;
}
@Expose
public int max_task_id = 0;
public int getMaxTaskId() {
return max_task_id++;
}
//--в отличие от пакета двм,где достаточно инфы о задачах, тут есть инфа о тестах и конфигурациях
@Expose
public List<SapforTestingSet_json> testingSets = new Vector<>(); //по факту, сет один. Наследие формирования пакетов.
@Expose
public List<SapforTask> tasks = new Vector<>();
//--
public Vector<String> getTasksKeys() {
Vector<String> keys = new Vector<>();
for (SapforTask task : tasks) {
String key = task.getUniqueKey();
if (!keys.contains(key))
keys.add(key);
}
return keys;
}
public Vector<String> getTestsNames() {
Vector<String> names = new Vector<>();
for (SapforTask task : tasks) {
if (!names.contains(task.test_description))
names.add(task.test_description);
}
names.sort(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
return names;
}
//--
public void sortTasks() {
tasks.sort(new Comparator<SapforTask>() {
@Override
public int compare(SapforTask o1, SapforTask o2) {
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
}
});
}
public void sortTasksForComparison() {
tasks.sort(new Comparator<SapforTask>() {
@Override
public int compare(SapforTask o1, SapforTask o2) {
return Integer.compare(o1.comparisonState.ordinal(), o2.comparisonState.ordinal());
}
});
}
public boolean containsKey(String key) {
for (SapforTask task : tasks) {
if (task.getUniqueKey().equals(key))
return true;
}
return false;
}
public SapforTask getTaskByKey(String key) {
for (SapforTask task : tasks) {
if (task.getUniqueKey().equals(key))
return task;
}
return null;
}
//-
public PackageSummary root = null;
public PackageComparisonSummary comparison_root = null;
//---------
public void DropComparison() {
comparison_root = null;
for (SapforTask task : tasks) {
task.comparisonState = ComparisonState.Unknown;
for (SapforVersion_json version : task.versions)
version.comparisonState = VersionComparisonState.Unknown;
for (SapforVersion_json version : task.variants)
version.comparisonState = VersionComparisonState.Unknown;
}
}
public void buildTree(SapforPackage package_in) {
//--
root = new PackageSummary();
root.count = tasks.size();
root.errors_count = 0;
//--
sortTasks();
//--
for (SapforTask task : tasks) {
DefaultMutableTreeNode taskNode = task.getNode(Paths.get(
package_in.getLocalWorkspace().getAbsolutePath(),
String.valueOf(task.set_id),
String.valueOf(task.sapfor_configuration_id)
).toFile());
root.add(taskNode);
if (task.state.equals(TaskState.DoneWithErrors))
root.errors_count++;
}
}
public void buildComparisonTree(SapforPackage package_in) {
comparison_root = new PackageComparisonSummary();
comparison_root.count = tasks.size();
comparison_root.mismatches_count = 0;
//--
sortTasksForComparison();
//--
for (SapforTask task : tasks) {
DefaultMutableTreeNode taskNode = task.getNode(Paths.get(
package_in.getLocalWorkspace().getAbsolutePath(),
String.valueOf(task.set_id),
String.valueOf(task.sapfor_configuration_id)
).toFile());
comparison_root.add(taskNode);
if (task.comparisonState.equals(ComparisonState.NotMatch))
comparison_root.mismatches_count++;
}
}
public void getVersionsFiles(SapforPackage package_in) {
for (SapforTask task : tasks) {
File configurationRoot = Paths.get(
package_in.getLocalWorkspace().getAbsolutePath(),
String.valueOf(task.set_id),
String.valueOf(task.sapfor_configuration_id)
).toFile();
for (SapforVersion_json version_json : task.versions) {
version_json.task = task;
version_json.getFiles(configurationRoot);
}
for (SapforVersion_json version_json : task.variants) {
version_json.task = task;
version_json.getFiles(configurationRoot);
}
}
}
public Vector<String> getConfigurationsNames() {
Vector<String> names = new Vector<>();
for (SapforTestingSet_json set : testingSets) {
for (SapforConfiguration_json configurationJson : set.configurations) {
if (!names.contains(configurationJson.name))
names.add(configurationJson.name);
}
}
names.sort(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
return names;
}
//---
public SapforPackage_json() {
}
public SapforPackage_json(ServerSapfor serverSapfor, LinkedHashMap<String, Test> testsByDescriptions, Vector<SapforConfiguration> configurations, int kernels_in) {
sapfor_drv=serverSapfor.call_command;
kernels = kernels_in;
//рудимент от формирования пакетов. возможно, объединить с текущим классом.
SapforTestingSet_json testingSet = new SapforTestingSet_json(testsByDescriptions, configurations);
testingSet.id = getMaxSetId();
testingSets.add(testingSet);
//формирование задач
LinkedHashMap<String, SapforTask> sortedTasks = new LinkedHashMap<>();
for (SapforConfiguration_json sapforConfiguration_json : testingSet.configurations) {
for (SapforTest_json test : testingSet.tests) {
SapforTask task = new SapforTask(testingSet, test, sapforConfiguration_json);
if (!sortedTasks.containsKey(task.getUniqueKey())) {
task.id = getMaxTaskId();
sortedTasks.put(task.getUniqueKey(), task);
}
}
}
tasks.addAll(sortedTasks.values());
}
}

View File

@@ -0,0 +1,20 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
import _VisualDVM.Global;
import _VisualDVM.TestingSystem.Common.Test.Test;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
public class SapforTest_json implements Serializable {
@Expose
public int id;
@Expose
public String description = "";
@Expose
public String group_description = "";
public SapforTest_json(){}
public SapforTest_json(Test test){
id = test.id;
description = test.description;
group_description = Global.testingServer.db.groups.get(test.group_id).description;
}
}

View File

@@ -0,0 +1,30 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
import Common.CommonConstants;
import _VisualDVM.ServerObjectsCache.SapforConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Vector;
public class SapforTestingSet_json implements Serializable {
@Expose
public int id = CommonConstants.Nan;
@Expose
public List<SapforTest_json> tests = new Vector<>();
@Expose
public List<SapforConfiguration_json> configurations = new Vector<>();
public SapforTestingSet_json(){}
public SapforTestingSet_json(LinkedHashMap<String, Test> testsByDescriptions, Vector<SapforConfiguration> sapforConfigurations) {
for (Test test : testsByDescriptions.values())
tests.add(new SapforTest_json(test));
for (SapforConfiguration configuration : sapforConfigurations) {
for (SapforSettings sapforSettings : ((SapforConfigurationCache) VisualCaches.GetCache(configuration)).getSettings())
configurations.add(new SapforConfiguration_json(sapforSettings));
}
}
}

View File

@@ -0,0 +1,7 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
import java.io.Serializable;
public enum SapforVersionState implements Serializable {
Empty, //версия оказалась пуста.
Normal, //версия построена
HasErrors //версия построена, но в журналах есть ошибка.
}

View File

@@ -0,0 +1,309 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Utils;
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.Files.FileType;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.ProjectData.Messages.Errors.MessageError;
import _VisualDVM.ProjectData.Project.db_project_info;
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import com.google.gson.annotations.Expose;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Vector;
import static java.lang.Character.isDigit;
public class SapforVersion_json implements Serializable {
@Expose
public String version = "";
@Expose
public String description = "";
//поля для отображения деревьев.
public File Home = null;
public LinkedHashMap<String, ProjectFile> files = new LinkedHashMap<>();
//--
public ProjectFile parse_out = null;
public ProjectFile parse_err = null;
public ProjectFile out = null;
public ProjectFile err = null;
//--
public SapforTask task = null; //родная задача. Нужна для построения дерева версий.
public db_project_info project = null;
//--
public SapforVersionState state = null;
public VersionComparisonState comparisonState = null;
//--
public SapforVersion_json(String version_in, String description_in) {
version = version_in;
description = description_in;
}
public SapforVersion_json(String root_in, String version_in, String description_in) {
version = version_in.substring(root_in.length() + 1);
description = description_in;
}
public void getFiles(File configurationRoot) {
//--
state = SapforVersionState.Empty;
comparisonState = VersionComparisonState.Unknown;
//--
String relativePath = CommonUtils.isWindows() ? CommonUtils.toW(version) : version;
Home = Paths.get(configurationRoot.getAbsolutePath(), relativePath).toFile();
files = new LinkedHashMap<>();
//--
File[] files_ = Home.listFiles();
if (files_ != null) {
for (File file : files_) {
if (file.isFile()) {
ProjectFile projectFile = new ProjectFile(file);
if (!projectFile.fileType.equals(FileType.forbidden)
) {
files.put(projectFile.file.getName(), projectFile);
}
}
}
if (!files.isEmpty())
state = SapforVersionState.Normal;
}
parse_out = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile());
parse_err = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile());
out = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile());
err = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile());
//--
Vector<File> out_files = new Vector<>();
out_files.add(parse_out.file);
out_files.add(parse_err.file);
out_files.add(out.file);
out_files.add(err.file);
for (File file : out_files) {
try {
if (file.exists()) {
Vector<String> lines = new Vector<>(FileUtils.readLines(file));
if (!Sapfor.checkLines(lines)) {
state = SapforVersionState.HasErrors;
return;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public boolean isMatch(SapforVersion_json version_json) {
if (!description.equals(version_json.description)) {
return false;
}
if (files.size() != version_json.files.size()) {
return false;
}
for (String name1 : files.keySet()) {
if (!version_json.files.containsKey(name1)) {
return false;
}
}
for (String name1 : files.keySet()) {
ProjectFile file1 = files.get(name1);
ProjectFile file2 = version_json.files.get(name1);
//---
String text1 = "";
String text2 = "";
try {
text1 = FileUtils.readFileToString(file1.file, Charset.defaultCharset());
} catch (Exception ex) {
ex.printStackTrace();
}
try {
text2 = FileUtils.readFileToString(file2.file, Charset.defaultCharset());
} catch (Exception ex) {
ex.printStackTrace();
}
if (!Utils.compareFortranTexts(text1, text2)) {
return false;
}
}
return true;
}
public MessageError unpackMessage(String line_in) throws Exception {
MessageError res = new MessageError();
res.file = "";
res.line = CommonConstants.Nan;
res.value = "";
String line = line_in.substring(9);
int i = 0;
int s = 0;
String lexeme = "";
//#1020: red43.fdv: line 988]: Active DVM directives are not supported (turn on DVM-directive support option)
for (char c : line.toCharArray()) {
switch (s) {
case 0:
//поиск groups_s
if (c == '#') {
s = 1;
lexeme = "";
} else return null;
break;
case 1:
//group_s
if (isDigit(c)) {
res.group_s += c;
lexeme += c;
} else if (c == ':') {
s = 2;
res.group = Integer.parseInt(lexeme);
} else return null;
break;
case 2:
//поиск filename
if (c == ' ') {
s = 3;
} else return null;
break;
case 3:
//filename
if (c == ':') {
s = 4;
} else {
res.file += c;
}
break;
case 4:
//поиск line
if (c == ' ') {
s = 5;
lexeme = "";
} else return null;
break;
case 5:
//line
if (c == ' ') {
if (!lexeme.equals("line"))
return null;
else {
s = 6;
lexeme = "";
}
} else {
lexeme += c;
}
break;
case 6:
//line number
if (isDigit(c)) {
lexeme += c;
} else if (c == ']') {
res.line = Integer.parseInt(lexeme);
s = 7;
} else return null;
break;
case 7:
//Поиск value
if (c == ':') {
s = 8;
} else return null;
break;
case 8:
if (c == ' ') {
s = 9;
} else return null;
break;
case 9:
//value
res.value += c;
break;
}
;
++i;
}
//--
if (s != 9)
return null;
//--
return res;
}
public void readMessagesFromFileDump(File file, Vector<MessageError> messages) {
try {
//Образец запакованного сообщения
//ERROR - [#1020: red43.fdv: line 988]: Active DVM directives are not supported (turn on DVM-directive support option)
Vector<String> lines = new Vector<>(FileUtils.readLines(file));
if (!lines.isEmpty()) {
for (int i = lines.size() - 1; i >= 0; --i) {
String line = lines.get(i);
if (line.startsWith("ERROR - ")) {
MessageError message = unpackMessage(line);
if (message != null)
messages.add(message);
//--
} else break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
//--
public void createProject(File rootHome) throws Exception {
project = null;
String version_ = CommonUtils.isWindows() ? CommonUtils.toW(version) : CommonUtils.toU(version);
project = new db_project_info();
project.Home = Paths.get(rootHome.getAbsolutePath(), version_).toFile();
project.name = project.Home.getName();
project.description = description;
project.languageName = LanguageName.fortran;
project.creationDate = CommonUtils.getDateNumber();
//---
FileUtils.copyDirectory(Home, project.Home);
///--------------------------------------
project.CreateVisualiserData();
}
public void ReadMessages() throws Exception {
if (project != null) {
Vector<MessageError> messages = new Vector<>();
//--
File p_out = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile();
File p_err = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile();
File out = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile();
File err = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile();
//--
if (p_out.exists()) {
project.Log += (FileUtils.readFileToString(p_out));
readMessagesFromFileDump(p_out, messages);
}
if (out.exists()) {
project.Log += "\n" + FileUtils.readFileToString(out);
readMessagesFromFileDump(out, messages);
}
//в потоки ошибок идет информация от операционной системы. сообщений там быть не должно.
if (p_err.exists())
project.Log += (FileUtils.readFileToString(p_err));
if (err.exists())
project.Log += "\n" + FileUtils.readFileToString(err);
//--
project.Open();
project.Update(); //Журнал
//а так же, убрать dep и txt
project.db.BeginTransaction();
for (MessageError m : messages) {
if (project.db.files.containsKey(m.file)) {
DBProjectFile file = project.db.files.Data.get(m.file);
file.CreateAndAddNewMessage(1, m.value, m.line, m.group);
//update file
project.db.Update(file);
}
}
project.db.Commit();
project.db.Disconnect();
}
}
@Override
public String toString() {
return Home.getName() + " : " + CommonUtils.Brackets(description) + " файлы: " + files.size();
}
}

View File

@@ -0,0 +1,6 @@
package _VisualDVM.TestingSystem.SAPFOR.Json;
public enum VersionComparisonState {
Unknown,
Match, //версия совпадает
NotMatch
}

View File

@@ -0,0 +1,64 @@
package _VisualDVM.TestingSystem.SAPFOR;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Utils;
import _VisualDVM.TestingSystem.Common.TaskThread;
import _VisualDVM.TestingSystem.Common.ThreadsPlanner.ThreadsPlanner;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforPackage_json;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Date;
public class PackageModeSupervisor extends ThreadsPlanner {
SapforPackage_json package_json = null;
File sapfor_drv = null;
public PackageModeSupervisor() throws Exception {
super(2000);
package_json = (SapforPackage_json) CommonUtils.jsonFromFile(new File(Constants.package_json), SapforPackage_json.class);
//--
File sapfor_src = new File(package_json.sapfor_drv);
sapfor_drv = new File(CommonUtils.getHomeDirectory(), CommonUtils.getDateName("SAPFOR_F"));
FileUtils.copyFile(sapfor_src, sapfor_drv);
if (!sapfor_drv.setExecutable(true))
throw new Exception("Не удалось сделать файл " + sapfor_drv.getName() + " исполняемым!");
File PID = new File("PID");
FileUtils.writeStringToFile(PID, sapfor_drv.getName(), Charset.defaultCharset());
//---
Date startDate = new Date();
File started = new File(Constants.STARTED);
FileUtils.writeStringToFile(started, String.valueOf(startDate));
//формирование списка задач.
setMaxKernels(package_json.kernels);
for (SapforTask task: package_json.tasks)
addThread(new TaskThread(task,sapfor_drv));
interruptThread.start();
}
@Override
public String printThread(Integer id) {
TaskThread taskThread = (TaskThread) threads.get(id);
return taskThread.task.getSummary();
}
@Override
protected void finalize() {
//записать результаты всех задач.
try {
CommonUtils.jsonToFile(package_json, new File(Constants.package_json));
FileUtils.writeStringToFile(new File(Constants.DONE), "");
//--
//Очистка
//очистка служебных файлов.
Utils.deleteFilesByExtensions(CommonUtils.getHomeDirectory(),
"proj", "dep", "jar"
// ,"sh", "exe", "bat"
);
//удаление сапфора
if (sapfor_drv.exists())
FileUtils.forceDelete(sapfor_drv);
} catch (Exception e) {
CommonUtils.MainLog.PrintException(e);
}
System.exit(0);
}
}

View File

@@ -0,0 +1,129 @@
package _VisualDVM.TestingSystem.SAPFOR;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforVersion_json;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import java.io.File;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.Vector;
public class PerformSapforTask extends Pass_2021<SapforTask> {
@Override
public String getDescription() {
return "";
// "Запуск задачи SAPFOR"; Оставляем пустое описание чтобы не засорять журнал.
}
@Override
protected boolean needsAnimation() {
return false;
}
//--
File sapfor_drv;
SapforVersion_json version_json;
//-----
File root;
File parentTask;
File task;
//-----
@Override
protected boolean canStart(Object... args) throws Exception {
//--
target = (SapforTask) args[0];
sapfor_drv = (File) args[1];
//--
version_json = null;
//--->>
parentTask = Paths.get(CommonUtils.getHomePath(),
String.valueOf(target.set_id),
String.valueOf(target.sapfor_configuration_id),
target.test_description).toFile();
root = Paths.get(CommonUtils.getHomePath(), String.valueOf(target.set_id), String.valueOf(target.sapfor_configuration_id)).toFile();
task = null;
//--->>
return true;
}
protected boolean parse() throws Exception {
if (Sapfor.parse(sapfor_drv, parentTask, target.flags)) {
return true;
} else {
target.state = TaskState.DoneWithErrors;
return false;
}
}
//слегка изменить подход.
protected boolean transformation(PassCode_2021 code) throws Exception {
task = new File(parentTask, "v1");
Utils.CheckAndCleanDirectory(task); //папка для преобразования.
//если версия пустая, это тоже результат тестирования. Поэтому должна учитываться в древе.
target.versions.add(version_json = new SapforVersion_json(
root.getAbsolutePath(),
task.getAbsolutePath(), code.getDescription()));
//---
if (Sapfor.performScript(
"transformation",
sapfor_drv,
parentTask,
code.getTestingCommand() + " -F " + CommonUtils.DQuotes(task.getAbsolutePath()),
target.flags,
Constants.out_file,
Constants.err_file
)) {
target.state = TaskState.Done;
parentTask = task;
return true;
}
target.state = TaskState.DoneWithErrors;
return false;
}
protected void variants() throws Exception {
//папки вариантов создается самим сапфором.
target.state = Sapfor.performScript(
"create_variants",
sapfor_drv,
parentTask,
" -t 13 -allVars",// -tinfo",
target.flags,
Constants.out_file,
Constants.err_file
) ? TaskState.Done : TaskState.DoneWithErrors;
//найти папки с вариантами.
File[] files_ = parentTask.listFiles((dir, name) -> dir.isDirectory() && Utils.isParallelVersionName(name));
if ((files_ != null) && (files_.length > 0)) {
Vector<File> files = new Vector<>(Arrays.asList(files_));
files.sort(Comparator.comparingInt(o -> Integer.parseInt(o.getName().substring(1))));
for (File file : files)
target.variants.add(
new SapforVersion_json(
root.getAbsolutePath(),
file.getAbsolutePath(), PassCode_2021.SPF_CreateParallelVariant.getDescription()));
}
}
//-------------------------------------------------->>
@Override
protected void body() throws Exception {
target.StartDate = new Date().getTime();
target.versions.add(version_json = new SapforVersion_json(target.test_description, "исходная"));
String [] data = target.codes.split(" ");
for (String code_s: data){
PassCode_2021 code = PassCode_2021.valueOf(code_s);
//--
if (parse()) {
if (code.equals(PassCode_2021.CreateParallelVariants))
variants();
else if (!transformation(code))
break;
} else
break;
//--
}
target.ChangeDate = new Date().getTime();
}
}

View File

@@ -0,0 +1,43 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration;
import _VisualDVM.ServerObjectsCache.ConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import Common.Utils.TextLog;
import _VisualDVM.ProjectData.LanguageName;
import _VisualDVM.TestingSystem.Common.Configuration.Configuration;
import _VisualDVM.TestingSystem.Common.Group.Group;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import java.util.Vector;
public class SapforConfiguration extends Configuration {
public SapforConfiguration(SapforConfiguration sapforConfiguration) {
this.SynchronizeFields(sapforConfiguration);
}
public SapforConfiguration() {
}
@Override
public boolean validate(TextLog Log) {
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(this);
//--
Vector<Group> groups = cache.getGroups();
Vector<LanguageName> groupsLanguages = new Vector<>();
Vector<SapforSettings> settingsArray= new Vector<>();
//-
//1. проверка цепочек команд на корректность
for (SapforSettings sapforSettings: settingsArray){
sapforSettings.validate(Log);
}
//2. Проверка входящих групп на единственный язык фортран
for (Group group : groups) {
if (!groupsLanguages.contains(group.language))
groupsLanguages.add(group.language);
}
if (groupsLanguages.size()>1){
Log.Writeln_("Запуск тестов на разных языках в рамках одного пакета запрещен!\n");
}
if ((!groupsLanguages.contains(LanguageName.fortran))) {
Log.Writeln_("Поддерживается пакетный режим только для языка Fortran");
}
//-
return Log.isEmpty();
}
}

View File

@@ -0,0 +1,130 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration;
import _VisualDVM.Current;
import Common.Visual.DataSetControlForm;
import Common.Visual.Tables.TableEditors;
import Common.Visual.Tables.TableRenderers;
import _VisualDVM.ServerObjectsCache.ConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import Common.Utils.Vector_;
import Common.Database.Tables.iDBTable;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.UI.SapforConfigurationFields;
import java.util.Vector;
public class SapforConfigurationDBTable extends iDBTable<SapforConfiguration> {
public SapforConfigurationDBTable() {
super(SapforConfiguration.class);
}
@Override
public Current CurrentName() {
return Current.SapforConfiguration;
}
@Override
public String getSingleDescription() {
return "конфигурация тестирования SAPFOR";
}
@Override
public String getPluralDescription() {
return "конфигурации";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
columns.get(4).setRenderer(TableRenderers.RendererAutoConfiguration);
columns.get(4).setEditor(TableEditors.EditorAutoConfiguration);
columns.get(4).setMinWidth(25);
columns.get(4).setMaxWidth(25);
columns.get(6).setMaxWidth(500);
columns.get(7).setRenderer(TableRenderers.RendererMultiline);
columns.get(7).setMaxWidth(500);
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"",
"ядра",
"параметры",
"группы",
"тестов"
};
}
@Override
public Object getFieldAt(SapforConfiguration object, int columnIndex) {
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(object);
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return object.printAuto();
case 5:
return object.kernels;
case 6:
return cache.settingsSummary;
case 7:
return cache.groupsSummary;
case 8:
return cache.getTestsCount();
default:
return null;
}
}
//--
@Override
public DBObjectDialog<SapforConfiguration, SapforConfigurationFields> getDialog() {
return new DBObjectDialog<SapforConfiguration, SapforConfigurationFields>(SapforConfigurationFields.class) {
@Override
public int getDefaultHeight() {
return 200;
}
@Override
public int getDefaultWidth() {
return 450;
}
@Override
public void validateFields() {
}
@Override
public void fillFields() {
fields.tfName.setText(Result.description);
fields.sKernels.setValue(Result.kernels);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.kernels = (int) fields.sKernels.getValue();
}
@Override
public void SetReadonly() {
fields.tfName.setEnabled(false);
fields.sTransformationMaxtime.setEnabled(false);
}
};
}
public Vector<SapforConfiguration> getAutoConfigurations() {
Vector<SapforConfiguration> res = new Vector_<>();
for (SapforConfiguration configuration : Data.values()) {
if (configuration.autoTesting != 0)
res.add(configuration);
}
return res;
}
//патч.потом удалить.
public SapforConfiguration getConfigurationByDescription(String description){
for (SapforConfiguration sapforConfiguration: Data.values())
if (sapforConfiguration.description.equals(description))
return sapforConfiguration;
return null;
}
}

View File

@@ -0,0 +1,17 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration;
import Common.Visual.Menus.DataMenuBar;
import Visual_DVM_2021.Passes.PassCode_2021;
public class SapforConfigurationsMenuBar extends DataMenuBar {
public SapforConfigurationsMenuBar() {
super("конфигурации",
PassCode_2021.PublishSapforConfiguration,
PassCode_2021.EditSapforConfiguration,
PassCode_2021.ShowCurrentSAPFORConfigurationTests,
PassCode_2021.SaveCurrentSAPFORConfiguration,
PassCode_2021.DeleteSapforConfiguration,
PassCode_2021.StartSelectedSAPFORConfigurations
);
}
}

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.UI.SapforConfigurationFields">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="342" height="160"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="d1d6e" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="3257b" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false">
<preferred-size width="99" height="20"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<vspacer id="224d6">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="99" height="14"/>
</grid>
</constraints>
</vspacer>
<component id="1eea4" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false">
<preferred-size width="99" height="20"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="ядра"/>
<toolTipText value="количество ядер, задействованное при тестировани"/>
</properties>
</component>
<component id="ecbf1" class="javax.swing.JTextField" binding="tfName" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="200" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="2a173" class="javax.swing.JSpinner" binding="sKernels">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,27 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.UI;
import _VisualDVM.Constants;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import javax.swing.*;
import java.awt.*;
public class SapforConfigurationFields implements DialogFields {
private JPanel content;
public JTextField tfName;
public JSpinner sTransformationMaxtime;
public JSpinner sKernels;
//--
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
}
public SapforConfigurationFields(){
sKernels.setModel(new SpinnerNumberModel(1, 1,
Constants.testingMaxKernels,
1));
}
}

View File

@@ -0,0 +1,122 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforPackage;
import Common.CommonConstants;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import _VisualDVM.Global;
import _VisualDVM.ServerObjectsCache.ConfigurationCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import Common.Utils.TextLog;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Account.Account;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.TestingSystem.Common.TasksPackageState;
import _VisualDVM.TestingSystem.Common.Test.Test;
import _VisualDVM.TestingSystem.Common.TestingPackage.TestingPackage;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforPackage_json;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Vector;
public class SapforPackage extends TestingPackage<SapforPackage_json> {
public int sapforId = CommonConstants.Nan; // так как сапфор на машине.
//--------------
public SapforPackage() {
}
public SapforPackage(SapforPackage sapforPackage) {
SynchronizeFields(sapforPackage);
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
SapforPackage p = (SapforPackage) src;
sapforId = p.sapforId;
}
@Override
public Class getJsonClass() {
return SapforPackage_json.class;
}
@Override
public File getHomeDirectory() {
return Global.SapforPackagesDirectory;
}
//--
public void init() throws Exception {
for (SapforTask task : package_json.tasks)
task.sapfortaskspackage_id = id;
Utils.CheckAndCleanDirectory(getLocalWorkspace());
saveJson();
package_json = null; // объект больше не нужен.
}
@Override
public boolean isVisible() {
return (!SapforPackageDBTable.filterMyOnly || Current.getAccount().email.equals(sender_address)) &&
(!SapforPackageDBTable.filterActive || state.isActive())
;
}
//---------
//конструктор. если 0 задач по итогу,значит пакет не запускаем вообще, и смотрим журнал.
//Запрещено выполнять на нитях, так как прямой доступ к бд.
public SapforPackage(Account account, ServerSapfor serverSapfor, Vector<SapforConfiguration> configurations,
int neeedsEmail_in,
TextLog Log) throws Exception {
id = CommonConstants.Nan;
sender_name = account.name;
sender_address = account.email;
//-
sapforId = serverSapfor.id;
//-
drv = serverSapfor.call_command;
version = serverSapfor.version;
///-------------------------------
needsEmail = neeedsEmail_in;
//-
state = TasksPackageState.Queued;
//--
boolean valid = true;
//проверка исходных данных тестов и групп
LinkedHashMap<String, Test> testsByDescriptions = new LinkedHashMap<>();
//--
kernels = 1;
for (SapforConfiguration configuration : configurations) {
kernels = Math.max(configuration.kernels, kernels);
configuration.validate(Log);
//-
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(configuration);
//--
for (Test test : cache.getTests()) {
String l_description = test.description.toLowerCase();
if (testsByDescriptions.containsKey(l_description)) {
Log.Writeln_("В пакет не могут входить тесты с одинаковыми именами (без учета регистра):" + test.description.toLowerCase());
valid = false;
} else {
testsByDescriptions.put(l_description, test);
}
}
}
valid = Log.isEmpty();
//формирование задач.
if (valid) {
package_json = new SapforPackage_json(serverSapfor, testsByDescriptions, configurations, kernels);
tasksCount = package_json.tasks.size();
saveConfigurationsAsJson(configurations);
}
}
@Override
public void checkFinishState() throws Exception {
readJson();
int good=0;
int bad = 0;
for (SapforTask task : package_json.tasks) {
if (!task.state.equals(TaskState.Done))
bad++;
else good++;
}
state = (bad > 0) ? TasksPackageState.DoneWithErrors : TasksPackageState.Done;
double percent = ( ((double)(good))/tasksCount)*100.0;
description = "Выполнено на "+((int)percent)+"%\n"+
"Всего задач: "+tasksCount+", из них с ошибками "+bad;
}
}

View File

@@ -0,0 +1,103 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforPackage;
import _VisualDVM.Current;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import _VisualDVM.ServerObjectsCache.PackageCache;
import _VisualDVM.ServerObjectsCache.VisualCaches;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import java.util.Comparator;
import java.util.Date;
import static Common.Visual.Tables.TableRenderers.*;
public class SapforPackageDBTable extends iDBTable<SapforPackage> {
public static boolean filterMyOnly = false;
public static boolean filterActive = false;
@Override
public Current CurrentName() {
return Current.SapforPackage;
}
@Override
public String getSingleDescription() {
return "пакет задач SAPFOR";
}
@Override
public String getPluralDescription() {
return "пакеты задач SAPFOR";
}
public SapforPackageDBTable() {
super(SapforPackage.class);
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
columns.get(4).setRenderer(RendererMultiline);
columns.get(7).setRenderer(RendererProgress);
columns.get(8).setRenderer(RendererDate);
columns.get(9).setRenderer(RendererDate);
columns.get(10).setRenderer(RendererStatusEnum);
}
@Override
public void MouseAction2() throws Exception {
Pass_2021.passes.get(PassCode_2021.CompareSapforPackages).Do();
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Автор",
"SAPFOR",
"Конфигурации",
"Задач",
"Ядер",
"Прогресс",
"Начало",
"Изменено",
"Статус"
};
}
@Override
public Object getFieldAt(SapforPackage object, int columnIndex) {
PackageCache cache = (PackageCache) VisualCaches.GetCache(object);
switch (columnIndex) {
case 2:
return object.sender_name;
case 3:
return object.version;
case 4:
return cache.getConfigurationsDescriptions();
case 5:
return object.tasksCount;
case 6:
return object.kernels;
case 7:
return object.progress;
case 8:
return new Date(object.StartDate);
case 9:
return new Date(object.ChangeDate);
case 10:
return object.state;
default:
return null;
}
}
@Override
public Comparator<SapforPackage> getComparator() {
return new Comparator<SapforPackage>() {
@Override
public int compare(SapforPackage o1, SapforPackage o2) {
return o2.id-o1.id;
}
};
// return Comparator.comparingInt(o -> o.).reversed();
}
}

View File

@@ -0,0 +1,105 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettings;
import Common.Database.Objects.DBObject;
import Common.Utils.CommonUtils;
import _VisualDVM.Global;
import Common.Utils.TextLog;
import _VisualDVM.TestingSystem.Common.Settings.Settings;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommand;
import Visual_DVM_2021.Passes.PassCode_2021;
import java.util.List;
import java.util.Vector;
public class SapforSettings extends Settings {
//настройки.
public int FREE_FORM = 0; //"Свободный выходной стиль"; -f90
public int STATIC_SHADOW_ANALYSIS = 0;//"Оптимизация теневых обменов"; -sh
public int MAX_SHADOW_WIDTH = 50; // "Максимальный размер теневых граней"; (%) -shwidth значение поля
public int KEEP_SPF_DIRECTIVES = 0; //"Сохранять SPF директивы при построении параллельных вариантов"; -keepSPF
public int KEEP_DVM_DIRECTIVES = 0;// "Учитывать DVM директивы"; -keepDVM
//----
//----
public void packFlags() {
Vector<String> res = new Vector<>();
//--
if (FREE_FORM > 0)
res.add("-f90");
if (STATIC_SHADOW_ANALYSIS > 0)
res.add("-sh");
if (MAX_SHADOW_WIDTH > 0)
res.add("-shwidth " + MAX_SHADOW_WIDTH);
if (KEEP_DVM_DIRECTIVES > 0)
res.add("-keepDVM");
if (KEEP_SPF_DIRECTIVES > 0)
res.add("-keepSPF");
//--
flags = String.join(" ", res);
}
//--
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
SapforSettings c = (SapforSettings) src;
FREE_FORM = c.FREE_FORM;
STATIC_SHADOW_ANALYSIS = c.STATIC_SHADOW_ANALYSIS;
MAX_SHADOW_WIDTH = c.MAX_SHADOW_WIDTH;
KEEP_SPF_DIRECTIVES = c.KEEP_SPF_DIRECTIVES;
KEEP_DVM_DIRECTIVES = c.KEEP_DVM_DIRECTIVES;
}
public SapforSettings(SapforSettings sapforSettings) {
this.SynchronizeFields(sapforSettings);
}
public SapforSettings() {
}
public Vector<PassCode_2021> getCodes() {
Vector<PassCode_2021> res = new Vector<>();
for (SapforSettingsCommand command : Global.testingServer.db.sapforSettingsCommands.Data.values())
if (command.sapforsettings_id == id) res.add(command.passCode);
return res;
}
public List<PassCode_2021> getCheckedCodes(){
Vector<PassCode_2021> res = getCodes();
if (!res.firstElement().equals(PassCode_2021.SPF_InsertIncludesPass))
res.insertElementAt(PassCode_2021.SPF_CorrectCodeStylePass,0); //всегда добавляется.
return res;
}
@Override
public boolean validate(TextLog Log) {
boolean res = true;
Vector<PassCode_2021> codes = getCodes();
if (codes.size() == 0) {
Log.Writeln_("Настройки:" + id + " не содержат ни одного прохода.");
return false;
}
//-
int first = 0;
int last = codes.size() - 1;
Vector<PassCode_2021> matches = new Vector<>();
for (int i = 0; i < codes.size(); ++i) {
PassCode_2021 code = codes.get(i);
if (code.isSapforStart()) {
if (i > first) {
Log.Writeln_("Неверные настройки:" + id + ": проход" +
CommonUtils.Brackets(code.getDescription()) +
" может быть только первым!");
res=false;
}
}
if (code.isSapforTerminal()) {
if (i < last) {
Log.Writeln_("Неверные настройки:" + id + ": проход " +
CommonUtils.Brackets(code.getDescription()) +
" может быть только последним!");
res= false;
}
}
if (matches.contains(code)) {
Log.Writeln_("Неверные настройки:" + id + ": проход " +
CommonUtils.Brackets(code.getDescription()) +
" запрещено применять более одного раза!");
res=false;
} else matches.add(code);
}
//-
return res;
}
}

View File

@@ -0,0 +1,13 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettings;
import Common.Visual.Menus.DataMenuBar;
import Visual_DVM_2021.Passes.PassCode_2021;
public class SapforSettingsBar extends DataMenuBar {
public SapforSettingsBar() {
super("параметры тестирования",
PassCode_2021.PublishSapforSettings,
PassCode_2021.CloneSapforSettings,
PassCode_2021.EditSapforSettings,
PassCode_2021.DeleteSapforSettings
);
}
}

View File

@@ -0,0 +1,118 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettings;
import Common.Utils.CommonUtils;
import _VisualDVM.Current;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.FKBehaviour;
import Common.Database.Tables.FKCurrentObjectBehaviuor;
import Common.Database.Tables.FKDataBehaviour;
import Common.Database.Tables.iDBTable;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI.SapforSettingsFields;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommand;
import java.util.LinkedHashMap;
public class SapforSettingsDBTable extends iDBTable<SapforSettings> {
public SapforSettingsDBTable() {
super(SapforSettings.class);
}
@Override
public Current CurrentName() {
return Current.SapforSettings;
}
@Override
public String getSingleDescription() {
return "параметры тестирования системы SAPFOR";
}
@Override
public String getPluralDescription() {
return "параметры тестирования системы SAPFOR";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
/*
columns.get(5).setRenderer(TableRenderers.RendererAutoConfiguration);
columns.get(5).setEditor(TableEditors.EditorAutoConfiguration);
columns.get(5).setMinWidth(25);
columns.get(5).setMaxWidth(25);
columns.get(6).setMaxWidth(300);
*/
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"флаги"
//"проходы"
};
}
@Override
public Object getFieldAt(SapforSettings object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return object.flags;
default:
return null;
}
}
//-
@Override
public DBObjectDialog<SapforSettings, SapforSettingsFields> getDialog() {
return new DBObjectDialog<SapforSettings, SapforSettingsFields>(SapforSettingsFields.class) {
@Override
public int getDefaultHeight() {
return 415;
}
@Override
public int getDefaultWidth() {
return 600;
}
@Override
public void validateFields() {
}
@Override
public void fillFields() {
fields.tfName.setText(Result.description);
fields.cbFREE_FORM.setSelected(Result.FREE_FORM != 0);
fields.cbKEEP_DVM_DIRECTIVES.setSelected(Result.KEEP_DVM_DIRECTIVES != 0);
fields.cbKEEP_SPF_DIRECTIVES.setSelected(Result.KEEP_SPF_DIRECTIVES != 0);
fields.cbSTATIC_SHADOW_ANALYSIS.setSelected(Result.STATIC_SHADOW_ANALYSIS != 0);
fields.sMAX_SHADOW_WIDTH.setValue(Result.MAX_SHADOW_WIDTH);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.FREE_FORM = CommonUtils.fromBoolean(fields.cbFREE_FORM.isSelected());
Result.KEEP_DVM_DIRECTIVES = CommonUtils.fromBoolean(fields.cbKEEP_DVM_DIRECTIVES.isSelected());
Result.KEEP_SPF_DIRECTIVES = CommonUtils.fromBoolean(fields.cbKEEP_SPF_DIRECTIVES.isSelected());
Result.STATIC_SHADOW_ANALYSIS = CommonUtils.fromBoolean(fields.cbSTATIC_SHADOW_ANALYSIS.isSelected());
Result.MAX_SHADOW_WIDTH = fields.sMAX_SHADOW_WIDTH.getValue();
Result.packFlags();
}
@Override
public void SetReadonly() {
fields.tfName.setEnabled(false);
}
};
}
@Override
public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
res.put(SapforSettingsCommand.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
return res;
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI.SapforSettingsCommandFields">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4edf7" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="проход"/>
</properties>
</component>
<vspacer id="40ef0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="64847" class="javax.swing.JComboBox" binding="cbPassCode" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<toolTipText value="выберите проход"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@@ -0,0 +1,33 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI;
import Common.Visual.CommonUI;
import Common.Visual.Tables.StyledCellLabel;
import Common.Visual.Windows.Dialog.DialogFields;
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
import Visual_DVM_2021.Passes.PassCode_2021;
import javax.swing.*;
import java.awt.*;
public class SapforSettingsCommandFields implements DialogFields {
private JPanel content;
public JComboBox<PassCode_2021> cbPassCode;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
cbPassCode = new JComboBox<>();
cbPassCode.setRenderer((list, value, index, isSelected, cellHasFocus) -> {
JLabel res = new StyledCellLabel();
res.setText(value.getDescription());
res.setBackground(isSelected ?
CommonUI.getTheme().selection_background : CommonUI.getTheme().background
);
return res;
});
//-
for (PassCode_2021 code : Sapfor.getScenariosCodes())
cbPassCode.addItem(code);
}
}

View File

@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI.SapforSettingsFields">
<grid id="27dc6" binding="content" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="528" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="3b4b2" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="2c43d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false">
<preferred-size width="284" height="20"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<vspacer id="2c147">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<preferred-size width="284" height="14"/>
</grid>
</constraints>
</vspacer>
<component id="7844f" class="javax.swing.JTextField" binding="tfName" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="200" height="30"/>
<preferred-size width="200" height="30"/>
<maximum-size width="200" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="7788a" class="javax.swing.JCheckBox" binding="cbFREE_FORM">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="284" height="25"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="14" style="2"/>
<icon value="icons/NotPick.png"/>
<selectedIcon value="icons/Pick.png"/>
<text value="Свободный выходной стиль"/>
</properties>
</component>
<component id="243fb" class="javax.swing.JCheckBox" binding="cbKEEP_SPF_DIRECTIVES">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="284" height="25"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="14" style="2"/>
<icon value="icons/NotPick.png"/>
<selectedIcon value="icons/Pick.png"/>
<text value="Сохранять SPF директивы"/>
</properties>
</component>
<component id="16d89" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="3" use-parent-layout="false">
<preferred-size width="284" height="17"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="14" style="2"/>
<text value="Максимальный размер теневых граней, %"/>
</properties>
</component>
<component id="5eba5" class="javax.swing.JCheckBox" binding="cbSTATIC_SHADOW_ANALYSIS">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="284" height="25"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="14" style="2"/>
<icon value="icons/NotPick.png"/>
<selectedIcon value="icons/Pick.png"/>
<text value="Оптимизация теневых обменов"/>
</properties>
</component>
<component id="27b84" class="javax.swing.JCheckBox" binding="cbKEEP_DVM_DIRECTIVES">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="284" height="25"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="14" style="2"/>
<icon value="icons/NotPick.png"/>
<selectedIcon value="icons/Pick.png"/>
<text value="Учитывать DVM директивы"/>
</properties>
</component>
<component id="d47f0" class="javax.swing.JSlider" binding="sMAX_SHADOW_WIDTH">
<constraints>
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="500" height="40"/>
<preferred-size width="500" height="40"/>
<maximum-size width="500" height="40"/>
</grid>
</constraints>
<properties>
<majorTickSpacing value="25"/>
<minorTickSpacing value="1"/>
<paintLabels value="true"/>
<paintTicks value="true"/>
<snapToTicks value="false"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -0,0 +1,23 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI;
import Common.Visual.TextField.StyledTextField;
import Common.Visual.Windows.Dialog.DialogFields;
import javax.swing.*;
import java.awt.*;
public class SapforSettingsFields implements DialogFields {
private JPanel content;
public JTextField tfName;
public JCheckBox cbFREE_FORM;
public JCheckBox cbKEEP_SPF_DIRECTIVES;
public JCheckBox cbSTATIC_SHADOW_ANALYSIS;
public JCheckBox cbKEEP_DVM_DIRECTIVES;
public JSlider sMAX_SHADOW_WIDTH;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
}
}

View File

@@ -0,0 +1,28 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand;
import Common.CommonConstants;
import _VisualDVM.Current;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import Visual_DVM_2021.Passes.PassCode_2021;
import com.sun.org.glassfish.gmbal.Description;
public class SapforSettingsCommand extends riDBObject {
@Description("DEFAULT -1")
public int sapforsettings_id = CommonConstants.Nan;
public PassCode_2021 passCode = PassCode_2021.SPF_RemoveDvmDirectives;
@Override
public boolean isVisible() {
return Current.HasSapforSettings() && (Current.getSapforSettings().id == sapforsettings_id);
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
SapforSettingsCommand c = (SapforSettingsCommand) src;
sapforsettings_id = c.sapforsettings_id;
passCode = c.passCode;
}
public SapforSettingsCommand() {
}
public SapforSettingsCommand(SapforSettingsCommand sapforSettingsCommand) {
this.SynchronizeFields(sapforSettingsCommand);
}
}

View File

@@ -0,0 +1,12 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand;
import Common.Visual.Menus.DataMenuBar;
import Visual_DVM_2021.Passes.PassCode_2021;
public class SapforSettingsCommandsBar extends DataMenuBar {
public SapforSettingsCommandsBar() {
super("команды",
PassCode_2021.PublishSapforSettingsCommand,
PassCode_2021.EditSapforSettingsCommand,
PassCode_2021.DeleteSapforSettingsCommand
);
}
}

View File

@@ -0,0 +1,83 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand;
import Common.Visual.CommonUI;
import _VisualDVM.Current;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.UI.SapforSettingsCommandFields;
import Visual_DVM_2021.Passes.PassCode_2021;
import java.util.Vector;
public class SapforSettingsCommandsDBTable extends iDBTable<SapforSettingsCommand> {
public SapforSettingsCommandsDBTable() {
super(SapforSettingsCommand.class);
}
@Override
public String getSingleDescription() {
return "команда";
}
@Override
public String getPluralDescription() {
return "команды";
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Проход"
};
}
@Override
public Object getFieldAt(SapforSettingsCommand object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.passCode.getDescription();
default:
return null;
}
}
@Override
public Current CurrentName() {
return Current.SapforSettingsCommand;
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
public boolean hasCheckBox() {
return true;
}
@Override
protected void AdditionalInitColumns() {
//columns.get(0).setVisible(false);
}
};
}
@Override
public DBObjectDialog<SapforSettingsCommand, SapforSettingsCommandFields> getDialog() {
return new DBObjectDialog<SapforSettingsCommand, SapforSettingsCommandFields>(SapforSettingsCommandFields.class) {
@Override
public int getDefaultHeight() {
return 250;
}
@Override
public void fillFields() {
CommonUI.TrySelect(fields.cbPassCode, Result.passCode);
}
@Override
public void ProcessResult() {
Result.passCode = (PassCode_2021) fields.cbPassCode.getSelectedItem();
Result.sapforsettings_id = Current.getSapforSettings().id;
}
};
}
//--
public Vector<PassCode_2021> getCodes(SapforSettings sapforSettings) {
Vector<PassCode_2021> res = new Vector<>();
for (SapforSettingsCommand command : Data.values()) {
if (command.sapforsettings_id == sapforSettings.id)
res.add(command.passCode);
}
return res;
}
}

View File

@@ -0,0 +1,33 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTask;
import Common.Visual.StatusEnum;
import Common.Visual.Fonts.VisualiserFonts;
public enum ComparisonState implements StatusEnum {
Unknown,
NotMatch,
Match;
public String getDescription() {
switch (this) {
case Unknown:
return "неизвестно";
case Match:
return "совпадений";
case NotMatch:
return "различий";
default:
return "?";
}
}
@Override
public VisualiserFonts getFont() {
switch (this) {
case Unknown:
return VisualiserFonts.UnknownState;
case Match:
return VisualiserFonts.GoodState;
case NotMatch:
return VisualiserFonts.BadState;
default:
return StatusEnum.super.getFont();
}
}
}

View File

@@ -0,0 +1,241 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTask;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import Common.Database.Objects.DBObject;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.TestingSystem.SAPFOR.Json.*;
import _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI.SapforPackageTreeNode;
import _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI.SapforTaskNode;
import _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI.VersionNode;
import Visual_DVM_2021.Passes.PassCode_2021;
import com.google.gson.annotations.Expose;
import com.sun.org.glassfish.gmbal.Description;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Vector;
public class SapforTask extends DBObject {
//------------------------------------>>
@Expose
public long id = CommonConstants.Nan;
@Expose
public int set_id = 0;
@Expose
public int sapfor_configuration_id = CommonConstants.Nan;
@Expose
public long sapfortaskspackage_id = CommonConstants.Nan;
//------------------------------------->>
@Expose
public String test_description = "";
@Expose
public String group_description = "";
@Expose
public String flags = "";
@Expose
public String codes = "";
@Expose
public long StartDate = 0; //дата начала выполнения
@Expose
public long ChangeDate = 0;//дата окончания выполнения
//в json не выносить. это только для БД.
@Description("DEFAULT ''")
public String versionsDescription = "";
//------
@Description("IGNORE")
@Expose
public Vector<SapforVersion_json> versions = new Vector<>();
//----------
@Description("IGNORE")
@Expose
public Vector<SapforVersion_json> variants = new Vector<>();
//-------------------------------------------------
@Expose
public TaskState state = TaskState.Inactive;
@Description("IGNORE")
public ComparisonState comparisonState = ComparisonState.Unknown; //для сравнения. в обычном режиме всегда Unknown!
//--------------------------------------------------
public String getUniqueKey() {
return group_description + "_" + test_description + "_" + sapfor_configuration_id;
}
public String getSummary() {
Vector<String> lines = new Vector<>();
lines.add(group_description);
lines.add(test_description);
lines.add(codes);
lines.add(flags);
return String.join(" ", lines);
}
//-----------
public SapforTask() {
}
public void Reset() {
state = TaskState.Inactive;
versions.clear();
variants.clear();
}
public SapforTask(SapforTask src) {
this.SynchronizeFields(src);
}
@Override
public Object getPK() {
return id;
}
@Override
public void SynchronizeFields(DBObject object) {
super.SynchronizeFields(object);
SapforTask t = (SapforTask) object;
id = t.id;
set_id = t.set_id;
sapfor_configuration_id = t.sapfor_configuration_id;
sapfortaskspackage_id = t.sapfortaskspackage_id;
//-
test_description = t.test_description;
group_description = t.group_description;
versionsDescription = t.versionsDescription;
//--
codes = t.codes;
state = t.state;
//--
}
public String getVersionsChain() {
Vector<String> versionsLines = new Vector<>();
for (int i = 1; i < versions.size(); ++i) {
versionsLines.add(CommonUtils.Brackets(versions.get(i).description));
}
if (!variants.isEmpty()) {
versionsLines.add(CommonUtils.Brackets(PassCode_2021.CreateParallelVariants.getDescription()));
}
return String.join("", versionsLines);
}
public LinkedHashMap<String, SapforVersion_json> getSortedVersions() {
LinkedHashMap<String, SapforVersion_json> res = new LinkedHashMap<>();
for (SapforVersion_json version_json : versions)
res.put(version_json.version, version_json);
//--
for (SapforVersion_json variant_json : variants)
res.put(variant_json.version, variant_json);
return res;
}
public void checkMatch(SapforTask task2) {
if (!state.equals(task2.state)) {
comparisonState = ComparisonState.NotMatch;
task2.comparisonState = ComparisonState.NotMatch;
}
if ((versions.size() != task2.versions.size()) || (variants.size() != task2.variants.size())) {
comparisonState = ComparisonState.NotMatch;
task2.comparisonState = ComparisonState.NotMatch;
}
LinkedHashMap<String, SapforVersion_json> versions1 = getSortedVersions();
LinkedHashMap<String, SapforVersion_json> versions2 = task2.getSortedVersions();
//---
for (String name1 : versions1.keySet()) {
if (versions2.containsKey(name1)) {
SapforVersion_json version1 = versions1.get(name1);
SapforVersion_json version2 = versions2.get(name1);
//---
if (!version1.isMatch(version2)) {
comparisonState = ComparisonState.NotMatch;
task2.comparisonState = ComparisonState.NotMatch;
version1.comparisonState = VersionComparisonState.NotMatch;
version2.comparisonState = VersionComparisonState.NotMatch;
//-
}else {
version1.comparisonState = VersionComparisonState.Match;
version2.comparisonState = VersionComparisonState.Match;
//-
}
} else {
comparisonState = ComparisonState.NotMatch;
task2.comparisonState = ComparisonState.NotMatch;
//--
}
}
//--
if (comparisonState.equals(ComparisonState.Unknown)) {
comparisonState = ComparisonState.Match;
task2.comparisonState = ComparisonState.Match;
}
}
public Date getStartDate() {
return new Date(StartDate);
}
public Date getChangeDate() {
return new Date(ChangeDate);
}
@Override
public String toString() {
return
"#" + id + " группа " + CommonUtils.Brackets(group_description) + " тест " + CommonUtils.Brackets(test_description) + " параметры " + CommonUtils.Brackets(sapfor_configuration_id);
// getUniqueKey();
}
public String getPassesInfo() {
String res = "";
String[] data = codes.split(" ");
Vector<String> strings = new Vector<>();
for (String code_s : data) {
PassCode_2021 code = PassCode_2021.valueOf(code_s);
strings.add(CommonUtils.Brackets(code.getDescription()));
}
return String.join("", strings);
}
//---
public DefaultMutableTreeNode getVersionsTree() {
VersionNode root = null;
VersionNode child = null;
VersionNode parent = null;
//--
for (SapforVersion_json version_json : versions) {
version_json.task = this;
child = new VersionNode(version_json);
if (parent == null) {
root = child;
parent = child;
} else {
parent.add(child);
parent = child;
}
//-
}
if (parent != null) {
for (SapforVersion_json version_json : variants) {
version_json.task = this;
parent.add(new VersionNode(version_json));
}
}
//--
return root;
}
//---
public DefaultMutableTreeNode getNode(File configurationRoot) {
SapforPackageTreeNode res = new SapforTaskNode(this);
//-
DefaultMutableTreeNode flags_info = new DefaultMutableTreeNode("флаги: " + this.flags);
DefaultMutableTreeNode passes_info = new DefaultMutableTreeNode("проходы: " + getPassesInfo());
//-
int total_versions_count = versions.size() + variants.size();
DefaultMutableTreeNode versions_info = new DefaultMutableTreeNode("версии: " + total_versions_count);
versions_info.add(getVersionsTree());
res.add(flags_info);
res.add(passes_info);
res.add(versions_info);
return res;
}
//-
public SapforTask(SapforTestingSet_json testingSet, SapforTest_json test, SapforConfiguration_json sapforConfiguration_json) {
id = CommonConstants.Nan;
set_id = testingSet.id;
sapfortaskspackage_id = CommonConstants.Nan;
//-- unique key--
group_description = test.group_description;
test_description = test.description;
sapfor_configuration_id = sapforConfiguration_json.id;
//---------------
flags = sapforConfiguration_json.flags;
Vector<String> codes_s = new Vector<>();
for (PassCode_2021 code : sapforConfiguration_json.codes)
codes_s.add(code.toString());
codes = String.join(" ", codes_s);
}
}

View File

@@ -0,0 +1,8 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import _VisualDVM.Visual.Menus.VisualiserMenu;
public class AddSapforPackageMenu extends VisualiserMenu {
public AddSapforPackageMenu() {
super("", "/icons/RedAdd.png");
// addPasses(PassCode_2021.AddSapforPackage,PassCode_2021.CloneSapforPackage);
}
}

View File

@@ -0,0 +1,15 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
public class PackageComparisonSummary extends SapforPackageTreeNode {
public int count = 0;
public int mismatches_count = 0;
@Override
public String getImageKey() {
return "Package";
}
public PackageComparisonSummary() {
}
@Override
public String toString() {
return "всего задач : " + count + ", различий : " + mismatches_count;
}
}

View File

@@ -0,0 +1,15 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
public class PackageSummary extends SapforPackageTreeNode {
public int count = 0;
public int errors_count=0;
@Override
public String getImageKey() {
return "Package";
}
public PackageSummary() {
}
@Override
public String toString() {
return "всего задач : " + count+", с ошибками : "+errors_count;
}
}

View File

@@ -0,0 +1,16 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import Common.Utils.CommonUtils;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public abstract class SapforPackageTreeNode extends DefaultMutableTreeNode {
public ImageIcon getIcon() {
ImageIcon res = new ImageIcon((getClass().getResource("/icons/versions/" + getImageKey() + ".png")));
if (res==null) {
CommonUtils.MainLog.Print("/icons/versions/" + getImageKey() + ".png=NULL");
// res= new ImageIcon((getClass().getResource("/icons/versions/Version.png")));
}
return (getImageKey() != null) ? res : null;
}
public abstract String getImageKey();
}

View File

@@ -0,0 +1,52 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import Common.Utils.CommonUtils;
import _VisualDVM.Global;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Controls.MenuBarButton;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackageDBTable;
import Visual_DVM_2021.Passes.PassCode_2021;
import javax.swing.*;
public class SapforPackagesBar extends DataMenuBar {
public SapforPackagesBar() {
super("пакеты задач SAPFOR");
addPasses(PassCode_2021.SynchronizeTests);
addSeparator();
addPasses(PassCode_2021.AbortSapforPackage);
addSeparator();
addPasses(PassCode_2021.CompareSapforPackages);
addSeparator();
addPasses(PassCode_2021.DeleteSapforPackage);
add(new JSeparator());
add(new MenuBarButton() {
{
setText("Свои");
setToolTipText("Отображать только пакеты тестов авторства пользователя");
Mark();
addActionListener(e -> {
SapforPackageDBTable.filterMyOnly = !SapforPackageDBTable.filterMyOnly;
Mark();
Global.testingServer.db.sapforPackages.ShowUI();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(SapforPackageDBTable.filterMyOnly ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
add(new MenuBarButton() {
{
setText("Активные");
setToolTipText("Отображать только активные пакеты тестов");
Mark();
addActionListener(e -> {
SapforPackageDBTable.filterActive = !SapforPackageDBTable.filterActive;
Mark();
Global.testingServer.db.sapforPackages.ShowUI();
});
}
public void Mark() {
setIcon(CommonUtils.getIcon(SapforPackageDBTable.filterActive ? "/icons/Pick.png" : "/icons/NotPick.png"));
}
});
}
}

View File

@@ -0,0 +1,20 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.ComparisonState;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
public class SapforTaskNode extends SapforPackageTreeNode {
public SapforTaskNode(SapforTask task_in) {
setUserObject(task_in);
}
@Override
public String getImageKey() {
SapforTask task = (SapforTask) getUserObject();
//обычный режим
if (task.comparisonState == ComparisonState.Unknown) {
return task.state.toString();
}
//режим сравнения.
else {
return task.comparisonState.toString()+task.state.toString();
}
}
}

View File

@@ -0,0 +1,71 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import Common.CurrentAnchestor;
import _VisualDVM.Current;
import Common.Visual.Trees.DataTree;
import Common.Visual.Trees.TreeRenderers;
import _VisualDVM.Visual.UI;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforVersion_json;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.util.Vector;
public class SapforTasksPackageTree extends DataTree {
Current current;
SapforTasksPackageTree slave_tree = null;
public void setSlaveTree(SapforTasksPackageTree slave_tree_in) {
slave_tree = slave_tree_in;
}
public SapforTasksPackageTree(DefaultMutableTreeNode root_in, Current current_in) {
super(root_in);
current = current_in;
}
@Override
protected int getStartLine() {
return 1;
}
@Override
public TreeRenderers getRenderer() {
return TreeRenderers.RendererSapforVersion;
}
@Override
public Current getCurrent() {
return current;
}
public void selectSamePath_r(TreePath example, int index, DefaultMutableTreeNode node, Vector<DefaultMutableTreeNode> res) {
if (index < example.getPathCount()) {
DefaultMutableTreeNode exampleNode = (DefaultMutableTreeNode) example.getPathComponent(index);
if (exampleNode.toString().equals(node.toString())) {
res.add(node);
for (int i = 0; i < node.getChildCount(); ++i)
selectSamePath_r(example, index + 1, (DefaultMutableTreeNode) node.getChildAt(i), res);
}
}
}
public void selectSamePath(TreePath path_in) {
Vector<DefaultMutableTreeNode> pathNodes = new Vector<>();
selectSamePath_r(path_in, 0, root, pathNodes);
if (!pathNodes.isEmpty()) {
TreePath path = new TreePath(pathNodes.toArray());
setSelectionPath(path);
}
}
@Override
public void SelectionAction(TreePath e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getLastPathComponent();
Object o = node.getUserObject();
//---
if (slave_tree != null) {
slave_tree.selectSamePath(e);
}
//---
if (o instanceof SapforVersion_json) {
SapforVersion_json version = (SapforVersion_json) o;
CurrentAnchestor.set(current, version);
if (current.equals(Current.SapforEtalonVersion))
UI.getMainWindow().getTestingWindow().ShowCurrentSapforPackageVersionEtalon();
else
UI.getMainWindow().getTestingWindow().ShowCurrentSapforPackageVersion();
//--
}
}
}

View File

@@ -0,0 +1,20 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import Common.Visual.Trees.StyledTreeCellRenderer;
import javax.swing.*;
public class SapforVersionsTreeCellRenderer extends StyledTreeCellRenderer {
public java.awt.Component getTreeCellRendererComponent(
JTree tree, Object value,
boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (value instanceof SapforPackageTreeNode) {
SapforPackageTreeNode node = (SapforPackageTreeNode) value;
setForeground(tree.getForeground());
setFont(getFont().deriveFont((float) 14.0));
if (node.getIcon() != null)
setIcon(node.getIcon());
}
return this;
}
}

View File

@@ -0,0 +1,15 @@
package _VisualDVM.TestingSystem.SAPFOR.SapforTasksPackage.UI;
import javax.swing.*;
import java.util.Objects;
public abstract class TreeSummary {
public String text = "";
public abstract void refreshText();
@Override
public String toString() {
return text;
}
public ImageIcon getIcon() {
return new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/versions/" + getImageKey() + ".png")));
}
public abstract String getImageKey();
}

Some files were not shown because too many files have changed in this diff Show More