прерывание по образцу двм, однотипное.

This commit is contained in:
2023-10-17 01:13:13 +03:00
parent 19f7230eb5
commit 66e1102e39
6 changed files with 69 additions and 68 deletions

View File

@@ -70,6 +70,5 @@ public enum ServerCode {
InstallSapforForTesting,
StartSapforTests,
GetFirstActiveSapforTasksPackage,
AbortSapforTasksPackage,
OLD
}

View File

@@ -12,6 +12,7 @@ public class SapforTasksPackage extends nDBObject {
public String sapfor_version = "?"; //тестируемая версия SAPFOR
public long sapfor_build_date = 0;
public String sapfor_drv="";
public String sapfor_process_name="";
//---
public String workspace = ""; //домашняя папка
//---
@@ -46,6 +47,7 @@ public class SapforTasksPackage extends nDBObject {
StartDate = p.StartDate;
ChangeDate = p.ChangeDate;
kernels = p.kernels;
sapfor_process_name = p.sapfor_process_name;
state = p.state;
}
}

View File

@@ -18,12 +18,13 @@ import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Vector;
public class SapforTasksPackageSupervisor {
protected TestingPlanner planner; //планировщик.
SapforTasksPackage sapforTasksPackage = null;
public SapforTasksPackageSupervisor(TestingPlanner planner_in, SapforTasksPackage sapforTasksPackage_in){
public SapforTasksPackageSupervisor(TestingPlanner planner_in, SapforTasksPackage sapforTasksPackage_in) {
planner = planner_in;
sapforTasksPackage = sapforTasksPackage_in;
}
@@ -78,7 +79,7 @@ public class SapforTasksPackageSupervisor {
FileUtils.copyFile(new File(sapforTasksPackage.sapfor_drv), sapforFile);
if (!sapforFile.setExecutable(true))
throw new Exception("Не удалось сделать файл " + sapforFile.getName() + " исполняемым!");
package_json.sapfor_drv = sapforFile.getName();
sapforTasksPackage.sapfor_process_name = package_json.sapfor_drv = sapforFile.getName();
//--->>
//копирование визуализатора
File visualiser = new File(sapforTasksPackage.workspace, "VisualSapfor.jar");
@@ -94,7 +95,6 @@ public class SapforTasksPackageSupervisor {
Utils.createScript(packageWorkspace, packageWorkspace, "start", "java -jar VisualSapfor.jar");
//--
}
void PackageStart() throws Exception {
System.out.println("start sapfor package " + sapforTasksPackage.id);
File workspace = new File(sapforTasksPackage.workspace);
@@ -104,7 +104,7 @@ public class SapforTasksPackageSupervisor {
procBuilder.start();
//--->>
File started = new File(sapforTasksPackage.workspace, Constants.STARTED);
while (!started.exists()){
while (!started.exists()) {
System.out.println("waiting for package start...");
Utils.sleep(1000);
}
@@ -130,21 +130,48 @@ public class SapforTasksPackageSupervisor {
}
}
//--
public boolean packageNeedsKill() throws Exception {
return (boolean) planner.ServerCommand(ServerCode.CheckPackageToKill, sapforTasksPackage.id);
}
public void killPackage() throws Exception {
//----
File interrupt_file = new File(sapforTasksPackage.workspace, Constants.INTERRUPT);
//----
FileUtils.writeStringToFile(interrupt_file, new Date().toString());
File aborted_file = new File(sapforTasksPackage.workspace, Constants.ABORTED);
do {
System.out.println("waiting for interrupt...");
Thread.sleep(1000);
} while (!aborted_file.exists());
System.out.println("coup de grace..");
String kill_command = "killall -SIGKILL " + sapforTasksPackage.sapfor_process_name;
System.out.println(kill_command);
Process killer = Runtime.getRuntime().exec(kill_command);
killer.waitFor();
System.out.println("done!");
}
public void Perform() throws Exception {
switch (sapforTasksPackage.state) {
case TestsSynchronize:
TestsSynchronize();
sapforTasksPackage.state = TasksPackageState.RunningPreparation;
planner.UpdateSapforPackage(sapforTasksPackage);
break;
case RunningPreparation:
PackageStart();
break;
case RunningExecution:
CheckPackageState();
break;
default:
break;
if (packageNeedsKill()) {
System.out.println("PACKAGE " + sapforTasksPackage.id + " NEEDS TO KILL");
killPackage();
sapforTasksPackage.state = TasksPackageState.Aborted;
planner.UpdateSapforPackage(sapforTasksPackage);
} else {
switch (sapforTasksPackage.state) {
case TestsSynchronize:
TestsSynchronize();
sapforTasksPackage.state = TasksPackageState.RunningPreparation;
planner.UpdateSapforPackage(sapforTasksPackage);
break;
case RunningPreparation:
PackageStart();
break;
case RunningExecution:
CheckPackageState();
break;
default:
break;
}
}
}
}

View File

@@ -1,5 +1,4 @@
package TestingSystem;
import Common.Constants;
import Common.Database.DBObject;
import Common.Database.rDBObject;
import Common.Global;
@@ -22,7 +21,6 @@ import TestingSystem.Tasks.TestCompilationTask;
import TestingSystem.Tasks.TestRunTask;
import TestingSystem.Tasks.TestTask;
import TestingSystem.TasksPackage.TasksPackage;
import TestingSystem.TasksPackage.TasksPackageState;
import TestingSystem.TasksPackageToKill.TasksPackageToKill;
import TestingSystem.Test.Test;
import TestingSystem.Test.TestInterface;
@@ -39,7 +37,6 @@ import javax.swing.*;
import java.io.File;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Vector;
import java.util.stream.Collectors;
@@ -314,31 +311,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
groups.sort(Comparator.comparing(o -> o.description));
return groups;
}
private void AbortSapforTasksPackage(SapforTasksPackage object) throws Exception {
if (object.state.equals(TasksPackageState.RunningExecution)) {
File workspace = new File(object.workspace);
//----
File interrupt_file = new File(object.workspace, Constants.INTERRUPT);
//----
FileUtils.writeStringToFile(interrupt_file, new Date().toString());
File aborted_file = new File(object.workspace, Constants.ABORTED);
do {
System.out.println("waiting for interrupt...");
Thread.sleep(1000);
} while (!aborted_file.exists());
System.out.println("coup de grace..");
File[] files = workspace.listFiles((dir, name) -> name.startsWith("SAPFOR_F_"));
if ((files != null) && (files.length > 0)) {
File sapfor = files[0];
String kill_command = "killall -SIGKILL " + sapfor.getName();
System.out.println(kill_command);
Process killer = Runtime.getRuntime().exec(kill_command);
killer.waitFor();
System.out.println("done!");
} else throw new Exception("Не найдена копия SAPFOR");
}else throw new RepositoryRefuseException()
}
@Override
protected void Session() throws Exception {
DBObject dbObject = null;
@@ -351,16 +324,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
//------------->>
response = new ServerExchangeUnit_2021(ServerCode.OK);
break;
case AbortSapforTasksPackage:
Print("Прервать пакет тестов SAPFOR");
SetCurrentAccountDB(request.arg);
if (account_db.sapforTasksPackages.containsKey(request.object)) {
SapforTasksPackage sapforTasksPackage = account_db.sapforTasksPackages.get(request.object);
AbortSapforTasksPackage(sapforTasksPackage);
response = new ServerExchangeUnit_2021(ServerCode.OK);
} else throw new RepositoryRefuseException("Не существует пакета " + Utils.Brackets(request.object));
break;
//--
case CheckPackageToKill:
SetCurrentAccountDB(request.arg);
String packageName = (String) request.object;

View File

@@ -3,8 +3,12 @@ import Common.Current;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import SapforTestingSystem.SapforTasksPackage.SapforTasksPackage;
import TestingSystem.TasksPackageToKill.TasksPackageToKill;
import Visual_DVM_2021.Passes.TestingSystemPass;
import java.util.Vector;
public class AbortSapforTaskPackage extends TestingSystemPass<SapforTasksPackage> {
Vector<TasksPackageToKill> packagesToKill;
@Override
public String getIconPath() {
return "/icons/Ban.PNG";
@@ -15,14 +19,25 @@ public class AbortSapforTaskPackage extends TestingSystemPass<SapforTasksPackage
}
@Override
protected boolean canStart(Object... args) throws Exception {
if (Current.Check(Log, Current.SapforTasksPackage)){
if (Current.Check(Log, Current.SapforTasksPackage)) {
packagesToKill = new Vector<>();
target = Current.getSapforTasksPackage();
return true;
};
switch (target.state) {
case Done:
case Aborted:
break;
default:
TasksPackageToKill tasksPackageToKill = new TasksPackageToKill();
tasksPackageToKill.packageName = target.id;
packagesToKill.add(tasksPackageToKill);
return true;
}
}
;
return false;
}
@Override
protected void ServerAction() throws Exception {
Command(new ServerExchangeUnit_2021(ServerCode.AbortSapforTasksPackage, Current.getAccount().email, target.id));
Command(new ServerExchangeUnit_2021(ServerCode.PublishAccountObjects, Current.getAccount().email, packagesToKill));
}
}