2023-12-15 18:10:27 +03:00
|
|
|
|
package TestingSystem.SAPFOR;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
import Common.Constants;
|
|
|
|
|
|
import Common.Current;
|
|
|
|
|
|
import Common.Global;
|
|
|
|
|
|
import Common.GlobalProperties;
|
|
|
|
|
|
import Common.Utils.Utils;
|
|
|
|
|
|
import Repository.Server.ServerCode;
|
2023-12-17 19:19:59 +03:00
|
|
|
|
import TestingSystem.Common.TasksPackageState;
|
2023-12-25 00:33:14 +03:00
|
|
|
|
import TestingSystem.Common.TestingPlanner;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
import TestingSystem.SAPFOR.Json.SapforConfiguration_json;
|
|
|
|
|
|
import TestingSystem.SAPFOR.Json.SapforTest_json;
|
2023-12-25 00:33:14 +03:00
|
|
|
|
import TestingSystem.SAPFOR.Json.SapforTestingSet_json;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
import TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
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();
|
|
|
|
|
|
//--
|
2023-12-25 00:33:14 +03:00
|
|
|
|
for (SapforTestingSet_json set_json : testingPackage.package_json.testingSets) {
|
|
|
|
|
|
File setWorkspace = new File(workspace, String.valueOf(set_json.id));
|
|
|
|
|
|
FileUtils.forceMkdir(setWorkspace);
|
|
|
|
|
|
//копирование тестов по конфигурациям.
|
|
|
|
|
|
for (SapforConfiguration_json configuration_json : set_json.configurations) {
|
|
|
|
|
|
//--
|
|
|
|
|
|
File configurationWorkspace = new File(setWorkspace, String.valueOf(configuration_json.id));
|
|
|
|
|
|
FileUtils.forceMkdir(configurationWorkspace);
|
|
|
|
|
|
//--->>>
|
|
|
|
|
|
for (SapforTest_json test_json : set_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);
|
|
|
|
|
|
}
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@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);
|
|
|
|
|
|
}
|
2023-12-25 00:33:14 +03:00
|
|
|
|
File pid = new File(workspace, "PID");
|
2023-12-16 03:57:01 +03:00
|
|
|
|
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 {
|
|
|
|
|
|
//не требуется.
|
2023-12-18 15:55:13 +03:00
|
|
|
|
testingPackage.progress = 100;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
@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!");
|
|
|
|
|
|
}
|
2023-12-15 18:10:27 +03:00
|
|
|
|
}
|