Перенос.

This commit is contained in:
2023-09-17 22:13:42 +03:00
parent dd2e0ca7e0
commit 629d8b8477
1239 changed files with 61161 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
package TestingSystem.Configuration;
import Common.Database.DBObject;
import Common.Database.rDBObject;
public class Configuration extends rDBObject {
//компиляция.
public String flags = "\n";
public int c_maxtime = 40;
//матрица
public int cube = 1;
public int max_proc_count = 4;
public int min_dim_proc_count = 1;
public int max_dim_proc_count = 4;
//запуск
public String environments="\n";
public String usr_par = "";
public int r_maxtime = 300;
//-
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
Configuration c = (Configuration) src;
flags = c.flags;
c_maxtime=c.c_maxtime;
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;
environments=c.environments;
usr_par=c.usr_par;
r_maxtime=c.r_maxtime;
}
public Configuration(Configuration src){
this.SynchronizeFields(src);
}
public Configuration(){}
}

View File

@@ -0,0 +1,69 @@
package TestingSystem.Configuration;
import Common.Utils.Utils;
import GlobalData.RunConfiguration.RunConfiguration;
import java.util.Vector;
public class ConfigurationInterface {
public static Vector<String> getFlags(TestingSystem.Configuration.Configuration object) {
return Utils.unpackStrings(object.flags);
}
public static Vector<String> getEnvironments(TestingSystem.Configuration.Configuration object) {
return Utils.unpackStrings(object.environments);
}
public static Vector<String> getParams(TestingSystem.Configuration.Configuration object) {
return Utils.unpackStrings(object.usr_par);
}
public static Vector<String> getMatrixes(TestingSystem.Configuration.Configuration object, int testDim) {
Vector<Vector<Integer>> res_ = new Vector<>();
Vector<String> res = new Vector<>();
if ((object.max_proc_count==0) || (object.min_dim_proc_count == 0 && object.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(object.min_dim_proc_count));
max_border.add(String.valueOf(object.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()) {
System.out.println("Верхняя и нижняя границы матриц конфигурации имеют разные размерности");
return res;
}
if (from.size() != testDim) {
System.out.println("Границы матриц не совпадают с размерностью конфигурации");
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, object.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 <= object.max_proc_count)
res.add(String.join(" ", ms));
}
} else res.add("");
}
return res;
}
public static String getParamsText(Configuration object) {
Vector<String> params = getParams(object);
if ((params.size() == 1) && params.get(0).isEmpty()) return "";
return String.join("\n", params);
}
public static String getSummary(Configuration configuration) {
return configuration.description;
}
}

View File

@@ -0,0 +1,165 @@
package TestingSystem.Configuration.UI;
import Common.Current;
import Common.Database.DBObject;
import Common.Database.DBTable;
import Common.UI.DataSetControlForm;
import Common.UI.Tables.TableRenderers;
import Common.UI.VisualiserStringList;
import Common.UI.Windows.Dialog.DBObjectDialog;
import Common.Utils.Utils;
import TestingSystem.Configuration.Configuration;
import TestingSystem.Configuration.ConfigurationInterface;
public class ConfigurationDBTable extends DBTable<String, Configuration> {
public static boolean email = false;
public ConfigurationDBTable() {
super(String.class, Configuration.class);
}
@Override
public Current CurrentName() {
return Current.Configuration;
}
@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(0).setVisible(false);
columns.get(4).setRenderer(TableRenderers.RendererMultiline);
columns.get(5).setRenderer(TableRenderers.RendererMultiline);
columns.get(12).setRenderer(TableRenderers.RendererMultiline);
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"флаги",
"окружение",
"c_time",
"куб",
"max",
"min dim",
"max dim",
"r_time",
"usr.par"
};
}
@Override
public Object getFieldAt(Configuration object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return Utils.unpackStrings(object.flags, true);
case 5:
return Utils.unpackStrings(object.environments, true);
case 6:
return object.c_maxtime;
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;
case 11:
return object.r_maxtime;
case 12:
return Utils.unpackStrings(object.usr_par, true);
default:
return null;
}
}
@Override
public DBObjectDialog<Configuration, ConfigurationFields> getDialog() {
return new DBObjectDialog<Configuration, ConfigurationFields>(ConfigurationFields.class) {
@Override
public int getDefaultHeight() {
return 480;
}
@Override
public int getDefaultWidth() {
return 1000;
}
@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);
//------->>>>
((VisualiserStringList) (fields.flagsList)).fill(ConfigurationInterface.getFlags(Result));
((VisualiserStringList) (fields.environmentsList)).fill(ConfigurationInterface.getEnvironments(Result));
((VisualiserStringList) (fields.parList)).fill(ConfigurationInterface.getParams(Result));
//------->>>>
fields.sCompilationMaxtime.setValue(Result.c_maxtime);
//-
fields.sMinDimProc.setValue(Result.min_dim_proc_count);
fields.sMaxDimProc.setValue(Result.max_dim_proc_count);
fields.cbCube.setSelected(Result.cube == 1);
fields.sRunMaxtime.setValue(Result.r_maxtime);
//-
fields.sMaxProc.setValue(Result.max_proc_count);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.c_maxtime = (int) fields.sCompilationMaxtime.getValue();
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.r_maxtime = (int) fields.sRunMaxtime.getValue();
Result.flags = ((VisualiserStringList) (fields.flagsList)).pack();
Result.environments = ((VisualiserStringList) (fields.environmentsList)).pack();
Result.usr_par = ((VisualiserStringList) (fields.parList)).pack();
}
@Override
public void SetReadonly() {
fields.tfName.setEnabled(false);
fields.sCompilationMaxtime.setEnabled(false);
fields.sRunMaxtime.setEnabled(false);
fields.sMinDimProc.setEnabled(false);
fields.sMaxDimProc.setEnabled(false);
fields.cbCube.setEnabled(false);
fields.sMaxProc.setEnabled(false);
fields.bAddFlags.setEnabled(false);
fields.bDeleteFlags.setEnabled(false);
fields.bAddEnvironments.setEnabled(false);
fields.bDeleteEnvironment.setEnabled(false);
fields.bAddPar.setEnabled(false);
fields.bDeletePar.setEnabled(false);
}
};
}
@Override
public boolean ShowEditObjectDialog(DBObject object) {
return (Current.getAccount().CheckAccessRights(((Configuration) object).sender_address, null)) ? super.ShowEditObjectDialog(object) : ViewObject(object);
}
}

View File

@@ -0,0 +1,402 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="TestingSystem.Configuration.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="821" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<splitpane id="78a2d" binding="SC1">
<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">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties>
<dividerLocation value="500"/>
<dividerSize value="3"/>
</properties>
<border type="none"/>
<children>
<grid id="ee2fd" 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>
<splitpane position="left"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="259d7" 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="264c1">
<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"/>
</constraints>
</vspacer>
<component id="6795f" 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="9219f" class="javax.swing.JSpinner" binding="sMinDimProc">
<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="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="5686a" 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="79cbe" 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="33803" class="javax.swing.JSpinner" binding="sMaxDimProc">
<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="9b066" 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="d706b" class="javax.swing.JSpinner" binding="sCompilationMaxtime">
<constraints>
<grid row="5" 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="a3108" 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="22d31" class="javax.swing.JSpinner" binding="sRunMaxtime">
<constraints>
<grid row="6" 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="cda3" class="javax.swing.JCheckBox" binding="cbCube">
<constraints>
<grid row="4" column="0" row-span="1" col-span="2" 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="a79b8" 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="a6c17" class="javax.swing.JSpinner" binding="sMaxProc">
<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>
<grid id="f79b4" 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>
<splitpane position="right"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<splitpane id="bd8be" binding="SC2">
<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">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties>
<dividerLocation value="180"/>
<dividerSize value="3"/>
<orientation value="0"/>
</properties>
<border type="none"/>
<children>
<grid id="a9834" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<splitpane position="left"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<toolbar id="4f6a1" binding="flagsTools">
<constraints border-constraint="North"/>
<properties>
<floatable value="false"/>
</properties>
<border type="none"/>
<children>
<component id="566f4" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<foreground color="-16777216"/>
<text value="флаги"/>
</properties>
</component>
<component id="79287" class="javax.swing.JButton" binding="bAddFlags">
<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="1cb75" class="javax.swing.JButton" binding="bDeleteFlags">
<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>
</children>
</toolbar>
<scrollpane id="99ead">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="c0373" class="javax.swing.JList" binding="flagsList" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
<grid id="b9287" 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>
<splitpane position="right"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<splitpane id="53277" binding="SC3">
<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">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties>
<dividerLocation value="85"/>
<dividerSize value="3"/>
<orientation value="0"/>
</properties>
<border type="none"/>
<children>
<grid id="3d5c8" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<splitpane position="right"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<toolbar id="612de" binding="parTools">
<constraints border-constraint="North"/>
<properties>
<floatable value="false"/>
</properties>
<border type="none"/>
<children>
<component id="4a428" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<foreground color="-16777216"/>
<text value="usr par"/>
</properties>
</component>
<component id="1d160" class="javax.swing.JButton" binding="bAddPar">
<constraints/>
<properties>
<borderPainted value="false"/>
<icon value="icons/RedAdd.png"/>
<maximumSize width="30" height="30"/>
<minimumSize width="30" height="30"/>
<preferredSize width="30" height="30"/>
<text value=""/>
<toolTipText value="Добавить параметр DVM системы"/>
</properties>
</component>
<component id="61ba8" class="javax.swing.JButton" binding="bDeletePar">
<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="Удалить параметр DVM системы"/>
</properties>
</component>
</children>
</toolbar>
<scrollpane id="d0f3b">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="7cdd5" class="javax.swing.JList" binding="parList" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
<grid id="4c856" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<splitpane position="left"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<toolbar id="81953" binding="environmentsTools">
<constraints border-constraint="North"/>
<properties>
<floatable value="false"/>
</properties>
<border type="none"/>
<children>
<component id="cec3c" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<foreground color="-16777216"/>
<text value="окружение"/>
</properties>
</component>
<component id="1e835" class="javax.swing.JButton" binding="bAddEnvironments">
<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="b9e9d" class="javax.swing.JButton" binding="bDeleteEnvironment">
<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>
</children>
</toolbar>
<scrollpane id="f94f5">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="951ed" class="javax.swing.JList" binding="environmentsList" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</splitpane>
</children>
</grid>
</children>
</splitpane>
</children>
</grid>
</children>
</splitpane>
</children>
</grid>
</form>

View File

@@ -0,0 +1,106 @@
package TestingSystem.Configuration.UI;
import Common.Current;
import Common.UI.VisualiserStringList;
import Common.UI.TextField.StyledTextField;
import Common.UI.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 ConfigurationFields implements DialogFields {
public JTextField tfName;
public JSpinner sMinDimProc;
public JSpinner sMaxDimProc;
public JSpinner sCompilationMaxtime;
public JSpinner sRunMaxtime;
public JCheckBox cbCube;
public JSpinner sMaxProc;
public JList<String> flagsList;
public JList<String> environmentsList;
public JList<String> parList;
//-
private JPanel content;
private JSplitPane SC1;
private JSplitPane SC2;
private JToolBar flagsTools;
public JButton bAddFlags;
public JButton bDeleteFlags;
private JSplitPane SC3;
private JToolBar parTools;
public JButton bAddPar;
public JButton bDeletePar;
private JToolBar environmentsTools;
public JButton bAddEnvironments;
public JButton bDeleteEnvironment;
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
//-
flagsList = new VisualiserStringList();
environmentsList = new VisualiserStringList();
parList = new VisualiserStringList();
}
public ConfigurationFields(){
sMinDimProc.setModel(new SpinnerNumberModel(1, 0, 128, 1));
sMaxDimProc.setModel(new SpinnerNumberModel(1, 0, 128, 1));
sMaxProc.setModel(new SpinnerNumberModel(0, 0, 128, 1));
sCompilationMaxtime.setModel(new SpinnerNumberModel(40,
5, 3600, 1
));
sRunMaxtime.setModel(new SpinnerNumberModel(40,
5, 3600, 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()))
((VisualiserStringList) flagsList).addElement((String) pass.target);
}
});
bDeleteFlags.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
((VisualiserStringList) flagsList).removeElement(flagsList.getSelectedValue());
}
});
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()))
((VisualiserStringList) environmentsList).addElement((String) pass.target);
}
});
bDeleteEnvironment.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
((VisualiserStringList) environmentsList).removeElement(environmentsList.getSelectedValue());
}
});
bDeletePar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
((VisualiserStringList) parList).removeElement(parList.getSelectedValue());
}
});
bAddPar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Pass_2021 pass = Pass_2021.passes.get(PassCode_2021.AddDVMParameterForTesting);
if (pass.Do()) {
((VisualiserStringList) parList).addElement((String) pass.target);
}
}
});
}
}

