use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.
the class InfrastructureManager method getDefaultCommandLineBuilder.
// **********************************************************************************************\\
// **************************************** API methods
// *****************************************\\
// **********************************************************************************************\\
/**
* This method returns a
* {@link org.ow2.proactive.resourcemanager.utils.CommandLineBuilder} filled
* in with "default" settings. That means that the returned
* CommandLineBuilder is useable as such.
* <ul>
* <li>It tries to set the Java Path to use, either JAVA_HOME retrieved from
* your environment or java.home set by Java itself.</li>
* <li>The target operating system is set to {@link OperatingSystem#UNIX}
* </li>
* <li>If a ProActive configuration file is provided, it is used as such.
* </li>
* <li>Finally, it tries to set the nodesource's name, the rm's URL and the
* node's name.</li>
* </ul>
*
* @param targetOS
* the operating system on which one the node will be deployed
*/
protected final CommandLineBuilder getDefaultCommandLineBuilder(OperatingSystem targetOS) {
CommandLineBuilder result = new CommandLineBuilder();
String javaPath = System.getProperty("java.home") + targetOS.fs + "bin" + targetOS.fs + "java";
result.setJavaPath(javaPath);
result.setTargetOS(targetOS);
if (CentralPAPropertyRepository.PA_CONFIGURATION_FILE.isSet()) {
try {
result.setPaProperties(new File(CentralPAPropertyRepository.PA_CONFIGURATION_FILE.getValue()));
} catch (IOException e) {
logger.debug("Cannot set default pa configuration file for " + CommandLineBuilder.class.getSimpleName(), e);
}
}
result.setRmURL(getRmUrl());
if (this.nodeSource != null) {
String nsName = this.nodeSource.getName();
result.setSourceName(nsName);
result.setNodeName(nsName + "_DefaultNodeName");
}
return result;
}
use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.
the class SSHInfrastructure method configure.
/**
* Configures the Infrastructure
*
* @param parameters
* parameters[4] : ssh Options, see {@link SSHClient}
* parameters[5] : java path on the remote machines parameters[6]
* : Scheduling path on remote machines parameters[7] : target
* OS' type (Linux, Windows or Cygwin) parameters[8] : extra java
* options parameters[9] : rm cred
* @throws IllegalArgumentException
* configuration failed
*/
@Override
public void configure(Object... parameters) {
super.configure(parameters);
int index = 4;
if (parameters != null && parameters.length >= 10) {
this.sshOptions = parameters[index++].toString();
this.javaPath = parameters[index++].toString();
if (this.javaPath == null || this.javaPath.equals("")) {
throw new IllegalArgumentException("A valid Java path must be supplied.");
}
this.schedulingPath = parameters[index++].toString();
// target OS
if (parameters[index] != null) {
OperatingSystem configuredTargetOs = OperatingSystem.getOperatingSystem(parameters[index++].toString());
if (configuredTargetOs == null) {
throw new IllegalArgumentException("Only 'Linux', 'Windows' and 'Cygwin' are valid values for Target OS Property.");
}
persistedInfraVariables.put(TARGET_OS_OBJ_KEY, configuredTargetOs);
} else {
throw new IllegalArgumentException("Target OS parameter cannot be null");
}
this.javaOptions = parameters[index++].toString();
// credentials
if (parameters[index] == null) {
throw new IllegalArgumentException("Credentials must be specified");
}
try {
persistedInfraVariables.put(CREDENTIALS_KEY, Credentials.getCredentialsBase64((byte[]) parameters[index++]));
} catch (KeyException e) {
throw new IllegalArgumentException("Could not retrieve base64 credentials", e);
}
} else {
throw new IllegalArgumentException("Invalid parameters for infrastructure creation");
}
}
use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.
the class NodesRecoveryProcessHelper method findPidAndSendSigKill.
public static void findPidAndSendSigKill(String javaProcessName) throws IOException, InterruptedException, ProcessNotFoundException {
int pidToKill;
OperatingSystem os = OperatingSystem.UNIX;
if (System.getProperty("os.name").contains("Windows")) {
os = OperatingSystem.WINDOWS;
}
switch(os) {
case WINDOWS:
pidToKill = getWindowsFirstJavaProcessPidWithName(javaProcessName);
break;
case UNIX:
pidToKill = getUnixFirstJavaProcessPidWithName(javaProcessName);
break;
default:
throw new IllegalStateException("Unsupported operating system");
}
// a process killer suitable for windows or unix operating systems
ProcessKiller processKiller = ProcessKiller.get();
processKiller.kill(pidToKill);
}
use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.
the class NodesRecoveryProcessHelper method buildJpsCommand.
private static String buildJpsCommand() {
OperatingSystem os;
String jpsCommandPath;
if (OsUtils.isWin32()) {
os = OperatingSystem.WINDOWS;
jpsCommandPath = "\"" + System.getProperty("java.home") + os.fs + ".." + os.fs + "bin" + os.fs + "jps.exe\"";
} else if (OsUtils.isUNIX()) {
os = OperatingSystem.UNIX;
jpsCommandPath = System.getProperty("java.home") + os.fs + ".." + os.fs + "bin" + os.fs + "jps";
} else {
throw new IllegalStateException("Operating system is not recognized");
}
return jpsCommandPath;
}
use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.
the class LocalInfrastructure method startNodeProcess.
private void startNodeProcess(int numberOfNodes) {
int currentIndex = getIndexAndIncrement();
String baseNodeName = "local-" + this.nodeSource.getName() + "-" + currentIndex;
OperatingSystem os = OperatingSystem.UNIX;
// assuming no cygwin, windows or the "others"...
if (System.getProperty("os.name").contains("Windows")) {
os = OperatingSystem.WINDOWS;
}
String rmHome = PAResourceManagerProperties.RM_HOME.getValueAsString();
if (!rmHome.endsWith(os.fs)) {
rmHome += os.fs;
}
CommandLineBuilder clb = this.getDefaultCommandLineBuilder(os);
// RM_Home set in bin/unix/env script
clb.setRmHome(rmHome);
ArrayList<String> paPropList = new ArrayList<>();
if (!this.paProperties.contains(CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getName())) {
paPropList.add(CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getCmdLine() + rmHome + "config" + os.fs + "security.java.policy-client");
}
if (!this.paProperties.contains(CentralPAPropertyRepository.PA_CONFIGURATION_FILE.getName())) {
paPropList.add(CentralPAPropertyRepository.PA_CONFIGURATION_FILE.getCmdLine() + rmHome + "config" + os.fs + "network" + os.fs + "node.ini");
}
if (!this.paProperties.contains(PAResourceManagerProperties.RM_HOME.getKey())) {
paPropList.add(PAResourceManagerProperties.RM_HOME.getCmdLine() + rmHome);
}
if (!this.paProperties.contains("java.library.path")) {
paPropList.add("-Djava.library.path=" + System.getProperty("java.library.path"));
}
if (!paProperties.isEmpty()) {
Collections.addAll(paPropList, this.paProperties.split(" "));
}
clb.setPaProperties(paPropList);
clb.setNodeName(baseNodeName);
clb.setNumberOfNodes(numberOfNodes);
try {
clb.setCredentialsValueAndNullOthers(new String(this.credentials.getBase64()));
} catch (KeyException e) {
createLostNodes(baseNodeName, numberOfNodes, "Cannot decrypt credentials value", e);
return;
}
List<String> cmd;
try {
cmd = clb.buildCommandLineAsList(false);
} catch (IOException e) {
createLostNodes(baseNodeName, numberOfNodes, "Cannot build command line", e);
return;
}
// The printed cmd with obfuscated credentials
final String obfuscatedCmd = Joiner.on(' ').join(cmd);
List<String> depNodeURLs = new ArrayList<>(numberOfNodes);
final List<String> createdNodeNames = RMNodeStarter.getWorkersNodeNames(baseNodeName, numberOfNodes);
ProcessExecutor processExecutor = null;
try {
depNodeURLs.addAll(addMultipleDeployingNodes(createdNodeNames, obfuscatedCmd, "Node launched locally", this.nodeTimeout));
// Deobfuscate the cred value
Collections.replaceAll(cmd, CommandLineBuilder.OBFUSC, clb.getCredentialsValue());
processExecutor = new ProcessExecutor(baseNodeName, cmd, false, true);
processExecutor.start();
processExecutors.put(processExecutor, depNodeURLs);
final ProcessExecutor tmpProcessExecutor = processExecutor;
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (tmpProcessExecutor != null && !tmpProcessExecutor.isProcessFinished()) {
tmpProcessExecutor.killProcess();
}
}
}));
logger.info("Local Nodes command started : " + obfuscatedCmd);
} catch (IOException e) {
String lf = System.lineSeparator();
String mess = "Cannot launch rm node " + baseNodeName + lf + Throwables.getStackTraceAsString(e);
multipleDeclareDeployingNodeLost(depNodeURLs, mess);
if (processExecutor != null) {
cleanProcess(processExecutor);
}
return;
}
// watching process
int threshold = 10;
while (!allNodesAcquiredOrLost()) {
if (processExecutor.isProcessFinished()) {
int exit = processExecutor.getExitCode();
if (exit != 0) {
String lf = System.lineSeparator();
String message = "RMNode exit code == " + exit + lf;
message += "Command: " + obfuscatedCmd + lf;
String out = Joiner.on('\n').join(processExecutor.getOutput());
String err = Joiner.on('\n').join(processExecutor.getErrorOutput());
message += "stdout: " + out + lf + "stderr: " + err;
multipleDeclareDeployingNodeLost(depNodeURLs, message);
}
} else {
logger.debug("Waiting for nodes " + baseNodeName + " acquisition");
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.warn("Interrupted while waiting for local process status", e);
threshold--;
if (threshold <= 0) {
break;
}
}
}
logger.debug("Local Infrastructure manager exits watching loop for nodes " + baseNodeName);
logNodeOutput(baseNodeName + " stdout: ", processExecutor.getOutput());
logNodeOutput(baseNodeName + " stderr: ", processExecutor.getErrorOutput());
if (allNodesLost(numberOfNodes)) {
// clean up the process
cleanProcess(processExecutor);
}
}
Aggregations