Search in sources :

Example 6 with OperatingSystem

use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.

the class SSHInfrastructureV2 method configure.

/**
 * Configures the Infrastructure
 *
 * @param parameters
 *            parameters[4] : ssh server port parameters[5] : ssh username
 *            parameters[6] : ssh password parameters[7] : ssh private key
 *            parameters[8] : optional ssh options file parameters[9] : java
 *            path on the remote machines parameters[10] : Scheduling path on
 *            remote machines parameters[11] : target OS' type (Linux,
 *            Windows or Cygwin) parameters[12] : extra java options
 * @throws IllegalArgumentException
 *             configuration failed
 */
@Override
public void configure(Object... parameters) {
    super.configure(parameters);
    int index = 4;
    if (parameters == null || parameters.length < 12) {
        throw new IllegalArgumentException("Invalid parameters for infrastructure creation");
    }
    try {
        this.sshPort = Integer.parseInt(parameters[index++].toString());
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("A valid port for ssh must be supplied");
    }
    this.sshUsername = parameters[index++].toString();
    if (this.sshUsername == null || this.sshUsername.equals("")) {
        throw new IllegalArgumentException("A valid ssh username must be supplied");
    }
    this.sshPassword = parameters[index++].toString();
    this.sshPrivateKey = (byte[]) parameters[index++];
    if (this.sshPassword.equals("")) {
        if (this.sshPrivateKey.length == 0)
            throw new IllegalArgumentException("If no password a valid private key must be supplied");
        else
            this.sshPassword = null;
    }
    this.sshOptions = new Properties();
    byte[] bytes = (byte[]) parameters[index++];
    if (bytes.length == 0) {
        this.sshOptions.put("StrictHostKeyChecking", "no");
    } else {
        try {
            this.sshOptions.load(new ByteArrayInputStream(bytes));
        } catch (IOException e) {
            throw new IllegalArgumentException("Could not read ssh options file", e);
        }
    }
    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();
    if (this.schedulingPath == null || this.schedulingPath.equals("")) {
        throw new IllegalArgumentException("A valid path of the scheduling dir must be supplied");
    }
    // target OS
    if (parameters[index] == null) {
        throw new IllegalArgumentException("Target OS parameter cannot be 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);
    this.javaOptions = parameters[index++].toString();
}
Also used : OperatingSystem(org.ow2.proactive.resourcemanager.utils.OperatingSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties)

Example 7 with OperatingSystem

use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.

the class CommandLineBuilder method buildCommandLineAsList.

/**
 * Same as {@link CommandLineBuilder#buildCommandLine(boolean)} but the command is a list of String.
 * @param displayCredentials if true displays the credentials in the command line if false, obfuscates them
 * @return The RMNodeStarter command line as a list of String.
 * @throws java.io.IOException if you supplied a ProActive Configuration file that doesn't exist.
 */
public List<String> buildCommandLineAsList(boolean displayCredentials) throws IOException {
    final ArrayList<String> command = new ArrayList<>();
    final OperatingSystem os = targetOS;
    final Properties paProp = paPropProperties;
    String rmHome = this.getRmHome();
    if (rmHome != null) {
        if (!rmHome.endsWith(os.fs)) {
            rmHome = rmHome + os.fs;
        }
    } else {
        rmHome = "";
    }
    if (detached) {
        makeDetachedCommand(command, os);
    }
    final String libRoot = rmHome + "dist" + os.fs + "lib" + os.fs;
    String javaPath = this.javaPath;
    if (javaPath != null) {
        command.add(javaPath);
    } else {
        RMNodeStarter.logger.warn("Java path isn't set in RMNodeStarter configuration.");
        command.add("java");
    }
    // building configuration
    if (paProp != null) {
        Set<Object> keys = paProp.keySet();
        for (Object key : keys) {
            command.add("-D" + key + "=" + paProp.get(key));
        }
    } else {
        if (this.paPropList != null) {
            command.addAll(this.paPropList);
        }
    }
    // forward current charset to the forked JVM
    String currentJvmCharset = PAProperties.getFileEncoding();
    command.add("-Dfile.encoding=" + currentJvmCharset);
    RMNodeStarter.logger.info("Using '" + currentJvmCharset + "' as file encoding");
    // building classpath
    command.add("-cp");
    final StringBuilder classpath = new StringBuilder(".");
    // add the content of addons dir on the classpath
    classpath.append(os.ps).append(rmHome).append(ADDONS_DIR);
    // add jars inside the addons directory
    classpath.append(os.ps).append(rmHome).append(ADDONS_DIR).append(os.fs).append("*");
    classpath.append(os.ps).append(libRoot).append("*");
    command.add(classpath.toString());
    command.add(RMNodeStarter.class.getName());
    // appending options
    String credsEnv = credentialsEnv;
    if (credsEnv != null) {
        command.add("-" + RMNodeStarter.OPTION_CREDENTIAL_ENV);
        command.add(credsEnv);
    }
    String credsFile = this.getCredentialsFile();
    if (credsFile != null) {
        command.add("-" + RMNodeStarter.OPTION_CREDENTIAL_FILE);
        command.add(credsFile);
    }
    String credsValue = this.getCredentialsValue();
    if (credsValue != null) {
        command.add("-" + RMNodeStarter.OPTION_CREDENTIAL_VAL);
        command.add(displayCredentials ? credsValue : OBFUSC);
    }
    String nodename = this.getNodeName();
    if (nodename != null) {
        command.add("-" + RMNodeStarter.OPTION_NODE_NAME);
        command.add(nodename);
    }
    String nodesource = this.getSourceName();
    if (nodesource != null) {
        command.add("-" + RMNodeStarter.OPTION_SOURCE_NAME);
        command.add(nodesource);
    }
    String rmurl = rmURL;
    if (rmurl != null) {
        command.add("-" + RMNodeStarter.OPTION_RM_URL);
        command.add(rmurl);
    }
    command.add("-" + RMNodeStarter.OPTION_WORKERS);
    command.add("" + nbNodes);
    if (detached && os.equals(OperatingSystem.UNIX)) {
        command.add("&");
    }
    return command;
}
Also used : ArrayList(java.util.ArrayList) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) Properties(java.util.Properties) PAProperties(org.ow2.proactive.utils.PAProperties)

Example 8 with OperatingSystem

use of org.ow2.proactive.utils.OperatingSystem in project scheduling by ow2-proactive.

the class JavaSpawnExecutable method getNativeExecLauncher.

/**
 * Returns the path to the native launcher script In case of Native
 * Executable normal termination test, we use a set of alternate scripts
 * which will not run a detached executable
 *
 * @param alternate
 *            to use alternate scripts
 */
public String[] getNativeExecLauncher(boolean alternate) throws Exception {
    String osName = System.getProperty("os.name");
    OperatingSystem operatingSystem = OperatingSystem.resolveOrError(osName);
    OperatingSystemFamily family = operatingSystem.getFamily();
    String[] nativeExecLauncher = null;
    switch(family) {
        case LINUX:
        case UNIX:
        case MAC:
            String executable = null;
            if (alternate) {
                executable = getExecutablePath(nativeLinuxExecLauncher2).getName();
            } else {
                executable = getExecutablePath(nativeLinuxExecLauncher).getName();
            }
            // TODO runAsMe mode for this Test
            nativeExecLauncher = new String[] { "/bin/sh", executable };
            break;
        case WINDOWS:
            if (alternate) {
                nativeExecLauncher = new String[] { "cmd.exe", "/C", getExecutablePath(nativeWindowsExecLauncher2).getName() };
            } else {
                nativeExecLauncher = new String[] { "cmd.exe", "/C", getExecutablePath(nativeWindowsExecLauncher).getName() };
            }
    }
    return nativeExecLauncher;
}
Also used : OperatingSystem(org.ow2.proactive.utils.OperatingSystem) OperatingSystemFamily(org.ow2.proactive.utils.OperatingSystemFamily)

Aggregations

OperatingSystem (org.ow2.proactive.resourcemanager.utils.OperatingSystem)5 IOException (java.io.IOException)3 KeyException (java.security.KeyException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 PAResourceManagerProperties (org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties)2 CommandLineBuilder (org.ow2.proactive.resourcemanager.utils.CommandLineBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 ProcessExecutor (org.ow2.proactive.process.ProcessExecutor)1 OperatingSystem (org.ow2.proactive.utils.OperatingSystem)1 OperatingSystemFamily (org.ow2.proactive.utils.OperatingSystemFamily)1 PAProperties (org.ow2.proactive.utils.PAProperties)1 ProcessKiller (org.ow2.tests.ProcessKiller)1