You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/05/21 15:39:27 UTC

[1/2] git commit: [KARAF-636] Support wildcards for instance:start/stop/destroy commands

Repository: karaf
Updated Branches:
  refs/heads/master c8bb82323 -> 5bd09d426


[KARAF-636] Support wildcards for instance:start/stop/destroy commands

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

Branch: refs/heads/master
Commit: e473b226533fd131364c885d381d10740f8a1f33
Parents: c8bb823
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Wed May 21 15:36:13 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Wed May 21 15:36:13 2014 +0200

----------------------------------------------------------------------
 .../karaf/instance/command/DestroyCommand.java  | 18 +++++-
 .../command/InstanceCommandSupport.java         | 27 +++++++++
 .../karaf/instance/command/StartCommand.java    | 64 +++++++++++++-------
 .../karaf/instance/command/StopCommand.java     | 19 +++++-
 4 files changed, 99 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/e473b226/instance/src/main/java/org/apache/karaf/instance/command/DestroyCommand.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/command/DestroyCommand.java b/instance/src/main/java/org/apache/karaf/instance/command/DestroyCommand.java
index fb2964f..f9d0dde 100644
--- a/instance/src/main/java/org/apache/karaf/instance/command/DestroyCommand.java
+++ b/instance/src/main/java/org/apache/karaf/instance/command/DestroyCommand.java
@@ -16,11 +16,15 @@
  */
 package org.apache.karaf.instance.command;
 
+import java.util.List;
+
 import org.apache.karaf.instance.command.completers.InstanceCompleter;
+import org.apache.karaf.instance.core.Instance;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.MultiException;
 
 /**
  * Destroy an existing instance.
@@ -29,12 +33,20 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
 @Service
 public class DestroyCommand extends InstanceCommandSupport
 {
-    @Argument(index = 0, name = "name", description= "The name of the container instance to destroy", required = true, multiValued = false)
+    @Argument(index = 0, name = "name", description= "The name of the container instance to destroy", required = true, multiValued = true)
     @Completion(InstanceCompleter.class)
-    private String instance = null;
+    private List<String> instances = null;
 
     protected Object doExecute() throws Exception {
-        getExistingInstance(instance).destroy();
+        final MultiException exception = new MultiException("Error destroying instance(s)");
+        for (Instance instance : getMatchingInstances(instances)) {
+            try {
+                instance.destroy();
+            } catch (Exception e) {
+                exception.addException(e);
+            }
+        }
+        exception.throwIfExceptions();
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/e473b226/instance/src/main/java/org/apache/karaf/instance/command/InstanceCommandSupport.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/command/InstanceCommandSupport.java b/instance/src/main/java/org/apache/karaf/instance/command/InstanceCommandSupport.java
index 3b0b535..6205dbb 100644
--- a/instance/src/main/java/org/apache/karaf/instance/command/InstanceCommandSupport.java
+++ b/instance/src/main/java/org/apache/karaf/instance/command/InstanceCommandSupport.java
@@ -16,6 +16,10 @@
  */
 package org.apache.karaf.instance.command;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
 import org.apache.karaf.instance.core.Instance;
 import org.apache.karaf.instance.core.InstanceService;
 import org.apache.karaf.shell.api.action.Action;
@@ -42,6 +46,29 @@ public abstract class InstanceCommandSupport implements Action {
         return i;
     }
 