View File

@@ -0,0 +1,40 @@
package TestingSystem.Group;
import Common.Current;
import Common.Database.DBObject;
import Common.Database.rDBObject;
import Common.UI.UI;
import ProjectData.LanguageName;
import TestingSystem.Test.TestType;
import com.sun.org.glassfish.gmbal.Description;
import java.util.LinkedHashMap;
public class Group extends rDBObject {
@Override
public boolean isVisible() {
return GroupInterface.isVisible(this);
}
@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 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().getTestingWindow().ShowCheckedTestsCount();
}
}

View File

@@ -0,0 +1,132 @@
package TestingSystem.Group;
import Common.Current;
import Common.Global;
import Common.Utils.Utils;
import ProjectData.Files.DBProjectFile;
import ProjectData.LanguageName;
import ProjectData.Project.db_project_info;
import java.io.File;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Vector;
//dynamic cats возможен через рефлексию.
//https://stackoverflow.com/questions/2127318/java-how-can-i-do-dynamic-casting-of-a-variable-from-one-type-to-another
public class GroupInterface {
//-
public static boolean filterMyOnly = true;
//--
public static boolean isVisible(Group object) {
return (!filterMyOnly || Current.getAccount().email.equals(object.sender_address)) &&
Global.testingServer.db.groups.applyFilters(object);
}
public static String getStyleOptions(DBProjectFile program) {
if (program.languageName == LanguageName.fortran) {
switch (program.style) {
case fixed:
case extended:
return "-FI";
case free:
return "-f90";
case none:
break;
}
}
return "";
}
public static String getLanguageCompileCommand(LanguageName language) {
switch (language) {
case fortran:
return "f";
case c:
return "c";
}
return "";
}
public static String getLanguageLinkCommand(LanguageName language) {
switch (language) {
case fortran:
return "flink";
case c:
return "clink";
}
return "";
}
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"),
getStyleOptions(program),
"-c",
program.getQSourceName(),
"-o",
object + "\n\n"
);
++i;
}
titles.add(String.join("\n",
LANG_ + "COMMAND=" + Utils.DQuotes(dvm_drv) + " " +
getLanguageCompileCommand(language),
LANG_ + "FLAGS=" + flags_in,
LANG_ + "OBJECTS=" + String.join(" ", module_objects),
""
));
objects.add(Utils.MFVar(LANG_ + "OBJECTS"));
bodies.add(module_body);
}
}
public static String GenerateMakefile(Group object, 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, object.language, titles, objects, bodies, flags_in);
//----->>
return String.join("\n",
"LINK_COMMAND=" + Utils.DQuotes(dvm_drv) + " " +
getLanguageLinkCommand(object.language),
"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 static void CopyFields(Group src, Group dst) {
dst.description = src.description;
dst.type = src.type;
dst.language = src.language;
}
public static String getSummary(Group group) {
return group.description + " " + group.language.getDescription();
}
//для тестирования Сапфора на локальной машине.
public static File getLocalWorkspaceD(Group group){
return Paths.get(Global.visualiser.getWorkspace().getAbsolutePath(), group.id).toFile();
}
}

View File

@@ -0,0 +1,185 @@
package TestingSystem.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.Group.UI.GroupFields;
import TestingSystem.Test.Test;
import TestingSystem.Test.TestType;
import javax.swing.*;
import java.util.LinkedHashMap;
import java.util.Vector;
//-
public class GroupsDBTable extends DBTable<String, Group> {
public Vector<TableFilter<Group>> typeFilters;
public Vector<TableFilter<Group>> languageFilters;
//------------------------------------------------>>>
public GroupsDBTable() {
super(String.class, 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();
}
};
}
}

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="TestingSystem.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 TestingSystem.Group.UI;
import Common.UI.TextField.StyledTextField;
import Common.UI.Windows.Dialog.DialogFields;
import ProjectData.LanguageName;
import TestingSystem.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,25 @@
package TestingSystem.MachineKernels;
import Common.Database.DBObject;
import com.sun.org.glassfish.gmbal.Description;
public class MachineKernels extends DBObject {
@Description("PRIMARY KEY, UNIQUE")
public String URL = "";
@Override
public Object getPK() {
return URL;
}
public MachineKernels() {
}
public MachineKernels(String URL_in) {
URL = URL_in;
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
MachineKernels mk = (MachineKernels) src;
URL = mk.URL;
}
public MachineKernels(MachineKernels src) {
this.SynchronizeFields(src);
}
}

View File

@@ -0,0 +1,22 @@
package TestingSystem.MachineMaxKernels;
import Common.Database.DBObject;
import TestingSystem.MachineKernels.MachineKernels;
import com.sun.org.glassfish.gmbal.Description;
public class MachineMaxKernels extends MachineKernels {
@Description("DEFAULT 4")
public int limit = 4;
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
MachineMaxKernels mk = (MachineMaxKernels) src;
limit = mk.limit;
}
public MachineMaxKernels(MachineMaxKernels src) {
this.SynchronizeFields(src);
}
public MachineMaxKernels() {
}
public MachineMaxKernels(String URL_in) {
super(URL_in);
}
}

View File

@@ -0,0 +1,7 @@
package TestingSystem.MachineMaxKernels;
import Common.Database.DBTable;
public class MachineMaxKernelsDBTable extends DBTable<String, MachineMaxKernels> {
public MachineMaxKernelsDBTable() {
super(String.class, MachineMaxKernels.class);
}
}

View File

@@ -0,0 +1,11 @@
package TestingSystem.Sapfor.SapforConfiguration;
import Common.Database.rDBObject;
public class SapforConfiguration extends rDBObject {
//настройки.
public int maxtime = 300; //лимит времени преобразования.
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
}

View File

@@ -0,0 +1,122 @@
package TestingSystem.Sapfor.SapforConfiguration;
import Common.Current;
import Common.Database.*;
import Common.Global;
import Common.UI.DataSetControlForm;
import Common.UI.Windows.Dialog.DBObjectDialog;
import Common.Utils.Utils;
import TestingSystem.Sapfor.SapforConfiguration.UI.SapforConfigurationFields;
import TestingSystem.Sapfor.SapforConfigurationCommand.SapforConfigurationCommand;
import java.util.LinkedHashMap;
public class SapforConfigurationDBTable extends DBTable<String, SapforConfiguration> {
public SapforConfigurationDBTable() {
super(String.class, 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
public void ShowCurrentObject() throws Exception {
super.ShowCurrentObject();
Global.db.sapforTasksPackages.ShowUI();
}
@Override
public void ShowNoCurrentObject() throws Exception {
super.ShowNoCurrentObject();
Global.db.sapforTasksPackages.ClearUI();
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"имя",
"автор",
"флаги",
"maxtime"
};
}
@Override
public Object getFieldAt(SapforConfiguration object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
case 4:
return SapforConfigurationInterface.getFlags(object);
case 5:
return object.maxtime;
default:
return null;
}
}
//--
@Override
public DBObjectDialog<SapforConfiguration, SapforConfigurationFields> getDialog() {
return new DBObjectDialog<SapforConfiguration, SapforConfigurationFields>(SapforConfigurationFields.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);
fields.sMaxtime.setValue(Result.maxtime);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.maxtime = (int) fields.sMaxtime.getValue();
// Result.transformations = ((StyledStringList) (fields.transformationsList)).pack();
Result.FREE_FORM = Utils.fromBoolean(fields.cbFREE_FORM.isSelected());
Result.KEEP_DVM_DIRECTIVES = Utils.fromBoolean(fields.cbKEEP_DVM_DIRECTIVES.isSelected());
Result.KEEP_SPF_DIRECTIVES = Utils.fromBoolean(fields.cbKEEP_SPF_DIRECTIVES.isSelected());
Result.STATIC_SHADOW_ANALYSIS = Utils.fromBoolean(fields.cbSTATIC_SHADOW_ANALYSIS.isSelected());
Result.MAX_SHADOW_WIDTH = fields.sMAX_SHADOW_WIDTH.getValue();
}
@Override
public void SetReadonly() {
fields.tfName.setEnabled(false);
fields.sMaxtime.setEnabled(false);
fields.sTransformationMaxtime.setEnabled(false);
}
};
}
@Override
public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
res.put(SapforConfigurationCommand.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
return res;
}
}

View File

@@ -0,0 +1,71 @@
package TestingSystem.Sapfor.SapforConfiguration;
import Common.Global;
import Common.Utils.TextLog;
import TestingSystem.Sapfor.SapforConfigurationCommand.SapforConfigurationCommand;
import Visual_DVM_2021.Passes.PassCode_2021;
import java.util.Vector;
public class SapforConfigurationInterface {
public static String getFlags(SapforConfiguration object) {
Vector<String> res = new Vector<>();
if (object.FREE_FORM > 0)
res.add("-f90");
if (object.STATIC_SHADOW_ANALYSIS > 0)
res.add("-sh");
if (object.MAX_SHADOW_WIDTH > 0)
res.add("-shwidth " + object.MAX_SHADOW_WIDTH);
if (object.KEEP_DVM_DIRECTIVES > 0)
res.add("-keepDVM");
if (object.KEEP_SPF_DIRECTIVES > 0)
res.add("-keepSPF");
return String.join(" ", res);
}
public static Vector<PassCode_2021> getPassCodes(SapforConfiguration object) {
Vector<PassCode_2021> res = new Vector<>();
for (SapforConfigurationCommand command : Global.testingServer.db.sapforConfigurationCommands.Data.values()) {
if (command.sapforconfiguration_id.equals(object.id)) {
res.add(command.passCode);
}
}
return res;
}
public static String getTransformationsNames(SapforConfiguration object) {
Vector<String> res = new Vector<>();
for (SapforConfigurationCommand command : Global.testingServer.db.sapforConfigurationCommands.Data.values()) {
if (command.sapforconfiguration_id.equals(object.id)) {
res.add(command.passCode.getDescription());
}
}
return String.join(";", res);
}
//todo вывести.
public static boolean validateCommands(SapforConfiguration sapforConfiguration, TextLog log) {
//1. получить список всех команд.
Vector<SapforConfigurationCommand> commands = new Vector<>();
int count = 0;
for (SapforConfigurationCommand command : Global.testingServer.db.sapforConfigurationCommands.Data.values()) {
if (command.sapforconfiguration_id.equals(sapforConfiguration.id)) {
commands.add(command);
if (command.passCode.equals(PassCode_2021.CreateParallelVariants))
count++;
}
}
if ((count == 0) || commands.isEmpty())
return true;
//--
if (count > 2) {
log.Writeln_("Неверная конфигурация:" + sapforConfiguration.id + ": построение параллельных вариантов возможно единожды.");
return false;
}
//--
if (count == 1) {
if (commands.size() == 1) return true;
if (!commands.lastElement().passCode.equals(PassCode_2021.CreateParallelVariants)) {
log.Writeln_("Неверная конфигурация:" + sapforConfiguration.id + ": построение параллельных вариантов может быть только завершающей командой!");
return false;
}
;
}
return true;
}
}

