You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/12/16 18:12:39 UTC

ignite git commit: Added function to start local node via ignite.sh

Repository: ignite
Updated Branches:
  refs/heads/ignite-gg-10889 [created] 3b23b71fb


Added function to start local node via ignite.sh


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3b23b71f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3b23b71f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3b23b71f

Branch: refs/heads/ignite-gg-10889
Commit: 3b23b71fb6b09f0085fb5a44ce2b12ed58f64f09
Parents: d8c8214
Author: AKuznetsov <ak...@gridgain.com>
Authored: Thu Dec 17 00:11:04 2015 +0700
Committer: AKuznetsov <ak...@gridgain.com>
Committed: Thu Dec 17 00:11:04 2015 +0700

----------------------------------------------------------------------
 .../internal/visor/util/VisorTaskUtils.java     | 65 +++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3b23b71f/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
index 579f50c..536e368 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/util/VisorTaskUtils.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.visor.util;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileFilter;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.net.InetAddress;
@@ -823,6 +824,68 @@ public class VisorTaskUtils {
     }
 
     /**
+     * Start local node in terminal.
+     *
+     * @param log Logger.
+     * @param cfgPath Path to node configuration to start with.
+     * @param nodesToStart Number of nodes to start.
+     * @param quite If {@code true} then start node in quiet mode.
+     * @return List of started processes.
+     * @throws IOException If failed to start.
+     */
+    public static List<Process> startLocalNode(@Nullable IgniteLogger log, String cfgPath, int nodesToStart,
+        boolean quite) throws IOException {
+        String quitePar = quite ? "" : "-v";
+
+        String cmdFile = new File("bin", U.isWindows() ? "ignite.bat" : "ignite.sh").getPath();
+
+        File cmdFilePath = U.resolveIgnitePath(cmdFile);
+
+        if (cmdFilePath == null || !cmdFilePath.exists())
+            throw new FileNotFoundException(String.format("File not found: %s", cmdFile));
+
+        String ignite = cmdFilePath.getCanonicalPath();
+
+        File nodesCfgPath = U.resolveIgnitePath(cfgPath);
+
+        if (nodesCfgPath == null || !nodesCfgPath.exists())
+            throw new FileNotFoundException(String.format("File not found: %s", cfgPath));
+
+        String nodeCfg = nodesCfgPath.getCanonicalPath();
+
+        log(log, String.format("Starting %s local %s with '%s' config", nodesToStart, nodesToStart > 1 ? "nodes" : "node", nodeCfg));
+
+        List<Process> run = new ArrayList<>();
+
+        try {
+            for (int i = 0; i < nodesToStart; i++) {
+                if (U.isMacOs()) {
+                    StringBuilder envs = new StringBuilder();
+
+                    for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
+                        String value = entry.getValue();
+
+                        if (value.indexOf(';') < 0 && value.indexOf('\'') < 0)
+                            envs.append(String.format("export %s='%s'; ",
+                                    entry.getKey(), value.replace('\n', ' ').replace("'", "\'")));
+                    }
+
+                    run.add(openInConsole(envs.toString(), ignite, quitePar, nodeCfg));
+                } else
+                    run.add(openInConsole(ignite, quitePar, nodeCfg));
+            }
+
+            return run;
+        }
+        catch (Exception e) {
+            for (Process proc: run)
+                proc.destroy();
+
+            throw e;
+        }
+    }
+
+    /**
      * Run command in separated console.
      *
      * @param args A string array containing the program and its arguments.
@@ -904,4 +967,4 @@ public class VisorTaskUtils {
 
         return bos.toByteArray();
     }
-}
\ No newline at end of file
+}