Search in sources :

Example 26 with RMException

use of org.ow2.proactive.resourcemanager.exception.RMException in project scheduling by ow2-proactive.

the class SSHInfrastructureV2 method declareLostAndThrow.

private void declareLostAndThrow(String errMsg, List<String> nodesUrl, ChannelExec chan, ByteArrayOutputStream baos, Exception e) throws RMException {
    String lf = System.lineSeparator();
    StringBuilder sb = new StringBuilder(errMsg);
    sb.append(lf).append(" > Process exit code: ").append(chan.getExitStatus());
    sb.append(lf).append(" > Process output: ").append(lf).append(new String(baos.toByteArray()));
    this.multipleDeclareDeployingNodeLost(nodesUrl, sb.toString());
    throw new RMException(errMsg, e);
}
Also used : Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 27 with RMException

use of org.ow2.proactive.resourcemanager.exception.RMException in project scheduling by ow2-proactive.

the class SSHInfrastructureV2 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
 */
public void startNodeImpl(final HostTracker hostTracker, final int nbNodes, final List<String> depNodeURLs) throws RMException {
    String fs = getTargetOSObj().fs;
    // we set the java security policy file
    ArrayList<String> sb = new ArrayList<>();
    final boolean containsSpace = schedulingPath.contains(" ");
    if (containsSpace) {
        sb.add("-Dproactive.home=\"" + schedulingPath + "\"");
    } else {
        sb.add("-Dproactive.home=" + schedulingPath);
    }
    String securitycmd = CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getCmdLine();
    if (!this.javaOptions.contains(securitycmd)) {
        if (containsSpace) {
            securitycmd += "\"";
        }
        securitycmd += this.schedulingPath + fs + "config" + fs;
        securitycmd += "security.java.policy-client";
        if (containsSpace) {
            securitycmd += "\"";
        }
        sb.add(securitycmd);
    }
    // we set the log4j configuration file
    String log4jcmd = CentralPAPropertyRepository.LOG4J.getCmdLine();
    if (!this.javaOptions.contains(log4jcmd)) {
        // log4j only understands urls
        if (containsSpace) {
            log4jcmd += "\"";
        }
        log4jcmd += "file:";
        if (!this.schedulingPath.startsWith("/")) {
            log4jcmd += "/";
        }
        log4jcmd += this.schedulingPath.replace("\\", "/");
        log4jcmd += "/config/log/node.properties";
        if (containsSpace) {
            log4jcmd += "\"";
        }
        sb.add(log4jcmd);
    }
    // we add extra java/PA configuration
    if (this.javaOptions != null && !this.javaOptions.trim().isEmpty()) {
        sb.add(this.javaOptions.trim());
    }
    CommandLineBuilder clb = super.getDefaultCommandLineBuilder(getTargetOSObj());
    final boolean deployNodesInDetachedMode = PAResourceManagerProperties.RM_NODES_RECOVERY.getValueAsBoolean() || PAResourceManagerProperties.RM_PRESERVE_NODES_ON_SHUTDOWN.getValueAsBoolean();
    if (deployNodesInDetachedMode) {
        // if we do not want to kill the nodes when the RM exits or
        // restarts, then we should launch the nodes in background and
        // ignore the RM termination signal
        clb.setDetached();
    }
    clb.setJavaPath(this.javaPath);
    clb.setRmHome(this.schedulingPath);
    clb.setPaProperties(sb);
    final String nodeName = nodeNameBuilder.generateNodeName(hostTracker);
    clb.setNodeName(nodeName);
    clb.setNumberOfNodes(nbNodes);
    // finally, the credential's value
    String credString;
    try {
        Client currentClient = super.nodeSource.getAdministrator();
        credString = new String(currentClient.getCredentials().getBase64());
    } catch (KeyException e) {
        throw new RMException("Could not get base64 credentials", e);
    }
    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 e) {
        throw new RMException("Cannot build the " + RMNodeStarter.class.getSimpleName() + "'s command line.", e);
    }
    // one escape the command to make it runnable through ssh
    if (cmdLine.contains("\"")) {
        cmdLine = cmdLine.replaceAll("\"", "\\\\\"");
    }
    final String finalCmdLine = cmdLine;
    // The final addDeployingNode() method will initiate a timeout that
    // will declare node as lost and set the description of the failure
    // with a simplistic message, since there is no way to override this
    // mechanism we consider only 90% of timeout to set custom description
    // in case of failure and still allow global timeout
    final int shorterTimeout = Math.round((90 * super.nodeTimeOut) / 100);
    JSch jsch = new JSch();
    final String msg = "deploy on " + hostTracker.getResolvedAddress();
    final List<String> createdNodeNames = RMNodeStarter.getWorkersNodeNames(nodeName, nbNodes);
    depNodeURLs.addAll(addMultipleDeployingNodes(createdNodeNames, obfuscatedCmdLine, msg, super.nodeTimeOut));
    addTimeouts(depNodeURLs);
    Session session;
    try {
        // Create ssh session to the hostname
        session = jsch.getSession(this.sshUsername, hostTracker.getResolvedAddress().getHostName(), this.sshPort);
        if (this.sshPassword == null) {
            jsch.addIdentity(this.sshUsername, this.sshPrivateKey, null, null);
        } else {
            session.setPassword(this.sshPassword);
        }
        session.setConfig(this.sshOptions);
        session.connect(shorterTimeout);
    } catch (JSchException e) {
        multipleDeclareDeployingNodeLost(depNodeURLs, "unable to " + msg + "\n" + getStackTraceAsString(e));
        throw new RMException("unable to " + msg, e);
    }
    SSHInfrastructureV2.logger.info("Executing SSH command: '" + finalCmdLine + "'");
    ScheduledExecutorService deployService = Executors.newSingleThreadScheduledExecutor();
    try {
        // Create ssh channel to run the cmd
        ByteArrayOutputStream baos = new ByteArrayOutputStream(DEFAULT_OUTPUT_BUFFER_LENGTH);
        ChannelExec channel;
        try {
            channel = (ChannelExec) session.openChannel("exec");
            channel.setCommand(finalCmdLine);
            channel.setOutputStream(baos);
            channel.setErrStream(baos);
            channel.connect();
        } catch (JSchException e) {
            multipleDeclareDeployingNodeLost(depNodeURLs, "unable to " + msg + "\n" + getStackTraceAsString(e));
            throw new RMException("unable to " + msg, e);
        }
        final ChannelExec chan = channel;
        Future<Void> deployResult = deployService.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                while (!shutDown.get() && !checkAllNodesAreAcquiredAndDo(createdNodeNames, null, null)) {
                    if (anyTimedOut(depNodeURLs)) {
                        throw new IllegalStateException("The upper infrastructure has issued a timeout");
                    }
                    // processes live completely independently
                    if (!deployNodesInDetachedMode && chan.getExitStatus() != PROCESS_STILL_RUNNING_VALUE) {
                        throw new IllegalStateException("The jvm process of the node has exited prematurely");
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        // we know the cause of this
                        return null;
                    // interruption just exit
                    }
                }
                // Victory
                return null;
            }
        });
        try {
            deployResult.get(shorterTimeout, TimeUnit.MILLISECONDS);
        } catch (ExecutionException e) {
            declareLostAndThrow("Unable to " + msg + " due to " + e.getCause(), depNodeURLs, channel, baos, e);
        } catch (InterruptedException e) {
            deployResult.cancel(true);
            declareLostAndThrow("Unable to " + msg + " due to an interruption", depNodeURLs, channel, baos, e);
        } catch (TimeoutException e) {
            deployResult.cancel(true);
            declareLostAndThrow("Unable to " + msg + " due to timeout", depNodeURLs, channel, baos, e);
        } finally {
            channel.disconnect();
        }
    } finally {
        removeTimeouts(depNodeURLs);
        session.disconnect();
        deployService.shutdownNow();
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ArrayList(java.util.ArrayList) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) CommandLineBuilder(org.ow2.proactive.resourcemanager.utils.CommandLineBuilder) JSch(com.jcraft.jsch.JSch) RMException(org.ow2.proactive.resourcemanager.exception.RMException) Client(org.ow2.proactive.resourcemanager.authentication.Client) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyException(java.security.KeyException) ChannelExec(com.jcraft.jsch.ChannelExec) KeyException(java.security.KeyException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) RMException(org.ow2.proactive.resourcemanager.exception.RMException) ExecutionException(java.util.concurrent.ExecutionException) JSchException(com.jcraft.jsch.JSchException) Session(com.jcraft.jsch.Session)