View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="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="883" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="d1d6e" layout-manager="GridLayoutManager" row-count="9" 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="284" height="20"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="название"/>
</properties>
</component>
<vspacer id="224d6">
<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">
<preferred-size width="284" height="14"/>
</grid>
</constraints>
</vspacer>
<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="3e6be" 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="284" height="20"/>
</grid>
</constraints>
<properties>
<font name="Times New Roman" size="16" style="2"/>
<text value="макс. время прохода"/>
</properties>
</component>
<component id="db389" class="javax.swing.JSpinner" binding="sMaxtime">
<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="240" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="b644a" class="javax.swing.JCheckBox" binding="cbFREE_FORM">
<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="7721e" class="javax.swing.JCheckBox" binding="cbKEEP_SPF_DIRECTIVES">
<constraints>
<grid row="5" 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="f44c1" 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="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="54e77" class="javax.swing.JCheckBox" binding="cbSTATIC_SHADOW_ANALYSIS">
<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="Оптимизация теневых обменов"/>
</properties>
</component>
<component id="4e865" class="javax.swing.JCheckBox" binding="cbKEEP_DVM_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="Учитывать DVM директивы"/>
</properties>
</component>
<component id="14243" class="javax.swing.JSlider" binding="sMAX_SHADOW_WIDTH">
<constraints>
<grid row="7" 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,31 @@
package TestingSystem.Sapfor.SapforConfiguration.UI;
import Common.UI.TextField.StyledTextField;
import Common.UI.Windows.Dialog.DialogFields;
import javax.swing.*;
import java.awt.*;
public class SapforConfigurationFields implements DialogFields {
private JPanel content;
public JTextField tfName;
public JSpinner sMaxtime;
public JSpinner sTransformationMaxtime;
public JCheckBox cbFREE_FORM;
public JSlider sMAX_SHADOW_WIDTH;
public JCheckBox cbSTATIC_SHADOW_ANALYSIS;
public JCheckBox cbKEEP_SPF_DIRECTIVES;
public JCheckBox cbKEEP_DVM_DIRECTIVES;
//--
@Override
public Component getContent() {
return content;
}
private void createUIComponents() {
// TODO: place custom component creation code here
tfName = new StyledTextField();
}
public SapforConfigurationFields(){
sMaxtime.setModel(new SpinnerNumberModel(40,
5, 3600, 1
));
}
}

View File

@@ -0,0 +1,13 @@
package TestingSystem.Sapfor.SapforConfigurationCommand;
import Common.Database.rDBObject;
import Visual_DVM_2021.Passes.PassCode_2021;
import com.sun.org.glassfish.gmbal.Description;
public class SapforConfigurationCommand extends rDBObject {
@Description("DEFAULT ''")
public String sapforconfiguration_id = "";
public PassCode_2021 passCode = PassCode_2021.SPF_RemoveDvmDirectives;
@Override
public boolean isVisible() {
return SapforConfigurationCommandInterface.isVisible(this);
}
}

View File

@@ -0,0 +1,7 @@
package TestingSystem.Sapfor.SapforConfigurationCommand;
import Common.Current;
public class SapforConfigurationCommandInterface {
public static boolean isVisible(SapforConfigurationCommand object) {
return Current.HasSapforConfiguration() && (Current.getSapforConfiguration().id.equals(object.sapforconfiguration_id));
}
}

View File

@@ -0,0 +1,71 @@
package TestingSystem.Sapfor.SapforConfigurationCommand;
import Common.Current;
import Common.Database.DBTable;
import Common.UI.DataSetControlForm;
import Common.UI.UI;
import Common.UI.Windows.Dialog.DBObjectDialog;
import TestingSystem.Sapfor.SapforConfigurationCommand.UI.SapforConfigurationCommandFields;
import Visual_DVM_2021.Passes.PassCode_2021;
public class SapforConfigurationCommandsDBTable extends DBTable<String, SapforConfigurationCommand> {
public SapforConfigurationCommandsDBTable() {
super(String.class, SapforConfigurationCommand.class);
}
@Override
public String getSingleDescription() {
return "команда";
}
@Override
public String getPluralDescription() {
return "команды";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this);
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Проход"
};
}
@Override
public Object getFieldAt(SapforConfigurationCommand object, int columnIndex) {
switch (columnIndex) {
case 1:
return object.passCode.getDescription();
default:
return null;
}
}
@Override
public Current CurrentName() {
return Current.SapforConfigurationCommand;
}
@Override
public DBObjectDialog<SapforConfigurationCommand, SapforConfigurationCommandFields> getDialog() {
return new DBObjectDialog<SapforConfigurationCommand, SapforConfigurationCommandFields>(SapforConfigurationCommandFields.class) {
@Override
public int getDefaultHeight() {
return 250;
}
@Override
public void fillFields() {
UI.TrySelect(fields.cbPassCode, Result.passCode);
}
@Override
public void ProcessResult() {
Result.passCode = (PassCode_2021) fields.cbPassCode.getSelectedItem();
Result.sapforconfiguration_id = Current.getSapforConfiguration().id;
}
@Override
public void validateFields() {
/*
Vector<ScenarioCommand> commands = new Vector<>(Current.getSapforConfiguration().getCommands().values());
if (!commands.isEmpty()&&commands.get(commands.size()-1).passCode.equals(PassCode_2021.CreateParallelVariantsCoverageForScenario)){
Log.Writeln_("После построения покрытия вариантов запрещено добавлять другие команды в сценарий.");
}
*/
}
};
}
}

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="TestingSystem.Sapfor.SapforConfigurationCommand.UI.SapforConfigurationCommandFields">
<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="97a3c" 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="7e4ea">
<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="e95d0" 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,32 @@
package TestingSystem.Sapfor.SapforConfigurationCommand.UI;
import Common.Current;
import Common.UI.Tables.StyledCellLabel;
import Common.UI.Windows.Dialog.DialogFields;
import Repository.Component.Sapfor.Sapfor;
import Visual_DVM_2021.Passes.PassCode_2021;
import javax.swing.*;
import java.awt.*;
public class SapforConfigurationCommandFields 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 ?
Current.getTheme().selection_background : Current.getTheme().background
);
return res;
});
//-
for (PassCode_2021 code : Sapfor.getScenariosCodes())
cbPassCode.addItem(code);
}
}

View File

@@ -0,0 +1,36 @@
package TestingSystem.Sapfor.SapforTask;
import Common.Current;
import Common.UI.StatusEnum;
import Common.UI.Themes.VisualiserFonts;
import java.awt.*;
public enum MatchState implements StatusEnum {
Unknown,
Match,
NotMatch;
public String getDescription() {
switch (this) {
case Unknown:
return "неизвестно";
case Match:
return "да";
case NotMatch:
return "нет";
default:
return "?";
}
}
@Override
public Font getFont() {
switch (this) {
case Unknown:
return Current.getTheme().Fonts.get(VisualiserFonts.UnknownState);
case Match:
return Current.getTheme().Fonts.get(VisualiserFonts.GoodState);
case NotMatch:
return Current.getTheme().Fonts.get(VisualiserFonts.BadState);
default:
return StatusEnum.super.getFont();
}
}
}

View File

@@ -0,0 +1,16 @@
package TestingSystem.Sapfor.SapforTask;
import Common.Database.DBObject;
import TestingSystem.Sapfor.SapforTasksPackage.SapforTasksPackage_2023;
public class SapforTaskResult extends DBObject {
public SapforTasksPackage_2023 sapforTasksPackage;
public SapforTask_2023 task;
public MatchState match_state = MatchState.Unknown;
@Override
public Object getPK() {
return task.test_description;
}
public SapforTaskResult(SapforTasksPackage_2023 package_in, SapforTask_2023 task_in) {
sapforTasksPackage = package_in;
task = task_in;
}
}

View File

@@ -0,0 +1,55 @@
package TestingSystem.Sapfor.SapforTask;
import Common.Database.DBObject;
import Common.Utils.Utils;
import GlobalData.Tasks.TaskState;
import TestingSystem.Sapfor.SapforVersion_json;
import com.google.gson.annotations.Expose;
import com.sun.org.glassfish.gmbal.Description;
import java.util.Vector;
public class SapforTask_2023 extends DBObject {
//------------------------------------>>
@Description("PRIMARY KEY, UNIQUE")
@Expose
public long id = Utils.Nan;
@Description("DEFAULT '-1'")
@Expose
public int sapfortaskspackage_2023_id = Utils.Nan;
//------------------------------------->>
@Description("DEFAULT ''")
@Expose
public String test_description = "";
//-------------------------------------->>
@Description("IGNORE")
@Expose
public Vector<SapforVersion_json> versions = new Vector<>();
@Description("IGNORE")
@Expose
public Vector<SapforVersion_json> variants = new Vector<>();
//-------------------------------------->>
@Description("DEFAULT 'Inactive'")
@Expose
public TaskState state = TaskState.Inactive;
@Description("DEFAULT '0'")
@Expose
public int versions_tree_built = 0;
//-----------
public SapforTask_2023() {
}
public SapforTask_2023(SapforTask_2023 src) {
this.SynchronizeFields(src);
}
@Override
public Object getPK() {
return id;
}
@Override
public void SynchronizeFields(DBObject object) {
super.SynchronizeFields(object);
SapforTask_2023 t = (SapforTask_2023) object;
id = t.id;
sapfortaskspackage_2023_id = t.sapfortaskspackage_2023_id;
test_description = t.test_description;
state = t.state;
}
}

View File

@@ -0,0 +1,56 @@
package TestingSystem.Sapfor.SapforTask;
import Common.Current;
import Common.Database.DBTable;
import Common.UI.DataSetControlForm;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import static Common.UI.Tables.TableRenderers.RendererStatusEnum;
public class SapforTasksDBTable extends DBTable<Long, SapforTask_2023> {
public SapforTasksDBTable() {
super(Long.class, SapforTask_2023.class);
}
@Override
public String getSingleDescription() {
return "задача";
}
@Override
public String getPluralDescription() {
return "задачи";
}
@Override
public Current CurrentName() {
return Current.SapforTask;
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
protected void AdditionalInitColumns() {
columns.get(2).setRenderer(RendererStatusEnum);
}
@Override
public void MouseAction2() throws Exception {
Pass_2021.passes.get(PassCode_2021.OpenSapforTest).Do();
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Тест",
"Статус"
};
}
@Override
public Object getFieldAt(SapforTask_2023 object, int columnIndex) {
switch (columnIndex) {
case 1:
return object.test_description;
case 2:
return object.state;
default:
return null;
}
}
}

View File

@@ -0,0 +1,79 @@
package TestingSystem.Sapfor.SapforTasksPackage;
import Common.Database.DBObject;
import Common.Database.iDBObject;
import TestingSystem.Sapfor.SapforConfiguration.SapforConfiguration;
import TestingSystem.TasksPackage.TasksPackageState;
import TestingSystem.Test.Test;
import Visual_DVM_2021.Passes.PassCode_2021;
import com.sun.org.glassfish.gmbal.Description;
import java.util.Vector;
public class SapforTasksPackage_2023 extends iDBObject {
public String summary = "";
//----
public int FREE_FORM = 0; //"Свободный выходной стиль"; -f90
public int STATIC_SHADOW_ANALYSIS = 0;//"Оптимизация теневых обменов"; -sh
public int MAX_SHADOW_WIDTH = 50; // "Максимальный размер теневых граней"; (%) -shwidth значение поля
public int STATIC_PRIVATE_ANALYSIS = 0; //"Статический анализ приватностей" -priv
public int KEEP_SPF_DIRECTIVES = 0; //"Сохранять SPF директивы при построении параллельных вариантов"; -keepSPF
public int KEEP_DVM_DIRECTIVES = 0;// "Учитывать DVM директивы"; -keepDVM
//---
@Description("DEFAULT ''")
public String flags = "";
@Description("DEFAULT ''")
public String passesNames = ""; //имена преобразований через ;
@Description("DEFAULT ''")
public String testsNames = "";//имена тестов через ;
//---
public String sapfor_version = "?";
//---
public String workspace = "";
//---
public int tasksCount = 0;
@Description("DEFAULT 0")
public int versions_tree_built = 0;
//---
public double Time; //время выполнения.
public long StartDate = 0; //дата начала выполнения
public long ChangeDate = 0;//дата окончания выполнения
@Description("DEFAULT ''")
public String sapforconfiguration_id = "";
//-
public TasksPackageState state = TasksPackageState.Queued;
//--
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
SapforTasksPackage_2023 tasksPackage = (SapforTasksPackage_2023) src;
summary = tasksPackage.summary;
sapfor_version = tasksPackage.sapfor_version;
tasksCount = tasksPackage.tasksCount;
Time = tasksPackage.Time;
StartDate = tasksPackage.StartDate;
ChangeDate = tasksPackage.ChangeDate;
state = tasksPackage.state;
workspace = tasksPackage.workspace;
//---
flags = tasksPackage.flags;
//---
FREE_FORM = tasksPackage.FREE_FORM;
STATIC_SHADOW_ANALYSIS = tasksPackage.FREE_FORM;
MAX_SHADOW_WIDTH = tasksPackage.MAX_SHADOW_WIDTH;
STATIC_PRIVATE_ANALYSIS = tasksPackage.STATIC_PRIVATE_ANALYSIS;
KEEP_SPF_DIRECTIVES = tasksPackage.KEEP_SPF_DIRECTIVES;
KEEP_DVM_DIRECTIVES = tasksPackage.KEEP_DVM_DIRECTIVES;
}
public SapforTasksPackage_2023(SapforTasksPackage_2023 src) {
this.SynchronizeFields(src);
}
public SapforTasksPackage_2023() {
}
//----
@Description("IGNORE")
public Vector<Test> tests = null;
@Description("IGNORE")
public Vector<PassCode_2021> codes = null;
public SapforTasksPackage_2023(SapforConfiguration configuration_in, Vector<Test> tests_in) {
}
}

