2024-10-09 22:21:57 +03:00
|
|
|
package _VisualDVM.TestingSystem.Common.MachineProcess;
|
2024-10-07 14:22:52 +03:00
|
|
|
import Common.CommonConstants;
|
2024-10-08 15:32:39 +03:00
|
|
|
import Common.Database.Objects.DBObject;
|
|
|
|
|
import Common.Mode;
|
2024-10-07 00:58:29 +03:00
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-09 22:01:19 +03:00
|
|
|
import _VisualDVM.Constants;
|
|
|
|
|
import _VisualDVM.GlobalProperties;
|
|
|
|
|
import _VisualDVM.Utils;
|
2024-10-09 22:21:57 +03:00
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
|
2024-10-08 15:32:39 +03:00
|
|
|
import _VisualDVM.Global;
|
2024-04-21 23:23:57 +03:00
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2024-04-27 18:44:36 +03:00
|
|
|
import java.net.InetAddress;
|
2024-04-21 23:23:57 +03:00
|
|
|
import java.util.Vector;
|
2024-04-23 22:48:02 +03:00
|
|
|
public class MachineProcess extends DBObject {
|
|
|
|
|
public String id = "";
|
2024-04-21 23:23:57 +03:00
|
|
|
public String machineAddress = "";
|
2024-10-07 14:22:52 +03:00
|
|
|
public int machinePort = CommonConstants.Nan;
|
2024-04-21 23:23:57 +03:00
|
|
|
public String userName = "";
|
|
|
|
|
public String userPassword = "";
|
|
|
|
|
public String userWorkspace = "";
|
|
|
|
|
public String testingSystemRoot = "";
|
2024-04-23 22:48:02 +03:00
|
|
|
public String serverName = "";
|
2024-04-21 23:23:57 +03:00
|
|
|
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;
|
2024-10-08 22:33:49 +03:00
|
|
|
testingSystemRoot =CommonUtils.getHomePath();
|
2024-04-23 22:48:02 +03:00
|
|
|
serverName = Global.testingServer.name;
|
2024-10-07 22:22:51 +03:00
|
|
|
id = CommonUtils.getDateName(machineAddress + "_" + machinePort + "_" + userName);
|
2024-04-23 22:48:02 +03:00
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public Object getPK() {
|
|
|
|
|
return id;
|
2024-04-23 00:36:37 +03:00
|
|
|
}
|
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 22:48:02 +03:00
|
|
|
serverName = p.serverName;
|
2024-04-21 23:23:57 +03:00
|
|
|
}
|
2024-04-23 16:40:05 +03:00
|
|
|
public String getUniqueKey() {
|
2024-04-23 00:36:37 +03:00
|
|
|
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() {
|
2024-04-23 22:48:02 +03:00
|
|
|
return new File(Global.MachinesDirectory, id);
|
2024-04-21 23:23:57 +03:00
|
|
|
}
|
2024-04-23 16:40:05 +03:00
|
|
|
public File getStartedFile() {
|
|
|
|
|
return new File(getWorkspace(), Constants.STARTED);
|
|
|
|
|
}
|
2024-04-21 23:23:57 +03:00
|
|
|
public File getAbortedFile() {
|
|
|
|
|
return new File(getWorkspace(), Constants.ABORTED);
|
|
|
|
|
}
|
|
|
|
|
//---
|
2024-04-23 16:40:05 +03:00
|
|
|
public boolean isAborted() {
|
|
|
|
|
File aborted = getAbortedFile();
|
|
|
|
|
return aborted.exists();
|
|
|
|
|
}
|
|
|
|
|
public boolean isStarted() {
|
|
|
|
|
File started = getStartedFile();
|
|
|
|
|
return started.exists();
|
|
|
|
|
}
|
2024-04-27 18:44:36 +03:00
|
|
|
public boolean isLocal() {
|
|
|
|
|
boolean local = false;
|
|
|
|
|
try {
|
|
|
|
|
InetAddress address = InetAddress.getByName(machineAddress);
|
|
|
|
|
InetAddress localAddress = InetAddress.getByName(Global.properties.ServerAddress);
|
|
|
|
|
local = localAddress.getHostAddress().equals(address.getHostAddress());
|
|
|
|
|
} catch (Exception ex) {
|
2024-10-07 22:04:09 +03:00
|
|
|
CommonUtils.MainLog.PrintException(ex);
|
2024-04-27 18:44:36 +03:00
|
|
|
}
|
|
|
|
|
return local;
|
|
|
|
|
}
|
2024-04-23 16:40:05 +03:00
|
|
|
//--
|
2024-04-21 23:23:57 +03:00
|
|
|
public void Start() {
|
|
|
|
|
try {
|
|
|
|
|
File workspace = getWorkspace();
|
|
|
|
|
Utils.CheckAndCleanDirectory(workspace);
|
|
|
|
|
//копирование визуализатора
|
2024-10-09 22:51:52 +03:00
|
|
|
File src = new File(CommonUtils.getHomeDirectory(), "TestingSystem.jar");
|
2024-04-21 23:23:57 +03:00
|
|
|
File supervisor = new File(workspace, "VisualSapfor.jar");
|
2024-04-23 01:39:54 +03:00
|
|
|
FileUtils.copyFile(src, supervisor);
|
2024-04-21 23:23:57 +03:00
|
|
|
//создание настроек
|
2024-04-24 22:23:50 +03:00
|
|
|
GlobalProperties properties = new GlobalProperties(Global.properties);
|
2024-10-08 15:32:39 +03:00
|
|
|
properties.Mode = Mode.MachineQueue;
|
2024-10-07 00:58:29 +03:00
|
|
|
CommonUtils.jsonToFile(properties, new File(workspace, "properties"));
|
2024-04-21 23:23:57 +03:00
|
|
|
Vector<String> args = new Vector<>();
|
2024-10-07 14:22:52 +03:00
|
|
|
args.add(CommonUtils.DQuotes(machineAddress));
|
|
|
|
|
args.add(CommonUtils.DQuotes(machinePort));
|
|
|
|
|
args.add(CommonUtils.DQuotes(userName));
|
|
|
|
|
args.add(CommonUtils.DQuotes(userPassword));
|
|
|
|
|
args.add(CommonUtils.DQuotes(userWorkspace));
|
|
|
|
|
args.add(CommonUtils.DQuotes(testingSystemRoot));
|
|
|
|
|
args.add(CommonUtils.DQuotes(Global.testingServer.name));
|
2024-04-21 23:23:57 +03:00
|
|
|
//--
|
2024-04-23 16:40:05 +03:00
|
|
|
Utils.startScript(workspace, workspace,
|
2024-04-21 23:23:57 +03:00
|
|
|
"start",
|
2024-04-24 22:23:50 +03:00
|
|
|
"java -jar VisualSapfor.jar " +
|
2024-04-27 18:44:36 +03:00
|
|
|
String.join(" ", args) + " 1>out.txt 2>err.txt");
|
2024-04-23 16:40:05 +03:00
|
|
|
//---
|
2024-04-21 23:23:57 +03:00
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|