no message
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
package _VisualDVM.TestingSystem.Common.MachineProcess;
|
||||
import Common.CommonConstants;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Mode;
|
||||
import Common.Utils.CommonUtils;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.GlobalProperties;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
|
||||
import _VisualDVM.Global;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Vector;
|
||||
public class MachineProcess extends DBObject {
|
||||
public String id = "";
|
||||
public String machineAddress = "";
|
||||
public int machinePort = CommonConstants.Nan;
|
||||
public String userName = "";
|
||||
public String userPassword = "";
|
||||
public String userWorkspace = "";
|
||||
public String testingSystemRoot = "";
|
||||
public String serverName = "";
|
||||
public MachineProcess() {
|
||||
}
|
||||
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 =CommonUtils.getHomePath();
|
||||
serverName = Global.testingServer.name;
|
||||
id = CommonUtils.getDateName(machineAddress + "_" + machinePort + "_" + userName);
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return id;
|
||||
}
|
||||
@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;
|
||||
serverName = p.serverName;
|
||||
}
|
||||
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);
|
||||
}
|
||||
public File getWorkspace() {
|
||||
return new File(Global.MachinesDirectory, id);
|
||||
}
|
||||
public File getStartedFile() {
|
||||
return new File(getWorkspace(), Constants.STARTED);
|
||||
}
|
||||
public File getAbortedFile() {
|
||||
return new File(getWorkspace(), Constants.ABORTED);
|
||||
}
|
||||
//---
|
||||
public boolean isAborted() {
|
||||
File aborted = getAbortedFile();
|
||||
return aborted.exists();
|
||||
}
|
||||
public boolean isStarted() {
|
||||
File started = getStartedFile();
|
||||
return started.exists();
|
||||
}
|
||||
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) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
return local;
|
||||
}
|
||||
//--
|
||||
public void Start() {
|
||||
try {
|
||||
File workspace = getWorkspace();
|
||||
Utils.CheckAndCleanDirectory(workspace);
|
||||
//копирование визуализатора
|
||||
File src = new File(CommonUtils.getHomeDirectory(), "_VisualDVM.TestingSystem.jar");
|
||||
File supervisor = new File(workspace, "VisualSapfor.jar");
|
||||
FileUtils.copyFile(src, supervisor);
|
||||
//создание настроек
|
||||
GlobalProperties properties = new GlobalProperties(Global.properties);
|
||||
properties.Mode = Mode.MachineQueue;
|
||||
CommonUtils.jsonToFile(properties, new File(workspace, "properties"));
|
||||
Vector<String> args = new Vector<>();
|
||||
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));
|
||||
//--
|
||||
Utils.startScript(workspace, workspace,
|
||||
"start",
|
||||
"java -jar VisualSapfor.jar " +
|
||||
String.join(" ", args) + " 1>out.txt 2>err.txt");
|
||||
//---
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package _VisualDVM.TestingSystem.Common.MachineProcess;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package _VisualDVM.TestingSystem.Common.MachineProcess;
|
||||
public enum MachineProcessState {
|
||||
Inactive,
|
||||
Active,
|
||||
Aborted
|
||||
}
|
||||
Reference in New Issue
Block a user