no message
This commit is contained in:
118
src/TestingSystem/Common/Group/Group.java
Normal file
118
src/TestingSystem/Common/Group/Group.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package TestingSystem.Common.Group;
|
||||
import Common.Current;
|
||||
import Common.Database.DBObject;
|
||||
import Common.Database.riDBObject;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.Utils.Utils;
|
||||
import ProjectData.Files.DBProjectFile;
|
||||
import ProjectData.LanguageName;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import 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;
|
||||
//--
|
||||
@Description("IGNORE")
|
||||
public LinkedHashMap<String, byte[]> testsFiles = new LinkedHashMap<>(); //транспорт.
|
||||
//--
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return (!GroupsDBTable.filterMyOnly || Current.getAccount().email.equals(sender_address)) &&
|
||||
Global.testingServer.db.groups.applyFilters(this);
|
||||
}
|
||||
//-
|
||||
public static void generateForLanguage(
|
||||
String dvm_drv,
|
||||
LinkedHashMap<LanguageName, Vector<DBProjectFile>> 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 (DBProjectFile program : programs.get(language)) {
|
||||
//--
|
||||
program.last_assembly_name = language + "_" + i + ".o";
|
||||
String object = Utils.DQuotes(program.last_assembly_name);
|
||||
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=" + Utils.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(db_project_info project, String dvm_drv, String flags_in) {
|
||||
//----->>
|
||||
LinkedHashMap<LanguageName, Vector<DBProjectFile>> programs = project.getPrograms();
|
||||
Vector<String> titles = new Vector<>();
|
||||
Vector<String> objects = new Vector<>();
|
||||
Vector<String> bodies = new Vector<>();
|
||||
String binary = Utils.DQuotes("0");
|
||||
//----->>
|
||||
generateForLanguage(dvm_drv, programs, language, titles, objects, bodies, flags_in);
|
||||
//----->>
|
||||
return String.join("\n",
|
||||
"LINK_COMMAND=" + Utils.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));
|
||||
}
|
||||
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 (Current.hasUI())
|
||||
UI.getMainWindow().ShowCheckedTestsCount();
|
||||
}
|
||||
}
|
||||
186
src/TestingSystem/Common/Group/GroupsDBTable.java
Normal file
186
src/TestingSystem/Common/Group/GroupsDBTable.java
Normal file
@@ -0,0 +1,186 @@
|
||||
package TestingSystem.Common.Group;
|
||||
import Common.Current;
|
||||
import Common.Database.*;
|
||||
import Common.UI.DataSetControlForm;
|
||||
import Common.UI.Menus_2023.GroupsMenuBar.GroupsMenuBar;
|
||||
import Common.UI.Menus_2023.VisualiserMenu;
|
||||
import Common.UI.UI;
|
||||
import Common.UI.Windows.Dialog.DBObjectDialog;
|
||||
import ProjectData.LanguageName;
|
||||
import TestingSystem.Common.Group.UI.GroupFields;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
import TestingSystem.Common.Test.TestType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
//-
|
||||
public class GroupsDBTable extends iDBTable<Group> {
|
||||
public static boolean filterMyOnly = false;
|
||||
public Vector<TableFilter<Group>> typeFilters;
|
||||
public Vector<TableFilter<Group>> languageFilters;
|
||||
//------------------------------------------------>>>
|
||||
public GroupsDBTable() {
|
||||
super(Group.class);
|
||||
if (Current.hasUI()) {
|
||||
//--
|
||||
typeFilters = new Vector<>();
|
||||
languageFilters = new Vector<>();
|
||||
//--
|
||||
for (TestType type : TestType.values()) {
|
||||
typeFilters.add(
|
||||
new TableFilter<Group>(this, type.getDescription()) {
|
||||
@Override
|
||||
protected boolean validate(Group object) {
|
||||
return object.type.equals(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
//--
|
||||
for (LanguageName languageName : LanguageName.values()) {
|
||||
languageFilters.add(new TableFilter<Group>(this, languageName.getDescription()) {
|
||||
@Override
|
||||
protected boolean validate(Group object) {
|
||||
return object.language.equals(languageName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mountUI(JPanel content_in) {
|
||||
super.mountUI(content_in);
|
||||
//---
|
||||
GroupsMenuBar menuBar = (GroupsMenuBar) UI.menuBars.get(getClass());
|
||||
menuBar.DropFilters();
|
||||
//----
|
||||
menuBar.addFilters(
|
||||
new VisualiserMenu("Тип", "/icons/Filter.png", true) {
|
||||
{
|
||||
for (TableFilter filter : typeFilters)
|
||||
add(filter.menuItem);
|
||||
}
|
||||
},
|
||||
new VisualiserMenu("Язык", "/icons/Filter.png", true) {
|
||||
{
|
||||
for (TableFilter filter : languageFilters)
|
||||
add(filter.menuItem);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void ResetFiltersCount() {
|
||||
for (TableFilter filter : typeFilters)
|
||||
filter.count = 0;
|
||||
for (TableFilter filter : languageFilters)
|
||||
filter.count = 0;
|
||||
}
|
||||
public void ShowFiltersCount() {
|
||||
for (TableFilter filter : typeFilters)
|
||||
filter.ShowDescriptionAndCount();
|
||||
for (TableFilter filter : languageFilters)
|
||||
filter.ShowDescriptionAndCount();
|
||||
}
|
||||
public boolean applyFilters(Group object) {
|
||||
for (TableFilter filter : typeFilters)
|
||||
if (!filter.Validate(object)) return false;
|
||||
for (TableFilter filter : languageFilters)
|
||||
if (!filter.Validate(object)) return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void ShowUI() {
|
||||
ResetFiltersCount();
|
||||
super.ShowUI();
|
||||
ShowFiltersCount();
|
||||
}
|
||||
@Override
|
||||
public void ShowUI(Object key) {
|
||||
ResetFiltersCount();
|
||||
super.ShowUI(key);
|
||||
ShowFiltersCount();
|
||||
}
|
||||
@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
|
||||
protected void AdditionalInitColumns() {
|
||||
//columns.get(0).setVisible(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
@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);
|
||||
UI.TrySelect(fields.cbType, Result.type);
|
||||
UI.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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
80
src/TestingSystem/Common/Group/UI/GroupFields.form
Normal file
80
src/TestingSystem/Common/Group/UI/GroupFields.form
Normal 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="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>
|
||||
32
src/TestingSystem/Common/Group/UI/GroupFields.java
Normal file
32
src/TestingSystem/Common/Group/UI/GroupFields.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package TestingSystem.Common.Group.UI;
|
||||
import Common.UI.TextField.StyledTextField;
|
||||
import Common.UI.Windows.Dialog.DialogFields;
|
||||
import ProjectData.LanguageName;
|
||||
import 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);
|
||||
}
|
||||
}
|
||||
35
src/TestingSystem/Common/TSetting/TSetting.java
Normal file
35
src/TestingSystem/Common/TSetting/TSetting.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package TestingSystem.Common.TSetting;
|
||||
import Common.Database.DBObject;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
public class TSetting extends DBObject {
|
||||
@Description("PRIMARY KEY,UNIQUE")
|
||||
public SettingName Name;
|
||||
public long value;
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return Name;
|
||||
}
|
||||
public TSetting(SettingName name_in, long value_in) {
|
||||
Name = name_in;
|
||||
value = value_in;
|
||||
}
|
||||
public TSetting(SettingName name_in, boolean value_in) {
|
||||
this(name_in, value_in ? 1 : 0);
|
||||
}
|
||||
public TSetting() {
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
TSetting t = (TSetting) src;
|
||||
Name = t.Name;
|
||||
value = t.value;
|
||||
}
|
||||
public TSetting(TSetting src) {
|
||||
this.SynchronizeFields(src);
|
||||
}
|
||||
public boolean toBoolean(){
|
||||
return value==1;
|
||||
}
|
||||
}
|
||||
7
src/TestingSystem/Common/TSetting/TSettingsDBTable.java
Normal file
7
src/TestingSystem/Common/TSetting/TSettingsDBTable.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package TestingSystem.Common.TSetting;
|
||||
import Common.Database.DBTable;
|
||||
public class TSettingsDBTable extends DBTable<String, TSetting> {
|
||||
public TSettingsDBTable() {
|
||||
super(String.class, TSetting.class);
|
||||
}
|
||||
}
|
||||
210
src/TestingSystem/Common/TasksDatabase.java
Normal file
210
src/TestingSystem/Common/TasksDatabase.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package TestingSystem.Common;
|
||||
import Common.Constants;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import Common.Global;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import TestingSystem.SAPFOR.SapforTask.SapforTasksDBTable;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackagesDBTable;
|
||||
import TestingSystem.Common.TSetting.TSetting;
|
||||
import TestingSystem.Common.TSetting.TSettingsDBTable;
|
||||
import TestingSystem.DVM.Tasks.TestCompilationTask;
|
||||
import TestingSystem.DVM.Tasks.TestCompilationTasksDBTable;
|
||||
import TestingSystem.DVM.Tasks.TestRunTask;
|
||||
import TestingSystem.DVM.Tasks.TestRunTasksDBTable;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackage;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackageDBTable;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||||
import TestingSystem.Common.TasksPackageToKill.TasksPackageToKillDBTable;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import javafx.util.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public class TasksDatabase extends SQLiteDatabase {
|
||||
public TSettingsDBTable settings;
|
||||
public TasksPackageDBTable packages;
|
||||
public TasksPackageToKillDBTable packagesToKill;
|
||||
public TestCompilationTasksDBTable testCompilationTasks;
|
||||
public TestRunTasksDBTable testRunTasks;
|
||||
PreparedStatement selectPackageRunTasks = null;
|
||||
//----------
|
||||
public SapforTasksPackagesDBTable sapforTasksPackages;
|
||||
public SapforTasksDBTable sapforTasks;
|
||||
//---------
|
||||
public TasksDatabase(String email) {
|
||||
super(Paths.get(Global.DataDirectory.getAbsolutePath(), email + "_" + Constants.tests_db_name + ".sqlite").toFile());
|
||||
}
|
||||
public TasksDatabase(File file_in) {
|
||||
super(file_in);
|
||||
}
|
||||
public void setFile(String email) {
|
||||
file = Paths.get(Global.DataDirectory.getAbsolutePath(), email + "_" + Constants.tests_db_name + ".sqlite").toFile();
|
||||
}
|
||||
@Override
|
||||
protected void initAllTables() throws Exception {
|
||||
addTable(settings = new TSettingsDBTable());
|
||||
addTable(packages = new TasksPackageDBTable());
|
||||
addTable(testCompilationTasks = new TestCompilationTasksDBTable());
|
||||
addTable(testRunTasks = new TestRunTasksDBTable());
|
||||
addTable(packagesToKill = new TasksPackageToKillDBTable());
|
||||
//-----------
|
||||
addTable(sapforTasksPackages = new SapforTasksPackagesDBTable());
|
||||
addTable(sapforTasks = new SapforTasksDBTable());
|
||||
}
|
||||
@Override
|
||||
public void Init() throws Exception {
|
||||
if (!settings.containsKey(SettingName.Email))
|
||||
Insert(new TSetting(SettingName.Email, 0));
|
||||
if (!settings.containsKey(SettingName.Pause))
|
||||
Insert(new TSetting(SettingName.Pause, 0));
|
||||
if (!settings.containsKey(SettingName.Queue))
|
||||
Insert(new TSetting(SettingName.Queue, 0));
|
||||
}
|
||||
@Override
|
||||
public PassCode_2021 getSynchronizePassCode() {
|
||||
return PassCode_2021.SynchronizeTestsTasks;
|
||||
}
|
||||
@Override
|
||||
public void prepareTablesStatements() throws Exception {
|
||||
super.prepareTablesStatements();
|
||||
selectPackageRunTasks = conn.prepareStatement("SELECT * FROM TestRunTask WHERE taskspackage_id = ?");
|
||||
}
|
||||
@Override
|
||||
protected void disconnect() throws Exception {
|
||||
if (selectPackageRunTasks != null) {
|
||||
selectPackageRunTasks.close();
|
||||
selectPackageRunTasks = null;
|
||||
}
|
||||
super.disconnect();
|
||||
}
|
||||
public LinkedHashMap<Long, TestRunTask> getPackageRunTasks(String package_id) throws Exception {
|
||||
LinkedHashMap<Long, TestRunTask> res = new LinkedHashMap<>();
|
||||
selectPackageRunTasks.setString(1, package_id);
|
||||
resSet = selectPackageRunTasks.executeQuery();
|
||||
while (resSet.next()) {
|
||||
Pair<Long, TestRunTask> record = readRecord(testRunTasks);
|
||||
res.put(record.getKey(), record.getValue());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
//------
|
||||
public TasksPackage getFirstActivePackage() {
|
||||
TasksPackage first_active = null;
|
||||
TasksPackage first_queued = null;
|
||||
if (!packages.Data.isEmpty()) {
|
||||
for (TasksPackage p : packages.Data.values()) {
|
||||
switch (p.state) {
|
||||
case Done:
|
||||
case Aborted:
|
||||
break;
|
||||
case Queued:
|
||||
if (first_queued == null) first_queued = p;
|
||||
break;
|
||||
default:
|
||||
if (first_active == null) first_active = p; //это и будет первый активный.
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (first_active != null) return first_active;
|
||||
if (first_queued != null) {
|
||||
first_queued.state = TasksPackageState.TestsSynchronize;
|
||||
try {
|
||||
Update(first_queued);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return first_queued;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public LinkedHashMap<Long, TestCompilationTask> getPackageCompilationTasks(TasksPackage tasksPackage) {
|
||||
if (tasksPackage == null) return null;
|
||||
LinkedHashMap<Long, TestCompilationTask> res = new LinkedHashMap<>();
|
||||
for (TestCompilationTask srcCompilationTask : testCompilationTasks.Data.values()) {
|
||||
if (srcCompilationTask.taskspackage_id.equals(tasksPackage.id)) {
|
||||
TestCompilationTask dstCompilationTask = new TestCompilationTask(srcCompilationTask);
|
||||
dstCompilationTask.runTasks = new Vector<>();
|
||||
for (TestRunTask testRunTask : testRunTasks.Data.values())
|
||||
if (testRunTask.testcompilationtask_id == srcCompilationTask.id)
|
||||
dstCompilationTask.runTasks.add(new TestRunTask(testRunTask));
|
||||
res.put(dstCompilationTask.id, dstCompilationTask);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public long getQueueSize(long date) throws Exception {
|
||||
long sum = 0L;
|
||||
for (TasksPackage tasksPackage : packages.Data.values()) {
|
||||
if (tasksPackage.StartDate < date) {
|
||||
Vector<TestRunTask> tasks = new Vector<>(getPackageRunTasks(tasksPackage.id).values());
|
||||
for (TestRunTask testRunTask : tasks)
|
||||
if (testRunTask.compilation_state.isActive() || testRunTask.state.isActive())
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
//--
|
||||
/*
|
||||
public Vector<TasksPackage> getActivePackages() {
|
||||
Vector<TasksPackage> res = new Vector<>();
|
||||
for (TasksPackage p : packages.Data.values())
|
||||
if (!p.state.equals(TasksPackageState.Done))
|
||||
res.add(p);
|
||||
return res;
|
||||
}
|
||||
public Vector<SapforTasksPackage> getActiveSapforPackages() {
|
||||
Vector<SapforTasksPackage> res = new Vector<>();
|
||||
for (SapforTasksPackage p : sapforTasksPackages.Data.values())
|
||||
if (!p.state.equals(TasksPackageState.Done))
|
||||
res.add(p);
|
||||
return res;
|
||||
}
|
||||
*/
|
||||
public SapforTasksPackage getFirstActiveSapforPackage() {
|
||||
SapforTasksPackage first_active = null;
|
||||
SapforTasksPackage first_queued = null;
|
||||
if (!sapforTasksPackages.Data.isEmpty()) {
|
||||
for (SapforTasksPackage p : sapforTasksPackages.Data.values()) {
|
||||
switch (p.state) {
|
||||
case Done:
|
||||
case Aborted:
|
||||
break;
|
||||
case Queued:
|
||||
if (first_queued == null) first_queued = p;
|
||||
break;
|
||||
default:
|
||||
if (first_active == null) first_active = p; //это и будет первый активный.
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (first_active != null) return first_active;
|
||||
if (first_queued != null) {
|
||||
first_queued.state = TasksPackageState.TestsSynchronize;
|
||||
try {
|
||||
Update(first_queued);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return first_queued;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean hasActivePackages() {
|
||||
for (TasksPackage tasksPackage : packages.Data.values()) {
|
||||
if (tasksPackage.state.isActive())
|
||||
return true;
|
||||
}
|
||||
for (SapforTasksPackage sapforTasksPackage : sapforTasksPackages.Data.values()) {
|
||||
if (sapforTasksPackage.state.isActive())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package TestingSystem.Common.TasksPackageToKill;
|
||||
import Common.Database.iDBObject;
|
||||
public class TasksPackageToKill extends iDBObject {
|
||||
public String packageName = "";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package TestingSystem.Common.TasksPackageToKill;
|
||||
import Common.Database.iDBTable;
|
||||
public class TasksPackageToKillDBTable extends iDBTable<TasksPackageToKill> {
|
||||
public TasksPackageToKillDBTable() {
|
||||
super(TasksPackageToKill.class);
|
||||
}
|
||||
}
|
||||
10
src/TestingSystem/Common/Test/ProjectFiles_json.java
Normal file
10
src/TestingSystem/Common/Test/ProjectFiles_json.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package TestingSystem.Common.Test;
|
||||
import 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<>();
|
||||
}
|
||||
56
src/TestingSystem/Common/Test/Test.java
Normal file
56
src/TestingSystem/Common/Test/Test.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package TestingSystem.Common.Test;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Database.DBObject;
|
||||
import Common.Database.riDBObject;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import GlobalData.User.UserState;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.io.File;
|
||||
public class Test extends riDBObject {
|
||||
@Description("DEFAULT 1")
|
||||
public int dim = 1; //размерность теста. для удобства пусть будет и внешним полем.
|
||||
@Description("DEFAULT ''")
|
||||
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
|
||||
@Description("DEFAULT -1")
|
||||
public int group_id = Constants.Nan;
|
||||
@Description("DEFAULT 'initial'")
|
||||
public UserState state = UserState.initial; //загружен ли тестовый проект.
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
Test t = (Test) src;
|
||||
dim = t.dim;
|
||||
args = t.args;
|
||||
group_id = t.group_id;
|
||||
}
|
||||
public Test(Test test) {
|
||||
this.SynchronizeFields(test);
|
||||
}
|
||||
public Test() {
|
||||
}
|
||||
@Override
|
||||
public void select(boolean flag) {
|
||||
super.select(flag);
|
||||
if (Current.hasUI())
|
||||
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));
|
||||
}
|
||||
}
|
||||
86
src/TestingSystem/Common/Test/TestDBTable.java
Normal file
86
src/TestingSystem/Common/Test/TestDBTable.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package TestingSystem.Common.Test;
|
||||
import Common.Current;
|
||||
import Common.Database.iDBTable;
|
||||
import Common.UI.DataSetControlForm;
|
||||
import Common.UI.Windows.Dialog.DBObjectDialog;
|
||||
import TestingSystem.Common.Test.UI.TestFields;
|
||||
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.dim;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String[] getUIColumnNames() {
|
||||
return new String[]{
|
||||
"имя", "размерность"};
|
||||
}
|
||||
@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.sDim.setValue(Result.dim);
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result.description = fields.tfName.getText();
|
||||
Result.dim = (int) fields.sDim.getValue();
|
||||
if (!edit) {
|
||||
Result.sender_name = Current.getAccount().name;
|
||||
Result.sender_address = Current.getAccount().email;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
22
src/TestingSystem/Common/Test/TestType.java
Normal file
22
src/TestingSystem/Common/Test/TestType.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package 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 "?";
|
||||
}
|
||||
}
|
||||
}
|
||||
55
src/TestingSystem/Common/Test/UI/TestFields.form
Normal file
55
src/TestingSystem/Common/Test/UI/TestFields.form
Normal file
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="TestingSystem.Common.Test.UI.TestFields">
|
||||
<grid id="27dc6" binding="content" 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>
|
||||
<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="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"/>
|
||||
</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="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="2b54" class="javax.swing.JSpinner" binding="sDim">
|
||||
<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>
|
||||
22
src/TestingSystem/Common/Test/UI/TestFields.java
Normal file
22
src/TestingSystem/Common/Test/UI/TestFields.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package TestingSystem.Common.Test.UI;
|
||||
import Common.UI.TextField.StyledTextField;
|
||||
import Common.UI.Windows.Dialog.DialogFields;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class TestFields implements DialogFields {
|
||||
public JTextField tfName;
|
||||
private JPanel content;
|
||||
public JSpinner sDim;
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
private void createUIComponents() {
|
||||
// TODO: place custom component creation code here
|
||||
tfName = new StyledTextField();
|
||||
}
|
||||
public TestFields(){
|
||||
sDim.setModel(new SpinnerNumberModel(1, 0, 16,1));
|
||||
}
|
||||
}
|
||||
235
src/TestingSystem/Common/TestingPlanner.java
Normal file
235
src/TestingSystem/Common/TestingPlanner.java
Normal file
@@ -0,0 +1,235 @@
|
||||
package TestingSystem.Common;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Machine.Machine;
|
||||
import GlobalData.User.User;
|
||||
import Repository.EmailMessage;
|
||||
import Repository.Server.ServerCode;
|
||||
import Repository.Server.ServerExchangeUnit_2021;
|
||||
import TestingSystem.DVM.UserConnection;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackageSupervisor.SapforTasksPackageSupervisor;
|
||||
import TestingSystem.DVM.Tasks.TestCompilationTask;
|
||||
import TestingSystem.DVM.Tasks.TestTask;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackage;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||||
import TestingSystem.DVM.TestsSupervisor_2022;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
|
||||
import javafx.util.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import static Common.Constants.tests_db_name;
|
||||
public class TestingPlanner {
|
||||
public String email;
|
||||
TasksPackage tasksPackage;
|
||||
TestsSupervisor_2022 supervisor;
|
||||
LinkedHashMap<String, Machine> machines = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, User> users = new LinkedHashMap<>();
|
||||
protected Machine machine = null;
|
||||
protected User user = null;
|
||||
public LinkedHashMap<Long, TestCompilationTask> packageTasks = new LinkedHashMap<>();
|
||||
//----------
|
||||
SapforTasksPackage sapforTasksPackage = null;
|
||||
//----------
|
||||
public void UpdateTask(TestTask task_in) throws Exception {
|
||||
task_in.ChangeDate = new Date().getTime();
|
||||
ServerCommand(ServerCode.EditAccountObject, task_in);
|
||||
}
|
||||
public void UpdatePackage() throws Exception {
|
||||
tasksPackage.ChangeDate = new Date().getTime();
|
||||
ServerCommand(ServerCode.EditAccountObject, tasksPackage);
|
||||
//---------------
|
||||
if ((tasksPackage.needsEmail == 1) &&
|
||||
(tasksPackage.state.equals(TasksPackageState.PackageStart) ||
|
||||
(tasksPackage.state.equals(TasksPackageState.Done)) ||
|
||||
(tasksPackage.state.equals(TasksPackageState.Aborted))
|
||||
)) {
|
||||
EmailMessage message = new EmailMessage();
|
||||
message.subject = "Состояние пакета задач " + Utils.Brackets(tasksPackage.id) + " изменилось на " + Utils.Brackets(tasksPackage.state.getDescription());
|
||||
message.text = tasksPackage.summary;
|
||||
message.targets.add(email);
|
||||
ServerCommand(ServerCode.Email, message);
|
||||
}
|
||||
}
|
||||
//-
|
||||
public Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
|
||||
TestingSystemPass<Object> pass = new TestingSystemPass<Object>() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
protected void ServerAction() throws Exception {
|
||||
Command(new ServerExchangeUnit_2021(code_in, arg, object_in));
|
||||
target = response.object;
|
||||
}
|
||||
};
|
||||
if (!pass.Do()) throw new PassException("Ошибка взаимодействия с сервером " + code_in);
|
||||
return pass.target;
|
||||
}
|
||||
public Object ServerCommand(ServerCode code_in, Serializable object_in) throws Exception {
|
||||
return ServerCommand(code_in, email, object_in);
|
||||
}
|
||||
Object ServerCommand(ServerCode code_in) throws Exception {
|
||||
return ServerCommand(code_in, email, null);
|
||||
}
|
||||
//-
|
||||
boolean isPrintOn() {
|
||||
return true;
|
||||
}
|
||||
public void Print(String message) {
|
||||
try {
|
||||
FileWriter testLog = new FileWriter(getClass().getSimpleName() + "_Log.txt", true);
|
||||
String dmessage = Utils.Brackets(new Date()) + " " + message;
|
||||
if (isPrintOn())
|
||||
System.out.println(dmessage);
|
||||
testLog.write(dmessage + "\n");
|
||||
testLog.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
boolean CheckConnection(Machine machine, User user) {
|
||||
//каждый раз соединяемся по новой. из за проблем с Exists.
|
||||
// к тому же, теперь задачи гоняет модуль, тут только проверка
|
||||
//так что время на разрыв уже не критично.
|
||||
try {
|
||||
user.connection = null;
|
||||
user.connection = new UserConnection(machine, user);
|
||||
Print("Соединение c " + machine.getURL() + " " + user.login + " успешно установлено.");
|
||||
user.connection.ShellCommand("ulimit -s unlimited"); // нужно, для запуска сишной части.
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
user.connection = null;
|
||||
Print("Не удалось установить соединение.");
|
||||
}
|
||||
return user.connection != null;
|
||||
}
|
||||
//-
|
||||
public void Perform() {
|
||||
Vector<String> emails = new Vector<>();
|
||||
while (true) {
|
||||
emails.clear();
|
||||
try {
|
||||
File[] accountsBases_ = Global.DataDirectory.listFiles(pathname ->
|
||||
pathname.isFile() &&
|
||||
Utils.getExtension(pathname).equals("sqlite") &&
|
||||
!Utils.getNameWithoutExtension(pathname.getName()).isEmpty() &&
|
||||
!pathname.getName().equals(tests_db_name + ".sqlite")
|
||||
);
|
||||
if (accountsBases_ != null) {
|
||||
for (File accountBase : accountsBases_) {
|
||||
String fileName = accountBase.getName();
|
||||
String account_email = accountBase.getName().substring(0, fileName.lastIndexOf('_'));
|
||||
emails.add(account_email);
|
||||
}
|
||||
for (String current_email : emails)
|
||||
emailPass(current_email);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
Utils.sleep(getSleepMillis());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected int getSleepMillis() {
|
||||
return 2000;
|
||||
}
|
||||
void emailPass(String email_in) {
|
||||
email = email_in;
|
||||
try {
|
||||
// System.out.println(email+" testing planner starts...");
|
||||
Pair<TasksPackage, LinkedHashMap<Long, TestCompilationTask>> p = (Pair<TasksPackage, LinkedHashMap<Long, TestCompilationTask>>) ServerCommand(ServerCode.GetFirstActiveAccountPackage);
|
||||
sapforTasksPackage = (SapforTasksPackage) ServerCommand(ServerCode.GetFirstActiveSapforTasksPackage);
|
||||
tasksPackage = null;
|
||||
packageTasks = null;
|
||||
tasksPackage = p.getKey();
|
||||
packageTasks = p.getValue();
|
||||
if (tasksPackage != null) {
|
||||
// System.out.println("found dvm package: "+sapforTasksPackage.id);
|
||||
String machine_url = tasksPackage.machine_address + ":" + tasksPackage.machine_port;
|
||||
if (!machines.containsKey(machine_url))
|
||||
machines.put(machine_url, new Machine(
|
||||
tasksPackage.machine_name,
|
||||
tasksPackage.machine_address,
|
||||
tasksPackage.machine_port,
|
||||
tasksPackage.machine_type));
|
||||
if (!users.containsKey(tasksPackage.user_name))
|
||||
users.put(tasksPackage.user_name,
|
||||
new User(tasksPackage.user_name, tasksPackage.user_password, tasksPackage.user_workspace));
|
||||
machine = machines.get(machine_url);
|
||||
//-->>
|
||||
user = users.get(tasksPackage.user_name);
|
||||
if (CheckConnection(machine, user)) {
|
||||
try {
|
||||
supervisor = new TestsSupervisor_2022(this, user.connection, tasksPackage, new Vector<>(packageTasks.values()));
|
||||
supervisor.Perform();
|
||||
} catch (Exception ex) {
|
||||
Print("Ошибка сеанса, соединение будет разорвано.");
|
||||
Print(ex.getMessage());
|
||||
if (user.connection != null) {
|
||||
user.connection.Disconnect();
|
||||
user.connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sapforTasksPackage != null) {
|
||||
System.out.println("found sapfor package: " + sapforTasksPackage.id + " state = " + sapforTasksPackage.state);
|
||||
try {
|
||||
(new SapforTasksPackageSupervisor(this, sapforTasksPackage)).Perform();
|
||||
} catch (Exception ex) {
|
||||
Print("Исключение при тестировании SAPROR");
|
||||
Print(ex.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
}
|
||||
}
|
||||
public String getStarter() {
|
||||
return String.join("/", user.workspace, ConnectionPass.modules, ConnectionPass.starter);
|
||||
}
|
||||
public String getLauncher() {
|
||||
return String.join("/", user.workspace, ConnectionPass.modules, ConnectionPass.launcher);
|
||||
}
|
||||
public String getPlanner() {
|
||||
return String.join("/", user.workspace, ConnectionPass.modules, ConnectionPass.planner);
|
||||
}
|
||||
//--
|
||||
public void UpdateSapforPackage() throws Exception {
|
||||
sapforTasksPackage.ChangeDate = new Date().getTime();
|
||||
EmailMessage message = null;
|
||||
ServerCommand(ServerCode.EditAccountObject, sapforTasksPackage);
|
||||
if (sapforTasksPackage.needsEmail == 1) {
|
||||
switch (sapforTasksPackage.state) {
|
||||
case RunningExecution:
|
||||
case Aborted:
|
||||
case Done:
|
||||
//результаты.
|
||||
message = new EmailMessage();
|
||||
message.subject = "Состояние пакета задач SAPFOR" + Utils.Brackets(sapforTasksPackage.id) + " изменилось на " + Utils.Brackets(sapforTasksPackage.state.getDescription());
|
||||
message.text = sapforTasksPackage.summary;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (message != null) {
|
||||
message.targets.add(email);
|
||||
ServerCommand(ServerCode.Email, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
488
src/TestingSystem/Common/TestingServer.java
Normal file
488
src/TestingSystem/Common/TestingServer.java
Normal file
@@ -0,0 +1,488 @@
|
||||
package TestingSystem.Common;
|
||||
import Common.Constants;
|
||||
import Common.Database.DBObject;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Machine.Machine;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import GlobalData.Tasks.TaskState;
|
||||
import GlobalData.User.User;
|
||||
import ProjectData.LanguageName;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import Repository.EmailMessage;
|
||||
import Repository.RepositoryRefuseException;
|
||||
import Repository.RepositoryServer;
|
||||
import Repository.Server.ServerCode;
|
||||
import Repository.Server.ServerExchangeUnit_2021;
|
||||
import TestingSystem.DVM.UserConnection;
|
||||
import TestingSystem.SAPFOR.SapforTask.SapforTask;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
|
||||
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.DVM.Tasks.TestCompilationTask;
|
||||
import TestingSystem.DVM.Tasks.TestRunTask;
|
||||
import TestingSystem.DVM.Tasks.TestTask;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackage;
|
||||
import TestingSystem.Common.TasksPackageToKill.TasksPackageToKill;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
import TestingSystem.Common.Test.TestType;
|
||||
import Visual_DVM_2021.Passes.All.DownloadRepository;
|
||||
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
|
||||
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 javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import static Common.Constants.tests_db_name;
|
||||
public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
LinkedHashMap<String, TasksDatabase> accountsBases = new LinkedHashMap<>();
|
||||
//--------------------------------->>>
|
||||
public TestingServer() {
|
||||
super(TestsDatabase.class);
|
||||
}
|
||||
//основа
|
||||
@Override
|
||||
public int getPort() {
|
||||
return 7998;
|
||||
}
|
||||
//---
|
||||
public TasksDatabase account_db = null;
|
||||
public void SetCurrentAccountDB(String email) {
|
||||
if (accountsBases.containsKey(email)) {
|
||||
account_db = accountsBases.get(email);
|
||||
} else {
|
||||
account_db = new TasksDatabase(email.equals("?") ? "undefined" : email);
|
||||
accountsBases.put(email, account_db);
|
||||
try {
|
||||
account_db.Connect();
|
||||
account_db.CreateAllTables();
|
||||
account_db.prepareTablesStatements();
|
||||
account_db.Synchronize();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void PublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof TasksPackage) {
|
||||
//объект уже вставлен.
|
||||
TasksPackage tasksPackage = (TasksPackage) object;
|
||||
//-
|
||||
for (int group_id : tasksPackage.sorted_tasks.keySet()) {
|
||||
if (db.groups.containsKey(group_id)) {
|
||||
Group group = db.groups.get(group_id);
|
||||
LinkedHashMap<Integer, Vector<TestCompilationTask>> group_tasks = tasksPackage.sorted_tasks.get((group_id));
|
||||
for (int test_id : group_tasks.keySet()) {
|
||||
if (db.tests.containsKey(test_id)) {
|
||||
Test test = db.tests.get(test_id);
|
||||
db_project_info project = new db_project_info(test);//Открытие бд проекта и ее синхронизация. неизбежно.
|
||||
//---
|
||||
for (TestCompilationTask task : group_tasks.get(test_id)) {
|
||||
Print("принять задачу на компиляцию " + group_id + ":" + test_id + ":" + task.flags);
|
||||
//Теперь эту задачу надо поставить в очередь. и вернуть пользователю, уже с id
|
||||
task.state = TaskState.Waiting;
|
||||
task.id = db.IncMaxTaskId();
|
||||
task.taskspackage_id = tasksPackage.id;
|
||||
task.makefile_text = group.GenerateMakefile(project, tasksPackage.dvm_drv, task.flags);
|
||||
task.test_home = tasksPackage.user_workspace + "/projects/" + test_id;
|
||||
//-->>
|
||||
task.remote_workspace =
|
||||
new RemoteFile(
|
||||
tasksPackage.user_workspace + "/tests/" + tasksPackage.id,
|
||||
String.valueOf(task.id), true).full_name;
|
||||
account_db.Insert(task);
|
||||
if (task.runTasks != null) {
|
||||
for (TestRunTask rt : task.runTasks) {
|
||||
rt.id = db.IncMaxTaskId();
|
||||
rt.taskspackage_id = tasksPackage.id;
|
||||
rt.testcompilationtask_id = task.id;
|
||||
rt.remote_workspace =
|
||||
new RemoteFile(
|
||||
tasksPackage.user_workspace + "/tests/" + tasksPackage.id,
|
||||
String.valueOf(rt.id), true).full_name;
|
||||
rt.binary_name = "spf_" + rt.id + "_" + rt.matrix.replace(" ", "_");
|
||||
account_db.Insert(rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Test) {
|
||||
Test new_test = (Test) object;
|
||||
// Utils.unpackFile(new_test.project_archive_bytes, new_test.getArchive());
|
||||
//распаковать архив в папку с тестами. для тестирования удобнее хранить их уже открытыми.
|
||||
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
|
||||
if (!unzipFolderPass.Do(
|
||||
new_test.getArchive().getAbsolutePath(),
|
||||
new_test.getServerPath().getParentFile().getAbsolutePath()))
|
||||
throw new RepositoryRefuseException("Не удалось распаковать Тест с id " + new_test.id);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DeleteAction(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) // todo group_name -> 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 SapforTasksPackage) {
|
||||
SapforTasksPackage sapforTasksPackage = (SapforTasksPackage) object;
|
||||
File workspace = new File(
|
||||
sapforTasksPackage.workspace
|
||||
);
|
||||
System.out.println(Utils.Brackets(workspace.getAbsolutePath()));
|
||||
Utils.forceDeleteWithCheck(workspace);
|
||||
Utils.forceDeleteWithCheck(sapforTasksPackage.getArchive());
|
||||
//внешние ключи не работают
|
||||
Vector<SapforTask> tasks = new Vector<>();
|
||||
for (SapforTask task : account_db.sapforTasks.Data.values()) {
|
||||
if (task.sapfortaskspackage_id.equals(sapforTasksPackage.id)) // todo group_name -> group_id
|
||||
tasks.add(task);
|
||||
}
|
||||
for (SapforTask task : tasks) {
|
||||
account_db.Delete(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean canDelete(DBObject object) throws Exception {
|
||||
if (object instanceof TestTask) {
|
||||
return !((TestTask) object).state.equals(TaskState.Running);
|
||||
} else
|
||||
return super.canDelete(object);
|
||||
}
|
||||
public void TestsSynchronize(String userWorkspace, Vector<Object> args) throws Exception {
|
||||
Machine machine = (Machine) args.get(0);
|
||||
User user = (User) args.get(1);
|
||||
Vector<String> test_ids = (Vector<String>) args.get(2);
|
||||
//---->>>
|
||||
UserConnection connection = new UserConnection(machine, user);
|
||||
for (String test_id : test_ids) {
|
||||
File test_src = Paths.get(Global.TestsDirectory.getAbsolutePath(), test_id).toFile();
|
||||
RemoteFile test_dst = new RemoteFile(userWorkspace + "/projects/" + test_id, true);
|
||||
connection.MKDIR(test_dst);
|
||||
connection.SynchronizeSubDirsR(test_src, test_dst);
|
||||
}
|
||||
//---->>>
|
||||
connection.Disconnect();
|
||||
}
|
||||
//--->>
|
||||
@Override
|
||||
protected void startAdditionalThreads() {
|
||||
testingThread.start();
|
||||
}
|
||||
protected TestingPlanner testingPlanner = new TestingPlanner();
|
||||
protected Thread testingThread = new Thread(() -> testingPlanner.Perform());
|
||||
//------>>>
|
||||
public static Timer checkTimer = null;
|
||||
public static void TimerOn() {
|
||||
System.out.println("timer on");
|
||||
checkTimer = new Timer(Global.properties.CheckTestingIntervalSeconds * 1000, e -> {
|
||||
Pass_2021.passes.get(PassCode_2021.SynchronizeTestsTasks).Do();
|
||||
});
|
||||
checkTimer.start();
|
||||
}
|
||||
public static void TimerOff() {
|
||||
System.out.println("timer off");
|
||||
if (checkTimer != null)
|
||||
checkTimer.stop();
|
||||
}
|
||||
public static void ResetTimer() {
|
||||
TimerOff();
|
||||
TimerOn();
|
||||
}
|
||||
//->>
|
||||
Group ConvertDirectoryToGroup(File src, LanguageName languageName, TestType testType) throws Exception {
|
||||
Group object = new Group();
|
||||
//->>
|
||||
object.description = src.getName();
|
||||
object.language = languageName;
|
||||
object.type = testType;
|
||||
//-->>
|
||||
//->>
|
||||
File[] testsFiles = src.listFiles(pathname ->
|
||||
pathname.isFile()
|
||||
&& !pathname.getName().equals("settings")
|
||||
&& !pathname.getName().equals("test-analyzer.sh")
|
||||
&& Utils.getExtension(pathname).startsWith(languageName.getDVMCompile()));
|
||||
;
|
||||
if (testsFiles != null) {
|
||||
for (File testFile : testsFiles)
|
||||
object.testsFiles.put(testFile.getName(), Utils.packFile(testFile));
|
||||
}
|
||||
//->>
|
||||
return object;
|
||||
}
|
||||
//->>
|
||||
public Vector<Group> getRepoGroupsInfo() throws Exception {
|
||||
Vector<Group> 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));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Performance:
|
||||
File groupDir = Paths.get(testsSrc.getAbsolutePath(), "Performance").toFile();
|
||||
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
groups.sort(Comparator.comparing(o -> o.description));
|
||||
return groups;
|
||||
}
|
||||
@Override
|
||||
protected void Session() throws Exception {
|
||||
DBObject dbObject = null;
|
||||
Test test = null;
|
||||
switch (code) {
|
||||
case EmailSapforAssembly:
|
||||
Print("Сообщить о сборке SAPFOR для пользователя " + request.arg);
|
||||
Vector<String> assembly_info = (Vector<String>) request.object;
|
||||
File out = Paths.get(Global.RepoDirectory.getAbsolutePath(), Constants.SAPFOR_REPOSITORY_BIN, Constants.out_file).toFile();
|
||||
File err = Paths.get(Global.RepoDirectory.getAbsolutePath(), Constants.SAPFOR_REPOSITORY_BIN, Constants.err_file).toFile();
|
||||
Vector<String> targets = new Vector<>();//Arrays.asList(Global.admins_mails));
|
||||
targets.add("vmk-post@yandex.ru");
|
||||
EmailMessage message = new EmailMessage(
|
||||
"Выполнена сборка системы SAPFOR",
|
||||
"Версия: " + assembly_info.get(0) + "\n" + "Статус: " + assembly_info.get(1),
|
||||
targets
|
||||
);
|
||||
Email(message, out, err);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case PublishSapforPackageTasks:
|
||||
Print("Опубликовать задачи SAPFOR для пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
Vector<Object> tasks = (Vector<Object>) request.object;
|
||||
account_db.BeginTransaction();
|
||||
for (Object object : tasks) {
|
||||
SapforTask task = (SapforTask) object;
|
||||
task.id = db.IncMaxTaskId();
|
||||
if (account_db.InsertWithCheck_(task) != null)
|
||||
PublishAction(task);
|
||||
}
|
||||
account_db.Commit();
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case DownloadSapforTasksPackage:
|
||||
Print("Загрузить пакет тестов SAPFOR " + request.object + " для пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
//---
|
||||
if (!account_db.sapforTasksPackages.containsKey(request.object))
|
||||
throw new RepositoryRefuseException("Не существует пакета с ключом " + Utils.Brackets(request.object));
|
||||
//--
|
||||
SapforTasksPackage sapforTasksPackage = account_db.sapforTasksPackages.get(request.object);
|
||||
//---
|
||||
//1 - архивировать пакет.
|
||||
File packageArchive = sapforTasksPackage.getArchive();
|
||||
Utils.forceDeleteWithCheck(packageArchive);
|
||||
System.out.println("src = " + Utils.Brackets(sapforTasksPackage.workspace));
|
||||
System.out.println("dst=" + Utils.Brackets(packageArchive.getAbsolutePath()));
|
||||
//---
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
if (zip.Do(sapforTasksPackage.workspace, packageArchive.getAbsolutePath())) {
|
||||
response.object = Utils.packFile(packageArchive);
|
||||
Print("Архив успешно запакован");
|
||||
} else throw new RepositoryRefuseException("Не удалось запаковать архив пакета");
|
||||
//---
|
||||
break;
|
||||
case SynchronizeTests:
|
||||
//временный проход. синхронизирует тесты на заданной машине, с сервера.
|
||||
Print("Синхронизация тестов");
|
||||
TestsSynchronize(request.arg, (Vector<Object>) request.object);
|
||||
//------------->>
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case CheckPackageToKill:
|
||||
SetCurrentAccountDB(request.arg);
|
||||
String packageName = (String) request.object;
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
boolean res_ = false;
|
||||
for (TasksPackageToKill tasksPackageToKill : account_db.packagesToKill.Data.values()) {
|
||||
if (tasksPackageToKill.packageName.equals(packageName)) {
|
||||
res_ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
response.object = res_;
|
||||
break;
|
||||
case EditAccountObject:
|
||||
SetCurrentAccountDB(request.arg);
|
||||
DBObject new_object = (DBObject) request.object;
|
||||
Print("Редактировать объект " + new_object.getPK() + " для пользователя " + request.arg);
|
||||
account_db.UpdateWithCheck(new_object);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case GetAccountObjectCopyByPK:
|
||||
SetCurrentAccountDB(request.arg);
|
||||
Pair<Class, Object> p = (Pair<Class, Object>) request.object;
|
||||
Print("Получить для пользователя " + request.arg + " копию объекта класса " + p.getKey().toString() + " по ключу " + p.getValue());
|
||||
dbObject = account_db.getObjectCopyByPK(p.getKey(), p.getValue());
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = dbObject;
|
||||
break;
|
||||
case PublishAccountObjects:
|
||||
Print("Опубликовать объекты для пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
Vector<Object> objects__ = (Vector<Object>) request.object;
|
||||
account_db.BeginTransaction();
|
||||
for (Object object : objects__)
|
||||
if (account_db.InsertWithCheck_((DBObject) object) != null)
|
||||
PublishAction((DBObject) object);
|
||||
account_db.Commit();
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
case CheckAccountObjectExistense:
|
||||
SetCurrentAccountDB(request.arg);
|
||||
p = (Pair<Class, Object>) request.object;
|
||||
Print("Проверить существование объекта класса для пользователя " + request.arg + " " + p.getKey().toString() + " с ключом " + p.getValue());
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = account_db.checkObjectExistense(p.getKey(), p.getValue());
|
||||
break;
|
||||
//------------------------------------------->>
|
||||
case DownloadTest:
|
||||
Print("Отправить клиенту тест " + request.arg);
|
||||
if (db.tests.containsKey(request.arg)) {
|
||||
test = db.tests.get(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK, "", Utils.packFile(test.getArchive()));
|
||||
} else
|
||||
throw new RepositoryRefuseException("Теста с именем " + request.arg + " не существует");
|
||||
break;
|
||||
//-------------------------------------------------------------------------------------->>>>
|
||||
case RefreshDVMTests:
|
||||
Print("Синхронизировать репозиторий тестов");
|
||||
// временно отключить для отладки.
|
||||
DownloadRepository downloadRepository = new DownloadRepository();
|
||||
if (!downloadRepository.Do())
|
||||
throw new RepositoryRefuseException("Не удалось обновить репозиторий");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = getRepoGroupsInfo();
|
||||
break;
|
||||
case GetAccountQueueSize:
|
||||
Print("Получить размер очереди для пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = (int) account_db.testCompilationTasks.Data.values().stream().filter(ctask -> ctask.state.isActive()).count()
|
||||
+ (int) account_db.testRunTasks.Data.values().stream().filter(rtask -> rtask.state.isActive()).count();
|
||||
break;
|
||||
case GetAccountObjectsCopiesByPKs:
|
||||
Print("Получить список копий объектов для пользователя " + request.arg);
|
||||
p = (Pair<Class, Object>) request.object;
|
||||
SetCurrentAccountDB(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = account_db.getObjectsCopies(p.getKey(), (Vector<Object>) p.getValue());
|
||||
break;
|
||||
case GetFirstActiveAccountPackage:
|
||||
Print("Получить первый активный пакет задач для пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
TasksPackage tasksPackage = account_db.getFirstActivePackage();
|
||||
LinkedHashMap<Long, TestCompilationTask> activeTasks = account_db.getPackageCompilationTasks(tasksPackage);
|
||||
response.object = new Pair<>(tasksPackage, activeTasks);
|
||||
break;
|
||||
case GetFirstActiveSapforTasksPackage:
|
||||
Print("Получить первый активный сценарий задач SAPFOR" + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = account_db.getFirstActiveSapforPackage();
|
||||
break;
|
||||
case GetQueueSize:
|
||||
Print("Получить размер глобальной очереди задач");
|
||||
long date = (long) request.object;
|
||||
long res = 0;
|
||||
Vector<String> emails = new Vector<>();
|
||||
File[] accountsBases_ = Global.DataDirectory.listFiles(pathname ->
|
||||
pathname.isFile() &&
|
||||
Utils.getExtension(pathname).equals("sqlite") &&
|
||||
!Utils.getNameWithoutExtension(pathname.getName()).isEmpty() &&
|
||||
!pathname.getName().equals(tests_db_name + ".sqlite")
|
||||
);
|
||||
if (accountsBases_ != null) {
|
||||
for (File accountBase : accountsBases_) {
|
||||
String fileName = accountBase.getName();
|
||||
String account_email = accountBase.getName().substring(0, fileName.lastIndexOf('_'));
|
||||
emails.add(account_email);
|
||||
}
|
||||
for (String email : emails) {
|
||||
SetCurrentAccountDB(email);
|
||||
res += account_db.getQueueSize(date);
|
||||
}
|
||||
}
|
||||
//пройтись по всем аккаунтам, и узнать все пакеты, чья дата меньше равна дате в арге
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = res;
|
||||
break;
|
||||
case ReceiveTestsDatabase:
|
||||
Print("Получить базу данных тестов");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = Utils.packFile(db.getFile());
|
||||
break;
|
||||
case ReceiveTestsTasksDatabase:
|
||||
Print("Получить базу данных тестовых задач пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = Utils.packFile(account_db.getFile());
|
||||
break;
|
||||
case DeleteAccountObjectByPK:
|
||||
Print("Удалить объект по ключу из базы пользователя " + request.arg);
|
||||
SetCurrentAccountDB(request.arg);
|
||||
Pair<Class, Object> to_delete = (Pair<Class, Object>) request.object;
|
||||
DeleteAction(account_db.DeleteByPK(to_delete.getKey(), to_delete.getValue()));
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
break;
|
||||
default:
|
||||
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/TestingSystem/Common/TestsDatabase.java
Normal file
65
src/TestingSystem/Common/TestsDatabase.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package TestingSystem.Common;
|
||||
import Common.Constants;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfigurationDBTable;
|
||||
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommandsDBTable;
|
||||
import TestingSystem.SAPFOR.ServerSapfor.ServerSapforsDBTable;
|
||||
import TestingSystem.DVM.Configuration.UI.ConfigurationDBTable;
|
||||
import TestingSystem.Common.Group.GroupsDBTable;
|
||||
import TestingSystem.Common.TSetting.TSetting;
|
||||
import TestingSystem.Common.TSetting.TSettingsDBTable;
|
||||
import TestingSystem.Common.Test.TestDBTable;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
public class TestsDatabase extends SQLiteDatabase {
|
||||
public ConfigurationDBTable configurations;
|
||||
public TestDBTable tests;
|
||||
public GroupsDBTable groups;
|
||||
public TSettingsDBTable settings;
|
||||
//--
|
||||
public SapforConfigurationDBTable sapforConfigurations;
|
||||
public SapforConfigurationCommandsDBTable sapforConfigurationCommands;
|
||||
//----
|
||||
public ServerSapforsDBTable serverSapfors;
|
||||
public TestsDatabase() {
|
||||
super(Paths.get(System.getProperty("user.dir"), "Data", Constants.tests_db_name + ".sqlite").toFile());
|
||||
}
|
||||
@Override
|
||||
protected void initAllTables() throws Exception {
|
||||
addTable(configurations = new ConfigurationDBTable());
|
||||
addTable(groups = new GroupsDBTable());
|
||||
addTable(tests = new TestDBTable());
|
||||
addTable(settings = new TSettingsDBTable());
|
||||
//-
|
||||
addTable(sapforConfigurations = new SapforConfigurationDBTable());
|
||||
addTable(sapforConfigurationCommands = new SapforConfigurationCommandsDBTable());
|
||||
addTable(serverSapfors = new ServerSapforsDBTable());
|
||||
}
|
||||
@Override
|
||||
public void Init() throws Exception {
|
||||
if (!settings.containsKey(SettingName.TaskMaxId))
|
||||
Insert(new TSetting(SettingName.TaskMaxId, 63128));
|
||||
if (!settings.containsKey(SettingName.SapforTaskMaxId))
|
||||
Insert(new TSetting(SettingName.SapforTaskMaxId, 0));
|
||||
}
|
||||
@Override
|
||||
public PassCode_2021 getSynchronizePassCode() {
|
||||
return PassCode_2021.SynchronizeTests;
|
||||
}
|
||||
public long IncMaxTaskId() throws Exception {
|
||||
TSetting setting = settings.get(SettingName.TaskMaxId);
|
||||
long res = setting.value;
|
||||
setting.value++;
|
||||
Update(setting);
|
||||
return res;
|
||||
}
|
||||
public long IncSapforMaxTaskId() throws Exception {
|
||||
TSetting setting = settings.get(SettingName.SapforTaskMaxId);
|
||||
long res = setting.value;
|
||||
setting.value++;
|
||||
Update(setting);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user