diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6a496413..0692e1b0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,14 +7,10 @@
-
-
-
-
+
+
-
-
@@ -36,8 +32,8 @@
-
+
diff --git a/src/TestingSystem/Common/MachineProcess/MachineProcess.java b/src/TestingSystem/Common/MachineProcess/MachineProcess.java
index e40b6620..0de3b971 100644
--- a/src/TestingSystem/Common/MachineProcess/MachineProcess.java
+++ b/src/TestingSystem/Common/MachineProcess/MachineProcess.java
@@ -6,6 +6,7 @@ import Common.Database.iDBObject;
import Common.Global;
import Common.GlobalProperties;
import Common.Utils.Utils;
+import TestingSystem.DVM.DVMPackage.DVMPackage;
import com.sun.org.glassfish.gmbal.Description;
import org.apache.commons.io.FileUtils;
@@ -32,6 +33,14 @@ public class MachineProcess extends iDBObject {
public MachineProcess(MachineProcess p) {
SynchronizeFields(p);
}
+ public MachineProcess(DVMPackage p) {
+ machineAddress = p.machine_address;
+ machinePort = p.machine_port;
+ userName = p.user_name;
+ userPassword = p.user_password;
+ userWorkspace = p.user_workspace;
+ testingSystemRoot = Global.Home;
+ }
@Override
public void SynchronizeFields(DBObject src) {
super.SynchronizeFields(src);
@@ -43,9 +52,18 @@ public class MachineProcess extends iDBObject {
userWorkspace = p.userWorkspace;
testingSystemRoot = p.testingSystemRoot;
}
+ public String getUniqueKey(){
+ Vector res = new Vector<>();
+ res.add(machineAddress);
+ res.add(String.valueOf(machinePort));
+ res.add(userName);
+ res.add(userWorkspace);
+ return String.join("_", res);
+ }
public File getWorkspace() {
return new File(Global.MachinesDirectory, String.valueOf(id));
}
+
public File getAbortedFile() {
return new File(getWorkspace(), Constants.ABORTED);
}
diff --git a/src/TestingSystem/Common/MachineProcess/MachineProcessDBTable.java b/src/TestingSystem/Common/MachineProcess/MachineProcessDBTable.java
index 934073fe..5e12340f 100644
--- a/src/TestingSystem/Common/MachineProcess/MachineProcessDBTable.java
+++ b/src/TestingSystem/Common/MachineProcess/MachineProcessDBTable.java
@@ -1,6 +1,7 @@
package TestingSystem.Common.MachineProcess;
import Common.Database.iDBTable;
+import java.util.LinkedHashMap;
import java.util.Vector;
public class MachineProcessDBTable extends iDBTable {
public MachineProcessDBTable() {
@@ -14,18 +15,12 @@ public class MachineProcessDBTable extends iDBTable {
public String getPluralDescription() {
return "процессы машины";
}
- public void checkProcesses() throws Exception {
- Vector toUpdate = new Vector<>();
- for (MachineProcess machineProcess : Data.values()) {
- if (machineProcess.isAborted()) {
- toUpdate.add(machineProcess);
- }
+ public LinkedHashMap getActiveSortedByKeys(){
+ LinkedHashMap res = new LinkedHashMap<>();
+ for (MachineProcess process: Data.values()){
+ if (process.state.equals(MachineProcessState.Active))
+ res.put(process.getUniqueKey(), process);
}
- getDb().BeginTransaction();
- for (MachineProcess machineProcess: toUpdate){
- machineProcess.state = MachineProcessState.Aborted;
- getDb().Update(machineProcess);
- }
- getDb().Commit();
+ return res;
}
}
diff --git a/src/TestingSystem/Common/TestingServer.java b/src/TestingSystem/Common/TestingServer.java
index cb0d4297..842f3c55 100644
--- a/src/TestingSystem/Common/TestingServer.java
+++ b/src/TestingSystem/Common/TestingServer.java
@@ -11,6 +11,8 @@ import Repository.RepositoryServer;
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;
@@ -118,10 +120,73 @@ public class TestingServer extends RepositoryServer {
protected DVMTestingPlanner DVMTestingPlanner = new DVMTestingPlanner();
protected SapforTestingPlanner sapforTestingPlanner = new SapforTestingPlanner();
//--
+ void checkMachinesActivity() {
+ System.out.println("Проверка активности нитей машин...");
+ try {
+ Vector toUpdate = new Vector<>();
+ for (MachineProcess machineProcess : db.machinesProcesses.Data.values()) {
+ if (machineProcess.isAborted()) {
+ toUpdate.add(machineProcess);
+ }
+ }
+ db.BeginTransaction();
+ for (MachineProcess machineProcess : toUpdate) {
+ machineProcess.state = MachineProcessState.Aborted;
+ db.Update(machineProcess);
+ }
+ db.Commit();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ System.out.println("done");
+ }
+ void startNecessaryMachines() {
+ System.out.println("Запуск необходимых нитей машин...");
+ //todo. когда БД машин будет перенесена только на сервер. просто идти по всем машинам.
+ try {
+ LinkedHashMap active_processes = db.machinesProcesses.getActiveSortedByKeys();
+ LinkedHashMap processes_to_start = new LinkedHashMap<>();
+ //1. Получить список всех пакетов, которые активны, и взять из них машины.
+ for (DVMPackage dvmPackage : db.dvmPackages.Data.values()) {
+ if (dvmPackage.state.isActive()) {
+ //-
+ Vector 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)) {
+ MachineProcess new_process = new MachineProcess(dvmPackage);
+ processes_to_start.put(key, 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("-------------------");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ System.out.println("done");
+ }
+ //--
protected Thread testingThread = new Thread(() -> {
while (true) {
- DVMTestingPlanner.Perform();
- sapforTestingPlanner.Perform();
+ // DVMTestingPlanner.Perform();
+ // sapforTestingPlanner.Perform();
+ checkMachinesActivity();
+ startNecessaryMachines();
+ System.out.println("sleep...");
+ Utils.sleep(5000);
}
});
//------>>>
@@ -310,7 +375,7 @@ public class TestingServer extends RepositoryServer {
private void GetFirstActiveDVMPackagesByMachines() {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = new Vector<>();
- // db.getFirstActiveDVMPackagesCopies(); //ЗАГЛУШКА. ЗА ПАКЕТЫ ДВМ ОТВЕЧАЕТ ОТДЕЛЬНЫЙ ПРОЦЕСС НА КАЖДУЮ МАШИНУ
+ // db.getFirstActiveDVMPackagesCopies(); //ЗАГЛУШКА. ЗА ПАКЕТЫ ДВМ ОТВЕЧАЕТ ОТДЕЛЬНЫЙ ПРОЦЕСС НА КАЖДУЮ МАШИНУ
}
private void GetFirstActiveSapforPackages() throws Exception {
response = new ServerExchangeUnit_2021(ServerCode.OK);
@@ -540,7 +605,7 @@ public class TestingServer extends RepositoryServer {
//-
Email(message, out, err);
}
- private void GetDVMPackagesJson() throws Exception{
+ private void GetDVMPackagesJson() throws Exception {
Vector packages_ids = (Vector) request.object;
Vector jsons = new Vector<>();
for (int package_id : packages_ids) {