Example 28 with RMException

use of org.ow2.proactive.resourcemanager.exception.RMException in project scheduling by ow2-proactive.

the class SchedulerRMProxyFactory method connectToRM.

public RMProxyUserInterface connectToRM(Credentials credentials) throws ActiveObjectCreationException, NodeException, RMException, KeyException, LoginException {
    RMProxyUserInterface rm = PAActiveObject.newActive(RMProxyUserInterface.class, new Object[] {});
    rm.init(PortalConfiguration.RM_URL.getValueAsString(), credentials);
    return rm;
}
Also used : RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)

Example 29 with RMException

use of org.ow2.proactive.resourcemanager.exception.RMException in project scheduling by ow2-proactive.

the class SchedulerRMProxyFactory method connectToRM.

public RMProxyUserInterface connectToRM(CredData credData) throws ActiveObjectCreationException, NodeException, RMException, KeyException, LoginException {
    RMProxyUserInterface rm = PAActiveObject.newActive(RMProxyUserInterface.class, new Object[] {});
    rm.init(PortalConfiguration.RM_URL.getValueAsString(), credData);
    return rm;
}
Also used : RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)

Example 30 with RMException

use of org.ow2.proactive.resourcemanager.exception.RMException in project scheduling by ow2-proactive.

the class RMFactory method startLocal.

