рабочий вариант отдельных процессов на разные машины
This commit is contained in:
@@ -1157,7 +1157,7 @@ public class Utils {
|
||||
for (int i = 1; i <= 10; ++i) {
|
||||
System.out.println("Проверка " + i + " существования файла " + Utils.Brackets(file.getAbsolutePath()));
|
||||
if (file.exists()) return true;
|
||||
else sleep(1000);
|
||||
else sleep(5000);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -70,14 +70,18 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
System.exit(0);
|
||||
return null;
|
||||
});
|
||||
protected static void Print(String message) throws IOException {
|
||||
protected static void Print(String message) {
|
||||
if (printOn) {
|
||||
Log = new FileWriter("Log.txt", true);
|
||||
String dmessage = Utils.Brackets("SESSION -> ") + new Date() +
|
||||
" " + message;
|
||||
System.out.println(dmessage);
|
||||
Log.write(dmessage + "\n");
|
||||
Log.close();
|
||||
try {
|
||||
Log = new FileWriter("Log.txt", true);
|
||||
String dmessage = Utils.Brackets("SESSION -> ") + new Date() +
|
||||
" " + message;
|
||||
System.out.println(dmessage);
|
||||
Log.write(dmessage + "\n");
|
||||
Log.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void checkTargets(EmailMessage message_in) {
|
||||
@@ -366,7 +370,7 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
}
|
||||
public void afterDeleteAction(DBObject object) throws Exception {
|
||||
}
|
||||
public void Ping(){
|
||||
public void Ping() {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,5 +83,7 @@ public enum ServerCode {
|
||||
GetSapforPackagesJson,
|
||||
GetFirstsActiveDVMPackages,
|
||||
Ping,
|
||||
GetFirstActiveDVMPackageForMachineURL;
|
||||
GetFirstActiveDVMPackageForMachineURL,
|
||||
GetServerName
|
||||
;
|
||||
}
|
||||
|
||||
@@ -2,30 +2,23 @@ package TestingSystem.Common.MachineProcess;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Database.DBObject;
|
||||
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;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
public class MachineProcess extends iDBObject {
|
||||
@Description("DEFAULT ''")
|
||||
public class MachineProcess extends DBObject {
|
||||
public String id = "";
|
||||
public String machineAddress = "";
|
||||
@Description("DEFAULT -1")
|
||||
public int machinePort = Constants.Nan;
|
||||
@Description("DEFAULT ''")
|
||||
public String userName = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String userPassword = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String userWorkspace = "";
|
||||
@Description("DEFAULT ''")
|
||||
public String testingSystemRoot = "";
|
||||
@Description("DEFAULT 'Inactive'")
|
||||
public String serverName = "";
|
||||
public MachineProcessState state = MachineProcessState.Inactive; //0 неактивен
|
||||
//--
|
||||
public MachineProcess() {
|
||||
@@ -34,12 +27,18 @@ public class MachineProcess extends iDBObject {
|
||||
SynchronizeFields(p);
|
||||
}
|
||||
public MachineProcess(DVMPackage p) {
|
||||
id = Utils.getDateName("machine_process");
|
||||
machineAddress = p.machine_address;
|
||||
machinePort = p.machine_port;
|
||||
userName = p.user_name;
|
||||
userPassword = p.user_password;
|
||||
userWorkspace = p.user_workspace;
|
||||
testingSystemRoot = Global.Home;
|
||||
serverName = Global.testingServer.name;
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return id;
|
||||
}
|
||||
@Override
|
||||
public void SynchronizeFields(DBObject src) {
|
||||
@@ -51,6 +50,7 @@ public class MachineProcess extends iDBObject {
|
||||
userPassword = p.userPassword;
|
||||
userWorkspace = p.userWorkspace;
|
||||
testingSystemRoot = p.testingSystemRoot;
|
||||
serverName = p.serverName;
|
||||
}
|
||||
public String getUniqueKey() {
|
||||
Vector<String> res = new Vector<>();
|
||||
@@ -61,7 +61,7 @@ public class MachineProcess extends iDBObject {
|
||||
return String.join("_", res);
|
||||
}
|
||||
public File getWorkspace() {
|
||||
return new File(Global.MachinesDirectory, String.valueOf(id));
|
||||
return new File(Global.MachinesDirectory, id);
|
||||
}
|
||||
public File getStartedFile() {
|
||||
return new File(getWorkspace(), Constants.STARTED);
|
||||
@@ -90,6 +90,7 @@ public class MachineProcess extends iDBObject {
|
||||
//создание настроек
|
||||
GlobalProperties properties = new GlobalProperties();
|
||||
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));
|
||||
@@ -98,10 +99,11 @@ public class MachineProcess extends iDBObject {
|
||||
args.add(Utils.DQuotes(userPassword));
|
||||
args.add(Utils.DQuotes(userWorkspace));
|
||||
args.add(Utils.DQuotes(testingSystemRoot));
|
||||
args.add(Utils.DQuotes(Global.testingServer.name));
|
||||
//--
|
||||
Utils.startScript(workspace, workspace,
|
||||
"start",
|
||||
"java -jar VisualSapfor.jar " + String.join(" ", args));
|
||||
"java -jar VisualSapfor.jar " + String.join(" ", args)+" ");
|
||||
//---
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package TestingSystem.Common.MachineProcess;
|
||||
import Common.Database.iDBTable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public class MachineProcessDBTable extends iDBTable<MachineProcess> {
|
||||
public MachineProcessDBTable() {
|
||||
super(MachineProcess.class);
|
||||
}
|
||||
@Override
|
||||
public String getSingleDescription() {
|
||||
return "процесс машины";
|
||||
}
|
||||
@Override
|
||||
public String getPluralDescription() {
|
||||
return "процессы машины";
|
||||
}
|
||||
public LinkedHashMap<String, MachineProcess> getActiveSortedByKeys(){
|
||||
LinkedHashMap<String, MachineProcess> res = new LinkedHashMap<>();
|
||||
for (MachineProcess process: Data.values()){
|
||||
if (process.state.equals(MachineProcessState.Active))
|
||||
res.put(process.getUniqueKey(), process);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package TestingSystem.Common.MachineProcess;
|
||||
import Common.Database.DataSet;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
public class MachineProcessSet extends DataSet<String, MachineProcess> {
|
||||
public MachineProcessSet() {
|
||||
super(String.class, MachineProcess.class);
|
||||
}
|
||||
public LinkedHashMap<String, MachineProcess> getSortedByKeys() {
|
||||
LinkedHashMap<String, MachineProcess> res = new LinkedHashMap<>();
|
||||
for (MachineProcess process : Data.values())
|
||||
res.put(process.getUniqueKey(), process);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
public String name = "?";
|
||||
@Override
|
||||
public void afterPublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof Test) {
|
||||
@@ -106,6 +107,8 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
//-->>>
|
||||
public TestingServer() {
|
||||
super(TestsDatabase.class);
|
||||
name = Utils.getDateName("testingServer");
|
||||
System.out.println("ServerName=" + Utils.Brackets(name));
|
||||
}
|
||||
//основа
|
||||
@Override
|
||||
@@ -120,31 +123,11 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
protected DVMTestingPlanner DVMTestingPlanner = new DVMTestingPlanner();
|
||||
protected SapforTestingPlanner sapforTestingPlanner = new SapforTestingPlanner();
|
||||
//--
|
||||
void checkMachinesActivity() {
|
||||
System.out.println("Проверка активности нитей машин...");
|
||||
try {
|
||||
Vector<MachineProcess> 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<String, MachineProcess> active_processes = db.machinesProcesses.getActiveSortedByKeys();
|
||||
LinkedHashMap<String, MachineProcess> active_processes = db.machinesProcesses.getSortedByKeys();
|
||||
LinkedHashMap<String, MachineProcess> processes_to_start = new LinkedHashMap<>();
|
||||
//1. Получить список всех пакетов, которые активны, и взять из них машины.
|
||||
for (DVMPackage dvmPackage : db.dvmPackages.Data.values()) {
|
||||
@@ -179,10 +162,10 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
process.Start();
|
||||
if (Utils.checkFileCreation(process.getStartedFile())) {
|
||||
process.state = MachineProcessState.Active;
|
||||
db.Insert(process);
|
||||
db.machinesProcesses.Data.put(process.id, process);
|
||||
System.out.println("Выполнено");
|
||||
}else {
|
||||
System.out.println("Не удалось запустить процесс.");
|
||||
} else {
|
||||
System.out.println("Не удалось запустить процесс.");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@@ -195,7 +178,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
while (true) {
|
||||
// DVMTestingPlanner.Perform();
|
||||
// sapforTestingPlanner.Perform();
|
||||
checkMachinesActivity();
|
||||
startNecessaryMachines();
|
||||
System.out.println("sleep...");
|
||||
Utils.sleep(5000);
|
||||
@@ -304,6 +286,10 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
Print("Получить первый активный пакет задач DVM на машине с адресом");
|
||||
GetFirstActiveDVMPackageForMachineURL();
|
||||
break;
|
||||
case GetServerName:
|
||||
Print("Получить имя сервера");
|
||||
GetServerName();
|
||||
break;
|
||||
default:
|
||||
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
||||
}
|
||||
@@ -647,6 +633,10 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = jsons;
|
||||
}
|
||||
private void GetServerName() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = name;
|
||||
}
|
||||
//--
|
||||
private void GetFirstActiveDVMPackageForMachineURL() {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
|
||||
@@ -8,7 +8,7 @@ import Repository.Component.Sapfor.Sapfor;
|
||||
import Repository.RepositoryRefuseException;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.Common.Group.GroupsDBTable;
|
||||
import TestingSystem.Common.MachineProcess.MachineProcessDBTable;
|
||||
import TestingSystem.Common.MachineProcess.MachineProcessSet;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
import TestingSystem.Common.Test.TestDBTable;
|
||||
import TestingSystem.Common.TestingPackageToKill.TestingPackagesToKillDBTable;
|
||||
@@ -47,8 +47,7 @@ public class TestsDatabase extends SQLiteDatabase {
|
||||
public ServerSapforsDBTable serverSapfors;
|
||||
//---
|
||||
public DVMRunTasksSet dvmRunTasks = new DVMRunTasksSet(); //задачи текущего пакета тестирования DVM
|
||||
//--
|
||||
public MachineProcessDBTable machinesProcesses;
|
||||
public MachineProcessSet machinesProcesses= new MachineProcessSet();
|
||||
//--
|
||||
public TestsDatabase() {
|
||||
super(Paths.get(System.getProperty("user.dir"), "Data", Constants.tests_db_name + ".sqlite").toFile());
|
||||
@@ -65,7 +64,6 @@ public class TestsDatabase extends SQLiteDatabase {
|
||||
addTable(sapforConfigurations = new SapforConfigurationDBTable());
|
||||
addTable(sapforConfigurationCommands = new SapforConfigurationCommandsDBTable());
|
||||
addTable(serverSapfors = new ServerSapforsDBTable());
|
||||
addTable(machinesProcesses = new MachineProcessDBTable());
|
||||
}
|
||||
@Override
|
||||
public PassCode_2021 getSynchronizePassCode() {
|
||||
|
||||
@@ -35,6 +35,7 @@ public class MachineQueueSupervisor extends TestingPlanner<DVMPackage> {
|
||||
boolean local;
|
||||
RemoteFile packageRemoteWorkspace = null;
|
||||
File packageLocalWorkspace = null;
|
||||
String serverName = "";
|
||||
//----
|
||||
public MachineQueueSupervisor(String... args) {
|
||||
Global.isWindows = System.getProperty("os.name").startsWith("Windows");
|
||||
@@ -45,6 +46,7 @@ public class MachineQueueSupervisor extends TestingPlanner<DVMPackage> {
|
||||
String userPassword = args[3];
|
||||
String userWorkspace = args[4];
|
||||
String testingSystemRoot = args[5];
|
||||
serverName = args[6];
|
||||
supervisorHome = new File(Global.Home); //при инициализации это текущая папка.
|
||||
//---
|
||||
Global.Log = new Loggable() {
|
||||
@@ -74,6 +76,7 @@ public class MachineQueueSupervisor extends TestingPlanner<DVMPackage> {
|
||||
Print("userWorkspace=" + Utils.Brackets(userWorkspace));
|
||||
Print("root=" + Utils.Brackets(Global.Home));
|
||||
Print("local=" + local);
|
||||
Print("serverName=" + serverName);
|
||||
Print("=====");
|
||||
//----
|
||||
File started = new File(supervisorHome, Constants.STARTED);
|
||||
@@ -454,11 +457,13 @@ public class MachineQueueSupervisor extends TestingPlanner<DVMPackage> {
|
||||
}
|
||||
@Override
|
||||
protected void MachineConnectionError() {
|
||||
System.out.println("MACHINE CONNECTION ERROR");
|
||||
Finalize("Количество безуспешных попыток соединения с машиной " + machine.getURL() +
|
||||
" превысило 10");
|
||||
}
|
||||
@Override
|
||||
protected void ServerConnectionError(ServerCode code_in) throws Exception {
|
||||
System.out.println("NO SERVER");
|
||||
Finalize("Не удалось выполнить команду " + code_in + " на сервере тестирования");
|
||||
}
|
||||
@Override
|
||||
@@ -470,6 +475,12 @@ public class MachineQueueSupervisor extends TestingPlanner<DVMPackage> {
|
||||
@Override
|
||||
public void Perform() {
|
||||
try {
|
||||
String currentServerName = (String) ServerCommand(ServerCode.GetServerName);
|
||||
System.out.println("current serverName="+Utils.Brackets(currentServerName));
|
||||
System.out.println("serverName="+Utils.Brackets(serverName));
|
||||
if (!serverName.equals(currentServerName)){
|
||||
Finalize("Устаревшее имя сервера");
|
||||
}
|
||||
testingPackage = null;
|
||||
Vector<DVMPackage> activePackages = (Vector<DVMPackage>) ServerCommand(getActivePackagesCode(), machine.getURL(), null);
|
||||
// System.out.println(this.getClass().getSimpleName()+": found "+activePackages.size()+" active packages");
|
||||
|
||||
Reference in New Issue
Block a user