View File

@@ -0,0 +1,96 @@
package TestingSystem.Sapfor.SapforTasksPackage;
import Common.Current;
import Common.Database.*;
import Common.UI.DataSetControlForm;
import TestingSystem.Sapfor.SapforTask.SapforTask_2023;
import java.util.Date;
import java.util.LinkedHashMap;
import static Common.UI.Tables.TableRenderers.RendererDate;
import static Common.UI.Tables.TableRenderers.RendererStatusEnum;
public class SapforTasksPackagesDBTable extends iDBTable<SapforTasksPackage_2023> {
public SapforTasksPackagesDBTable() {
super(SapforTasksPackage_2023.class);
}
@Override
public Current CurrentName() {
return Current.SapforTasksPackage;
}
@Override
public String getSingleDescription() {
return "пакеты задач Sapfor";
}
@Override
public String getPluralDescription() {
return "пакеты задач";
}
@Override
protected DataSetControlForm createUI() {
return new DataSetControlForm(this) {
@Override
protected void AdditionalInitColumns() {
columns.get(7).setRenderer(RendererDate);
columns.get(8).setRenderer(RendererDate);
columns.get(9).setRenderer(RendererStatusEnum);
}
@Override
public void ShowCurrentObject() throws Exception {
super.ShowCurrentObject();
// UI.getNewMainWindow().getTestingWindow().DropTestRunTasksComparison();
}
@Override
public void ShowNoCurrentObject() throws Exception {
super.ShowNoCurrentObject();
// UI.getNewMainWindow().getTestingWindow().DropTestRunTasksComparison();
}
@Override
public boolean hasCheckBox() {
return true;
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"SAPFOR",
"Флаги",
"Проходы",
"Тесты",
"Задач",
"Начало",
"Изменено",
"Статус"
};
}
@Override
public Object getFieldAt(SapforTasksPackage_2023 object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.sapfor_version;
case 3:
return object.flags;
case 4:
return object.passesNames;
case 5:
return object.testsNames;
case 6:
return object.tasksCount;
case 7:
return new Date(object.StartDate);
case 8:
return new Date(object.ChangeDate);
case 9:
return object.state;
default:
return null;
}
}
@Override
public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
res.put(SapforTask_2023.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
return res;
}
}

View File

@@ -0,0 +1,12 @@
package TestingSystem.Sapfor;
import com.google.gson.annotations.Expose;
public class SapforVersion_json {
@Expose
public String version = "";
@Expose
public String description = "";
public SapforVersion_json(String version_in, String description_in) {
version = version_in;
description = description_in;
}
}

View File

@@ -0,0 +1,10 @@
package TestingSystem.Sapfor;
import TestingSystem.Sapfor.SapforTask.SapforTask_2023;
import com.google.gson.annotations.Expose;
import java.util.List;
import java.util.Vector;
public class ScenarioResults_json {
@Expose
public List<SapforTask_2023> tasks = new Vector<>();
}

View File

@@ -0,0 +1,14 @@
package TestingSystem.Sapfor;
import Visual_DVM_2021.Passes.PassCode_2021;
import com.google.gson.annotations.Expose;
import java.util.List;
import java.util.Vector;
public class Scenario_json {
@Expose
public String flags;
@Expose
public List<PassCode_2021> codes = new Vector<>();
@Expose
public List<String> tests = new Vector<>();
}

View File

@@ -0,0 +1,35 @@
package TestingSystem.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;
}
}

View File

@@ -0,0 +1,7 @@
package TestingSystem.TSetting;
import Common.Database.DBTable;
public class TSettingsDBTable extends DBTable<String, TSetting> {
public TSettingsDBTable() {
super(String.class, TSetting.class);
}
}

View File

@@ -0,0 +1,28 @@
package TestingSystem.TaskKey;
import Common.Database.DBObject;
import com.sun.org.glassfish.gmbal.Description;
public class TaskKey_2022 extends DBObject {
@Description("PRIMARY KEY, UNIQUE")
public long task_id = 0;
public String package_id = "";
@Override
public Object getPK() {
return task_id;
}
public TaskKey_2022(TaskKey_2022 src) {
this.SynchronizeFields(src);
}
public TaskKey_2022(long task_id_in, String package_id_in) {
task_id = task_id_in;
package_id = package_id_in;
}
public TaskKey_2022() {
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
TaskKey_2022 key = (TaskKey_2022) src;
task_id = key.task_id;
package_id = key.package_id;
}
}

View File

@@ -0,0 +1,7 @@
package TestingSystem.TaskKey;
import Common.Database.DBTable;
public class TaskKeysDBTable extends DBTable<Long, TaskKey_2022> {
public TaskKeysDBTable() {
super(Long.class, TaskKey_2022.class);
}
}

View File

@@ -0,0 +1,51 @@
package TestingSystem.Tasks;
import Common.Database.DBObject;
import TestingSystem.Configuration.Configuration;
import TestingSystem.Group.Group;
import TestingSystem.Test.Test;
import com.sun.org.glassfish.gmbal.Description;
import java.util.Vector;
//-
public class TestCompilationTask extends TestTask {
@Description("DEFAULT ''")
public String makefile_text = "";
@Description("DEFAULT ''")
public String test_home = ""; //место где лежит код теста.
@Description("IGNORE")
public Vector<TestRunTask> runTasks = null;
@Override
public Vector<String> pack(int kernels_in) {
Vector<String> res = new Vector<>();
res.add(String.valueOf(id)); //1
res.add(String.valueOf(maxtime)); //2
res.add(test_id); //3
res.add(makefile_text.replace("\n", "|")); //4
//игнор аргумента. ядро всегда одно.
return res;
}
public TestCompilationTask() {
}
public TestCompilationTask(Configuration configuration, Group group, Test test, String flags_in) {
super(configuration, group, test, flags_in);
flags = flags_in;
maxtime = configuration.c_maxtime;
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
TestCompilationTask ct = (TestCompilationTask) src;
makefile_text = ct.makefile_text;
test_home = ct.test_home;
if (ct.runTasks == null) this.runTasks = null;
else {
this.runTasks = new Vector<>();
for (TestRunTask runTask : ct.runTasks) {
this.runTasks.add(new TestRunTask(runTask));
}
}
}
public TestCompilationTask(TestCompilationTask src) {
this.SynchronizeFields(src);
}
}

View File

@@ -0,0 +1,16 @@
package TestingSystem.Tasks;
import Common.Current;
import Common.Database.DBTable;
public class TestCompilationTasksDBTable extends DBTable<Integer, TestCompilationTask> {
public TestCompilationTasksDBTable() {
super(Integer.class, TestCompilationTask.class);
}
@Override
public String getSingleDescription() {
return "задачи на компиляцию тестов";
}
@Override
public Current CurrentName() {
return Current.TestCompilationTask;
}
}

View File

@@ -0,0 +1,106 @@
package TestingSystem.Tasks;
import Common.Database.DBObject;
import Common.Utils.Utils;
import GlobalData.Tasks.TaskState;
import ProjectData.LanguageName;
import TestingSystem.Configuration.Configuration;
import TestingSystem.Group.Group;
import TestingSystem.Test.Test;
import com.sun.org.glassfish.gmbal.Description;
import java.util.Vector;
public class TestRunTask extends TestTask {
//не факт что тут нужно переводить на полный интерфейс. достаточно убрать фильтрацию
@Override
public boolean isVisible() {
return TestRunTaskInterface.isVisible(this);
}
//--
public long testcompilationtask_id = Utils.Nan;
public String matrix = "";
@Description("DEFAULT ''")
public String args = "";
public double CleanTime = 0.0;
@Description("DEFAULT 0")
public int progress = 0;
public LanguageName language = LanguageName.fortran;
public int cube = 1;
public int min_dim = 1;
public int max_dim = 1;
public String environments = "";
public String usr_par = "";
public int compilation_maxtime = 40;
public String compilation_output = "";
public String compilation_errors = "";
public TaskState compilation_state = TaskState.Waiting;
public double compilation_time = 0.0;
public String statistic = "";
public String jsonStatistic = "";
public TestRunTask(Configuration configuration,
Group group, Test test,
String matrix_in, String flags_in,
String environments_in,
String par_in) {
super(configuration, group, test, flags_in);
//--------------------------
//инфа о компиляции.
language = group.language;
compilation_maxtime = configuration.c_maxtime;
compilation_output = "";
compilation_errors = "";
compilation_state = TaskState.Waiting;
//инфа о запуске
cube = configuration.cube;
min_dim = configuration.max_dim_proc_count;
max_dim = configuration.max_dim_proc_count;
maxtime = configuration.r_maxtime;
environments = environments_in;
usr_par = par_in;
args = test.args;
//---------
matrix = matrix_in;
}
public TestRunTask() {
}
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
TestRunTask rt = (TestRunTask) src;
testcompilationtask_id = rt.testcompilationtask_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_output = rt.compilation_output;
compilation_errors = rt.compilation_errors;
compilation_state = rt.compilation_state;
compilation_time = rt.compilation_time;
statistic = rt.statistic;
args = rt.args;
jsonStatistic = rt.jsonStatistic;
}
public TestRunTask(TestRunTask src) {
this.SynchronizeFields(src);
}
//-
@Override
public Vector<String> pack(int kernels_in) {
Vector<String> res = new Vector<>();
res.add(String.valueOf(id)); //1
res.add(String.valueOf(maxtime)); //2
res.add(String.valueOf(testcompilationtask_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_in)); //8
return res;
}
}

View File