/**
 * Creates and starts a Resource manager on the local host using the given initializer to configure it.
 * Only one RM can be started by JVM.
 *
 * @param initializer Use to configure the Resource Manager before starting it.
 * 		This parameter can be null, if so the Resource Manager will try to start on the JVM properties and
 * 		the "pa.rm.home" property MUST be set to the root of the RM directory.
 * @return a RM authentication that allow you to administer the RM or get its connection URL.
 *
 * @throws NodeException If the RM's node can't be created
 * @throws ActiveObjectCreationException If RMCore cannot be created
 * @throws AlreadyBoundException if a node with the same RMNode's name is already exist.
 * @throws IOException If node and RMCore fails.
 * @throws RMException if the connection to the authentication interface fails.
 */
public static RMAuthentication startLocal(RMInitializer initializer) throws Exception {
    if (rmcore == null) {
        if (initializer != null) {
            // configure application
            configure(initializer);
        }
        configureLog4j();
        Node nodeRM = NodeFactory.createLocalNode(PAResourceManagerProperties.RM_NODE_NAME.getValueAsString(), false, null, null);
        String RMCoreName = RMConstants.NAME_ACTIVE_OBJECT_RMCORE;
        rmcore = (RMCore) // the class to deploy
        PAActiveObject.newActive(// the class to deploy
        RMCore.class.getName(), new Object[] { RMCoreName, nodeRM }, nodeRM);
        logger.debug("New RM core started locally");
        return RMConnection.waitAndJoin(null);
    } else {
        throw new RMException("RM Core already running locally");
    }
}
Also used : RMCore(org.ow2.proactive.resourcemanager.core.RMCore) Node(org.objectweb.proactive.core.node.Node) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Aggregations

RMException (org.ow2.proactive.resourcemanager.exception.RMException)19 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)9 IOException (java.io.IOException)8 Node (org.objectweb.proactive.core.node.Node)8 KeyException (java.security.KeyException)6 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)6 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)5 CredData (org.ow2.proactive.authentication.crypto.CredData)4 UnknownHostException (java.net.UnknownHostException)3 Test (org.junit.Test)3 Credentials (org.ow2.proactive.authentication.crypto.Credentials)3 AbstractRMNode (org.ow2.proactive.resourcemanager.rmnode.AbstractRMNode)3 CommandLineBuilder (org.ow2.proactive.resourcemanager.utils.CommandLineBuilder)3 Permission (java.security.Permission)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)2 RMProxyUserInterface (org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)2