Search in sources :

Example 71 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client 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)

Example 72 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SSHInfrastructure method startNodeImpl.

/**
 * Internal node acquisition method
 * <p>
 * Starts a PA runtime on remote host using SSH, register it manually in the
 * nodesource.
 *
 * @param hostTracker The host on which one the node will be started
 * @param nbNodes number of nodes to deploy
 * @param depNodeURLs list of deploying or lost nodes urls created
 * @throws RMException
 *             acquisition failed
 */
protected void startNodeImpl(HostTracker hostTracker, int nbNodes, final List<String> depNodeURLs) throws RMException {
    String fs = getTargetOSObj().fs;
    CommandLineBuilder clb = super.getDefaultCommandLineBuilder(getTargetOSObj());
    // we take care of spaces in java path
    clb.setJavaPath(this.javaPath);
    // we set the rm.home prop
    clb.setRmHome(schedulingPath);
    // we set the java security policy file
    StringBuilder sb = new StringBuilder();
    final boolean containsSpace = schedulingPath.contains(" ");
    String securitycmd = CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getCmdLine();
    if (!this.javaOptions.contains(securitycmd)) {
        sb.append(securitycmd);
        if (containsSpace) {
            sb.append("\"");
        }
        sb.append(schedulingPath);
        sb.append(fs);
        sb.append("config");
        sb.append(fs);
        sb.append("security.java.policy-client");
        if (containsSpace) {
            sb.append("\"");
        }
        sb.append(" ");
    }
    // we set the log4j configuration file
    String log4jcmd = CentralPAPropertyRepository.LOG4J.getCmdLine();
    if (!this.javaOptions.contains(log4jcmd)) {
        sb.append(log4jcmd);
        if (containsSpace) {
            sb.append("\"");
        }
        // log4j only understands urls
        sb.append("file:");
        if (!schedulingPath.startsWith("/")) {
            sb.append("/" + schedulingPath.replace("\\", "/"));
        } else {
            sb.append(schedulingPath.replace("\\", "/"));
        }
        sb.append("/");
        sb.append("config");
        sb.append("/");
        sb.append("log");
        sb.append("/");
        sb.append("node.properties");
        if (containsSpace) {
            sb.append("\"");
        }
        sb.append(" ");
    }
    // we add extra java/PA configuration
    sb.append(this.javaOptions);
    clb.setPaProperties(sb.toString());
    // afterwards, node's name
    // generate the node name
    // current rmcore shortID should be added to ensure uniqueness
    final String nodeName = nodeNameBuilder.generateNodeName(hostTracker);
    clb.setNodeName(nodeName);
    clb.setNumberOfNodes(nbNodes);
    // finally, the credential's value
    String credString = null;
    try {
        credString = new String(getCredentials().getBase64());
    } catch (KeyException e1) {
        throw new RMException("Could not get base64 credentials", e1);
    }
    clb.setCredentialsValueAndNullOthers(credString);
    // add an expected node. every unexpected node will be discarded
    String cmdLine;
    String obfuscatedCmdLine;
    try {
        cmdLine = clb.buildCommandLine(true);
        obfuscatedCmdLine = clb.buildCommandLine(false);
    } catch (IOException e2) {
        throw new RMException("Cannot build the " + RMNodeStarter.class.getSimpleName() + "'s command line.", e2);
    }
    // one escape the command to make it runnable through ssh
    if (cmdLine.contains("\"")) {
        cmdLine = cmdLine.replaceAll("\"", "\\\\\"");
    }
    // we create a new deploying node before ssh command ran
    final List<String> createdNodeNames = RMNodeStarter.getWorkersNodeNames(nodeName, nbNodes);
    depNodeURLs.addAll(addMultipleDeployingNodes(createdNodeNames, obfuscatedCmdLine, "Deploying nodes on host " + hostTracker.getResolvedAddress(), super.nodeTimeOut));
    addTimeouts(depNodeURLs);
    Process p = null;
    try {
        p = Utils.runSSHCommand(hostTracker.getResolvedAddress(), cmdLine, sshOptions);
    } catch (IOException e1) {
        multipleDeclareDeployingNodeLost(depNodeURLs, "Cannot run command: " + cmdLine + ", with ssh options: " + sshOptions + " -\n The following exception occutred:\n " + getStackTraceAsString(e1));
        throw new RMException("Cannot run command: " + cmdLine + ", with ssh options: " + sshOptions, e1);
    }
    String lf = System.lineSeparator();
    int circuitBreakerThreshold = 5;
    while (!anyTimedOut(depNodeURLs) && circuitBreakerThreshold > 0) {
        try {
            int exitCode = p.exitValue();
            if (exitCode != 0) {
                logger.error("SSH subprocess at " + hostTracker.getResolvedAddress().getHostName() + " exited abnormally (" + exitCode + ").");
            } else {
                logger.error("Launching node process has exited normally whereas it shouldn't.");
            }
            String pOutPut = Utils.extractProcessOutput(p);
            String pErrPut = Utils.extractProcessErrput(p);
            final String description = "SSH command failed to launch node on host " + hostTracker.getResolvedAddress().getHostName() + lf + "   >Error code: " + exitCode + lf + "   >Errput: " + pErrPut + "   >Output: " + pOutPut;
            logger.error(description);
            if (super.checkAllNodesAreAcquiredAndDo(createdNodeNames, null, new Runnable() {

                public void run() {
                    SSHInfrastructure.this.multipleDeclareDeployingNodeLost(depNodeURLs, description);
                }
            })) {
                return;
            } else {
                // there isn't any race regarding node registration
                throw new RMException("SSH Node " + nodeName + " is not expected anymore because of an error.");
            }
        } catch (IllegalThreadStateException e) {
            logger.trace("IllegalThreadStateException while waiting for " + nodeName + " registration");
        }
        if (super.checkNodeIsAcquiredAndDo(nodeName, null, null)) {
            // registration is ok, we destroy the process
            p.destroy();
            return;
        }
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            circuitBreakerThreshold--;
            logger.trace("An exception occurred while monitoring ssh subprocess", e);
        }
    }
    // if we exit because of a timeout
    if (anyTimedOut(depNodeURLs)) {
        // we remove it
        removeTimeouts(depNodeURLs);
        // we destroy the process
        p.destroy();
        throw new RMException("Deploying Node " + nodeName + " not expected any more");
    }
    if (circuitBreakerThreshold <= 0) {
        logger.error("Circuit breaker threshold reached while monitoring ssh subprocess.");
        throw new RMException("Several exceptions occurred while monitoring ssh subprocess.");
    }
}
Also used : Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) CommandLineBuilder(org.ow2.proactive.resourcemanager.utils.CommandLineBuilder) IOException(java.io.IOException) KeyException(java.security.KeyException) RMException(org.ow2.proactive.resourcemanager.exception.RMException) KeyException(java.security.KeyException) IOException(java.io.IOException) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 73 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMMonitoringImpl method addRMEventListener.