+    protected List<Instance> getMatchingInstances(List<String> patterns) {
+        List<Instance> instances = new ArrayList<>();
+        Instance[] allInstances = instanceService.getInstances();
+        for (Instance instance : allInstances) {
+            if (match(instance.getName(), patterns)) {
+                instances.add(instance);
+            }
+        }
+        if (instances.isEmpty()) {
+            throw new IllegalArgumentException("No matching instances");
+        }
+        return instances;
+    }
+
+    private boolean match(String name, List<String> patterns) {
+        for (String pattern : patterns) {
+            if (name.matches(pattern)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     @Override
     public Object execute() throws Exception {
         return doExecute();

http://git-wip-us.apache.org/repos/asf/karaf/blob/e473b226/instance/src/main/java/org/apache/karaf/instance/command/StartCommand.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/command/StartCommand.java b/instance/src/main/java/org/apache/karaf/instance/command/StartCommand.java
index 8c52d5e..bff2167 100644
--- a/instance/src/main/java/org/apache/karaf/instance/command/StartCommand.java
+++ b/instance/src/main/java/org/apache/karaf/instance/command/StartCommand.java
@@ -16,6 +16,9 @@
  */
 package org.apache.karaf.instance.command;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.karaf.instance.command.completers.InstanceCompleter;
 import org.apache.karaf.instance.core.Instance;
 import org.apache.karaf.shell.api.action.Argument;
@@ -23,6 +26,7 @@ import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.MultiException;
 
 @Command(scope = "instance", name = "start", description = "Start an existing container instance.")
 @Service
@@ -37,38 +41,52 @@ public class StartCommand extends InstanceCommandSupport {
     @Option(name = "-w", aliases = { "--wait"}, description = "Wait for the instance to be fully started", required = false, multiValued = false)
     private boolean wait;
 
-    @Argument(index = 0, name = "name", description = "The name of the container instance", required = true, multiValued = false)
+    @Argument(index = 0, name = "name", description = "The name of the container instance", required = true, multiValued = true)
     @Completion(InstanceCompleter.class)
-    private String instance = null;
+    private List<String> instances = null;
 
     static final String DEBUG_OPTS = " -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005";
     static final String DEFAULT_OPTS = "-server -Xmx512M -Dcom.sun.management.jmxremote";
 
     protected Object doExecute() throws Exception {
-        Instance child = getExistingInstance(instance);
-        String opts = javaOpts;
-        if (opts == null) {
-            opts = child.getJavaOpts();
-        }
-        if (opts == null) {
-            opts = DEFAULT_OPTS;
-        }
-        if (debug) {
-            opts += DEBUG_OPTS;
+        MultiException exception = new MultiException("Error starting instance(s)");
+        List<Instance> toWaitFor = new ArrayList<>();
+        for (Instance instance : getMatchingInstances(instances)) {
+            try {
+                String opts = javaOpts;
+                if (opts == null) {
+                    opts = instance.getJavaOpts();
+                }
+                if (opts == null) {
+                    opts = DEFAULT_OPTS;
+                }
+                if (debug) {
+                    opts += DEBUG_OPTS;
+                }
+                if (wait) {
+                    String state = instance.getState();
+                    if (Instance.STOPPED.equals(state)) {
+                        instance.start(opts);
+                        toWaitFor.add(instance);
+                    }
+                } else {
+                    instance.start(opts);
+                }
+            } catch (Exception e) {
+                exception.addException(e);
+            }
         }
-        if (wait) {
-            String state = child.getState();
-            if (Instance.STOPPED.equals(state)) {
-                child.start(opts);
+        exception.throwIfExceptions();
+        while (true) {
+            boolean allStarted = true;
+            for (Instance child : toWaitFor) {
+                allStarted &= Instance.STARTED.equals(child.getState());
             }
-            if (!Instance.STARTED.equals(state)) {
-                do {
-                    Thread.sleep(500);
-                    state = child.getState();
-                } while (Instance.STARTING.equals(state));
+            if (allStarted) {
+                break;
+            } else {
+                Thread.sleep(500);
             }
-        } else {
-            child.start(opts);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/e473b226/instance/src/main/java/org/apache/karaf/instance/command/StopCommand.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/command/StopCommand.java b/instance/src/main/java/org/apache/karaf/instance/command/StopCommand.java
index 6c8de10..b3ec1e6 100644
--- a/instance/src/main/java/org/apache/karaf/instance/command/StopCommand.java
+++ b/instance/src/main/java/org/apache/karaf/instance/command/StopCommand.java
@@ -16,22 +16,35 @@
  */
 package org.apache.karaf.instance.command;
 
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
 import org.apache.karaf.instance.command.completers.InstanceCompleter;
+import org.apache.karaf.instance.core.Instance;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.MultiException;
 
 @Command(scope = "instance", name = "stop", description = "Stop an existing container instance.")
 @Service
 public class StopCommand extends InstanceCommandSupport {
 
-    @Argument(index = 0, name = "name", description = "The name of the container instance", required = true, multiValued = false)
+    @Argument(index = 0, name = "name", description = "The name of the container instance", required = true, multiValued = true)
     @Completion(InstanceCompleter.class)
-    private String instance = null;
+    private List<String> instances = null;
 
     protected Object doExecute() throws Exception {
-        getExistingInstance(instance).stop();
+        final MultiException exception = new MultiException("Error stopping instance(s)");
+        for (Instance instance : getMatchingInstances(instances)) {
+            try {
+                instance.stop();
+            } catch (Exception e) {
+                exception.addException(e);
+            }
+        }
+        exception.throwIfExceptions();
         return null;
     }
 


[2/2] git commit: [KARAF-2994] Use the current distribution configuration for default boot features when creating children

Posted by gn...@apache.org.
[KARAF-2994] Use the current distribution configuration for default boot features when creating children

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5bd09d42
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5bd09d42
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5bd09d42

Branch: refs/heads/master
Commit: 5bd09d426f326db5699a6f479f21055f2e32e361
Parents: e473b22
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Wed May 21 15:39:12 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Wed May 21 15:39:12 2014 +0200

----------------------------------------------------------------------
 .../karaf/instance/command/CreateCommand.java   | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/5bd09d42/instance/src/main/java/org/apache/karaf/instance/command/CreateCommand.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/command/CreateCommand.java b/instance/src/main/java/org/apache/karaf/instance/command/CreateCommand.java
index 0dcc3ac..3ad54ad 100644
--- a/instance/src/main/java/org/apache/karaf/instance/command/CreateCommand.java
+++ b/instance/src/main/java/org/apache/karaf/instance/command/CreateCommand.java
@@ -16,8 +16,12 @@
  */
 package org.apache.karaf.instance.command;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import org.apache.felix.utils.properties.Properties;
 import org.apache.karaf.features.command.completers.AllFeatureCompleter;
 import org.apache.karaf.features.command.completers.InstalledRepoUriCompleter;
 import org.apache.karaf.instance.core.InstanceSettings;
@@ -34,6 +38,12 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
 @Service
 public class CreateCommand extends InstanceCommandSupport
 {
+
+    public static final String FEATURES_SERVICE_CONFIG_FILE = "org.apache.karaf.features.cfg";
+
+    @Option(name = "-b", aliases = "--bare", description = "Do not use add default features")
+    boolean bare;
+
     @Option(name = "-s", aliases = {"--ssh-port"}, description = "Port number for remote secure shell connection", required = false, multiValued = false)
     int sshPort = 0;
 
@@ -66,6 +76,21 @@ public class CreateCommand extends InstanceCommandSupport
     String instance = null;
 
     protected Object doExecute() throws Exception {
+        if (!bare) {
+            Properties configuration = new Properties();
+            File configFile = new File(System.getProperty("karaf.etc"), FEATURES_SERVICE_CONFIG_FILE);
+            configuration.load(configFile);
+            String featuresRepositories = configuration.getProperty("featuresRepositories", "");
+            String featuresBoot = configuration.getProperty("featuresBoot", "");
+            if (featureURLs == null) {
+                featureURLs = new ArrayList<>();
+            }
+            featureURLs.addAll(Arrays.asList(featuresRepositories.split(",")));
+            if (features == null) {
+                features = new ArrayList<>();
+            }
+            features.addAll(Arrays.asList(featuresBoot.split(",")));
+        }
         InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, featureURLs, features);
         getInstanceService().createInstance(instance, settings, verbose);
         return null;