ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [21/22] ignite git commit: Added support for passing env. variables.
Date Fri, 18 Dec 2015 03:42:24 GMT
Added support for passing env. variables.


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

Branch: refs/heads/ignite-gg-10889
Commit: 131a6c98c396484b516d26788802f4f652b4f2a5
Parents: 562c70a
Author: vsisko <vsisko@gridgain.com>
Authored: Fri Dec 18 10:27:14 2015 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Fri Dec 18 10:27:14 2015 +0700

----------------------------------------------------------------------
 .../internal/visor/util/VisorTaskUtils.java     | 39 ++++++++++++++++++--
 1 file changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/131a6c98/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 536e368..15bde25 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
@@ -830,11 +830,12 @@ public class VisorTaskUtils {
      * @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.
+     * @param envVars Optional map with environment variables.
      * @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 {
+        boolean quite, Map<String, String> envVars) throws IOException {
         String quitePar = quite ? "" : "-v";
 
         String cmdFile = new File("bin", U.isWindows() ? "ignite.bat" : "ignite.sh").getPath();
@@ -870,9 +871,9 @@ public class VisorTaskUtils {
                                     entry.getKey(), value.replace('\n', ' ').replace("'",
"\'")));
                     }
 
-                    run.add(openInConsole(envs.toString(), ignite, quitePar, nodeCfg));
+                    run.add(openInConsole(null, envVars, envs.toString(), ignite, quitePar,
nodeCfg));
                 } else
-                    run.add(openInConsole(ignite, quitePar, nodeCfg));
+                    run.add(openInConsole(null, envVars, ignite, quitePar, nodeCfg));
             }
 
             return run;
@@ -902,9 +903,22 @@ public class VisorTaskUtils {
      * @param workFolder Work folder for command.
      * @param args A string array containing the program and its arguments.
      * @return Started process.
+     * @throws IOException in case of error.
+     */
+    public static Process openInConsole(@Nullable File workFolder, String... args) throws
IOException {
+        return openInConsole(workFolder, null, args);
+    }
+
+    /**
+     * Run command in separated console.
+     *
+     * @param workFolder Work folder for command.
+     * @param envVars Optional map with environment variables.
+     * @param args A string array containing the program and its arguments.
+     * @return Started process.
      * @throws IOException If failed to start process.
      */
-    public static Process openInConsole(@Nullable File workFolder, String... args)
+    public static Process openInConsole(@Nullable File workFolder, Map<String, String>
envVars, String... args)
         throws IOException {
         String[] commands = args;
 
@@ -925,6 +939,23 @@ public class VisorTaskUtils {
         if (workFolder != null)
             pb.directory(workFolder);
 
+        if (envVars != null) {
+            String sep = U.isWindows() ? ";" : ":";
+
+            Map<String, String> goalVars = pb.environment();
+
+            for (Map.Entry<String, String> var: envVars.entrySet()) {
+                String envVar = goalVars.get(var.getKey());
+
+                if (envVar == null || envVar.isEmpty())
+                    envVar = var.getValue();
+                else
+                    envVar += sep + var.getValue();
+
+                goalVars.put(var.getKey(), envVar);
+            }
+        }
+
         return pb.start();
     }
 


Mime
View raw message