рефакторинг серверной части сапфора.
This commit is contained in:
@@ -3,9 +3,10 @@ import Common.Constants;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class SapforConfiguration_json {
|
||||
public class SapforConfiguration_json implements Serializable {
|
||||
@Expose
|
||||
public int id = Constants.Nan;
|
||||
@Expose
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package TestingSystem.SAPFOR.Json;
|
||||
import TestingSystem.SAPFOR.SapforTask.SapforTask;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.UI.PackageSummary;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class SapforTasksPackage_json {
|
||||
public class SapforTasksPackage_json implements Serializable {
|
||||
@Expose
|
||||
public int kernels = 1;
|
||||
@Expose
|
||||
@@ -12,4 +15,7 @@ public class SapforTasksPackage_json {
|
||||
public List<SapforTest_json> tests = new Vector<>();
|
||||
@Expose
|
||||
public List<SapforConfiguration_json> configurations = new Vector<>();
|
||||
//---
|
||||
@Expose
|
||||
public List<SapforTask> tasks = new Vector<>();
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import com.google.gson.annotations.Expose;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class SapforTasksResults_json {
|
||||
public class SapforTasksResults_json implements Serializable {
|
||||
//---
|
||||
public PackageSummary root = null;
|
||||
public PackageSummary comparison_root = null;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package TestingSystem.SAPFOR.Json;
|
||||
import com.google.gson.annotations.Expose;
|
||||
public class SapforTest_json {
|
||||
|
||||
import java.io.Serializable;
|
||||
public class SapforTest_json implements Serializable {
|
||||
@Expose
|
||||
public String test_description = "";
|
||||
public int id;
|
||||
@Expose
|
||||
public String description = "";
|
||||
@Expose
|
||||
public String group_description = "";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package TestingSystem.SAPFOR.Json;
|
||||
public enum SapforVersionState {
|
||||
import java.io.Serializable;
|
||||
public enum SapforVersionState implements Serializable {
|
||||
Empty, //версия оказалась пуста.
|
||||
Normal, //версия построена
|
||||
HasErrors //в журнале версии есть ошибки. то есть, не удалось построить следующую версию.
|
||||
|
||||
@@ -13,31 +13,42 @@ import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
public class PackageModeSupervisor extends ThreadsPlanner {
|
||||
SapforTasksPackage_json package_json = null;
|
||||
SapforTasksResults_json results_json = new SapforTasksResults_json();
|
||||
File sapfor_drv=null;
|
||||
|
||||
public PackageModeSupervisor() throws Exception {
|
||||
super(2000);
|
||||
package_json = (SapforTasksPackage_json) Utils.jsonFromFile(new File(Global.Home, Constants.package_json), SapforTasksPackage_json.class);
|
||||
package_json = (SapforTasksPackage_json) Utils.jsonFromFile(new File(Constants.package_json), SapforTasksPackage_json.class);
|
||||
//--
|
||||
File sapfor_src = new File(package_json.sapfor_drv);
|
||||
sapfor_drv = new File(Global.Home,Utils.getDateName("SAPFOR_F"));
|
||||
FileUtils.copyFile(sapfor_src, sapfor_drv);
|
||||
if (!sapfor_drv.setExecutable(true))
|
||||
throw new Exception("Не удалось сделать файл " + sapfor_drv.getName() + " исполняемым!");
|
||||
File PID = new File( "PID");
|
||||
FileUtils.writeStringToFile(PID, sapfor_drv.getName(), Charset.defaultCharset());
|
||||
//---
|
||||
Date startDate = new Date();
|
||||
results_json.StartDate = startDate.getTime();
|
||||
File started = new File(Constants.STARTED);
|
||||
FileUtils.writeStringToFile(started, String.valueOf(startDate));
|
||||
//формирование списка задач.
|
||||
File sapfor_drv = new File(Global.Home, package_json.sapfor_drv);
|
||||
setMaxKernels(package_json.kernels);
|
||||
int max_rask_id=0;
|
||||
for (SapforConfiguration_json sapforConfiguration_json : package_json.configurations) {
|
||||
for (SapforTest_json test : package_json.tests) {
|
||||
//--- чтобы было можно на нее сослаться после выполнения всех нитей.
|
||||
SapforTask task = new SapforTask();
|
||||
task.id = max_rask_id++;
|
||||
task.group_description = test.group_description;
|
||||
task.test_description = test.test_description;
|
||||
task.test_description = test.description;
|
||||
task.flags = sapforConfiguration_json.flags;
|
||||
task.sapfor_configuration_id = sapforConfiguration_json.id;
|
||||
task.sapfortaskspackage_id = Integer.parseInt(new File(Global.Home).getName());
|
||||
results_json.tasks.add(task);
|
||||
package_json.tasks.add(task);
|
||||
Vector<String> codes_s = new Vector<>();
|
||||
for (PassCode_2021 code : sapforConfiguration_json.codes) {
|
||||
codes_s.add(code.toString());
|
||||
@@ -56,11 +67,22 @@ public class PackageModeSupervisor extends ThreadsPlanner {
|
||||
}
|
||||
@Override
|
||||
protected void finalize() {
|
||||
results_json.EndDate = new Date().getTime();
|
||||
//записать результаты всех задач.
|
||||
try {
|
||||
Utils.jsonToFile(results_json, new File(Global.Home, Constants.results_json));
|
||||
Utils.jsonToFile(package_json, new File(Constants.package_json));
|
||||
FileUtils.writeStringToFile(new File(Constants.DONE), "");
|
||||
//--
|
||||
//Очистка
|
||||
|
||||
//очистка служебных файлов.
|
||||
Utils.deleteFilesByExtensions(new File(Global.Home),
|
||||
"proj", "dep", "jar"
|
||||
// ,"sh", "exe", "bat"
|
||||
);
|
||||
//удаление сапфора
|
||||
|
||||
if (sapfor_drv.exists())
|
||||
FileUtils.forceDelete(sapfor_drv);
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package TestingSystem.SAPFOR.SapforPackage;
|
||||
import Common.Constants;
|
||||
import Common.Database.DBObject;
|
||||
import Common.Global;
|
||||
import TestingSystem.Common.TestingPackage.TestingPackage;
|
||||
import TestingSystem.SAPFOR.Json.SapforTasksResults_json;
|
||||
import TestingSystem.SAPFOR.Json.SapforTasksPackage_json;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.io.File;
|
||||
public class SapforPackage extends TestingPackage {
|
||||
public class SapforPackage extends TestingPackage<SapforTasksPackage_json> {
|
||||
@Description("DEFAULT ''")
|
||||
public String testsNames = "";//имена тестов через ; для отображения
|
||||
//---
|
||||
@@ -15,9 +16,24 @@ public class SapforPackage extends TestingPackage {
|
||||
public String testsIds = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String configurationsIds = "";
|
||||
public SapforPackage(){
|
||||
|
||||
}
|
||||
public SapforPackage(SapforPackage sapforPackage) {
|
||||
SynchronizeFields(sapforPackage);
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
super.SynchronizeFields(src);
|
||||
SapforPackage p = (SapforPackage) src;
|
||||
testsNames = p.testsNames;
|
||||
sapforId = p.sapforId;
|
||||
testsIds = p.testsIds;
|
||||
configurationsIds = p.configurationsIds;
|
||||
}
|
||||
@Override
|
||||
public Class getJsonClass() {
|
||||
return SapforTasksResults_json.class;
|
||||
return SapforTasksPackage_json.class;
|
||||
}
|
||||
@Override
|
||||
public File getHomeDirectory() {
|
||||
|
||||
@@ -3,10 +3,11 @@ import Common.UI.Menus_2023.DataMenuBar;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
public class SapforPackagesBar extends DataMenuBar {
|
||||
public SapforPackagesBar() {
|
||||
super("пакеты задач SAPFOR"
|
||||
//, PassCode_2021.AddSapforPackage
|
||||
// PassCode_2021.AbortSapforTaskPackage,
|
||||
// PassCode_2021.DeleteSapforTasksPackage
|
||||
);
|
||||
super("пакеты задач SAPFOR",
|
||||
PassCode_2021.AddSapforPackage,
|
||||
PassCode_2021.StartSapforPackage,
|
||||
PassCode_2021.AbortSapforPackage,
|
||||
PassCode_2021.DeleteSapforPackage
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SapforTasksPackageSupervisor {
|
||||
package_json.kernels = sapforTasksPackage.kernels;
|
||||
for (Test test : data.tests.values()) {
|
||||
SapforTest_json test_json = new SapforTest_json();
|
||||
test_json.test_description = test.description;
|
||||
test_json.description = test.description;
|
||||
test_json.group_description = data.groups.get(test.group_id).description;
|
||||
package_json.tests.add(test_json);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,125 @@
|
||||
package TestingSystem.SAPFOR;
|
||||
public class SapforTestingPlanner {
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.GlobalProperties;
|
||||
import Common.Utils.Utils;
|
||||
import Repository.Server.ServerCode;
|
||||
import TestingSystem.Common.TestingPlanner;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||||
import TestingSystem.SAPFOR.Json.SapforConfiguration_json;
|
||||
import TestingSystem.SAPFOR.Json.SapforTest_json;
|
||||
import TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
public class SapforTestingPlanner extends TestingPlanner<SapforPackage> {
|
||||
File workspace;
|
||||
@Override
|
||||
protected ServerCode getActivePackageCode() {
|
||||
return ServerCode.GetFirstActiveSapforPackage;
|
||||
}
|
||||
@Override
|
||||
protected ServerCode getCheckIfNeedsKillCode() {
|
||||
return ServerCode.SapforPackageNeedsKill;
|
||||
}
|
||||
@Override
|
||||
protected TasksPackageState getStateAfterStart() {
|
||||
return TasksPackageState.RunningExecution;
|
||||
}
|
||||
@Override
|
||||
protected void InitSessionCredentials() {
|
||||
workspace = testingPackage.getLocalWorkspace();
|
||||
}
|
||||
@Override
|
||||
protected void TestsSynchronize() throws Exception {
|
||||
testingPackage.readJson();
|
||||
//--
|
||||
//копирование тестов по конфигурациям.
|
||||
for (SapforConfiguration_json configuration_json : testingPackage.package_json.configurations) {
|
||||
//--
|
||||
//-->>
|
||||
File configurationWorkspace = new File(workspace, String.valueOf(configuration_json.id));
|
||||
FileUtils.forceMkdir(configurationWorkspace);
|
||||
//--->>>
|
||||
for (SapforTest_json test_json : testingPackage.package_json.tests) {
|
||||
File test_root = new File(configurationWorkspace, test_json.description);
|
||||
Utils.CheckAndCleanDirectory(test_root);
|
||||
FileUtils.copyDirectory(new File(Global.TestsDirectory, String.valueOf(test_json.id)), test_root);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void PackageWorkspaceCreation() throws Exception {
|
||||
//копирование визуализатора
|
||||
File visualiser = new File(workspace, "VisualSapfor.jar");
|
||||
FileUtils.copyFile(new File(Global.Home, "TestingSystem.jar"), visualiser);
|
||||
//создание настроек
|
||||
GlobalProperties properties = new GlobalProperties();
|
||||
properties.Mode = Current.Mode.Package;
|
||||
Utils.jsonToFile(properties, new File(workspace, "properties"));
|
||||
//подготовка пакетного режима. Запустит его уже очередь.
|
||||
Utils.createScript(workspace, workspace, "start", "java -jar VisualSapfor.jar");
|
||||
}
|
||||
@Override
|
||||
protected void PackageStart() throws Exception {
|
||||
File script = new File(workspace, "start");
|
||||
ProcessBuilder procBuilder = new ProcessBuilder(script.getAbsolutePath());
|
||||
procBuilder.directory(workspace);
|
||||
procBuilder.start();
|
||||
//--->>
|
||||
File started = new File(workspace, Constants.STARTED);
|
||||
while (!started.exists()) {
|
||||
Print("waiting for package start...");
|
||||
Utils.sleep(1000);
|
||||
}
|
||||
File pid = new File(workspace,"PID");
|
||||
testingPackage.PID = FileUtils.readFileToString(pid, Charset.defaultCharset());
|
||||
}
|
||||
@Override
|
||||
protected boolean CheckNextState() throws Exception {
|
||||
File workspace = testingPackage.getLocalWorkspace();
|
||||
File done = new File(workspace, Constants.DONE);
|
||||
File aborted = new File(workspace, Constants.ABORTED);
|
||||
if (done.exists()) {
|
||||
testingPackage.state = TasksPackageState.Analysis;
|
||||
return true;
|
||||
} else if (aborted.exists()) {
|
||||
testingPackage.state = TasksPackageState.Aborted;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void DownloadResults() throws Exception {
|
||||
//не требуется.
|
||||
}
|
||||
@Override
|
||||
protected void AnalyseResults() throws Exception {
|
||||
//не требуется.
|
||||
}
|
||||
@Override
|
||||
protected void Kill() throws Exception {
|
||||
File workspace = testingPackage.getLocalWorkspace();
|
||||
//----
|
||||
File interrupt_file = new File(workspace, Constants.INTERRUPT);
|
||||
//----
|
||||
FileUtils.writeStringToFile(interrupt_file, new Date().toString());
|
||||
File aborted_file = new File(workspace, Constants.ABORTED);
|
||||
do {
|
||||
Print("waiting for interrupt...");
|
||||
Thread.sleep(1000);
|
||||
} while (!aborted_file.exists());
|
||||
Print("coup de grace..");
|
||||
String kill_command = "killall -SIGKILL " + testingPackage.PID;
|
||||
Print(kill_command);
|
||||
Process killer = Runtime.getRuntime().exec(kill_command);
|
||||
killer.waitFor();
|
||||
Print("done!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user