Доделаны процессы для разных машин
This commit is contained in:
@@ -19,15 +19,12 @@ public class MachineProcess extends DBObject {
|
||||
public String userWorkspace = "";
|
||||
public String testingSystemRoot = "";
|
||||
public String serverName = "";
|
||||
public MachineProcessState state = MachineProcessState.Inactive; //0 неактивен
|
||||
//--
|
||||
public MachineProcess() {
|
||||
}
|
||||
public MachineProcess(MachineProcess p) {
|
||||
SynchronizeFields(p);
|
||||
}
|
||||
public MachineProcess(DVMPackage p) {
|
||||
id = Utils.getDateName("machine_process");
|
||||
machineAddress = p.machine_address;
|
||||
machinePort = p.machine_port;
|
||||
userName = p.user_name;
|
||||
@@ -35,6 +32,7 @@ public class MachineProcess extends DBObject {
|
||||
userWorkspace = p.user_workspace;
|
||||
testingSystemRoot = Global.Home;
|
||||
serverName = Global.testingServer.name;
|
||||
id = Utils.getDateName(machineAddress+"_"+machinePort+"_"+userName);
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
@@ -88,9 +86,8 @@ public class MachineProcess extends DBObject {
|
||||
File supervisor = new File(workspace, "VisualSapfor.jar");
|
||||
FileUtils.copyFile(src, supervisor);
|
||||
//создание настроек
|
||||
GlobalProperties properties = new GlobalProperties();
|
||||
GlobalProperties properties = new GlobalProperties(Global.properties);
|
||||
properties.Mode = Current.Mode.MachineQueue;
|
||||
properties.TestingServerPort = 7996;
|
||||
Utils.jsonToFile(properties, new File(workspace, "properties"));
|
||||
Vector<String> args = new Vector<>();
|
||||
args.add(Utils.DQuotes(machineAddress));
|
||||
@@ -103,7 +100,8 @@ public class MachineProcess extends DBObject {
|
||||
//--
|
||||
Utils.startScript(workspace, workspace,
|
||||
"start",
|
||||
"java -jar VisualSapfor.jar " + String.join(" ", args)+" ");
|
||||
"java -jar VisualSapfor.jar " +
|
||||
String.join(" ", args)+" 1>out.txt 2>err.txt");
|
||||
//---
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package TestingSystem.Common.MachineProcess;
|
||||
import Common.Database.DataSet;
|
||||
import TestingSystem.DVM.DVMPackage.DVMPackage;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
public class MachineProcessSet extends DataSet<String, MachineProcess> {
|
||||
@@ -12,4 +13,17 @@ public class MachineProcessSet extends DataSet<String, MachineProcess> {
|
||||
res.put(process.getUniqueKey(), process);
|
||||
return res;
|
||||
}
|
||||
public boolean hasProcessForPackage(DVMPackage package_in) {
|
||||
for (MachineProcess process : Data.values()) {
|
||||
if (
|
||||
process.machineAddress.equals(package_in.machine_address) &&
|
||||
process.machinePort == package_in.machine_port &&
|
||||
process.userName.equals(package_in.user_name) &&
|
||||
process.userWorkspace.equals(package_in.user_workspace)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
}
|
||||
//---
|
||||
protected Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
|
||||
System.out.println("Команда серверу " + code_in.toString() + "arg=" + arg + " object=" + object_in);
|
||||
TestingSystemPass<Object> pass = new TestingSystemPass<Object>() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
@@ -31,10 +32,13 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
Command(new ServerExchangeUnit_2021(code_in, arg, object_in));
|
||||
target = response.object;
|
||||
}
|
||||
@Override
|
||||
protected boolean validate() {
|
||||
return Log.isEmpty();
|
||||
}
|
||||
};
|
||||
if (!pass.Do()) {
|
||||
ServerConnectionError(code_in);
|
||||
}
|
||||
if (!pass.Do())
|
||||
ServerConnectionError(code_in, pass.Log.toString());
|
||||
return pass.target;
|
||||
}
|
||||
protected Object ServerCommand(ServerCode code_in, Serializable object_in) throws Exception {
|
||||
@@ -105,22 +109,22 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
}
|
||||
protected void Disconnect() {
|
||||
}
|
||||
protected void MachineConnectionError(){
|
||||
protected void MachineConnectionError() {
|
||||
}
|
||||
protected void ServerConnectionError(ServerCode code_in) throws Exception{
|
||||
protected void ServerConnectionError(ServerCode code_in, String logText) throws Exception {
|
||||
throw new PassException("Ошибка взаимодействия с сервером " + code_in);
|
||||
}
|
||||
// ---
|
||||
protected void PerformPackage(TestingPackage package_in) throws Exception{
|
||||
protected void PerformPackage(TestingPackage package_in) throws Exception {
|
||||
testingPackage = (P) package_in;
|
||||
//--
|
||||
Print(testingPackage.id + ":" + testingPackage.state.getDescription());
|
||||
//--
|
||||
if (testingPackage.connectionErrosCount>=10){
|
||||
Print(testingPackage.id+" had 10 connection errors. stop");
|
||||
if (testingPackage.connectionErrosCount >= 10) {
|
||||
Print(testingPackage.id + " had 10 connection errors. stop");
|
||||
UpdatePackageState(TasksPackageState.ConnectionError);
|
||||
MachineConnectionError();
|
||||
}else {
|
||||
} else {
|
||||
//--
|
||||
InitSessionCredentials();
|
||||
if (testingPackage.state.equals(TasksPackageState.Analysis)) {
|
||||
@@ -182,14 +186,13 @@ public abstract class TestingPlanner<P extends TestingPackage> {
|
||||
testingPackage = null;
|
||||
System.gc();
|
||||
//--
|
||||
|
||||
}
|
||||
public void Perform() {
|
||||
try {
|
||||
testingPackage = null;
|
||||
Vector<P> activePackages = (Vector<P>) ServerCommand(getActivePackagesCode());
|
||||
// System.out.println(this.getClass().getSimpleName()+": found "+activePackages.size()+" active packages"); //Тесты:
|
||||
for (P activePackage: activePackages)
|
||||
// System.out.println(this.getClass().getSimpleName()+": found "+activePackages.size()+" active packages"); //Тесты:
|
||||
for (P activePackage : activePackages)
|
||||
PerformPackage(activePackage);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -12,13 +12,11 @@ import Repository.Server.ServerCode;
|
||||
import Repository.Server.ServerExchangeUnit_2021;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.Common.MachineProcess.MachineProcess;
|
||||
import TestingSystem.Common.MachineProcess.MachineProcessState;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
import TestingSystem.Common.Test.TestType;
|
||||
import TestingSystem.Common.TestingPackageToKill.TestingPackageToKill;
|
||||
import TestingSystem.DVM.DVMPackage.DVMPackage;
|
||||
import TestingSystem.DVM.DVMPackage.DVMPackage_json;
|
||||
import TestingSystem.DVM.DVMTestingPlanner;
|
||||
import TestingSystem.SAPFOR.Json.SapforPackage_json;
|
||||
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
|
||||
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommand;
|
||||
@@ -120,65 +118,56 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
protected void startAdditionalThreads() {
|
||||
testingThread.start();
|
||||
}
|
||||
protected DVMTestingPlanner DVMTestingPlanner = new DVMTestingPlanner();
|
||||
protected SapforTestingPlanner sapforTestingPlanner = new SapforTestingPlanner();
|
||||
//--
|
||||
void startNecessaryMachines() {
|
||||
System.out.println("Запуск необходимых нитей машин...");
|
||||
//todo. когда БД машин будет перенесена только на сервер. просто идти по всем машинам.
|
||||
System.out.println("Проверка процессов машин...");
|
||||
try {
|
||||
LinkedHashMap<String, MachineProcess> active_processes = db.machinesProcesses.getSortedByKeys();
|
||||
Vector<String> aborted = new Vector<>();
|
||||
for (MachineProcess process : db.machinesProcesses.Data.values()) {
|
||||
if (process.isAborted()) {
|
||||
aborted.add(process.id);
|
||||
}
|
||||
}
|
||||
//---
|
||||
for (String key : aborted) {
|
||||
System.out.println(key + " остановлен");
|
||||
db.machinesProcesses.Data.remove(key);
|
||||
}
|
||||
//---
|
||||
System.out.println(db.machinesProcesses.size() + " активных процессов");
|
||||
//--
|
||||
LinkedHashMap<String, MachineProcess> processes_to_start = new LinkedHashMap<>();
|
||||
//1. Получить список всех пакетов, которые активны, и взять из них машины.
|
||||
for (DVMPackage dvmPackage : db.dvmPackages.Data.values()) {
|
||||
if (dvmPackage.state.isActive()) {
|
||||
//-
|
||||
Vector<String> k = new Vector<>();
|
||||
k.add(dvmPackage.machine_address);
|
||||
k.add(String.valueOf(dvmPackage.machine_port));
|
||||
k.add(dvmPackage.user_name);
|
||||
k.add(dvmPackage.user_workspace);
|
||||
//-
|
||||
String key = String.join("_", k);
|
||||
if (!active_processes.containsKey(key)) {
|
||||
if (!db.machinesProcesses.hasProcessForPackage(dvmPackage)) {
|
||||
MachineProcess new_process = new MachineProcess(dvmPackage);
|
||||
processes_to_start.put(key, new_process);
|
||||
processes_to_start.put(new_process.getUniqueKey(), new_process);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Активные процессы: " + active_processes.size());
|
||||
for (String key : active_processes.keySet()) {
|
||||
System.out.println(key);
|
||||
}
|
||||
System.out.println("-------------------");
|
||||
System.out.println("Ожидающие запуск процессы: " + processes_to_start.size());
|
||||
for (String key : processes_to_start.keySet()) {
|
||||
System.out.println(key);
|
||||
}
|
||||
System.out.println("-------------------");
|
||||
//запуск.
|
||||
for (MachineProcess process : processes_to_start.values()) {
|
||||
System.out.println("Запуск процесса " + process.getUniqueKey() + " ...");
|
||||
process.Start();
|
||||
if (Utils.checkFileCreation(process.getStartedFile())) {
|
||||
process.state = MachineProcessState.Active;
|
||||
db.machinesProcesses.Data.put(process.id, process);
|
||||
System.out.println("Выполнено");
|
||||
} else {
|
||||
System.out.println("Не удалось запустить процесс.");
|
||||
System.out.println(process.getUniqueKey()+" запущен");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
System.out.println("done");
|
||||
}
|
||||
//--
|
||||
protected Thread testingThread = new Thread(() -> {
|
||||
while (true) {
|
||||
// DVMTestingPlanner.Perform();
|
||||
// sapforTestingPlanner.Perform();
|
||||
startNecessaryMachines();
|
||||
sapforTestingPlanner.Perform();
|
||||
System.out.println("sleep...");
|
||||
Utils.sleep(5000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user