@@ -0,0 +1,85 @@
package TestingSystem.Tasks;
import Common.Current;
import Common.Global;
import Common.Utils.StringTemplate;
import GlobalData.Tasks.TaskState;
import javafx.util.Pair;
import java.util.List;
public class TestRunTaskInterface {
public static String filterName = "";
public static boolean isVisible(TestRunTask object) {
return
Current.HasTasksPackage() &&
object.taskspackage_id.equals(Current.getTasksPackage().id) &&
object.test_id.contains(filterName) &&
Global.testingServer.account_db.testRunTasks.applyFilters(object);
}
public static String getEnvironments(TestRunTask object) {
return object.environments.replace("\n", ";");
}
public static String getUsrPar(TestRunTask object) {
return object.usr_par.replace("\n", ";");
}
//--
public static boolean isCrushedLine(String line) {
return line.contains("RTS err")
|| line.contains("RTS stack trace")
|| line.contains("RTS fatal err")
|| line.contains("SIGEGV")
|| line.contains("There are not enough slots available in the system to satisfy the")
|| line.contains("forrtl: severe")
|| line.contains("invalid pointer")
|| line.contains("forrtl: error");
}
public static boolean isCrushed(List<String> output_lines, List<String> errors_lines) {
return output_lines.stream().anyMatch(TestRunTaskInterface::isCrushedLine) || errors_lines.stream().anyMatch(TestRunTaskInterface::isCrushedLine);
}
public static Pair<TaskState, Integer> analyzeCorrectness(List<String> lines) {
int complete = 0;
int errors = 0;
int total = 0;
for (String s : lines) {
String line = s.toUpperCase();
if (line.contains("COMPLETE")) {
complete++;
total++;
} else if (line.contains("ERROR")) {
errors++;
total++;
}
}
return new Pair<>(
(errors > 0) ? TaskState.DoneWithErrors : ((complete > 0) ? TaskState.Done : TaskState.WrongTestFormat),
(int) ((((double) complete) / total) * 100)
);
}
public static Pair<TaskState, Integer> analyzePerformance(List<String> lines) {
StringTemplate stringTemplate = new StringTemplate("Verification =", "");
for (String line : lines) {
String param = stringTemplate.check_and_get_param(line);
if (param != null) {
switch (param) {
case "SUCCESSFUL":
return new Pair<>(TaskState.Done, 100);
case "UNSUCCESSFUL":
return new Pair<>(TaskState.DoneWithErrors, 0);
default:
break;
}
}
}
return new Pair<>(TaskState.WrongTestFormat, 0);
}
public static double parseCleanTime(String output) {
double res = 0.0;
StringTemplate template = new StringTemplate("Time in seconds =", "");
String p = template.check_and_get_param(output);
try {
if (p != null) res = Double.parseDouble(p);
} catch (Exception ex) {
Global.Log.PrintException(ex);
}
return res;
}
}

View File

@@ -0,0 +1,188 @@
package TestingSystem.Tasks;
import Common.Current;
import Common.Database.DBTable;
import Common.Database.TableFilter;
import Common.UI.DataSetControlForm;
import Common.UI.Menus_2023.TestRunTasksMenuBar.TestRunTasksMenuBar;
import Common.UI.Menus_2023.VisualiserMenu;
import Common.UI.UI;
import GlobalData.Tasks.TaskState;
import javax.swing.*;
import java.util.Comparator;
import java.util.Vector;
import static Common.UI.Tables.TableRenderers.RendererProgress;
import static Common.UI.Tables.TableRenderers.RendererStatusEnum;
public class TestRunTasksDBTable extends DBTable<Long, TestRunTask> {
public Vector<TableFilter<TestRunTask>> compilationFilters;
public Vector<TableFilter<TestRunTask>> runFilters;
public TestRunTasksDBTable() {
super(Long.class, TestRunTask.class);
//--
if (Current.hasUI()) {
compilationFilters = new Vector<>();
runFilters = new Vector<>();
//--
for (TaskState state : TaskState.values()) {
if (state.isVisible()) {
compilationFilters.add(new TableFilter<TestRunTask>(this, state.getDescription()) {
@Override
protected boolean validate(TestRunTask object) {
return object.compilation_state.equals(state);
}
});
}
}
//--
for (TaskState state : TaskState.values()) {
if (state.isVisible()) {
runFilters.add(new TableFilter<TestRunTask>(this, state.getDescription()) {
@Override
protected boolean validate(TestRunTask object) {
return object.state.equals(state);
}
});
}
}
}
}
public void ResetFiltersCount() {
for (TableFilter<TestRunTask> filter : compilationFilters)
filter.count = 0;
for (TableFilter<TestRunTask> filter : runFilters)
filter.count = 0;
}
public void ShowFiltersCount() {
for (TableFilter<TestRunTask> filter : compilationFilters) {
filter.ShowDescriptionAndCount();
}
for (TableFilter<TestRunTask> filter : runFilters) {
filter.ShowDescriptionAndCount();
}
}
public boolean applyFilters(TestRunTask object) {
for (TableFilter<TestRunTask> filter : compilationFilters)
if (!filter.Validate(object)) return false;
for (TableFilter<TestRunTask> filter : runFilters)
if (!filter.Validate(object)) return false;
return true;
}
@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(2).setVisible(false);
columns.get(6).setRenderer(RendererStatusEnum);
columns.get(7).setRenderer(RendererStatusEnum);
columns.get(14).setRenderer(RendererProgress);
}
};
}
@Override
public void mountUI(JPanel content_in) {
super.mountUI(content_in);
//-
TestRunTasksMenuBar menuBar = (TestRunTasksMenuBar) UI.menuBars.get(getClass());
menuBar.DropFilters();
//----
menuBar.addFilters(
new VisualiserMenu("Компиляция", "/icons/Filter.png", true) {
{
for (TableFilter filter : compilationFilters)
add(filter.menuItem);
}
},
new VisualiserMenu("Запуск", "/icons/Filter.png", true) {
{
for (TableFilter filter : runFilters)
add(filter.menuItem);
}
}
);
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Группа",
"Тест",
"Язык",
"Флаги",
"Сборка",
"Запуск",
"Время компиляции(с)",
"Матрица",
"Окружение",
"usr.par",
"Время выполнения (с)",
"Чистое время (с)",
"Прогресс",
};
}
@Override
public Object getFieldAt(TestRunTask object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.group_description;
case 3:
return object.test_description;
case 4:
return object.language;
case 5:
return object.flags;
case 6:
return object.compilation_state;
case 7:
return object.state;
case 8:
return object.compilation_time;
case 9:
return object.matrix;
case 10:
return TestRunTaskInterface.getEnvironments(object);
case 11:
return TestRunTaskInterface.getUsrPar(object);
case 12:
return object.Time;
case 13:
return object.CleanTime;
case 14:
return object.progress;
default:
return null;
}
}
@Override
public Comparator<TestRunTask> getComparator() {
return (o1, o2) -> -o1.getChangeDate().compareTo(o2.getChangeDate());
}
@Override
public Current CurrentName() {
return Current.TestRunTask;
}
@Override
public void ShowUI() {
ResetFiltersCount();
super.ShowUI();
ShowFiltersCount();
}
@Override
public void ShowUI(Object key) {
ResetFiltersCount();
super.ShowUI(key);
ShowFiltersCount();
}
}

View File

@@ -0,0 +1,99 @@
package TestingSystem.Tasks;
import Common.Database.DBObject;
import Common.Utils.Utils;
import GlobalData.Tasks.TaskState;
import TestingSystem.Configuration.Configuration;
import TestingSystem.Group.Group;
import TestingSystem.Test.Test;
import TestingSystem.Test.TestType;
import com.sun.org.glassfish.gmbal.Description;
import java.util.Date;
import java.util.Vector;
//тут все поля должны быть текстовыми. никаких ссылок по ид. мало ли, группу удалят
public class TestTask extends DBObject {
@Description("PRIMARY KEY, UNIQUE")
public long id = Utils.Nan;
@Description("DEFAULT ''")
public String taskspackage_id = "";
@Description("DEFAULT ''")
public String group_id = "";
@Description("DEFAULT ''")
public String group_description = ""; //видимое имя группы для юзера
@Description("DEFAULT ''")
public String test_id = ""; //ключ - будет генерироваться автоматически.
@Description("DEFAULT ''")
public String test_description = ""; //видимое имя теста для юзера
@Description("DEFAULT ''")
public String flags = "";
@Description("DEFAULT 'Inactive'")
public TaskState state = TaskState.Inactive;
@Description("DEFAULT ''")
public String PID = "";
@Description("DEFAULT 40")
public int maxtime = 40;
@Description("DEFAULT ''")
public String remote_workspace = ""; //вывести. память экономим.
@Description("DEFAULT ''")
public String binary_name = ""; //вывести. имя генерим по ид задачи и матрице.
@Description("DEFAULT 'Default'")
public TestType test_type = TestType.Default;
//результаты-------------------------------
public double Time; //время выполнения.
public long StartDate = 0; //дата начала выполнения
public long ChangeDate = 0;//дата изменения
@Description("DEFAULT ''")
public String output = "";
@Description("DEFAULT ''")
public String errors = "";
//------------------------------------------------------
@Override
public Object getPK() {
return id;
}
public Date getChangeDate() {
return new Date(ChangeDate);
}
//--->>>
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
TestTask t = (TestTask) src;
id = t.id;
taskspackage_id = t.taskspackage_id;
group_id = t.group_id;
group_description = t.group_description;
test_id = t.test_id;
test_description = t.test_description;
flags = t.flags;
state = t.state;
PID = t.PID;
maxtime = t.maxtime;
remote_workspace = t.remote_workspace;
binary_name = t.binary_name;
test_type = t.test_type;
Time = t.Time;
StartDate = t.StartDate;
ChangeDate = t.ChangeDate;
output = t.output;
errors = t.errors;
}
public TestTask(TestTask src) {
this.SynchronizeFields(src);
}
public TestTask() {
}
public TestTask(Configuration 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;
flags = flags_in;
}
public Vector<String> pack (int kernels){
return null;
}
}

View File

