Search in sources :

Example 1 with ProcessExecutor

use of org.ow2.proactive.process.ProcessExecutor in project scheduling by ow2-proactive.

the class LocalInfrastructure method removeNodeAndMaybeKillProcessIfEmpty.

private ProcessExecutor removeNodeAndMaybeKillProcessIfEmpty(Map<String, ProcessExecutor> urlToProcess, Map<ProcessExecutor, List<String>> processToUrl, String url, boolean killProcessIfEmpty, int deploymentIndex) {
    ProcessExecutor executor = urlToProcess.remove(url);
    if (executor != null) {
        List<String> urlsAssociatedWithTheProcess = processToUrl.get(executor);
        urlsAssociatedWithTheProcess.remove(url);
        if (killProcessIfEmpty && urlsAssociatedWithTheProcess.isEmpty()) {
            processToUrl.remove(executor);
            executor.killProcess();
            if (deploymentIndex >= 0) {
                removeIndexWithLockAndPersist(deploymentIndex);
            }
        } else if (urlsAssociatedWithTheProcess.isEmpty()) {
            processToUrl.remove(executor);
        }
    }
    return executor;
}
Also used : ProcessExecutor(org.ow2.proactive.process.ProcessExecutor)

Example 2 with ProcessExecutor

use of org.ow2.proactive.process.ProcessExecutor in project scheduling by ow2-proactive.

the class LocalInfrastructure method notifyAcquiredNode.

@Override
protected void notifyAcquiredNode(Node node) throws RMException {
    incrementNumberOfAcquiredNodesWithLockAndPersist();
    String deployingNodeURL = this.buildDeployingNodeURL(node.getNodeInformation().getName());
    ProcessExecutor associatedProcess = removeNodeAndMaybeKillProcessIfEmpty(deployingToProcessExecutors, processExecutorsToDeploying, deployingNodeURL, false, -1);
    acquiredToProcessExecutors.put(node.getNodeInformation().getURL(), associatedProcess);
    List<String> nodesUrls = processExecutorsToAcquired.putIfAbsent(associatedProcess, Lists.newArrayList(node.getNodeInformation().getURL()));
    if (nodesUrls != null) {
        nodesUrls.add(node.getNodeInformation().getURL());
    }
}
Also used : ProcessExecutor(org.ow2.proactive.process.ProcessExecutor)

Example 3 with ProcessExecutor

use of org.ow2.proactive.process.ProcessExecutor in project scheduling by ow2-proactive.

the class LocalInfrastructure method shutDown.

@Override
public void shutDown() {
    for (ProcessExecutor processExecutor : this.processExecutorsToDeploying.keySet()) {
        if (processExecutor != null) {
            processExecutor.killProcess();
        }
    }
    this.processExecutorsToDeploying.clear();
    // do not set processExecutor to null here or NPE can appear in the startProcess method, running in a different thread.
    logger.info("All process associated with node source '" + this.nodeSource.getName() + "' are being destroyed.");
}
Also used : ProcessExecutor(org.ow2.proactive.process.ProcessExecutor)

Example 4 with ProcessExecutor

use of org.ow2.proactive.process.ProcessExecutor in project scheduling by ow2-proactive.

the class LocalInfrastructure method startNodeProcess.

private void startNodeProcess(int numberOfNodes) {
    logger.debug("Starting a new process to acquire " + numberOfNodes + " nodes");
    int currentIndex = getIndexAndIncrementWithLockAndPersist();
    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 (!this.paProperties.isEmpty()) {
        Collections.addAll(paPropList, this.paProperties.split(" "));
    }
    clb.setPaProperties(paPropList);
    clb.setNodeName(baseNodeName);
    clb.setNumberOfNodes(numberOfNodes);
    try {
        clb.setCredentialsValueAndNullOthers(getCredentials());
    } 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);
        this.processExecutorsToDeploying.put(processExecutor, depNodeURLs);
        for (String deployingNodeUrl : depNodeURLs) {
            this.deployingToProcessExecutors.put(deployingNodeUrl, processExecutor);
        }
        processExecutor.start();
        final ProcessExecutor tmpProcessExecutor = processExecutor;
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            if (tmpProcessExecutor != null && !tmpProcessExecutor.isProcessFinished()) {
                tmpProcessExecutor.killProcess();
            }
        }));
        logger.debug("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) {
            processExecutor.killProcess();
            this.processExecutorsToDeploying.remove(processExecutor);
            for (String deployingNodeUrl : depNodeURLs) {
                this.deployingToProcessExecutors.remove(deployingNodeUrl);
            }
        }
    }
}
Also used : OperatingSystem(org.ow2.proactive.resourcemanager.utils.OperatingSystem) ArrayList(java.util.ArrayList) CommandLineBuilder(org.ow2.proactive.resourcemanager.utils.CommandLineBuilder) IOException(java.io.IOException) ProcessExecutor(org.ow2.proactive.process.ProcessExecutor) KeyException(java.security.KeyException)

Aggregations

ProcessExecutor (org.ow2.proactive.process.ProcessExecutor)4 IOException (java.io.IOException)1 KeyException (java.security.KeyException)1 ArrayList (java.util.ArrayList)1 CommandLineBuilder (org.ow2.proactive.resourcemanager.utils.CommandLineBuilder)1 OperatingSystem (org.ow2.proactive.resourcemanager.utils.OperatingSystem)1