2024-04-21 23:23:57 +03:00
|
|
|
|
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;
|
2024-04-23 00:36:37 +03:00
|
|
|
|
import TestingSystem.DVM.DVMPackage.DVMPackage;
|
2024-04-21 23:23:57 +03:00
|
|
|
|
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 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 MachineProcessState state = MachineProcessState.Inactive; //0 неактивен
|
|
|
|
|
|
//--
|
|
|
|
|
|
public MachineProcess() {
|
|
|
|
|
|
}
|
|
|
|
|
|
public MachineProcess(MachineProcess p) {
|
|
|
|
|
|
SynchronizeFields(p);
|
|
|
|
|
|
}
|
2024-04-23 00:36:37 +03:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2024-04-21 23:23:57 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public void SynchronizeFields(DBObject src) {
|
|
|
|
|
|
super.SynchronizeFields(src);
|
|
|
|
|
|
MachineProcess p = (MachineProcess) src;
|
|
|
|
|
|
machineAddress = p.machineAddress;
|
|
|
|
|
|
machinePort = p.machinePort;
|
|
|
|
|
|
userName = p.userName;
|
|
|
|
|
|
userPassword = p.userPassword;
|
|
|
|
|
|
userWorkspace = p.userWorkspace;
|
|
|
|
|
|
testingSystemRoot = p.testingSystemRoot;
|
|
|
|
|
|
}
|
2024-04-23 00:36:37 +03:00
|
|
|
|
public String getUniqueKey(){
|
|
|
|
|
|
Vector<String> res = new Vector<>();
|
|
|
|
|
|
res.add(machineAddress);
|
|
|
|
|
|
res.add(String.valueOf(machinePort));
|
|
|
|
|
|
res.add(userName);
|
|
|
|
|
|
res.add(userWorkspace);
|
|
|
|
|
|
return String.join("_", res);
|
|
|
|
|
|
}
|
2024-04-21 23:23:57 +03:00
|
|
|
|
public File getWorkspace() {
|
|
|
|
|
|
return new File(Global.MachinesDirectory, String.valueOf(id));
|
|
|
|
|
|
}
|
2024-04-23 00:36:37 +03:00
|
|
|
|
|
2024-04-21 23:23:57 +03:00
|
|
|
|
public File getAbortedFile() {
|
|
|
|
|
|
return new File(getWorkspace(), Constants.ABORTED);
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
public void Start() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
File workspace = getWorkspace();
|
|
|
|
|
|
Utils.CheckAndCleanDirectory(workspace);
|
|
|
|
|
|
//копирование визуализатора
|
|
|
|
|
|
File src = new File(Global.Home, "TestingSystem.jar");
|
|
|
|
|
|
File supervisor = new File(workspace, "VisualSapfor.jar");
|
|
|
|
|
|
FileUtils.copyFile(Global.visualiser.getFile(), supervisor);
|
|
|
|
|
|
//создание настроек
|
|
|
|
|
|
GlobalProperties properties = new GlobalProperties();
|
|
|
|
|
|
properties.Mode = Current.Mode.MachineQueue;
|
|
|
|
|
|
Utils.jsonToFile(properties, new File(workspace, "properties"));
|
|
|
|
|
|
Vector<String> args = new Vector<>();
|
|
|
|
|
|
args.add(Utils.DQuotes(machineAddress));
|
|
|
|
|
|
args.add(Utils.DQuotes(machinePort));
|
|
|
|
|
|
args.add(Utils.DQuotes(userName));
|
|
|
|
|
|
args.add(Utils.DQuotes(userPassword));
|
|
|
|
|
|
args.add(Utils.DQuotes(testingSystemRoot));
|
|
|
|
|
|
//--
|
|
|
|
|
|
//подготовка пакетного режима. Запустит его уже очередь.
|
|
|
|
|
|
Utils.createScript(workspace, workspace,
|
|
|
|
|
|
"start",
|
|
|
|
|
|
"java -jar VisualSapfor.jar " + String.join(" ", args));
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
public boolean isAborted() {
|
|
|
|
|
|
File aborted = getAbortedFile();
|
|
|
|
|
|
return aborted.exists();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|