@@ -0,0 +1,201 @@
package TestingSystem;
import Common.Database.SQLITE.SQLiteDatabase;
import Common.Global;
import GlobalData.Settings.SettingName;
import TestingSystem.TSetting.TSetting;
import TestingSystem.TSetting.TSettingsDBTable;
import TestingSystem.TaskKey.TaskKey_2022;
import TestingSystem.Tasks.TestCompilationTask;
import TestingSystem.Tasks.TestCompilationTasksDBTable;
import TestingSystem.Tasks.TestRunTask;
import TestingSystem.Tasks.TestRunTasksDBTable;
import TestingSystem.TasksPackage.TasksPackage;
import TestingSystem.TasksPackage.TasksPackageDBTable;
import TestingSystem.TasksPackage.TasksPackageState;
import TestingSystem.TasksPackageToKill.TasksPackageToKillDBTable;
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 static final String tests_db_name = "tests2023";
public TSettingsDBTable settings;
public TasksPackageDBTable packages;
public TasksPackageToKillDBTable packagesToKill;
public TestCompilationTasksDBTable testCompilationTasks;
public TestRunTasksDBTable testRunTasks;
PreparedStatement selectPackageRunTasks = null;
// PreparedStatement selectSapforPackageSapforTasks = null;
//----------
// public SapforTasksPackagesDBTable sapforTasksPackages;
// public SapforTasksDBTable sapforTasks = null;
//---------
public TasksDatabase(String email) {
super(Paths.get(Global.DataDirectory.getAbsolutePath(), email + "_" + 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 + "_" + 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 void prepareTablesStatements() throws Exception {
super.prepareTablesStatements();
selectPackageRunTasks = conn.prepareStatement("SELECT * FROM TestRunTask WHERE taskspackage_id = ?");
// selectSapforPackageSapforTasks = conn.prepareStatement("SELECT * FROM SapforTask WHERE sapfortaskspackage_id = ?");
}
@Override
protected void disconnect() throws Exception {
if (selectPackageRunTasks != null) {
selectPackageRunTasks.close();
selectPackageRunTasks = null;
}
/*
if (selectSapforPackageSapforTasks != null) {
selectSapforPackageSapforTasks.close();
selectSapforPackageSapforTasks = 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 LinkedHashMap<Long, SapforTask> getSapforPackageTasks(String package_id) throws Exception {
LinkedHashMap<Long, SapforTask> res = new LinkedHashMap<>();
selectSapforPackageSapforTasks.setString(1, package_id);
resSet = selectSapforPackageSapforTasks.executeQuery();
while (resSet.next()) {
Pair<Long, SapforTask> record = readRecord(sapforTasks);
res.put(record.getKey(), record.getValue());
}
return res;
}
*/
/*
public LinkedHashMap<Long, SapforTask> getSapforPackageTasks(String package_id) throws Exception {
LinkedHashMap<Long, SapforTask> res = new LinkedHashMap<>();
for (SapforTask task : sapforTasks.Data.values()) {
if (task.sapfortaskspackage_id.equals(package_id)) {
res.put(task.id, task);
}
}
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 void CheckKeysActuality() throws Exception {
Vector<TaskKey_2022> toDelete = new Vector<>();
for (TaskKey_2022 taskKey : Global.db.tasksKeys.Data.values()) {
if (!testRunTasks.containsKey(taskKey.task_id) || testRunTasks.get(taskKey.task_id).state.isComplete())
toDelete.add(taskKey);
}
System.out.println("to delete size = " + toDelete.size());
if (!toDelete.isEmpty()) {
Global.db.BeginTransaction();
for (TaskKey_2022 taskKey : toDelete)
Global.db.Delete(taskKey);
Global.db.Commit();
}
}
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;
}
}

View File

@@ -0,0 +1,80 @@
package TestingSystem.TasksPackage;
import Common.Database.DBObject;
import Common.Database.nDBObject;
import GlobalData.Machine.MachineType;
import TestingSystem.Tasks.TestCompilationTask;
import java.util.LinkedHashMap;
import java.util.Vector;
public class TasksPackage extends nDBObject {
public String pid=""; //сишная часть.
public String summary = "";
//---
public String dvm_version = "?";
public String sapfor_version = "?";
public String dvm_drv = "";
//---
public String machine_name = "";
public String machine_address = "";
public int machine_port = 22;
public MachineType machine_type;
public String user_name = "";
public String user_password;
public String user_workspace;
//---
public int compilationTasksCount = 0;
public int runTasksCount = 0;
public int needsEmail = 0;
//---
public double Time; //время выполнения.
public long StartDate = 0; //дата начала выполнения
public long ChangeDate = 0;//дата окончания выполнения
//-
public TasksPackageState state = TasksPackageState.Queued;
//--
//нужно только для публикации задач.
public LinkedHashMap<String, LinkedHashMap<String, Vector<TestCompilationTask>>> sorted_tasks = new LinkedHashMap<>();
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
TasksPackage tasksPackage = (TasksPackage) src;
pid = tasksPackage.pid;
summary = tasksPackage.summary;
dvm_drv = tasksPackage.dvm_drv;
dvm_version = tasksPackage.dvm_version;
sapfor_version = tasksPackage.sapfor_version;
machine_name = tasksPackage.machine_name;
machine_address = tasksPackage.machine_address;
machine_port = tasksPackage.machine_port;
machine_type = tasksPackage.machine_type;
user_name = tasksPackage.user_name;
user_workspace = tasksPackage.user_workspace;
user_password = tasksPackage.user_password;
compilationTasksCount = tasksPackage.compilationTasksCount;
runTasksCount = tasksPackage.runTasksCount;
needsEmail = tasksPackage.needsEmail;
Time = tasksPackage.Time;
StartDate = tasksPackage.StartDate;
ChangeDate = tasksPackage.ChangeDate;
sorted_tasks = new LinkedHashMap<>();
state = tasksPackage.state;
//-
for (String group_id : tasksPackage.sorted_tasks.keySet()) {
LinkedHashMap<String, Vector<TestCompilationTask>> src_groupTasks = tasksPackage.sorted_tasks.get(group_id);
LinkedHashMap<String, Vector<TestCompilationTask>> dst_groupTasks = new LinkedHashMap<>();
for (String test_id : src_groupTasks.keySet()) {
Vector<TestCompilationTask> src_testTasks = src_groupTasks.get(test_id);
Vector<TestCompilationTask> dst_testTasks = new Vector<>();
for (TestCompilationTask src_testCompilationTask : src_testTasks)
dst_testTasks.add(new TestCompilationTask(src_testCompilationTask));
dst_groupTasks.put(test_id, dst_testTasks);
}
sorted_tasks.put(group_id, dst_groupTasks);
}
}
public TasksPackage(TasksPackage src) {
this.SynchronizeFields(src);
}
public TasksPackage() {
}
}

View File

@@ -0,0 +1,98 @@
package TestingSystem.TasksPackage;
import Common.Current;
import Common.Database.*;
import Common.UI.DataSetControlForm;
import Common.UI.UI;
import Common.Utils.Utils;
import TestingSystem.Tasks.TestRunTask;
import TestingSystem.TestingServer;
import javax.swing.*;
import java.util.Date;
import java.util.LinkedHashMap;
import static Common.UI.Tables.TableRenderers.RendererDate;
import static Common.UI.Tables.TableRenderers.RendererStatusEnum;
public class TasksPackageDBTable extends DBTable<String, TasksPackage> {
public TasksPackageDBTable() {
super(String.class, TasksPackage.class);
}
@Override
public Current CurrentName() {
return Current.TasksPackage;
}
@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(6).setRenderer(RendererDate);
columns.get(7).setRenderer(RendererDate);
columns.get(8).setRenderer(RendererStatusEnum);
}
@Override
public void ShowCurrentObject() throws Exception {
super.ShowCurrentObject();
UI.getMainWindow().getTestingWindow().DropTestRunTasksComparison();
}
@Override
public void ShowNoCurrentObject() throws Exception {
super.ShowNoCurrentObject();
UI.getMainWindow().getTestingWindow().DropTestRunTasksComparison();
}
};
}
@Override
public String[] getUIColumnNames() {
return new String[]{
"Машина",
"Пользователь",
"DVM",
"Задач",
"Начало",
"Изменено",
"Статус"
};
}
@Override
public Object getFieldAt(TasksPackage object, int columnIndex) {
switch (columnIndex) {
case 2:
return object.machine_address + ":" + object.machine_port;
case 3:
return object.user_name;
case 4:
return object.dvm_version;
case 5:
return object.runTasksCount;
case 6:
return new Date(object.StartDate);
case 7:
return new Date(object.ChangeDate);
case 8:
return object.state;
default:
return null;
}
}
@Override
public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
res.put(TestRunTask.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
return res;
}
}

View File

@@ -0,0 +1,80 @@
package TestingSystem.TasksPackage;
import Common.Current;
import Common.UI.StatusEnum;
import Common.UI.Themes.VisualiserFonts;
import java.awt.*;
public enum TasksPackageState implements StatusEnum {
Queued,
TestsSynchronize, //оставить.
PackageWorkspaceCreation,
PackageStart,
//
CompilationWorkspacesCreation,
CompilationPreparation,
CompilationExecution,
//-
RunningWorkspacesCreation,
RunningPreparation,
RunningExecution,
//--
RunningEnd, //скачка архива
Cleaning, //todo удаление папки пакета на удаленной машине. пока отладки ради не делать.
//---------------------------------------
Analysis,
Done,
Aborted
;
@Override
public Font getFont() {
switch (this) {
case TestsSynchronize:
case Analysis:
return Current.getTheme().Fonts.get(VisualiserFonts.BlueState);
case CompilationExecution:
case RunningExecution:
return Current.getTheme().Fonts.get(VisualiserFonts.ProgressState);
case Done:
return Current.getTheme().Fonts.get(VisualiserFonts.GoodState);
default:
return StatusEnum.super.getFont();
}
}
//-
public String getDescription() {
switch (this) {
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 Cleaning:
return "очистка";
case Done:
return "завершен";
default:
return StatusEnum.super.getDescription();
}
}
}

View File

@@ -0,0 +1,5 @@
package TestingSystem.TasksPackageToKill;
import Common.Database.iDBObject;
public class TasksPackageToKill extends iDBObject {
public String packageName = "";
}

View File

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

View File

@@ -0,0 +1,10 @@
package TestingSystem.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<>();
}

View File

@@ -0,0 +1,43 @@
package TestingSystem.Test;
import Common.Current;
import Common.Database.DBObject;
import Common.Database.rDBObject;
import Common.UI.UI;
import com.sun.org.glassfish.gmbal.Description;
public class Test extends rDBObject {
@Override
public boolean isVisible() {
return TestInterface.isVisible(this);
}
@Description("DEFAULT 1")
public int dim = 1; //размерность теста. для удобства пусть будет и внешним полем.
@Description("DEFAULT ''")
public String args = ""; //аргументы командной строки. на всякий случай поле зарезервирую. пусть будут.
@Description("DEFAULT ''")
public String group_id = "";
@Description("DEFAULT ''")
public String project_description = "";
@Description("IGNORE")
public byte[] project_archive_bytes = null;
@Description("DEFAULT ''")
public String files_json = "";
@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().getTestingWindow().ShowCheckedTestsCount();
}
}

View File

@@ -0,0 +1,92 @@
package TestingSystem.Test;
import Common.Current;
import Common.Database.DBTable;
import Common.UI.DataSetControlForm;
import Common.UI.Windows.Dialog.DBObjectDialog;
import TestingSystem.Test.UI.TestFields;
public class TestDBTable extends DBTable<String, Test> {
public TestDBTable() {
super(String.class, 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.project_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);
// fields.tfProjectDescription.setText(Result.project_description);
}
@Override
public void ProcessResult() {
Result.description = fields.tfName.getText();
Result.dim = (int) fields.sDim.getValue();
// Result.project_description = fields.tfProjectDescription.getText();
if (!edit) {
Result.genName();
Result.sender_name = Current.getAccount().name;
Result.sender_address = Current.getAccount().email;
}
}
};
}
}

View File

@@ -0,0 +1,41 @@
package TestingSystem.Test;
import Common.Current;
import Common.Global;
import java.io.File;
import java.nio.file.Paths;
import java.util.Date;
public class TestInterface {
public static String filterName = "";
public static String filterSenderName = "";
public static boolean filterMyOnly = false;
public static boolean isVisible(Test object) {
return Current.HasGroup() && (Current.getGroup().id.equals(object.group_id))
&&
object.id.toUpperCase().contains(filterName.toUpperCase()) &&
object.sender_name.toUpperCase().contains(filterSenderName.toUpperCase()) &&
(!filterMyOnly || object.sender_address.equalsIgnoreCase(Current.getAccount().email));
}
//-
public static Date getDate(Test object) {
return new Date(object.date);
}
public static void CopyFields(Test src, Test dst) {
dst.dim = src.dim;
dst.description = src.description;
dst.args = src.args;
}
public static File getArchive(Test object) {
return Paths.get(System.getProperty("user.dir"), "Tests", object.id + ".zip").toFile();
}
public static File getServerPath(Test object) {
return Paths.get(System.getProperty("user.dir"), "Tests", object.id).toFile();
}
public static File getHomePath(Test object) {
return Paths.get(Global.visualiser.getWorkspace().getAbsolutePath(), object.id).toFile();
}
public static String getSummary(Test test) {
return test.description;
}
//--
}

View File

@@ -0,0 +1,22 @@
package TestingSystem.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,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="TestingSystem.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>

View File

@@ -0,0 +1,22 @@
package TestingSystem.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));
}
}

View File

@@ -0,0 +1,196 @@
package TestingSystem;
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.MachineMaxKernels.MachineMaxKernels;
import TestingSystem.Tasks.TestCompilationTask;
import TestingSystem.Tasks.TestTask;
import TestingSystem.TasksPackage.TasksPackage;
import TestingSystem.TasksPackage.TasksPackageState;
import TestingSystem.TestsSupervisor_2022.TestsSupervisor_2022;
import Visual_DVM_2021.Passes.PassException;
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
import Visual_DVM_2021.Passes.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 TestingSystem.TasksDatabase.tests_db_name;
public class TestingPlanner {
protected 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<>();
public MachineMaxKernels maxKernels = null;
//----------
public void UpdateTask(TestTask task_in) throws Exception {
task_in.ChangeDate = new Date().getTime();
ServerCommand(ServerCode.EditAccountObject, task_in);
}
public void UpdatePackage(TasksPackage package_in) throws Exception {
package_in.ChangeDate = new Date().getTime();
ServerCommand(ServerCode.EditAccountObject, package_in);
//---------------
if ((package_in.needsEmail == 1) &&
(package_in.state.equals(TasksPackageState.PackageStart) ||
(package_in.state.equals(TasksPackageState.Done)))) {
EmailMessage message = new EmailMessage();
message.subject = "Состояние пакета задач " + Utils.Brackets(package_in.id) + " изменилось на " + Utils.Brackets(package_in.state.getDescription());
message.text = package_in.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 {
Pair<TasksPackage, LinkedHashMap<Long, TestCompilationTask>> p = (Pair<TasksPackage, LinkedHashMap<Long, TestCompilationTask>>) ServerCommand(ServerCode.GetFirstActiveAccountPackage);
tasksPackage = null;
packageTasks = null;
tasksPackage = p.getKey();
packageTasks = p.getValue();
if (tasksPackage != null) {
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);
//-->>
maxKernels = (MachineMaxKernels) ServerCommand(ServerCode.GetObjectCopyByPK, "", new Pair<>(MachineMaxKernels.class, 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;
}
}
}
}
} 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);
}
}

View File

@@ -0,0 +1,449 @@
package TestingSystem;
import Common.Database.DBObject;
import Common.Database.rDBObject;
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.RepositoryRefuseException;
import Repository.RepositoryServer;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import TestingSystem.Group.Group;
import TestingSystem.Group.GroupInterface;
import TestingSystem.Tasks.TestCompilationTask;
import TestingSystem.Tasks.TestRunTask;
import TestingSystem.Tasks.TestTask;
import TestingSystem.TasksPackage.TasksPackage;
import TestingSystem.TasksPackageToKill.TasksPackageToKill;
import TestingSystem.Test.Test;
import TestingSystem.Test.TestInterface;
import TestingSystem.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 org.apache.commons.io.FileUtils;
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 java.util.stream.Collectors;
import static TestingSystem.TasksDatabase.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 (String group_id : tasksPackage.sorted_tasks.keySet()) {
if (db.groups.containsKey(group_id)) {
Group group = db.groups.get(group_id);
LinkedHashMap<String, Vector<TestCompilationTask>> group_tasks = tasksPackage.sorted_tasks.get((group_id));
for (String 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 = GroupInterface.GenerateMakefile(group, 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, TestInterface.getArchive(new_test));
//распаковать архив в папку с тестами. для тестирования удобнее хранить их уже открытыми.
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
if (!unzipFolderPass.Do(
TestInterface.getArchive(new_test).getAbsolutePath(),
TestInterface.getServerPath(new_test).getParentFile().getAbsolutePath()))
throw new RepositoryRefuseException("Не удалось распаковать Тест с именем " + new_test.id);
}
}
@Override
public void CopyAction(rDBObject src, rDBObject dst) throws Exception {
if (src instanceof Group) {
Group groupSrc = (Group) src;
Group groupDst = (Group) dst;
//тут есть право использовать Базу данных напрямую, ибо проход в серверной очереди.
//1. Получить список тестов.
Vector<Test> toCopy = db.tests.Data.values().stream().filter(test -> test.group_id.equals(groupSrc.id)).collect(Collectors.toCollection(Vector::new));
for (Test testSrc : toCopy) {
Test testCopy = new Test(testSrc);
testCopy.genName();
testCopy.sender_name = groupDst.sender_name;
testCopy.sender_address = groupDst.sender_address;
testCopy.group_id = groupDst.id;
//1 скопировать папку
FileUtils.copyDirectory(TestInterface.getServerPath(testSrc), TestInterface.getServerPath(testCopy));
//создать архив из скопированной папки.
ZipFolderPass zip = new ZipFolderPass();
if (!zip.Do(TestInterface.getServerPath(testCopy).getAbsolutePath(), TestInterface.getArchive(testCopy).getAbsolutePath()))
throw new RepositoryRefuseException("Не удалось создать архив копии теста");
db.Insert(testCopy);
}
}
}
@Override
public void DeleteAction(DBObject object) throws Exception {
if (object instanceof Test) {
Test test = (Test) object;
Utils.forceDeleteWithCheck(TestInterface.getArchive(test));
Utils.forceDeleteWithCheck(TestInterface.getServerPath(test));
} 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.equals(group.id)) // todo group_name -> group_id
tests.add(group_test);
}
for (Test group_test : tests) {
db.Delete(group_test);
Utils.forceDeleteWithCheck(TestInterface.getArchive(group_test));
Utils.forceDeleteWithCheck(TestInterface.getServerPath(group_test));
}
}
}
@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 Session() throws Exception {
DBObject dbObject = null;
Test test = null;
switch (code) {
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 DeleteAccountObjects:
Print("Удалить список объектов с базы пользователя " + request.arg);
SetCurrentAccountDB(request.arg);
Vector<Object> objects = (Vector<Object>) request.object;
account_db.BeginTransaction();
for (Object object : objects) {
dbObject = (DBObject) object;
if (canDelete(dbObject)) {
account_db.DeleteWithCheck(dbObject);
DeleteAction(dbObject);
}
}
account_db.Commit();
response = new ServerExchangeUnit_2021(ServerCode.OK);
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(TestInterface.getArchive(test)));
} 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 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;
default:
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
}
}
@Override
protected void startAdditionalThreads() {
testingThread.start();
}
protected TestingPlanner testingPlanner = new TestingPlanner();
protected Thread testingThread = new Thread(() -> testingPlanner.Perform());
//------>>>
public static boolean checkTasks = false;
//--
public static void switchTimer(boolean on) {
if (on)
TimerOn();
else
TimerOff();
}
public static int checkIntervalSecond = 10;
public static Timer checkTimer = null;
public static void TimerOn() {
checkTasks = true;
checkTimer = new Timer(checkIntervalSecond * 1000, e -> {
Pass_2021.passes.get(PassCode_2021.ActualizePackages).Do();
});
checkTimer.start();
}
public static void TimerOff() {
System.out.println("timer off");
if (checkTimer != null)
checkTimer.stop();
checkTasks = false;
}
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;
}
}

View File

@@ -0,0 +1,61 @@
package TestingSystem;
import Common.Database.SQLITE.SQLiteDatabase;
import GlobalData.Settings.SettingName;
import TestingSystem.Configuration.UI.ConfigurationDBTable;
import TestingSystem.Group.GroupsDBTable;
import TestingSystem.MachineMaxKernels.MachineMaxKernelsDBTable;
import TestingSystem.Sapfor.SapforConfiguration.SapforConfigurationDBTable;
import TestingSystem.Sapfor.SapforConfigurationCommand.SapforConfigurationCommandsDBTable;
import TestingSystem.TSetting.TSetting;
import TestingSystem.TSetting.TSettingsDBTable;
import TestingSystem.Test.TestDBTable;
import java.nio.file.Paths;
public class TestsDatabase extends SQLiteDatabase {
public ConfigurationDBTable configurations;
public TestDBTable tests;
public GroupsDBTable groups;
public MachineMaxKernelsDBTable machinesMaxKernels;
public TSettingsDBTable settings;
//--
public SapforConfigurationDBTable sapforConfigurations;
public SapforConfigurationCommandsDBTable sapforConfigurationCommands;
//
//--
public TestsDatabase() {
super(Paths.get(System.getProperty("user.dir"), "Data", TasksDatabase.tests_db_name + ".sqlite").toFile());
}
@Override
protected void initAllTables() throws Exception {
addTable(configurations = new ConfigurationDBTable());
addTable(groups = new GroupsDBTable());
addTable(tests = new TestDBTable());
addTable(machinesMaxKernels = new MachineMaxKernelsDBTable());
addTable(settings = new TSettingsDBTable());
//-
addTable(sapforConfigurations = new SapforConfigurationDBTable());
addTable(sapforConfigurationCommands = new SapforConfigurationCommandsDBTable());
}
@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));
}
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;
}
}

View File

@@ -0,0 +1,322 @@
package TestingSystem.TestsSupervisor_2022;
import Common.Global;
import Common.Utils.Utils;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.Tasks.TaskState;
import ProjectData.Project.db_project_info;
import Repository.Server.ServerCode;
import TestingSystem.Tasks.TestCompilationTask;
import TestingSystem.Tasks.TestRunTask;
import TestingSystem.Tasks.TestRunTaskInterface;
import TestingSystem.Tasks.TestTask;
import TestingSystem.TasksPackage.TasksPackage;
import TestingSystem.TasksPackage.TasksPackageState;
import TestingSystem.Test.TestType;
import TestingSystem.TestingPlanner;
import TestingSystem.UserConnection;
import com.jcraft.jsch.ChannelSftp;
import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Vector;
public class TestsSupervisor_2022 {
protected TestingPlanner planner; //планировщик.
protected UserConnection connection;
protected TasksPackage tasksPackage;
protected RemoteFile packageRemoteWorkspace;
protected File packageLocalWorkspace;
protected Vector<TestCompilationTask> compilationTasks; //список задач на компиляцию
protected int count = 0; //число активных задач.
//----
public TestsSupervisor_2022(TestingPlanner planner_in, UserConnection connection_in, TasksPackage tasksPackage_in, Vector<TestCompilationTask> tasks_in) {
planner = planner_in;
connection = connection_in;
tasksPackage = tasksPackage_in;
compilationTasks = tasks_in;
planner.Print(getClass().getSimpleName() + ": найдено задач на компиляцию: " + compilationTasks.size());
packageRemoteWorkspace = new RemoteFile(tasksPackage.user_workspace + "/tests", tasksPackage.id, true);
packageLocalWorkspace = Paths.get(Global.PackagesDirectory.getAbsolutePath(), tasksPackage.id).toFile();
}
public boolean packageNeedsKill() throws Exception{
return (boolean) planner.ServerCommand(ServerCode.CheckPackageToKill,tasksPackage.id);
}
public void Perform() throws Exception {
if (packageNeedsKill()){
System.out.println("PACKAGE "+tasksPackage.id+" NEEDS TO KILL");
if (!tasksPackage.pid.isEmpty()) {
connection.ShellCommand("kill -9 " + tasksPackage.pid);
}
tasksPackage.state = TasksPackageState.Aborted;
planner.UpdatePackage(tasksPackage);
}else {
switch (tasksPackage.state) {
case TestsSynchronize:
TestsSynchronize();
tasksPackage.state = TasksPackageState.PackageWorkspaceCreation;
planner.UpdatePackage(tasksPackage);
break;
case PackageWorkspaceCreation:
PackageWorkspaceCreation();
tasksPackage.state = TasksPackageState.PackageStart;
planner.UpdatePackage(tasksPackage);
break;
case PackageStart:
PackageStart();
tasksPackage.state = TasksPackageState.CompilationWorkspacesCreation;
planner.UpdatePackage(tasksPackage);
break;
case CompilationWorkspacesCreation:
case CompilationPreparation:
case CompilationExecution:
case RunningWorkspacesCreation:
case RunningPreparation:
case RunningExecution:
checkNextState();
break;
case RunningEnd:
DownloadResults();
tasksPackage.state = TasksPackageState.Analysis;
planner.UpdatePackage(tasksPackage);
break;
case Analysis:
AnalyseResults();
tasksPackage.state = TasksPackageState.Done;
planner.UpdatePackage(tasksPackage);
break;
default:
break;
}
}
}
private void TestsSynchronize() throws Exception {
//1, получить набор уникальных тестов.
Vector<String> test_ids = new Vector<>();
for (TestCompilationTask current_task : compilationTasks)
if (!test_ids.contains(current_task.test_id))
test_ids.add(current_task.test_id);
//синхронизировать их.
for (String test_id : test_ids) {
File test_src = Paths.get(Global.TestsDirectory.getAbsolutePath(), test_id).toFile();
RemoteFile test_dst = new RemoteFile(tasksPackage.user_workspace + "/projects/" + test_id, true);
connection.MKDIR(test_dst);
connection.SynchronizeSubDirsR(test_src, test_dst);
}
}
private void PackageWorkspaceCreation() throws Exception {
//создать папку для пакета.
connection.sftpChannel.mkdir(packageRemoteWorkspace.full_name);
//положить туда запакованные тексты задач.
Vector<String> compilationLines = new Vector<>();
Vector<String> runLines = new Vector<>();
for (TestCompilationTask compilationTask : planner.packageTasks.values()) {
compilationLines.addAll(compilationTask.pack(1));
for (TestRunTask runTask : compilationTask.runTasks) {
int rt_kernels = (runTask.test_type == TestType.Performance) ? planner.maxKernels.limit :
Math.min(Utils.getMatrixProcessors(runTask.matrix), planner.maxKernels.limit);
runLines.addAll(runTask.pack(rt_kernels));
}
}
RemoteFile compilationPackage = new RemoteFile(packageRemoteWorkspace, "compilationTasks");
RemoteFile runPackage = new RemoteFile(packageRemoteWorkspace, "runTasks");
connection.writeToFile(String.join("\n", compilationLines) + "\n", compilationPackage);
connection.writeToFile(String.join("\n", runLines) + "\n", runPackage);
// --
connection.MKDIR(new RemoteFile(packageRemoteWorkspace, "state"));
}
private void PackageStart() throws Exception {
String plannerStartCommand =
String.join(" ",
"nohup",
Utils.DQuotes(planner.getPlanner()),
Utils.DQuotes(tasksPackage.user_workspace),
Utils.DQuotes(packageRemoteWorkspace.full_name),
Utils.DQuotes(planner.maxKernels.limit),
Utils.DQuotes(tasksPackage.dvm_drv),
"&"
);
connection.ShellCommand(plannerStartCommand);
RemoteFile PID = new RemoteFile(packageRemoteWorkspace, "PID");
while (!connection.Exists(packageRemoteWorkspace.full_name, "STARTED")){
System.out.println("waiting for package start...");
Utils.sleep(1000);
}
if (connection.Exists(packageRemoteWorkspace.full_name, "PID")){
tasksPackage.pid = connection.readFromFile(PID);
}
}
public void checkNextState() throws Exception {
TasksPackageState oldState = tasksPackage.state;
Vector<ChannelSftp.LsEntry> files_ = connection.sftpChannel.ls(packageRemoteWorkspace.full_name + "/state");
Vector<ChannelSftp.LsEntry> files = new Vector<>();
for (ChannelSftp.LsEntry file : files_) {
try {
TasksPackageState.valueOf(file.getFilename());
files.add(file);
} catch (Exception ignore) {
}
}
files.sort(Comparator.comparingInt(o -> o.getAttrs().getMTime()));
if (!files.isEmpty()) {
String fileName = files.get(files.size() - 1).getFilename();
System.out.println(fileName + " last file");
tasksPackage.state = TasksPackageState.valueOf(files.get(files.size() - 1).getFilename());
if (tasksPackage.state != oldState)
planner.UpdatePackage(tasksPackage);
}
}
public void DownloadResults() throws Exception {
Utils.CheckDirectory(packageLocalWorkspace);
for (TestCompilationTask testCompilationTask : compilationTasks) {
//------------>>>
if (TryDownloadTask(testCompilationTask)) {
for (TestRunTask testRunTask : testCompilationTask.runTasks) {
TryDownloadTask(testRunTask);
}
}else {
//задача на компиляцию не состоялась. значит и все ее задачи на запуск тоже.
for (TestRunTask testRunTask : testCompilationTask.runTasks) {
testRunTask.state = TaskState.Canceled;
planner.UpdateTask(testRunTask);
}
}
//--->>>>>>>>>
}
}
public boolean TryDownloadTask(TestTask testTask) throws Exception {
if (
!testTask.state.equals(TaskState.ResultsDownloaded) &&
!testTask.state.equals(TaskState.Canceled)
) {
File taskLocalWorkspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), String.valueOf(testTask.id)).toFile();
RemoteFile taskRemoteWorkspace = new RemoteFile(packageRemoteWorkspace.full_name, String.valueOf(testTask.id));
Utils.CheckDirectory(taskLocalWorkspace);
if (connection.Exists(packageRemoteWorkspace.full_name, String.valueOf(testTask.id))) {
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, db_project_info.out_file);
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, db_project_info.err_file);
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, db_project_info.time_file);
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, "TaskState");
if (testTask instanceof TestRunTask)
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, "sts.gz+");
testTask.state = TaskState.ResultsDownloaded;
planner.UpdateTask(testTask);
return true;
} else {
testTask.state = TaskState.Canceled;
planner.UpdateTask(testTask);
return false;
//нет раб пространства. значит задача не выполнялась.
}
} else return true;
}
public void CheckTaskFile(RemoteFile taskRemoteWorkspace, File taskLocalWorkspace, String fileName) throws Exception {
RemoteFile rFile = new RemoteFile(taskRemoteWorkspace.full_name, fileName);
File lFile = Paths.get(taskLocalWorkspace.getAbsolutePath(), fileName).toFile();
if (connection.Exists(taskRemoteWorkspace.full_name, fileName)) {
connection.getSingleFile(rFile, lFile, 0);
}
}
public void AnalyseResults() throws Exception {
System.out.println("analysing results");
int ct_count = 0;
int rt_count = 0;
for (TestCompilationTask testCompilationTask : compilationTasks) {
ct_count++;
if (CheckTask(testCompilationTask)) {
planner.UpdateTask(testCompilationTask);
for (TestRunTask testRunTask : testCompilationTask.runTasks) {
rt_count++;
testRunTask.compilation_state = testCompilationTask.state;
testRunTask.compilation_output = testCompilationTask.output;
testRunTask.compilation_errors = testCompilationTask.errors;
if (testCompilationTask.state == TaskState.DoneWithErrors) {
testRunTask.state = TaskState.Canceled;
} else {
CheckTask(testRunTask);
}
planner.UpdateTask(testRunTask);
if (testRunTask.state.equals(TaskState.Finished)) {
//анализ задачи на запуск.
List<String> output_lines = Arrays.asList(testRunTask.output.split("\n"));
List<String> errors_lines = Arrays.asList(testRunTask.errors.split("\n"));
//---
if (TestRunTaskInterface.isCrushed(output_lines, errors_lines)) {
testRunTask.state = TaskState.Crushed;
} else {
Pair<TaskState, Integer> results = new Pair<>(TaskState.Done, 100);
switch (testRunTask.test_type) {
case Correctness:
results = TestRunTaskInterface.analyzeCorrectness(output_lines);
break;
case Performance:
results = TestRunTaskInterface.analyzePerformance(output_lines);
break;
default:
break;
}
testRunTask.state = results.getKey();
testRunTask.progress = results.getValue();
testRunTask.CleanTime = TestRunTaskInterface.parseCleanTime(testRunTask.output);
}
File local_sts_text = Utils.getTempFileName("sts_text");
Vector<ChannelSftp.LsEntry> files = connection.sftpChannel.ls(testRunTask.remote_workspace);
for (ChannelSftp.LsEntry file : files) {
if (file.getFilename().equals("sts.gz+")) {
RemoteFile remote_sts = new RemoteFile(
testRunTask.remote_workspace, file.getFilename(), false);
RemoteFile remote_sts_text = new RemoteFile(
testRunTask.remote_workspace, "statistic.txt", false);
try {
connection.ShellCommand(Utils.DQuotes(tasksPackage.dvm_drv) + " pa " +
Utils.DQuotes(remote_sts.full_name) + " " + Utils.DQuotes(remote_sts_text.full_name));
connection.getSingleFile(remote_sts_text, local_sts_text, 10240);
} catch (Exception ex) {
ex.printStackTrace();
}
if (local_sts_text.exists()) {
try {
testRunTask.statistic = FileUtils.readFileToString(local_sts_text, Charset.defaultCharset());
} catch (Exception e) {
e.printStackTrace();
}
}
break;
}
}
}
planner.UpdateTask(testRunTask);
}
}
}
System.out.println("ct_count=" + ct_count + " rt count=" + rt_count);
}
public boolean CheckTask(TestTask testTask) throws Exception {
if (testTask.state.equals(TaskState.ResultsDownloaded)) {
File taskWorkspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), String.valueOf(testTask.id)).toFile();
System.out.println("id=" + testTask.id + ": path=" + taskWorkspace.getAbsolutePath());
File stateFile = Paths.get(taskWorkspace.getAbsolutePath(), "TaskState").toFile();
File outFile = Paths.get(taskWorkspace.getAbsolutePath(), db_project_info.out_file).toFile();
File errFile = Paths.get(taskWorkspace.getAbsolutePath(), db_project_info.err_file).toFile();
File timeFile = Paths.get(taskWorkspace.getAbsolutePath(), db_project_info.time_file).toFile();
if (outFile.exists())
testTask.output = FileUtils.readFileToString(outFile);
if (errFile.exists())
testTask.errors = FileUtils.readFileToString(errFile);
if (timeFile.exists())
testTask.Time = Double.parseDouble(Utils.ReadAllText(timeFile));
if (stateFile.exists()) {
String stateText = FileUtils.readFileToString(stateFile, Charset.defaultCharset()).replace("\n", "");
testTask.state = TaskState.valueOf(stateText);
} else testTask.state = TaskState.InternalError; //поменять на то что состояние не найдено. ?
return true;
}
return false;
}
}

View File

@@ -0,0 +1,228 @@
package TestingSystem;
import Common.Global;
import Common.Utils.Utils;
import Common.Utils.Validators.ShellParser;
import GlobalData.Machine.Machine;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.User.User;
import ProjectData.Project.db_project_info;
import Visual_DVM_2021.Passes.PassException;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.ChannelShell;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Vector;
public class UserConnection {
public ChannelSftp sftpChannel = null;
public ChannelShell shellChannel = null;
//--
JSch jsch = null;
Session session = null;
//---
PipedInputStream in = null;
PipedOutputStream out = null;
//---
PipedOutputStream pin = null;
PipedInputStream pout = null;
InputStreamReader fromServer = null;
//---
public UserConnection(Machine machine, User user) throws Exception {
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();
//-->
//создать канал для команд
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 Disconnect() {
if (in != null) {
try {
in.close();
} catch (Exception exception) {
Global.Log.PrintException(exception);
}
}
if (out != null) {
try {
out.close();
} catch (Exception exception) {
Global.Log.PrintException(exception);
}
}
if (pin != null) {
try {
pin.close();
} catch (Exception exception) {
Global.Log.PrintException(exception);
}
}
if (pout != null) {
try {
pout.close();
} catch (Exception exception) {
Global.Log.PrintException(exception);
}
}
if (fromServer != null) {
try {
fromServer.close();
} catch (Exception exception) {
Global.Log.PrintException(exception);
}
}
if (sftpChannel != null) sftpChannel.disconnect();
if (shellChannel != null) shellChannel.disconnect();
if (session != null) session.disconnect();
//----------------------
sftpChannel = null;
shellChannel = null;
jsch = null;
session = null;
//---
in = null;
out = null;
//---
pin = null;
pout = null;
fromServer = null;
System.gc();
}
//--
//из за мусора результатом пользоваться в общем случае невозможно.
public String ShellCommand(String command) throws Exception {
StringBuilder result = new StringBuilder();
// System.out.println("command=" + Utils.Brackets(command));
pin.write((command + "\r\n").getBytes());
ShellParser.ReadInvitation(fromServer); //первое приглашение после эхо. возможен мусор.
result.append(ShellParser.getCommandResult(fromServer)); //возможный результат и второе приглашение.
// System.out.println("answer=" + Utils.Brackets(result));
//в реалиях визуалиазтора нас интересует только ПОСЛЕДНЯЯ СТРОКА ОТВЕТА.
String[] data = result.toString().split("\n");
// System.out.println("res="+Utils.Brackets(res));
return (data.length > 0) ? data[data.length - 1] : result.toString();
}
//--
//тут имя файла короткое.
public boolean Exists(String folder, String name) throws Exception {
Vector<ChannelSftp.LsEntry> files = sftpChannel.ls(folder);
for (ChannelSftp.LsEntry file : files) {
file.getAttrs().getSize();
if (file.getFilename().equals(name)) {
return true;
}
}
return false;
}
//--
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 boolean getSingleFile(RemoteFile src, File dst, int maxSize) throws Exception {
if (Exists(src.parent, src.name)) {
if ((maxSize == 0) || getFileKBSize(src.full_name) <= maxSize) {
getSingleFile(src.full_name, dst.getAbsolutePath());
return true;
} else {
Utils.WriteToFile(dst, "Размер файла превышает " + maxSize + " KB.\n" + "Файл не загружен. Его можно просмотреть на машине по адресу\n" + Utils.Brackets(src.full_name));
}
}
return false;
}
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.parent, dir.name)) sftpChannel.mkdir(dir.full_name);
}
//-
public void RMDIR(String dir) throws Exception {
if (!dir.isEmpty() && !dir.equals("/") && !dir.equals("\\") && !dir.equals("*")) {
ShellCommand("rm -rf " + Utils.DQuotes(dir));
} else throw new PassException("Недопустимый путь для удаления папки " + Utils.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(db_project_info.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 copy(RemoteFile src, RemoteFile dst) throws Exception {
ShellCommand("cp " + Utils.DQuotes(src.full_name) + " " + Utils.DQuotes(dst.full_name));
}
*/
//-------
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());
}
}