no message

This commit is contained in:
2023-11-17 00:04:21 +03:00
parent 1ff88fc5fb
commit beb1359544
132 changed files with 617 additions and 591 deletions

View File

@@ -0,0 +1,36 @@
package TestingSystem.DVM.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.DVM.Configuration;
import Common.Utils.Utils;
import GlobalData.RunConfiguration.RunConfiguration;
import java.util.Vector;
public class ConfigurationInterface {
public static Vector<String> getFlags(TestingSystem.DVM.Configuration.Configuration object) {
return Utils.unpackStrings(object.flags);
}
public static Vector<String> getEnvironments(TestingSystem.DVM.Configuration.Configuration object) {
return Utils.unpackStrings(object.environments);
}
public static Vector<String> getParams(TestingSystem.DVM.Configuration.Configuration object) {
return Utils.unpackStrings(object.usr_par);
}
public static Vector<String> getMatrixes(TestingSystem.DVM.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,164 @@
package TestingSystem.DVM.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.DVM.Configuration.Configuration;
import TestingSystem.DVM.Configuration.ConfigurationInterface;
public class ConfigurationDBTable extends DBTable<String, Configuration> {
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.DVM.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.DVM.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,51 @@
package TestingSystem.DVM.Tasks;
import Common.Database.DBObject;
import TestingSystem.DVM.Configuration.Configuration;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.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(String.valueOf(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.DVM.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.DVM.Tasks;
import Common.Constants;
import Common.Database.DBObject;
import GlobalData.Tasks.TaskState;
import ProjectData.LanguageName;
import TestingSystem.DVM.Configuration.Configuration;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.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 = Constants.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,83 @@
package TestingSystem.DVM.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 boolean isVisible(TestRunTask object) {
return
Current.HasTasksPackage() &&
object.taskspackage_id.equals(Current.getTasksPackage().id) &&
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.DVM.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.DVM.Tasks;
import Common.Constants;
import Common.Database.DBObject;
import GlobalData.Tasks.TaskState;
import TestingSystem.DVM.Configuration.Configuration;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Test.Test;
import TestingSystem.Common.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 = Constants.Nan;
@Description("DEFAULT ''")
public String taskspackage_id = "";
@Description("DEFAULT -1")
public int group_id = Constants.Nan;
@Description("DEFAULT ''")
public String group_description = ""; //видимое имя группы для юзера
@Description("DEFAULT -1")
public int test_id = Constants.Nan; //ключ - будет генерироваться автоматически.
@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,83 @@
package TestingSystem.DVM.TasksPackage;
import Common.Database.DBObject;
import Common.Database.nDBObject;
import GlobalData.Machine.MachineType;
import TestingSystem.DVM.Tasks.TestCompilationTask;
import com.sun.org.glassfish.gmbal.Description;
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 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;//дата окончания выполнения
//-
@Description("DEFAULT 1")
public int kernels = 1;
//-
public TasksPackageState state = TasksPackageState.Queued;
//--
//нужно только для публикации задач.
public LinkedHashMap<Integer, LinkedHashMap<Integer, 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;
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<>();
kernels = tasksPackage.kernels;
state = tasksPackage.state;
//-
for (int group_id : tasksPackage.sorted_tasks.keySet()) {
LinkedHashMap<Integer, Vector<TestCompilationTask>> src_groupTasks = tasksPackage.sorted_tasks.get(group_id);
LinkedHashMap<Integer, Vector<TestCompilationTask>> dst_groupTasks = new LinkedHashMap<>();
for (int 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,100 @@
package TestingSystem.DVM.TasksPackage;
import Common.Current;
import Common.Database.*;
import Common.UI.DataSetControlForm;
import Common.UI.UI;
import TestingSystem.DVM.Tasks.TestRunTask;
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(0).setVisible(false);
columns.get(7).setRenderer(RendererDate);
columns.get(8).setRenderer(RendererDate);
columns.get(9).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 object.kernels;
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(TestRunTask.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
return res;
}
}

View File

@@ -0,0 +1,88 @@
package TestingSystem.DVM.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;
public boolean isActive() {
switch (this) {
case Done:
case Aborted:
return false;
default:
return true;
}
}
@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,321 @@
package TestingSystem.DVM;
import Common.Constants;
import Common.Global;
import Common.Utils.Utils;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.Tasks.TaskState;
import Repository.Server.ServerCode;
import TestingSystem.DVM.Tasks.TestCompilationTask;
import TestingSystem.DVM.Tasks.TestRunTask;
import TestingSystem.DVM.Tasks.TestRunTaskInterface;
import TestingSystem.DVM.Tasks.TestTask;
import TestingSystem.DVM.TasksPackage.TasksPackage;
import TestingSystem.DVM.TasksPackage.TasksPackageState;
import TestingSystem.Common.Test.TestType;
import TestingSystem.Common.TestingPlanner;
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();
}else {
switch (tasksPackage.state) {
case TestsSynchronize:
TestsSynchronize();
tasksPackage.state = TasksPackageState.PackageWorkspaceCreation;
planner.UpdatePackage();
break;
case PackageWorkspaceCreation:
PackageWorkspaceCreation();
tasksPackage.state = TasksPackageState.PackageStart;
planner.UpdatePackage();
break;
case PackageStart:
PackageStart();
tasksPackage.state = TasksPackageState.CompilationWorkspacesCreation;
planner.UpdatePackage();
break;
case CompilationWorkspacesCreation:
case CompilationPreparation:
case CompilationExecution:
case RunningWorkspacesCreation:
case RunningPreparation:
case RunningExecution:
checkNextState();
break;
case RunningEnd:
DownloadResults();
tasksPackage.state = TasksPackageState.Analysis;
planner.UpdatePackage();
break;
case Analysis:
AnalyseResults();
tasksPackage.state = TasksPackageState.Done;
planner.UpdatePackage();
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(String.valueOf(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) ? tasksPackage.kernels :
Math.min(Utils.getMatrixProcessors(runTask.matrix), tasksPackage.kernels);
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(tasksPackage.kernels),
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();
}
}
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, Constants.out_file);
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, Constants.err_file);
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, Constants.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(), Constants.out_file).toFile();
File errFile = Paths.get(taskWorkspace.getAbsolutePath(), Constants.err_file).toFile();
File timeFile = Paths.get(taskWorkspace.getAbsolutePath(), Constants.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.DVM;
import Common.Constants;
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 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(Constants.data)) {
RemoteFile rsd = null;
if (!remote_subdirs.containsKey(lsd.getName()))
sftpChannel.mkdir((rsd = new RemoteFile(remote_dir.full_name, lsd.getName(), true)).full_name);
else rsd = remote_subdirs.get(lsd.getName());
SynchronizeSubDirsR(lsd, rsd);
}
}
}
if (local_files != null) {
for (File lf : local_files) {
RemoteFile rf = null;
if (!remote_files.containsKey(lf.getName())) {
rf = new RemoteFile(remote_dir.full_name, lf.getName());
putSingleFile(lf, rf);
} else {
rf = remote_files.get(lf.getName());
if (lf.lastModified() > rf.updateTime) {
putSingleFile(lf, rf);
}
}
}
}
}
/*
public void 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());
}
}