прерывание по образцу двм, однотипное.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user