рефакторинг серверной части сапфора.
This commit is contained in:
@@ -7,14 +7,4 @@ public class TestingPackageToKill extends iDBObject {
|
||||
public int type = 0; // 0 - dvm /1 - sapfor
|
||||
public TestingPackageToKill() {
|
||||
}
|
||||
public TestingPackageToKill(DVMPackage dvmPackage) {
|
||||
packageId = dvmPackage.id;
|
||||
type = 0;
|
||||
}
|
||||
/*
|
||||
public TestingPackagetoKill(SAPFORPackage sapforPackage){
|
||||
packageId = sapforPackage.id;
|
||||
type = 1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -90,20 +90,6 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
}
|
||||
protected void Disconnect() {
|
||||
}
|
||||
//---
|
||||
/*
|
||||
protected void CheckExecutionStates() throws Exception{
|
||||
|
||||
case CompilationWorkspacesCreation:
|
||||
case CompilationPreparation:
|
||||
case CompilationExecution:
|
||||
case RunningWorkspacesCreation:
|
||||
case RunningPreparation:
|
||||
case RunningExecution:
|
||||
if (CheckNextState()) UpdatePackage();
|
||||
break;
|
||||
}
|
||||
*/
|
||||
//жизненный цикл планировщика
|
||||
protected void Session() throws Exception {
|
||||
switch (testingPackage.state) {
|
||||
@@ -136,7 +122,6 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
}
|
||||
// ---
|
||||
public void Perform() {
|
||||
while (true) {
|
||||
try {
|
||||
testingPackage = null;
|
||||
testingPackage = (P) ServerCommand(getActivePackageCode());
|
||||
@@ -173,11 +158,11 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
System.gc();
|
||||
//--
|
||||
}
|
||||
//else Print(this.getClass().getSimpleName()+": no active package found");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
Utils.sleep(getSleepMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,11 @@ import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||||
import TestingSystem.DVM.UserConnection;
|
||||
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
|
||||
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommand;
|
||||
import TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
||||
import TestingSystem.SAPFOR.SapforTask.SapforTask;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforPackageData;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
|
||||
import TestingSystem.SAPFOR.SapforTestingPlanner;
|
||||
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
|
||||
import Visual_DVM_2021.Passes.All.DownloadRepository;
|
||||
import Visual_DVM_2021.Passes.All.ZipFolderPass;
|
||||
@@ -50,6 +52,149 @@ import java.util.*;
|
||||
|
||||
import static Common.Constants.tests_db_name;
|
||||
public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
@Override
|
||||
public void beforePublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof TasksPackage) {
|
||||
TasksPackage tasksPackage = (TasksPackage) object;
|
||||
tasksPackage.id = db.IncKey(SettingName.DVMPackageMaxId);
|
||||
} else if (object instanceof SapforTasksPackage) {
|
||||
SapforTasksPackage sapforTasksPackage = (SapforTasksPackage) object;
|
||||
sapforTasksPackage.id = db.IncKey(SettingName.SAPFORPackageId);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void afterPublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof TasksPackage) {
|
||||
//объект уже вставлен.
|
||||
TasksPackage tasksPackage = (TasksPackage) object;
|
||||
//-
|
||||
for (int group_id : tasksPackage.sorted_tasks.keySet()) {
|
||||
if (db.groups.containsKey(group_id)) {
|
||||
Group group = db.groups.get(group_id);
|
||||
LinkedHashMap<Integer, Vector<TestCompilationTask>> group_tasks = tasksPackage.sorted_tasks.get((group_id));
|
||||
for (int test_id : group_tasks.keySet()) {
|
||||
if (db.tests.containsKey(test_id)) {
|
||||
Test test = db.tests.get(test_id);
|
||||
//---
|
||||
for (TestCompilationTask task : group_tasks.get(test_id)) {
|
||||
Print("принять задачу на компиляцию " + group_id + ":" + test_id + ":" + task.flags);
|
||||
//Теперь эту задачу надо поставить в очередь. и вернуть пользователю, уже с id
|
||||
task.state = TaskState.Waiting;
|
||||
task.id = db.IncKey(SettingName.TaskMaxId);
|
||||
task.taskspackage_id = tasksPackage.id;
|
||||
task.makefile_text = group.GenerateMakefile(test, tasksPackage.dvm_drv, task.flags);
|
||||
task.test_home = tasksPackage.user_workspace + "/projects/" + test_id;
|
||||
//-->>
|
||||
task.remote_workspace =
|
||||
new RemoteFile(
|
||||
tasksPackage.user_workspace + "/tests/" + tasksPackage.id,
|
||||
String.valueOf(task.id), true).full_name;
|
||||
account_db.Insert(task);
|
||||
if (task.runTasks != null) {
|
||||
for (TestRunTask rt : task.runTasks) {
|
||||
rt.id = db.IncKey(SettingName.TaskMaxId);
|
||||
rt.taskspackage_id = tasksPackage.id;
|
||||
rt.testcompilationtask_id = task.id;
|
||||
rt.remote_workspace =
|
||||
new RemoteFile(
|
||||
tasksPackage.user_workspace + "/tests/" + tasksPackage.id,
|
||||
String.valueOf(rt.id), true).full_name;
|
||||
rt.binary_name = "spf_" + rt.id + "_" + rt.matrix.replace(" ", "_");
|
||||
account_db.Insert(rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Test) {
|
||||
Test test = (Test) object;
|
||||
if (!test.unpackProjectOnServer()) {
|
||||
db.Delete(test);
|
||||
throw new RepositoryRefuseException(
|
||||
"Не удалось прикрепить проект к тесту с id " + test.id
|
||||
+ "\nТест будет удален"
|
||||
);
|
||||
}
|
||||
} else if (object instanceof DVMPackage) {
|
||||
DVMPackage dvmPackage = (DVMPackage) object;
|
||||
//--
|
||||
Utils.CheckAndCleanDirectory(dvmPackage.getLocalWorkspace());
|
||||
//--
|
||||
dvmPackage.saveJson();
|
||||
dvmPackage.package_json = null; // объект больше не нужен.
|
||||
} else if (object instanceof SapforPackage) {
|
||||
SapforPackage sapforPackage = (SapforPackage) object;
|
||||
//--
|
||||
Utils.CheckAndCleanDirectory(sapforPackage.getLocalWorkspace());
|
||||
//--
|
||||
sapforPackage.saveJson();
|
||||
sapforPackage.package_json = null; // объект больше не нужен.
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void afterDeleteAction(DBObject object) throws Exception {
|
||||
if (object instanceof Test) {
|
||||
Test test = (Test) object;
|
||||
Utils.forceDeleteWithCheck(test.getArchive());
|
||||
Utils.forceDeleteWithCheck(test.getServerPath());
|
||||
} else if (object instanceof Group) {
|
||||
Group group = (Group) object;
|
||||
Vector<Test> tests = new Vector<>();
|
||||
for (Test group_test : db.tests.Data.values()) {
|
||||
if (group_test.group_id == group.id)
|
||||
tests.add(group_test);
|
||||
}
|
||||
for (Test group_test : tests) {
|
||||
db.Delete(group_test);
|
||||
Utils.forceDeleteWithCheck(group_test.getArchive());
|
||||
Utils.forceDeleteWithCheck(group_test.getServerPath());
|
||||
}
|
||||
} else if (object instanceof ServerSapfor) {
|
||||
Utils.forceDeleteWithCheck(
|
||||
new File(
|
||||
((ServerSapfor) object).home_path
|
||||
)
|
||||
);
|
||||
} else if (object instanceof SapforTasksPackage) {
|
||||
SapforTasksPackage sapforTasksPackage = (SapforTasksPackage) object;
|
||||
File workspace = new File(
|
||||
sapforTasksPackage.workspace
|
||||
);
|
||||
System.out.println(Utils.Brackets(workspace.getAbsolutePath()));
|
||||
Utils.forceDeleteWithCheck(workspace);
|
||||
Utils.forceDeleteWithCheck(sapforTasksPackage.getArchive());
|
||||
//внешние ключи не работают
|
||||
Vector<SapforTask> tasks = new Vector<>();
|
||||
for (SapforTask task : account_db.sapforTasks.Data.values()) {
|
||||
if (task.sapfortaskspackage_id == sapforTasksPackage.id) // todo group_name -> group_id
|
||||
tasks.add(task);
|
||||
}
|
||||
for (SapforTask task : tasks) {
|
||||
account_db.Delete(task);
|
||||
}
|
||||
} else if (object instanceof SapforConfiguration) {
|
||||
SapforConfiguration sapforConfiguration = (SapforConfiguration) object;
|
||||
Vector<SapforConfigurationCommand> commands = new Vector<>();
|
||||
for (SapforConfigurationCommand command : db.sapforConfigurationCommands.Data.values()) {
|
||||
if (command.sapforconfiguration_id == sapforConfiguration.id)
|
||||
commands.add(command);
|
||||
}
|
||||
for (SapforConfigurationCommand command : commands) {
|
||||
db.Delete(command);
|
||||
}
|
||||
} else if (object instanceof DVMPackage) {
|
||||
DVMPackage dvmPackage = (DVMPackage) object;
|
||||
File workspace = dvmPackage.getLocalWorkspace();
|
||||
Utils.forceDeleteWithCheck(workspace);
|
||||
} else if (object instanceof SapforPackage) {
|
||||
SapforPackage sapforPackage = (SapforPackage) object;
|
||||
File workspace = sapforPackage.getLocalWorkspace();
|
||||
Utils.forceDeleteWithCheck(workspace);
|
||||
}
|
||||
}
|
||||
//-->>>
|
||||
LinkedHashMap<String, TasksDatabase> accountsBases = new LinkedHashMap<>();
|
||||
//--------------------------------->>>
|
||||
public TestingServer() {
|
||||
@@ -109,8 +254,16 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
protected TestingPlanner_OLD testingPlannerOLD = new TestingPlanner_OLD();
|
||||
protected Thread testingThread = new Thread(() -> testingPlannerOLD.Perform());
|
||||
//---
|
||||
protected DVMTestingPlanner DVMTestingPlanner_ = new DVMTestingPlanner();
|
||||
protected Thread testingThread_2023 = new Thread(() -> DVMTestingPlanner_.Perform());
|
||||
protected DVMTestingPlanner DVMTestingPlanner = new DVMTestingPlanner();
|
||||
protected SapforTestingPlanner sapforTestingPlanner = new SapforTestingPlanner();
|
||||
//--
|
||||
protected Thread testingThread_2023 = new Thread(() -> {
|
||||
while (true) {
|
||||
DVMTestingPlanner.Perform();
|
||||
sapforTestingPlanner.Perform();
|
||||
}
|
||||
});
|
||||
//------>>>
|
||||
//------>>>
|
||||
public static Timer checkTimer = null;
|
||||
public static void TimerOn() {
|
||||
@@ -380,13 +533,25 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
GetFirstActiveDVMPackage();
|
||||
break;
|
||||
case DVMPackageNeedsKill:
|
||||
Print("Проверить нуждает ли пакет DVM в убийстве");
|
||||
Print("Проверить нуждается ли пакет DVM в убийстве");
|
||||
DVMPackageNeedsKill();
|
||||
break;
|
||||
case UpdateActiveDVMPackages:
|
||||
Print("Получить данные по пакетам DVM");
|
||||
UpdateActiveDVMPackages();
|
||||
break;
|
||||
case GetFirstActiveSapforPackage:
|
||||
Print("Получить первый активный пакет задач SAPFOR");
|
||||
GetFirstActiveSapforPackage();
|
||||
break;
|
||||
case SapforPackageNeedsKill:
|
||||
Print("Проверить нуждает ли пакет SAPFOR в убийстве");
|
||||
SapforPackageNeedsKill();
|
||||
break;
|
||||
case UpdateActiveSapforPackages:
|
||||
Print("Получить данные по пакетам Sapfor");
|
||||
UpdateActiveSapforPackages();
|
||||
break;
|
||||
default:
|
||||
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
||||
}
|
||||
@@ -539,137 +704,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
SetCurrentAccountDB(request.arg);
|
||||
return account_db;
|
||||
}
|
||||
@Override
|
||||
public void beforePublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof TasksPackage) {
|
||||
TasksPackage tasksPackage = (TasksPackage) object;
|
||||
tasksPackage.id = db.IncKey(SettingName.DVMPackageMaxId);
|
||||
} else if (object instanceof SapforTasksPackage) {
|
||||
SapforTasksPackage sapforTasksPackage = (SapforTasksPackage) object;
|
||||
sapforTasksPackage.id = db.IncKey(SettingName.SAPFORPackageId);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void afterPublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof TasksPackage) {
|
||||
//объект уже вставлен.
|
||||
TasksPackage tasksPackage = (TasksPackage) object;
|
||||
//-
|
||||
for (int group_id : tasksPackage.sorted_tasks.keySet()) {
|
||||
if (db.groups.containsKey(group_id)) {
|
||||
Group group = db.groups.get(group_id);
|
||||
LinkedHashMap<Integer, Vector<TestCompilationTask>> group_tasks = tasksPackage.sorted_tasks.get((group_id));
|
||||
for (int test_id : group_tasks.keySet()) {
|
||||
if (db.tests.containsKey(test_id)) {
|
||||
Test test = db.tests.get(test_id);
|
||||
//---
|
||||
for (TestCompilationTask task : group_tasks.get(test_id)) {
|
||||
Print("принять задачу на компиляцию " + group_id + ":" + test_id + ":" + task.flags);
|
||||
//Теперь эту задачу надо поставить в очередь. и вернуть пользователю, уже с id
|
||||
task.state = TaskState.Waiting;
|
||||
task.id = db.IncKey(SettingName.TaskMaxId);
|
||||
task.taskspackage_id = tasksPackage.id;
|
||||
task.makefile_text = group.GenerateMakefile(test, tasksPackage.dvm_drv, task.flags);
|
||||
task.test_home = tasksPackage.user_workspace + "/projects/" + test_id;
|
||||
//-->>
|
||||
task.remote_workspace =
|
||||
new RemoteFile(
|
||||
tasksPackage.user_workspace + "/tests/" + tasksPackage.id,
|
||||
String.valueOf(task.id), true).full_name;
|
||||
account_db.Insert(task);
|
||||
if (task.runTasks != null) {
|
||||
for (TestRunTask rt : task.runTasks) {
|
||||
rt.id = db.IncKey(SettingName.TaskMaxId);
|
||||
rt.taskspackage_id = tasksPackage.id;
|
||||
rt.testcompilationtask_id = task.id;
|
||||
rt.remote_workspace =
|
||||
new RemoteFile(
|
||||
tasksPackage.user_workspace + "/tests/" + tasksPackage.id,
|
||||
String.valueOf(rt.id), true).full_name;
|
||||
rt.binary_name = "spf_" + rt.id + "_" + rt.matrix.replace(" ", "_");
|
||||
account_db.Insert(rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Test) {
|
||||
Test test = (Test) object;
|
||||
if (!test.unpackProjectOnServer()) {
|
||||
db.Delete(test);
|
||||
throw new RepositoryRefuseException(
|
||||
"Не удалось прикрепить проект к тесту с id " + test.id
|
||||
+ "\nТест будет удален"
|
||||
);
|
||||
}
|
||||
} else if (object instanceof DVMPackage) {
|
||||
DVMPackage dvmPackage = (DVMPackage) object;
|
||||
//--
|
||||
Utils.CheckAndCleanDirectory(dvmPackage.getLocalWorkspace());
|
||||
//--
|
||||
dvmPackage.saveJson();
|
||||
dvmPackage.package_json = null; // объект больше не нужен.
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void afterDeleteAction(DBObject object) throws Exception {
|
||||
if (object instanceof Test) {
|
||||
Test test = (Test) object;
|
||||
Utils.forceDeleteWithCheck(test.getArchive());
|
||||
Utils.forceDeleteWithCheck(test.getServerPath());
|
||||
} else if (object instanceof Group) {
|
||||
Group group = (Group) object;
|
||||
Vector<Test> tests = new Vector<>();
|
||||
for (Test group_test : db.tests.Data.values()) {
|
||||
if (group_test.group_id == group.id)
|
||||
tests.add(group_test);
|
||||
}
|
||||
for (Test group_test : tests) {
|
||||
db.Delete(group_test);
|
||||
Utils.forceDeleteWithCheck(group_test.getArchive());
|
||||
Utils.forceDeleteWithCheck(group_test.getServerPath());
|
||||
}
|
||||
} else if (object instanceof ServerSapfor) {
|
||||
Utils.forceDeleteWithCheck(
|
||||
new File(
|
||||
((ServerSapfor) object).home_path
|
||||
)
|
||||
);
|
||||
} else if (object instanceof SapforTasksPackage) {
|
||||
SapforTasksPackage sapforTasksPackage = (SapforTasksPackage) object;
|
||||
File workspace = new File(
|
||||
sapforTasksPackage.workspace
|
||||
);
|
||||
System.out.println(Utils.Brackets(workspace.getAbsolutePath()));
|
||||
Utils.forceDeleteWithCheck(workspace);
|
||||
Utils.forceDeleteWithCheck(sapforTasksPackage.getArchive());
|
||||
//внешние ключи не работают
|
||||
Vector<SapforTask> tasks = new Vector<>();
|
||||
for (SapforTask task : account_db.sapforTasks.Data.values()) {
|
||||
if (task.sapfortaskspackage_id == sapforTasksPackage.id) // todo group_name -> group_id
|
||||
tasks.add(task);
|
||||
}
|
||||
for (SapforTask task : tasks) {
|
||||
account_db.Delete(task);
|
||||
}
|
||||
} else if (object instanceof SapforConfiguration) {
|
||||
SapforConfiguration sapforConfiguration = (SapforConfiguration) object;
|
||||
Vector<SapforConfigurationCommand> commands = new Vector<>();
|
||||
for (SapforConfigurationCommand command : db.sapforConfigurationCommands.Data.values()) {
|
||||
if (command.sapforconfiguration_id == sapforConfiguration.id)
|
||||
commands.add(command);
|
||||
}
|
||||
for (SapforConfigurationCommand command : commands) {
|
||||
db.Delete(command);
|
||||
}
|
||||
} else if (object instanceof DVMPackage) {
|
||||
DVMPackage dvmPackage = (DVMPackage) object;
|
||||
File workspace = new File(Global.PackagesDirectory, String.valueOf(dvmPackage.id));
|
||||
Utils.forceDeleteWithCheck(workspace);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------->>>
|
||||
//устарели. убрать.
|
||||
void ActualizeDVMPackages() throws Exception {
|
||||
@@ -736,6 +770,15 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
response.object = new DVMPackage(dvmPackage);
|
||||
}
|
||||
}
|
||||
private void GetFirstActiveSapforPackage() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = null;
|
||||
SapforPackage sapforPackage = db.getFirstActiveSapforPackage();
|
||||
if (sapforPackage != null) {
|
||||
//нужно вернуть копию объекта с иным адресом!!
|
||||
response.object = new SapforPackage(sapforPackage);
|
||||
}
|
||||
}
|
||||
//---
|
||||
void UpdateActiveDVMPackages() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
@@ -751,6 +794,20 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
response.object = res;
|
||||
}
|
||||
private void UpdateActiveSapforPackages() {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
Vector<Pair<Integer, Long>> keys_pairs = (Vector<Pair<Integer, Long>>) request.object;
|
||||
Vector<SapforPackage> res = new Vector<>();
|
||||
//--
|
||||
for (Pair<Integer, Long> p : keys_pairs) {
|
||||
if (db.sapforPackages.containsKey(p.getKey())) {
|
||||
SapforPackage actual = db.sapforPackages.get(p.getKey());
|
||||
if (actual.ChangeDate != p.getValue())
|
||||
res.add(new SapforPackage(actual));
|
||||
}
|
||||
}
|
||||
response.object = res;
|
||||
}
|
||||
private void DVMPackageNeedsKill() {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
int packageId = (int) request.object;
|
||||
@@ -763,4 +820,16 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
response.object = res_;
|
||||
}
|
||||
private void SapforPackageNeedsKill() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
int packageId = (int) request.object;
|
||||
boolean res_ = false;
|
||||
for (TestingPackageToKill packageToKill : db.testingPackagesToKill.Data.values()) {
|
||||
if ((packageToKill.packageId == packageId) && (packageToKill.type == 1)) {
|
||||
res_ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
response.object = res_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ import TestingSystem.DVM.DVMPackage.DVMPackageDBTable;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||||
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfigurationDBTable;
|
||||
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommandsDBTable;
|
||||
import TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
||||
import TestingSystem.SAPFOR.SapforPackage.SapforPackageDBTable;
|
||||
import TestingSystem.SAPFOR.SapforTasksPackage.SapforTasksPackage;
|
||||
import TestingSystem.SAPFOR.ServerSapfor.ServerSapforsDBTable;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
|
||||
@@ -105,4 +107,34 @@ public class TestsDatabase extends SQLiteDatabase {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public SapforPackage getFirstActiveSapforPackage() {
|
||||
SapforPackage first_active = null;
|
||||
SapforPackage first_queued = null;
|
||||
if (!sapforPackages.Data.isEmpty()) {
|
||||
for (SapforPackage p : sapforPackages.Data.values()) {
|
||||
switch (p.state) {
|
||||
case Done:
|
||||
case Aborted:
|
||||
break;
|
||||
case Queued:
|
||||
if (first_queued == null) first_queued = p;
|
||||
break;
|
||||
default:
|
||||
if (first_active == null) first_active = p; //это и будет первый активный.
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (first_active != null) return first_active;
|
||||
if (first_queued != null) {
|
||||
first_queued.state = TasksPackageState.TestsSynchronize;
|
||||
try {
|
||||
Update(first_queued);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return first_queued;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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