/**
 * Register a new Resource manager listener.
 * Way to a monitor object to ask at RMMonitoring to throw
 * RM events to it.
 * @param stub a listener object which implements {@link RMEventListener}
 * interface.
 * @param events list of wanted events that must be received.
 * @return RMInitialState snapshot of RM's current state : nodes and node sources.
 */
public RMInitialState addRMEventListener(RMEventListener stub, RMEventType... events) {
    UniqueID id = PAActiveObject.getContext().getCurrentRequest().getSourceBodyID();
    logger.debug("Adding the RM listener for " + id.shortString());
    synchronized (dispatchers) {
        Client client = null;
        synchronized (RMCore.clients) {
            client = RMCore.clients.get(id);
        }
        if (client == null) {
            throw new IllegalArgumentException("Unknown client " + id.shortString());
        }
        EventDispatcher eventDispatcher = null;
        if (stub instanceof RMGroupEventListener) {
            eventDispatcher = new GroupEventDispatcher(client, stub, events);
        } else {
            eventDispatcher = new EventDispatcher(client, stub, events);
        }
        this.dispatchers.put(id, eventDispatcher);
        RMInitialState rmInitialState = rmcore.getRMInitialState();
        eventDispatcher.setCounter(rmInitialState.getLatestCounter());
        return rmInitialState;
    }
}
Also used : UniqueID(org.objectweb.proactive.core.UniqueID) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 74 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class NodeSource method removeNode.

/**
 * Removes the node from the node source.
 *
 * @param nodeUrl the url of the node to be released
 */
public BooleanWrapper removeNode(String nodeUrl, Client initiator) {
    Node node = null;
    // node could have fallen between remove request and the confirm
    if (this.nodes.containsKey(nodeUrl)) {
        logger.info("[" + this.name + "] removing node: " + nodeUrl);
        node = this.nodes.remove(nodeUrl);
    } else if (this.downNodes.containsKey(nodeUrl)) {
        logger.info("[" + this.name + "] removing down node: " + nodeUrl);
        node = this.downNodes.remove(nodeUrl);
    }
    if (node == null) {
        logger.error("[" + this.name + "] cannot remove node: " + nodeUrl + " because it is unknown");
        return new BooleanWrapper(false);
    } else {
        this.removedNodes.put(nodeUrl, node);
        RMCore.topologyManager.removeNode(node);
        try {
            this.infrastructureManager.internalRemoveNode(node);
        } catch (RMException e) {
            logger.error(e.getCause().getMessage(), e);
        }
        return new BooleanWrapper(true);
    }
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) RMDeployingNode(org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode) Node(org.objectweb.proactive.core.node.Node) AbstractRMNode(org.ow2.proactive.resourcemanager.rmnode.AbstractRMNode) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 75 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class SchedulerClient method init.

@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
    HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
    SchedulerRestClient restApiClient = new SchedulerRestClient(connectionInfo.getUrl(), new ApacheHttpClient4Engine(client));
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.register(new WildCardTypeReader());
    factory.register(new OctetStreamReader());
    factory.register(new TaskResultReader());
    SchedulerRestClient.registerGzipEncoding(factory);
    setApiClient(restApiClient);
    this.connectionInfo = connectionInfo;
    this.initialized = true;
    renewSession();
}
Also used : WildCardTypeReader(org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader) TaskResultReader(org.ow2.proactive.scheduler.rest.readers.TaskResultReader) OctetStreamReader(org.ow2.proactive.scheduler.rest.readers.OctetStreamReader) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) SchedulerRestClient(org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Aggregations

Test (org.junit.Test)69 ISchedulerClient (org.ow2.proactive.scheduler.rest.ISchedulerClient)36 Client (org.ow2.proactive.resourcemanager.authentication.Client)31 JobId (org.ow2.proactive.scheduler.common.job.JobId)30 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)28 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)25 SimpleJob (functionaltests.jobs.SimpleJob)25 Job (org.ow2.proactive.scheduler.common.job.Job)25 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)18 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)18 ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)18 File (java.io.File)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)11 Node (org.objectweb.proactive.core.node.Node)9 IOException (java.io.IOException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)8 NodeSet (org.ow2.proactive.utils.NodeSet)7