Search in sources :

Example 56 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class StartNodeCallableImpl method call.

/** {@inheritDoc} */
@Override
public ClusterStartNodeResult call() {
    JSch ssh = new JSch();
    Session ses = null;
    try {
        if (spec.key() != null)
            ssh.addIdentity(spec.key().getAbsolutePath());
        ses = ssh.getSession(spec.username(), spec.host(), spec.port());
        if (spec.password() != null)
            ses.setPassword(spec.password());
        ses.setConfig("StrictHostKeyChecking", "no");
        ses.connect(timeout);
        boolean win = isWindows(ses);
        char separator = win ? '\\' : '/';
        spec.fixPaths(separator);
        String igniteHome = spec.igniteHome();
        if (igniteHome == null)
            igniteHome = win ? DFLT_IGNITE_HOME_WIN : DFLT_IGNITE_HOME_LINUX;
        String script = spec.script();
        if (script == null)
            script = DFLT_SCRIPT_LINUX;
        String cfg = spec.configuration();
        if (cfg == null)
            cfg = "";
        String startNodeCmd;
        String scriptOutputFileName = FILE_NAME_DATE_FORMAT.format(new Date()) + '-' + UUID.randomUUID().toString().substring(0, 8) + ".log";
        if (win)
            throw new UnsupportedOperationException("Apache Ignite cannot be auto-started on Windows from IgniteCluster.startNodes(…) API.");
        else {
            // Assume Unix.
            int spaceIdx = script.indexOf(' ');
            String scriptPath = spaceIdx > -1 ? script.substring(0, spaceIdx) : script;
            String scriptArgs = spaceIdx > -1 ? script.substring(spaceIdx + 1) : "";
            String rmtLogArgs = buildRemoteLogArguments(spec.username(), spec.host());
            String tmpDir = env(ses, "$TMPDIR", "/tmp/");
            String scriptOutputDir = tmpDir + "ignite-startNodes";
            shell(ses, "mkdir " + scriptOutputDir);
            // Mac os don't support ~ in double quotes. Trying get home path from remote system.
            if (igniteHome.startsWith("~")) {
                String homeDir = env(ses, "$HOME", "~");
                igniteHome = igniteHome.replaceFirst("~", homeDir);
            }
            startNodeCmd = new SB().a("nohup ").a("\"").a(igniteHome).a('/').a(scriptPath).a("\"").a(" ").a(scriptArgs).a(!cfg.isEmpty() ? " \"" : "").a(cfg).a(!cfg.isEmpty() ? "\"" : "").a(rmtLogArgs).a(" > ").a(scriptOutputDir).a("/").a(scriptOutputFileName).a(" 2>& 1 &").toString();
        }
        info("Starting remote node with SSH command: " + startNodeCmd, spec.logger(), log);
        shell(ses, startNodeCmd);
        return new ClusterStartNodeResultImpl(spec.host(), true, null);
    } catch (IgniteInterruptedCheckedException e) {
        return new ClusterStartNodeResultImpl(spec.host(), false, e.getMessage());
    } catch (Exception e) {
        return new ClusterStartNodeResultImpl(spec.host(), false, X.getFullStackTrace(e));
    } finally {
        if (ses != null && ses.isConnected())
            ses.disconnect();
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterStartNodeResultImpl(org.apache.ignite.internal.cluster.ClusterStartNodeResultImpl) JSch(com.jcraft.jsch.JSch) Date(java.util.Date) IOException(java.io.IOException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) JSchException(com.jcraft.jsch.JSchException) Session(com.jcraft.jsch.Session) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 57 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class StartNodeCallableImpl method buildRemoteLogArguments.

/**
     * Builds ignite.sh attributes to set up SSH username and password and log directory for started node.
     *
     * @param username SSH user name.
     * @param host Host.
     * @return {@code ignite.sh} script arguments.
     */
private String buildRemoteLogArguments(String username, String host) {
    assert username != null;
    assert host != null;
    SB sb = new SB();
    sb.a(" -J-D").a(IGNITE_SSH_HOST).a("=\"").a(host).a("\"").a(" -J-D").a(IGNITE_SSH_USER_NAME).a("=\"").a(username).a("\"");
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

SB (org.apache.ignite.internal.util.typedef.internal.SB)57 Map (java.util.Map)8 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)4 IgfsLogger (org.apache.ignite.internal.igfs.common.IgfsLogger)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ObjectName (javax.management.ObjectName)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2