2023-12-15 18:10:27 +03:00
|
|
|
|
package TestingSystem.SAPFOR;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
|
|
|
|
|
import Common_old.Constants;
|
|
|
|
|
|
import Common_old.Current;
|
|
|
|
|
|
import _VisualDVM.Global;
|
|
|
|
|
|
import Common_old.GlobalProperties;
|
|
|
|
|
|
import Common_old.Utils.Utils;
|
2024-05-08 01:56:17 +03:00
|
|
|
|
import ProjectData.LanguageName;
|
2024-05-16 01:26:03 +03:00
|
|
|
|
import Repository.Component.Sapfor.Sapfor;
|
2024-05-17 01:33:39 +03:00
|
|
|
|
import Repository.EmailMessage;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
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;
|
2024-05-07 01:06:47 +03:00
|
|
|
|
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
|
2024-05-08 00:06:43 +03:00
|
|
|
|
import TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
|
2024-05-08 01:56:17 +03:00
|
|
|
|
import javafx.util.Pair;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.charset.Charset;
|
2024-05-08 00:06:43 +03:00
|
|
|
|
import java.nio.file.Paths;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
import java.util.Date;
|
2024-05-17 01:33:39 +03:00
|
|
|
|
import java.util.Vector;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
public class SapforTestingPlanner extends TestingPlanner<SapforPackage> {
|
|
|
|
|
|
File workspace;
|
2024-05-07 01:06:47 +03:00
|
|
|
|
ServerSapfor sapfor;
|
2024-05-08 00:57:48 +03:00
|
|
|
|
//--
|
|
|
|
|
|
File repo;
|
|
|
|
|
|
File repoSapforHome;
|
2024-05-08 01:56:17 +03:00
|
|
|
|
int max_version;
|
|
|
|
|
|
int current_version;
|
|
|
|
|
|
//--
|
2024-05-08 00:57:48 +03:00
|
|
|
|
File repo_bin;
|
|
|
|
|
|
File repo_out;
|
|
|
|
|
|
File repo_err;
|
|
|
|
|
|
//--
|
|
|
|
|
|
public SapforTestingPlanner() {
|
|
|
|
|
|
repo = new File(Global.Home, "Repo");
|
|
|
|
|
|
repoSapforHome = Paths.get(Global.Home, "Repo", Constants.SAPFOR_REPOSITORY_BIN).toFile();
|
|
|
|
|
|
repo_bin = new File(repoSapforHome, "Sapfor_F");
|
|
|
|
|
|
repo_out = new File(repoSapforHome, Constants.out_file);
|
|
|
|
|
|
repo_err = new File(repoSapforHome, Constants.err_file);
|
|
|
|
|
|
}
|
2023-12-16 03:57:01 +03:00
|
|
|
|
@Override
|
2024-10-03 16:21:11 +03:00
|
|
|
|
public String packageDescription() {
|
|
|
|
|
|
return "SAPFOR";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2024-03-21 19:02:08 +03:00
|
|
|
|
protected ServerCode getActivePackagesCode() {
|
|
|
|
|
|
return ServerCode.GetFirstActiveSapforPackages;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
@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);
|
|
|
|
|
|
//создание настроек
|
2024-04-24 22:23:50 +03:00
|
|
|
|
GlobalProperties properties = new GlobalProperties(Global.properties);
|
2023-12-16 03:57:01 +03:00
|
|
|
|
properties.Mode = Current.Mode.Package;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
CommonUtils.jsonToFile(properties, new File(workspace, "properties"));
|
2023-12-16 03:57:01 +03:00
|
|
|
|
//подготовка пакетного режима. Запустит его уже очередь.
|
|
|
|
|
|
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 {
|
2024-02-16 23:49:04 +03:00
|
|
|
|
boolean progress_changed = false;
|
|
|
|
|
|
boolean state_changed = false;
|
|
|
|
|
|
//--
|
2023-12-16 03:57:01 +03:00
|
|
|
|
File workspace = testingPackage.getLocalWorkspace();
|
2024-02-16 23:49:04 +03:00
|
|
|
|
//--
|
|
|
|
|
|
File progress = new File(workspace, "progress");
|
|
|
|
|
|
if (progress.exists()) {
|
|
|
|
|
|
String s = FileUtils.readFileToString(progress);
|
|
|
|
|
|
int current_progress = Integer.parseInt(s);
|
|
|
|
|
|
if (current_progress != testingPackage.progress) {
|
|
|
|
|
|
Print("progress changed: " + current_progress);
|
|
|
|
|
|
testingPackage.progress = current_progress;
|
|
|
|
|
|
progress_changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2023-12-16 03:57:01 +03:00
|
|
|
|
File done = new File(workspace, Constants.DONE);
|
|
|
|
|
|
File aborted = new File(workspace, Constants.ABORTED);
|
|
|
|
|
|
if (done.exists()) {
|
|
|
|
|
|
testingPackage.state = TasksPackageState.Analysis;
|
2024-02-16 23:49:04 +03:00
|
|
|
|
state_changed = true;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
} else if (aborted.exists()) {
|
|
|
|
|
|
testingPackage.state = TasksPackageState.Aborted;
|
2024-02-16 23:49:04 +03:00
|
|
|
|
state_changed = true;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2024-02-16 23:49:04 +03:00
|
|
|
|
return progress_changed || state_changed;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void DownloadResults() throws Exception {
|
|
|
|
|
|
//не требуется.
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void AnalyseResults() throws Exception {
|
|
|
|
|
|
//не требуется.
|
2023-12-18 15:55:13 +03:00
|
|
|
|
testingPackage.progress = 100;
|
2024-10-03 16:21:11 +03:00
|
|
|
|
testingPackage.checkFinishState();
|
|
|
|
|
|
UpdatePackageState();
|
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!");
|
|
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
//--
|
2024-05-05 23:20:12 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public void perform() throws Exception {
|
2024-05-08 00:57:48 +03:00
|
|
|
|
checkServerSapforsForCompilation();
|
2024-05-05 23:20:12 +03:00
|
|
|
|
super.perform();
|
|
|
|
|
|
}
|
2024-05-08 00:57:48 +03:00
|
|
|
|
//--------------------
|
2024-05-07 01:06:47 +03:00
|
|
|
|
public void getServerSapforForCompilation() throws Exception {
|
2024-05-08 00:57:48 +03:00
|
|
|
|
sapfor = (ServerSapfor) ServerCommand(ServerCode.GetSapforForCompilation);
|
2024-05-07 01:06:47 +03:00
|
|
|
|
}
|
2024-05-08 00:06:43 +03:00
|
|
|
|
void UpdateSapforState(ServerSapforState state_in) throws Exception {
|
|
|
|
|
|
sapfor.state = state_in;
|
|
|
|
|
|
ServerCommand(ServerCode.EditObject, sapfor);
|
|
|
|
|
|
}
|
2024-05-08 00:57:48 +03:00
|
|
|
|
void SyncronizeRepository() throws Exception {
|
2024-05-18 23:31:45 +03:00
|
|
|
|
UpdateSapforState(ServerSapforState.DVMRepositorySynchronization);
|
2024-05-08 00:57:48 +03:00
|
|
|
|
Utils.startScript(repo, repo, "dvm_checkout",
|
|
|
|
|
|
"svn checkout " +
|
|
|
|
|
|
Constants.REPOSITORY_AUTHENTICATION +
|
|
|
|
|
|
" " + Constants.DVM_REPOSITORY + " 1>dvm_out.txt 2>dvm_err.txt\n").waitFor();
|
2024-05-18 23:31:45 +03:00
|
|
|
|
UpdateSapforState(ServerSapforState.SAPFORRepositorySynchronization);
|
2024-05-08 00:57:48 +03:00
|
|
|
|
Utils.startScript(repo, repo, "spf_checkout",
|
|
|
|
|
|
"svn checkout " +
|
|
|
|
|
|
Constants.REPOSITORY_AUTHENTICATION +
|
|
|
|
|
|
" " + Constants.SAPFOR_REPOSITORY + " 1>spf_out.txt 2>spf_err.txt\n").waitFor();
|
|
|
|
|
|
}
|
|
|
|
|
|
void CompileSapfor() throws Exception {
|
2024-05-18 23:31:45 +03:00
|
|
|
|
UpdateSapforState(ServerSapforState.Compilation);
|
2024-05-08 00:57:48 +03:00
|
|
|
|
//-
|
|
|
|
|
|
if (repo_bin.exists())
|
|
|
|
|
|
FileUtils.forceDelete(repo_bin);
|
|
|
|
|
|
if (repo_out.exists())
|
|
|
|
|
|
FileUtils.forceDelete(repo_out);
|
|
|
|
|
|
if (repo_err.exists())
|
|
|
|
|
|
FileUtils.forceDelete(repo_err);
|
|
|
|
|
|
//--
|
|
|
|
|
|
Utils.startScript(repoSapforHome, repoSapforHome, "build_sapfor",
|
|
|
|
|
|
"cmake ../ 1>" +
|
|
|
|
|
|
Constants.out_file +
|
|
|
|
|
|
" 2>" +
|
|
|
|
|
|
Constants.err_file +
|
|
|
|
|
|
"\nmake -j 14 1>>" +
|
|
|
|
|
|
Constants.out_file +
|
|
|
|
|
|
" 2>>" +
|
|
|
|
|
|
Constants.err_file +
|
|
|
|
|
|
"\n").waitFor();
|
|
|
|
|
|
}
|
|
|
|
|
|
//--------------------
|
|
|
|
|
|
public void checkServerSapforsForCompilation() throws Exception {
|
2024-05-07 01:06:47 +03:00
|
|
|
|
sapfor = null;
|
|
|
|
|
|
getServerSapforForCompilation();
|
|
|
|
|
|
if (sapfor != null) {
|
2024-05-08 01:56:17 +03:00
|
|
|
|
//---
|
|
|
|
|
|
max_version = Constants.Nan;
|
|
|
|
|
|
current_version = Constants.Nan;
|
|
|
|
|
|
//--
|
2024-05-08 00:57:48 +03:00
|
|
|
|
SyncronizeRepository();
|
2024-05-08 01:56:17 +03:00
|
|
|
|
max_version = (int) ServerCommand(ServerCode.GetMaxSapforVersion);
|
2024-05-16 01:26:03 +03:00
|
|
|
|
current_version = Sapfor.readVersionFromCode(Paths.get(repo.getAbsolutePath(), "/sapfor/experts/Sapfor_2017/_src/Utils/version.h").toFile());
|
2024-05-08 01:56:17 +03:00
|
|
|
|
if (current_version==max_version){
|
|
|
|
|
|
ServerCommand(ServerCode.DeleteObjectByPK, new Pair(ServerSapfor.class,sapfor.id));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-05-08 00:57:48 +03:00
|
|
|
|
//-
|
|
|
|
|
|
File sapforHome = new File(Global.SapforsDirectory, Utils.getDateName("sapfor"));
|
2024-05-08 01:56:17 +03:00
|
|
|
|
//--
|
|
|
|
|
|
sapfor.home_path = sapforHome.getAbsolutePath();
|
|
|
|
|
|
sapfor.languageName = LanguageName.fortran;
|
|
|
|
|
|
//--
|
2024-05-08 00:57:48 +03:00
|
|
|
|
File sapforBin = new File(sapforHome, "Sapfor_F");
|
2024-05-08 00:06:43 +03:00
|
|
|
|
File sapforOut = new File(sapforHome, Constants.out_file);
|
|
|
|
|
|
File sapforErr = new File(sapforHome, Constants.err_file);
|
2024-05-08 00:57:48 +03:00
|
|
|
|
//-
|
|
|
|
|
|
CompileSapfor();
|
|
|
|
|
|
sapforHome.mkdir();
|
2024-05-08 00:06:43 +03:00
|
|
|
|
//--
|
|
|
|
|
|
if (repo_out.exists())
|
|
|
|
|
|
FileUtils.copyFile(repo_out, sapforOut);
|
|
|
|
|
|
if (repo_err.exists())
|
|
|
|
|
|
FileUtils.copyFile(repo_err, sapforErr);
|
|
|
|
|
|
if (repo_bin.exists()) {
|
|
|
|
|
|
FileUtils.copyFile(repo_bin, sapforBin);
|
|
|
|
|
|
sapforBin.setExecutable(true, false);
|
2024-05-08 01:56:17 +03:00
|
|
|
|
//--
|
|
|
|
|
|
sapfor.version= String.valueOf(current_version);
|
|
|
|
|
|
sapfor.call_command = sapforBin.getAbsolutePath();
|
|
|
|
|
|
sapfor.buildDate = new Date().getTime();
|
|
|
|
|
|
//--
|
2024-05-08 00:06:43 +03:00
|
|
|
|
UpdateSapforState(ServerSapforState.Done);
|
2024-05-17 01:33:39 +03:00
|
|
|
|
EmailSapforAssembly(current_version, true, sapforOut, sapforErr);
|
2024-09-26 21:31:18 +03:00
|
|
|
|
//запуск автоматического тестирования.
|
2024-10-01 17:33:08 +03:00
|
|
|
|
ServerCommand(ServerCode.PerformAutoSapforTesting, String.valueOf(sapfor.id), null);
|
2024-05-08 00:57:48 +03:00
|
|
|
|
} else {
|
2024-05-08 00:06:43 +03:00
|
|
|
|
UpdateSapforState(ServerSapforState.DoneWithErrors);
|
2024-05-17 01:33:39 +03:00
|
|
|
|
EmailSapforAssembly(current_version, false, sapforOut, sapforErr);
|
2024-05-08 00:06:43 +03:00
|
|
|
|
}
|
2024-05-07 01:06:47 +03:00
|
|
|
|
}
|
2024-05-05 23:20:12 +03:00
|
|
|
|
}
|
2024-05-17 01:33:39 +03:00
|
|
|
|
void EmailSapforAssembly(int version, boolean done, File out, File err) throws Exception {
|
|
|
|
|
|
String version_s = (version == Constants.Nan) ? "?" : String.valueOf(version);
|
|
|
|
|
|
String status = done ? "Успешно" : "С ошибками";
|
|
|
|
|
|
//-
|
|
|
|
|
|
EmailMessage message = new EmailMessage(
|
|
|
|
|
|
"Выполнена сборка системы SAPFOR",
|
|
|
|
|
|
"Версия: " + version_s + "\n" + "Статус: " + status,
|
2024-09-24 23:34:41 +03:00
|
|
|
|
new Vector<>()
|
2024-05-17 01:33:39 +03:00
|
|
|
|
);
|
|
|
|
|
|
//-
|
|
|
|
|
|
ServerCommand(ServerCode.Email, "", message);
|
|
|
|
|
|
}
|
2023-12-15 18:10:27 +03:00
|
|
|
|
}
|