Unverified Commit 38ccd304 authored by TAO Xinxiu (Isabelle)'s avatar TAO Xinxiu (Isabelle) Committed by GitHub
Browse files

allow SSHInfra and SSHInfraV2 to have empty javaPath and schedulingPath (#3799)

parent 6093b11f
......@@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.objectweb.proactive.core.config.CentralPAPropertyRepository;
import org.objectweb.proactive.core.node.Node;
......@@ -78,20 +79,7 @@ public class SSHInfrastructure extends HostsFileBasedInfrastructureManager {
* Path to the Java executable on the remote hosts
*/
@Configurable(description = "Absolute path of the java\nexecutable on the remote hosts", sectionSelector = 1)
protected String javaPath = System.getProperty("java.home") + "/bin/java";
/**
* Use the Java from JAVA_HOME if defined
*/
{
String jhome = System.getenv("JAVA_HOME");
if (jhome != null) {
File f = new File(jhome);
if (f.exists() && f.isDirectory()) {
javaPath = jhome + ((jhome.endsWith("/")) ? "" : "/") + "bin/java";
}
}
}
protected String javaPath = Utils.getDefaultJavaPath();
/**
* Path to the Scheduling installation on the remote hosts
......@@ -321,10 +309,13 @@ public class SSHInfrastructure extends HostsFileBasedInfrastructureManager {
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.");
if (this.javaPath == null || StringUtils.isBlank(this.javaPath)) {
this.javaPath = Utils.getDefaultJavaPath();
}
this.schedulingPath = parameters[index++].toString();
if (this.schedulingPath == null || StringUtils.isBlank(this.schedulingPath)) {
this.schedulingPath = PAResourceManagerProperties.RM_HOME.getValueAsString();
}
// target OS
if (parameters[index] != null) {
OperatingSystem configuredTargetOs = OperatingSystem.getOperatingSystem(parameters[index++].toString());
......
......@@ -43,6 +43,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.objectweb.proactive.core.config.CentralPAPropertyRepository;
import org.objectweb.proactive.core.node.Node;
......@@ -97,7 +98,7 @@ public class SSHInfrastructureV2 extends HostsFileBasedInfrastructureManager {
protected Properties sshOptions;
@Configurable(description = "Absolute path of the java executable on the remote hosts", sectionSelector = 1)
protected String javaPath = PAResourceManagerProperties.getAbsolutePath("jre/bin/java");
protected String javaPath = Utils.getDefaultJavaPath();
@Configurable(description = "Absolute path of the Resource Manager (or Scheduler)root directory on the remote hosts", sectionSelector = 1)
protected String schedulingPath = PAResourceManagerProperties.RM_HOME.getValueAsString();
......@@ -373,13 +374,13 @@ public class SSHInfrastructureV2 extends HostsFileBasedInfrastructureManager {
}
this.javaPath = parameters[index++].toString();
if (this.javaPath == null || this.javaPath.equals("")) {
throw new IllegalArgumentException("A valid Java path must be supplied");
if (this.javaPath == null || StringUtils.isBlank(this.javaPath)) {
this.javaPath = Utils.getDefaultJavaPath();
}
this.schedulingPath = parameters[index++].toString();
if (this.schedulingPath == null || this.schedulingPath.equals("")) {
throw new IllegalArgumentException("A valid path of the scheduling dir must be supplied");
if (this.schedulingPath == null || StringUtils.isBlank(this.schedulingPath)) {
this.schedulingPath = PAResourceManagerProperties.RM_HOME.getValueAsString();
}
// target OS
......
......@@ -206,4 +206,18 @@ public class Utils {
}
}
}
/**
* Get default javaPath: use Java from JAVA_HOME if defined, otherwise use Java from system property java.home
*/
public static String getDefaultJavaPath() {
String jhome = System.getenv("JAVA_HOME");
if (jhome != null) {
File f = new File(jhome);
if (f.exists() && f.isDirectory()) {
return jhome + ((jhome.endsWith("/")) ? "" : "/") + "bin/java";
}
}
return System.getProperty("java.home") + "/bin/java";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment