You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/10 18:56:57 UTC

[1/5] camel git commit: CAMEL-8044: Camel commands should be more reusable for remote JVMs

Repository: camel
Updated Branches:
  refs/heads/master d86c5c427 -> e4009f494


CAMEL-8044: Camel commands should be more reusable for remote JVMs


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

Branch: refs/heads/master
Commit: 288ea67664f9b7e0df93a36bfca124e871bb0cee
Parents: d86c5c4
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 18:21:31 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 18:21:31 2014 +0100

----------------------------------------------------------------------
 .../camel/commands/AbstractCamelController.java | 40 +++++++------
 .../apache/camel/commands/CamelController.java  |  5 +-
 .../camel/commands/EndpointExplainCommand.java  | 25 ++++-----
 .../camel/commands/EndpointListCommand.java     | 59 +++++++-------------
 4 files changed, 56 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/288ea676/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
index c6ae955..7837d51 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
@@ -34,6 +34,8 @@ import javax.xml.bind.JAXBException;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.StatefulService;
 import org.apache.camel.catalog.CamelComponentCatalog;
 import org.apache.camel.catalog.DefaultCamelComponentCatalog;
 import org.apache.camel.commands.internal.RegexUtil;
@@ -251,8 +253,8 @@ public abstract class AbstractCamelController implements CamelController {
         return xml;
     }
 
-    public List<Endpoint> getEndpoints(String camelContextName) {
-        List<Endpoint> answer = new ArrayList<Endpoint>();
+    public List<Map<String, String>> getEndpoints(String camelContextName) {
+        List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
 
         if (camelContextName != null) {
             CamelContext context = this.getCamelContext(camelContextName);
@@ -265,21 +267,13 @@ public abstract class AbstractCamelController implements CamelController {
                         return o1.getEndpointKey().compareTo(o2.getEndpointKey());
                     }
                 });
-                answer.addAll(endpoints);
-            }
-        } else {
-            // already sorted by camel context
-            List<CamelContext> camelContexts = this.getCamelContexts();
-            for (CamelContext camelContext : camelContexts) {
-                List<Endpoint> endpoints = new ArrayList<Endpoint>(camelContext.getEndpoints());
-                // sort routes
-                Collections.sort(endpoints, new Comparator<Endpoint>() {
-                    @Override
-                    public int compare(Endpoint o1, Endpoint o2) {
-                        return o1.getEndpointKey().compareTo(o2.getEndpointKey());
-                    }
-                });
-                answer.addAll(endpoints);
+                for (Endpoint endpoint : endpoints) {
+                    Map<String, String> row = new LinkedHashMap<String, String>();
+                    row.put("camelContextName", context.getName());
+                    row.put("uri", endpoint.getEndpointUri());
+                    row.put("state", getEndpointState(endpoint));
+                    answer.add(row);
+                }
             }
         }
         return answer;
@@ -490,4 +484,16 @@ public abstract class AbstractCamelController implements CamelController {
 
         return answer;
     }
+
+    private static String getEndpointState(Endpoint endpoint) {
+        // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
+        if (endpoint instanceof StatefulService) {
+            ServiceStatus status = ((StatefulService) endpoint).getStatus();
+            return status.name();
+        }
+
+        // assume started if not a ServiceSupport instance
+        return ServiceStatus.Started.name();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/288ea676/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
index 8eca54e..f6e150e 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
@@ -23,7 +23,6 @@ import java.util.Set;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
-import org.apache.camel.spi.RestRegistry;
 
 /**
  * CamelController interface defines the expected behaviors to manipulate Camel resources (context, route, etc).
@@ -125,9 +124,9 @@ public interface CamelController {
      * Return the endpoints
      *
      * @param camelContextName the Camel context.
-     * @return the endpoints
+     * @return a list of key/value pairs with endpoint information
      */
-    List<Endpoint> getEndpoints(String camelContextName);
+    List<Map<String, String>> getEndpoints(String camelContextName);
 
     /**
      * Return the definition of the REST services as XML for the given Camel context.

http://git-wip-us.apache.org/repos/asf/camel/blob/288ea676/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
index cb65cce..8ff4368 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
@@ -23,7 +23,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.camel.Endpoint;
+import org.apache.camel.CamelContext;
 import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.JsonSchemaHelper;
 import org.apache.camel.util.URISupport;
@@ -31,44 +31,43 @@ import org.apache.camel.util.URISupport;
 /**
  * Explain the Camel endpoints available in the JVM.
  */
-public class EndpointExplainCommand extends AbstractCamelCommand {
+public class EndpointExplainCommand extends AbstractContextCommand {
 
-    private String name;
     private boolean verbose;
     private String filter;
 
     public EndpointExplainCommand(String name, boolean verbose, String filter) {
-        this.name = name;
+        super(name);
         this.verbose = verbose;
         this.filter = filter;
     }
 
     @Override
-    public Object execute(CamelController camelController, PrintStream out, PrintStream err) throws Exception {
-        List<Endpoint> endpoints = camelController.getEndpoints(name);
+    protected Object performContextCommand(CamelController camelController, CamelContext camelContext, PrintStream out, PrintStream err) throws Exception {
+        List<Map<String, String>> endpoints = camelController.getEndpoints(context);
         if (endpoints == null || endpoints.isEmpty()) {
             return null;
         }
 
         // filter endpoints
         if (filter != null) {
-            Iterator<Endpoint> it = endpoints.iterator();
+            Iterator<Map<String, String>> it = endpoints.iterator();
             while (it.hasNext()) {
-                Endpoint endpoint = it.next();
-                if (!EndpointHelper.matchPattern(endpoint.getEndpointUri(), filter)) {
+                Map<String, String> row = it.next();
+                if (!EndpointHelper.matchPattern(row.get("uri"), filter)) {
                     // did not match
                     it.remove();
                 }
             }
         }
 
-        for (Endpoint endpoint : endpoints) {
-            String json = camelController.explainEndpointAsJSon(endpoint.getCamelContext().getName(), endpoint.getEndpointUri(), verbose);
+        for (Map<String, String> row : endpoints) {
+            String json = camelController.explainEndpointAsJSon(context, row.get("uri"), verbose);
 
-            out.println("Context:\t" + endpoint.getCamelContext().getName());
+            out.println("Context:\t" + context);
 
             // sanitize and mask uri so we dont see passwords
-            String uri = URISupport.sanitizeUri(endpoint.getEndpointUri());
+            String uri = URISupport.sanitizeUri(row.get("uri"));
             String header = "Uri:            " + uri;
             out.println(header);
             for (int i = 0; i < header.length(); i++) {

http://git-wip-us.apache.org/repos/asf/camel/blob/288ea676/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointListCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointListCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointListCommand.java
index e68cae6..9c3e88d 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointListCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointListCommand.java
@@ -24,9 +24,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.camel.Endpoint;
-import org.apache.camel.ServiceStatus;
-import org.apache.camel.StatefulService;
+import org.apache.camel.CamelContext;
 import org.apache.camel.util.JsonSchemaHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.URISupport;
@@ -34,9 +32,8 @@ import org.apache.camel.util.URISupport;
 /**
  * List the Camel endpoints available in the JVM.
  */
-public class EndpointListCommand extends AbstractCamelCommand {
+public class EndpointListCommand extends AbstractContextCommand {
 
-    private static final String CONTEXT_COLUMN_LABEL = "Context";
     private static final String URI_COLUMN_LABEL = "Uri";
     private static final String STATUS_COLUMN_LABEL = "Status";
 
@@ -50,44 +47,42 @@ public class EndpointListCommand extends AbstractCamelCommand {
     private static final int MAX_COLUMN_WIDTH = 120;
     private static final int MIN_COLUMN_WIDTH = 12;
 
-    String name;
     boolean decode = true;
     boolean verbose;
     boolean explain;
 
-    public EndpointListCommand(String name, boolean decode, boolean verbose, boolean explain) {
-        this.name = name;
+    public EndpointListCommand(String context, boolean decode, boolean verbose, boolean explain) {
+        super(context);
         this.decode = decode;
         this.verbose = verbose;
         this.explain = explain;
     }
 
     @Override
-    public Object execute(CamelController camelController, PrintStream out, PrintStream err) throws Exception {
-        List<Endpoint> endpoints = camelController.getEndpoints(name);
+    protected Object performContextCommand(CamelController camelController, CamelContext camelContext, PrintStream out, PrintStream err) throws Exception {
+        List<Map<String, String>> endpoints = camelController.getEndpoints(context);
 
         final Map<String, Integer> columnWidths = computeColumnWidths(endpoints);
         final String headerFormat = buildFormatString(columnWidths, true);
         final String rowFormat = buildFormatString(columnWidths, false);
 
         if (endpoints.size() > 0) {
-            out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, URI_COLUMN_LABEL, STATUS_COLUMN_LABEL));
-            out.println(String.format(headerFormat, "-------", "---", "------"));
-            for (final Endpoint endpoint : endpoints) {
-                String contextId = endpoint.getCamelContext().getName();
-                String uri = endpoint.getEndpointUri();
+            out.println(String.format(headerFormat, URI_COLUMN_LABEL, STATUS_COLUMN_LABEL));
+            out.println(String.format(headerFormat, "---", "------"));
+            for (Map<String, String> row : endpoints) {
+                String uri = row.get("uri");
                 if (decode) {
                     // decode uri so its more human readable
                     uri = URLDecoder.decode(uri, "UTF-8");
                 }
                 // sanitize and mask uri so we dont see passwords
                 uri = URISupport.sanitizeUri(uri);
-                String state = getEndpointState(endpoint);
-                out.println(String.format(rowFormat, contextId, uri, state));
+                String state = row.get("state");
+                out.println(String.format(rowFormat, uri, state));
 
                 if (explain) {
                     boolean first = true;
-                    String json = camelController.explainEndpointAsJSon(endpoint.getCamelContext().getName(), endpoint.getEndpointUri(), verbose);
+                    String json = camelController.explainEndpointAsJSon(context, row.get("uri"), verbose);
                     // use a basic json parser
                     List<Map<String, String>> options = JsonSchemaHelper.parseJsonSchema("properties", json, true);
 
@@ -148,19 +143,17 @@ public class EndpointListCommand extends AbstractCamelCommand {
         return null;
     }
 
-    private Map<String, Integer> computeColumnWidths(final Iterable<Endpoint> endpoints) throws Exception {
+    private Map<String, Integer> computeColumnWidths(final Iterable<Map<String, String>> endpoints) throws Exception {
         if (endpoints == null) {
             throw new IllegalArgumentException("Unable to determine column widths from null Iterable<Endpoint>");
         } else {
-            int maxContextLen = 0;
             int maxUriLen = 0;
             int maxStatusLen = 0;
 
-            for (final Endpoint endpoint : endpoints) {
-                final String name = endpoint.getCamelContext().getName();
-                maxContextLen = java.lang.Math.max(maxContextLen, name == null ? 0 : name.length());
+            for (Map<String, String> row : endpoints) {
+                final String name = row.get("camelContextName");
 
-                String uri = endpoint.getEndpointUri();
+                String uri = row.get("uri");
                 if (decode) {
                     // decode uri so its more human readable
                     uri = URLDecoder.decode(uri, "UTF-8");
@@ -170,12 +163,11 @@ public class EndpointListCommand extends AbstractCamelCommand {
 
                 maxUriLen = java.lang.Math.max(maxUriLen, uri == null ? 0 : uri.length());
 
-                final String status = getEndpointState(endpoint);
+                final String status = row.get("state");
                 maxStatusLen = java.lang.Math.max(maxStatusLen, status == null ? 0 : status.length());
             }
 
-            final Map<String, Integer> retval = new Hashtable<String, Integer>(3);
-            retval.put(CONTEXT_COLUMN_LABEL, maxContextLen);
+            final Map<String, Integer> retval = new Hashtable<String, Integer>();
             retval.put(URI_COLUMN_LABEL, maxUriLen);
             retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
 
@@ -197,15 +189,12 @@ public class EndpointListCommand extends AbstractCamelCommand {
         }
         columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
 
-        int contextLen = java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + columnWidthIncrement, getMaxColumnWidth());
         int uriLen = java.lang.Math.min(columnWidths.get(URI_COLUMN_LABEL) + columnWidthIncrement, getMaxColumnWidth());
         int statusLen = java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + columnWidthIncrement, getMaxColumnWidth());
-        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
         uriLen = Math.max(MIN_COLUMN_WIDTH, uriLen);
         // last row does not have min width
 
         final StringBuilder retval = new StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
-        retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append(' ');
         retval.append(fieldPreamble).append("%-").append(uriLen).append('.').append(uriLen).append('s').append(fieldPostamble).append(' ');
         retval.append(fieldPreamble).append("%-").append(statusLen).append('.').append(statusLen).append('s').append(fieldPostamble).append(' ');
 
@@ -220,14 +209,4 @@ public class EndpointListCommand extends AbstractCamelCommand {
         }
     }
 
-    private static String getEndpointState(Endpoint endpoint) {
-        // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
-        if (endpoint instanceof StatefulService) {
-            ServiceStatus status = ((StatefulService) endpoint).getStatus();
-            return status.name();
-        }
-
-        // assume started if not a ServiceSupport instance
-        return ServiceStatus.Started.name();
-    }
 }


[5/5] camel git commit: CAMEL-8044: Camel commands should be more reusable for remote JVMs

Posted by da...@apache.org.
CAMEL-8044: Camel commands should be more reusable for remote JVMs


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

Branch: refs/heads/master
Commit: e4009f49419a7685da59cd40c2fb771e2ade1012
Parents: 453e405
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 18:55:45 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 18:56:48 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/commands/AbstractCamelController.java  | 4 ++--
 .../java/org/apache/camel/commands/EndpointExplainCommand.java   | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e4009f49/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
index 9480662..8c90cca 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
@@ -116,7 +116,7 @@ public abstract class AbstractCamelController implements CamelController {
         return answer;
     }
 
-    public void resetRouteStats(String camelContextName) throws Exception{
+    public void resetRouteStats(String camelContextName) throws Exception {
         CamelContext context = this.getCamelContext(camelContextName);
         if (context == null) {
             return;
@@ -441,7 +441,7 @@ public abstract class AbstractCamelController implements CamelController {
         for (String label : labels) {
             List<Map<String, String>> components = listComponentsCatalog(label);
             if (!components.isEmpty()) {
-                Set<String> names = new LinkedHashSet<>();
+                Set<String> names = new LinkedHashSet<String>();
                 for (Map<String, String> info : components) {
                     String name = info.get("name");
                     if (name != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e4009f49/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
index 8ff4368..dcf8e4c 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/EndpointExplainCommand.java
@@ -63,6 +63,9 @@ public class EndpointExplainCommand extends AbstractContextCommand {
 
         for (Map<String, String> row : endpoints) {
             String json = camelController.explainEndpointAsJSon(context, row.get("uri"), verbose);
+            if (json == null) {
+                continue;
+            }
 
             out.println("Context:\t" + context);
 


[3/5] camel git commit: CAMEL-8044: Camel commands should be more reusable for remote JVMs

Posted by da...@apache.org.
CAMEL-8044: Camel commands should be more reusable for remote JVMs


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

Branch: refs/heads/master
Commit: 8048c6cec1a44bfed21ada3a8d21d93dbcdec75e
Parents: b33acc3
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 18:38:45 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 18:38:45 2014 +0100

----------------------------------------------------------------------
 .../camel/commands/AbstractCamelController.java | 41 ++++++++++++++-----
 .../camel/commands/AbstractRouteCommand.java    | 43 ++++++--------------
 .../apache/camel/commands/CamelController.java  |  9 ++--
 .../apache/camel/commands/RouteListCommand.java | 25 +++++-------
 .../commands/completers/RouteCompleter.java     |  8 ++--
 5 files changed, 62 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8048c6ce/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
index eaf42c5..9480662 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
@@ -62,19 +62,23 @@ public abstract class AbstractCamelController implements CamelController {
         return null;
     }
 
-    public List<Route> getRoutes(String camelContextName) throws Exception {
+    public List<Map<String, String>> getRoutes(String camelContextName) throws Exception {
         return getRoutes(camelContextName, null);
     }
 
-    public List<Route> getRoutes(String camelContextName, String filter) throws Exception {
-        List<Route> routes = new ArrayList<Route>();
+    public List<Map<String, String>> getRoutes(String camelContextName, String filter) throws Exception {
+        List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
 
         if (camelContextName != null) {
             CamelContext context = this.getCamelContext(camelContextName);
             if (context != null) {
                 for (Route route : context.getRoutes()) {
                     if (filter == null || route.getId().matches(filter)) {
-                        routes.add(route);
+                        Map<String, String> row = new LinkedHashMap<String, String>();
+                        row.put("camelContextName", context.getName());
+                        row.put("routeId", route.getId());
+                        row.put("state", getRouteState(route));
+                        answer.add(row);
                     }
                 }
             }
@@ -83,29 +87,33 @@ public abstract class AbstractCamelController implements CamelController {
             for (CamelContext camelContext : camelContexts) {
                 for (Route route : camelContext.getRoutes()) {
                     if (filter == null || route.getId().matches(filter)) {
-                        routes.add(route);
+                        Map<String, String> row = new LinkedHashMap<String, String>();
+                        row.put("camelContextName", camelContext.getName());
+                        row.put("routeId", route.getId());
+                        row.put("state", getRouteState(route));
+                        answer.add(row);
                     }
                 }
             }
         }
 
         // sort the list
-        Collections.sort(routes, new Comparator<Route>() {
+        Collections.sort(answer, new Comparator<Map<String, String>>() {
             @Override
-            public int compare(Route o1, Route o2) {
+            public int compare(Map<String, String> o1, Map<String, String> o2) {
                 // group by camel context first, then by route name
-                String c1 = o1.getRouteContext().getCamelContext().getName();
-                String c2 = o2.getRouteContext().getCamelContext().getName();
+                String c1 = o1.get("camelContextName");
+                String c2 = o2.get("camelContextName");
 
                 int answer = c1.compareTo(c2);
                 if (answer == 0) {
                     // okay from same camel context, then sort by route id
-                    answer = o1.getId().compareTo(o2.getId());
+                    answer = o1.get("routeId").compareTo(o2.get("routeId"));
                 }
                 return answer;
             }
         });
-        return routes;
+        return answer;
     }
 
     public void resetRouteStats(String camelContextName) throws Exception{
@@ -458,4 +466,15 @@ public abstract class AbstractCamelController implements CamelController {
         return ServiceStatus.Started.name();
     }
 
+    private static String getRouteState(Route route) {
+        // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
+        if (route instanceof StatefulService) {
+            ServiceStatus status = ((StatefulService) route).getStatus();
+            return status.name();
+        }
+
+        // assume started if not a ServiceSupport instance
+        return ServiceStatus.Started.name();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8048c6ce/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
index 81fd2a6..74611e8 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
@@ -20,13 +20,10 @@ import java.io.PrintStream;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Route;
 import org.apache.camel.commands.internal.RegexUtil;
 
-import static org.apache.camel.util.CamelContextHelper.getRouteStartupOrder;
-
 /**
  * Abstract command for working with a one ore more routes.
  */
@@ -45,7 +42,7 @@ public abstract class AbstractRouteCommand extends AbstractCamelCommand {
     }
 
     public Object execute(CamelController camelController, PrintStream out, PrintStream err) throws Exception {
-        List<Route> camelRoutes = camelController.getRoutes(context, RegexUtil.wildcardAsRegex(route));
+        List<Map<String, String>> camelRoutes = camelController.getRoutes(context, RegexUtil.wildcardAsRegex(route));
         if (camelRoutes == null || camelRoutes.isEmpty()) {
             err.println("Camel routes using " + route + " not found.");
             return null;
@@ -53,16 +50,10 @@ public abstract class AbstractRouteCommand extends AbstractCamelCommand {
         // we want the routes sorted
         Collections.sort(camelRoutes, new RouteComparator());
 
-        for (Route camelRoute : camelRoutes) {
-            CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-            // Setting thread context classloader to the bundle classloader to enable legacy code that relies on it
-            ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
-            Thread.currentThread().setContextClassLoader(camelContext.getApplicationContextClassLoader());
-            try {
-                executeOnRoute(camelController, camelContext.getName(), camelRoute.getId(), out, err);
-            } finally {
-                Thread.currentThread().setContextClassLoader(oldClassloader);
-            }
+        for (Map<String, String> row : camelRoutes) {
+            String camelContextName = row.get("camelContextName");
+            String routeId = row.get("routeId");
+            executeOnRoute(camelController, camelContextName, routeId, out, err);
         }
 
         return null;
@@ -73,26 +64,18 @@ public abstract class AbstractRouteCommand extends AbstractCamelCommand {
     /**
      * To sort the routes.
      */
-    private static final class RouteComparator implements Comparator<Route> {
+    private static final class RouteComparator implements Comparator<Map<String, String>> {
 
         @Override
-        public int compare(Route route1, Route route2) {
+        public int compare(Map<String, String> route1, Map<String, String> route2) {
             // sort by camel context first
-            CamelContext camel1 = route1.getRouteContext().getCamelContext();
-            CamelContext camel2 = route2.getRouteContext().getCamelContext();
+            String camel1 = route1.get("camelContextName");
+            String camel2 = route2.get("camelContextName");
 
-            if (camel1.getName().equals(camel2.getName())) {
-                // and then accordingly to startup order
-                Integer order1 = getRouteStartupOrder(camel1, route1.getId());
-                Integer order2 = getRouteStartupOrder(camel2, route2.getId());
-                if (order1 == 0 && order2 == 0) {
-                    // fallback and use name if not startup order was found
-                    return route1.getId().compareTo(route2.getId());
-                } else {
-                    return order1.compareTo(order2);
-                }
+            if (camel1.equals(camel2)) {
+                return route1.get("routeId").compareTo(route2.get("routeId"));
             } else {
-                return camel1.getName().compareTo(camel2.getName());
+                return camel1.compareTo(camel2);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/8048c6ce/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
index 5f61140..378cdb1 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
@@ -21,7 +21,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
 
 /**
@@ -50,20 +49,20 @@ public interface CamelController {
      * Get all routes. If Camel context name is null, all routes from all contexts are listed.
      *
      * @param camelContextName the Camel context name. If null, all contexts are considered.
-     * @return the list of the Camel routes.
+     * @return a list of key/value pairs with routes information
      * @throws java.lang.Exception can be thrown
      */
-    List<Route> getRoutes(String camelContextName) throws Exception;
+    List<Map<String, String>> getRoutes(String camelContextName) throws Exception;
 
     /**
      * Get all routes filtered by the regex.
      *
      * @param camelContextName the Camel context name. If null, all contexts are considered.
      * @param filter           the filter which supports * and ? as wildcards
-     * @return the list of the Camel routes.
+     * @return a list of key/value pairs with routes information
      * @throws java.lang.Exception can be thrown
      */
-    List<Route> getRoutes(String camelContextName, String filter) throws Exception;
+    List<Map<String, String>> getRoutes(String camelContextName, String filter) throws Exception;
 
     /**
      * Reset all the route stats for the given Camel context

http://git-wip-us.apache.org/repos/asf/camel/blob/8048c6ce/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
index b2e63ca..8c00d7a 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteListCommand.java
@@ -21,9 +21,6 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.camel.Route;
-import org.apache.camel.ServiceStatus;
-
 /**
  * Command to list all Camel routes.
  */
@@ -50,7 +47,7 @@ public class RouteListCommand extends AbstractCamelCommand {
 
     @Override
     public Object execute(CamelController camelController, PrintStream out, PrintStream err) throws Exception {
-        List<Route> routes = camelController.getRoutes(name);
+        List<Map<String, String>> routes = camelController.getRoutes(name);
 
         final Map<String, Integer> columnWidths = computeColumnWidths(routes);
         final String headerFormat = buildFormatString(columnWidths, true);
@@ -59,18 +56,18 @@ public class RouteListCommand extends AbstractCamelCommand {
         if (routes.size() > 0) {
             out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, ROUTE_COLUMN_LABEL, STATUS_COLUMN_LABEL));
             out.println(String.format(headerFormat, "-------", "-----", "------"));
-            for (Route route : routes) {
-                String contextId = route.getRouteContext().getCamelContext().getName();
-                String routeId = route.getId();
-                ServiceStatus status = route.getRouteContext().getCamelContext().getRouteStatus(routeId);
-                out.println(String.format(rowFormat, contextId, routeId, status));
+            for (Map<String, String> row : routes) {
+                String contextId = row.get("camelContextName");
+                String routeId = row.get("routeId");
+                String state = row.get("state");
+                out.println(String.format(rowFormat, contextId, routeId, state));
             }
         }
 
         return null;
     }
 
-    private static Map<String, Integer> computeColumnWidths(final Iterable<Route> routes) throws Exception {
+    private static Map<String, Integer> computeColumnWidths(final Iterable<Map<String, String>> routes) throws Exception {
         if (routes == null) {
             throw new IllegalArgumentException("Unable to determine column widths from null Iterable<Route>");
         } else {
@@ -78,14 +75,14 @@ public class RouteListCommand extends AbstractCamelCommand {
             int maxRouteLen = 0;
             int maxStatusLen = 0;
 
-            for (final Route route : routes) {
-                final String contextId = route.getRouteContext().getCamelContext().getName();
+            for (Map<String, String> row : routes) {
+                final String contextId = row.get("camelContextName");
                 maxContextLen = java.lang.Math.max(maxContextLen, contextId == null ? 0 : contextId.length());
 
-                final String routeId = route.getId();
+                final String routeId = row.get("routeId");
                 maxRouteLen = java.lang.Math.max(maxRouteLen, routeId == null ? 0 : routeId.length());
 
-                final String status = route.getRouteContext().getCamelContext().getRouteStatus(routeId).name();
+                final String status = row.get("state");
                 maxStatusLen = java.lang.Math.max(maxStatusLen, status == null ? 0 : status.length());
             }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8048c6ce/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/RouteCompleter.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/RouteCompleter.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/RouteCompleter.java
index 53a3d4d..fbcd1d3 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/RouteCompleter.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/RouteCompleter.java
@@ -17,9 +17,9 @@
 package org.apache.camel.karaf.commands.completers;
 
 import java.util.List;
+import java.util.Map;
 
 import jline.console.completer.StringsCompleter;
-import org.apache.camel.Route;
 
 /**
  * A Jline completer for the Camel routes.
@@ -30,9 +30,9 @@ public class RouteCompleter extends CamelCompleterSupport {
     public int complete(String buffer, int cursor, List candidates) {
         try {
             StringsCompleter delegate = new StringsCompleter();
-            List<Route> routes = camelController.getRoutes(null);
-            for (Route route : routes) {
-                delegate.getStrings().add(route.getId());
+            List<Map<String, String>> routes = camelController.getRoutes(null);
+            for (Map<String, String> row : routes) {
+                delegate.getStrings().add(row.get("routeId"));
             }
             return delegate.complete(buffer, cursor, candidates);
         } catch (Exception e) {


[2/5] camel git commit: CAMEL-8044: Camel commands should be more reusable for remote JVMs

Posted by da...@apache.org.
CAMEL-8044: Camel commands should be more reusable for remote JVMs


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

Branch: refs/heads/master
Commit: b33acc35bf763094b4ac932bc6b3ddc07623649e
Parents: 288ea67
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 18:25:59 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 18:25:59 2014 +0100

----------------------------------------------------------------------
 .../camel/commands/AbstractCamelController.java | 124 +++++++------------
 .../apache/camel/commands/CamelController.java  |  50 +++++---
 2 files changed, 75 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b33acc35/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
index 7837d51..eaf42c5 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
@@ -29,7 +29,6 @@ import java.util.Properties;
 import java.util.Set;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.xml.bind.JAXBException;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
@@ -46,7 +45,6 @@ import org.apache.camel.model.rest.RestsDefinition;
 import org.apache.camel.spi.ManagementAgent;
 import org.apache.camel.spi.RestRegistry;
 import org.apache.camel.util.JsonSchemaHelper;
-import org.apache.camel.util.ObjectHelper;
 
 /**
  * Abstract {@link org.apache.camel.commands.CamelController} that implementators should extend.
@@ -55,7 +53,7 @@ public abstract class AbstractCamelController implements CamelController {
 
     private CamelComponentCatalog catalog = new DefaultCamelComponentCatalog();
 
-    public CamelContext getCamelContext(String name) {
+    public CamelContext getCamelContext(String name) throws Exception {
         for (CamelContext camelContext : this.getCamelContexts()) {
             if (camelContext.getName().equals(name)) {
                 return camelContext;
@@ -64,11 +62,11 @@ public abstract class AbstractCamelController implements CamelController {
         return null;
     }
 
-    public List<Route> getRoutes(String camelContextName) {
+    public List<Route> getRoutes(String camelContextName) throws Exception {
         return getRoutes(camelContextName, null);
     }
 
-    public List<Route> getRoutes(String camelContextName, String filter) {
+    public List<Route> getRoutes(String camelContextName, String filter) throws Exception {
         List<Route> routes = new ArrayList<Route>();
 
         if (camelContextName != null) {
@@ -110,78 +108,58 @@ public abstract class AbstractCamelController implements CamelController {
         return routes;
     }
 
-    public void resetRouteStats(String camelContextName) {
+    public void resetRouteStats(String camelContextName) throws Exception{
         CamelContext context = this.getCamelContext(camelContextName);
         if (context == null) {
             return;
         }
 
-        try {
-            ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
-            if (agent != null) {
-                MBeanServer mBeanServer = agent.getMBeanServer();
-
-                // reset route mbeans
-                ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
-                Set<ObjectName> set = mBeanServer.queryNames(query, null);
-                for (ObjectName routeMBean : set) {
-                    String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
-                    if (camelId != null && camelId.equals(context.getName())) {
-                        mBeanServer.invoke(routeMBean, "reset", new Object[]{true}, new String[]{"boolean"});
-                    }
+        ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
+        if (agent != null) {
+            MBeanServer mBeanServer = agent.getMBeanServer();
+
+            // reset route mbeans
+            ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
+            Set<ObjectName> set = mBeanServer.queryNames(query, null);
+            for (ObjectName routeMBean : set) {
+                String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
+                if (camelId != null && camelId.equals(context.getName())) {
+                    mBeanServer.invoke(routeMBean, "reset", new Object[]{true}, new String[]{"boolean"});
                 }
             }
-        } catch (Exception e) {
-            throw ObjectHelper.wrapRuntimeCamelException(e);
         }
     }
 
-    public void startRoute(String camelContextName, String routeId) {
+    public void startRoute(String camelContextName, String routeId) throws Exception {
         CamelContext context = getCamelContext(camelContextName);
         if (context != null) {
-            try {
-                context.startRoute(routeId);
-            } catch (Exception e) {
-                throw ObjectHelper.wrapRuntimeCamelException(e);
-            }
+            context.startRoute(routeId);
         }
     }
 
-    public void stopRoute(String camelContextName, String routeId) {
+    public void stopRoute(String camelContextName, String routeId) throws Exception {
         CamelContext context = getCamelContext(camelContextName);
         if (context != null) {
-            try {
-                context.stopRoute(routeId);
-            } catch (Exception e) {
-                throw ObjectHelper.wrapRuntimeCamelException(e);
-            }
+            context.stopRoute(routeId);
         }
     }
 
-    public void suspendRoute(String camelContextName, String routeId) {
+    public void suspendRoute(String camelContextName, String routeId) throws Exception {
         CamelContext context = getCamelContext(camelContextName);
         if (context != null) {
-            try {
-                context.suspendRoute(routeId);
-            } catch (Exception e) {
-                throw ObjectHelper.wrapRuntimeCamelException(e);
-            }
+            context.suspendRoute(routeId);
         }
     }
 
-    public void resumeRoute(String camelContextName, String routeId) {
+    public void resumeRoute(String camelContextName, String routeId) throws Exception {
         CamelContext context = getCamelContext(camelContextName);
         if (context != null) {
-            try {
-                context.resumeRoute(routeId);
-            } catch (Exception e) {
-                throw ObjectHelper.wrapRuntimeCamelException(e);
-            }
+            context.resumeRoute(routeId);
         }
     }
 
     @SuppressWarnings("deprecation")
-    public String getRouteModelAsXml(String routeId, String camelContextName) {
+    public String getRouteModelAsXml(String routeId, String camelContextName) throws Exception {
         CamelContext context = this.getCamelContext(camelContextName);
         if (context == null) {
             return null;
@@ -191,47 +169,37 @@ public abstract class AbstractCamelController implements CamelController {
             return null;
         }
 
-        String xml;
-        try {
-            xml = ModelHelper.dumpModelAsXml(route);
-        } catch (JAXBException e) {
-            throw ObjectHelper.wrapRuntimeCamelException(e);
-        }
-        return xml;
+        return ModelHelper.dumpModelAsXml(route);
     }
 
     @Override
-    public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) {
+    public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception {
         CamelContext context = this.getCamelContext(camelContextName);
         if (context == null) {
             return null;
         }
 
-        try {
-            ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
-            if (agent != null) {
-                MBeanServer mBeanServer = agent.getMBeanServer();
-                Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" + routeId + "\",*"), null);
-                Iterator<ObjectName> iterator = set.iterator();
-                if (iterator.hasNext()) {
-                    ObjectName routeMBean = iterator.next();
-
-                    // the route must be part of the camel context
-                    String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
-                    if (camelId != null && camelId.equals(camelContextName)) {
-                        String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml", new Object[]{fullStats, includeProcessors}, new String[]{"boolean", "boolean"});
-                        return xml;
-                    }
+        ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
+        if (agent != null) {
+            MBeanServer mBeanServer = agent.getMBeanServer();
+            Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" + routeId + "\",*"), null);
+            Iterator<ObjectName> iterator = set.iterator();
+            if (iterator.hasNext()) {
+                ObjectName routeMBean = iterator.next();
+
+                // the route must be part of the camel context
+                String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
+                if (camelId != null && camelId.equals(camelContextName)) {
+                    String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml", new Object[]{fullStats, includeProcessors}, new String[]{"boolean", "boolean"});
+                    return xml;
                 }
             }
-        } catch (Exception e) {
-            throw ObjectHelper.wrapRuntimeCamelException(e);
         }
         return null;
     }
 
     @SuppressWarnings("deprecation")
-    public String getRestModelAsXml(String camelContextName) {
+    public String getRestModelAsXml(String camelContextName) throws Exception {
         CamelContext context = this.getCamelContext(camelContextName);
         if (context == null) {
             return null;
@@ -244,16 +212,10 @@ public abstract class AbstractCamelController implements CamelController {
         // use a rests definition to dump the rests
         RestsDefinition def = new RestsDefinition();
         def.setRests(rests);
-        String xml;
-        try {
-            xml = ModelHelper.dumpModelAsXml(def);
-        } catch (JAXBException e) {
-            throw ObjectHelper.wrapRuntimeCamelException(e);
-        }
-        return xml;
+        return ModelHelper.dumpModelAsXml(def);
     }
 
-    public List<Map<String, String>> getEndpoints(String camelContextName) {
+    public List<Map<String, String>> getEndpoints(String camelContextName) throws Exception {
         List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
 
         if (camelContextName != null) {
@@ -279,7 +241,7 @@ public abstract class AbstractCamelController implements CamelController {
         return answer;
     }
 
-    public List<Map<String, String>> getRestServices(String camelContextName) {
+    public List<Map<String, String>> getRestServices(String camelContextName) throws Exception {
         List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
 
         if (camelContextName != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/b33acc35/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
index f6e150e..5f61140 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
@@ -33,24 +33,27 @@ public interface CamelController {
      * Get the list of Camel context.
      *
      * @return the list of Camel contexts.
+     * @throws java.lang.Exception can be thrown
      */
-    List<CamelContext> getCamelContexts();
+    List<CamelContext> getCamelContexts() throws Exception;
 
     /**
      * Get a Camel context identified by the given name.
      *
      * @param name the Camel context name.
      * @return the Camel context or null if not found.
+     * @throws java.lang.Exception can be thrown
      */
-    CamelContext getCamelContext(String name);
+    CamelContext getCamelContext(String name) throws Exception;
 
     /**
      * Get all routes. If Camel context name is null, all routes from all contexts are listed.
      *
      * @param camelContextName the Camel context name. If null, all contexts are considered.
      * @return the list of the Camel routes.
+     * @throws java.lang.Exception can be thrown
      */
-    List<Route> getRoutes(String camelContextName);
+    List<Route> getRoutes(String camelContextName) throws Exception;
 
     /**
      * Get all routes filtered by the regex.
@@ -58,47 +61,53 @@ public interface CamelController {
      * @param camelContextName the Camel context name. If null, all contexts are considered.
      * @param filter           the filter which supports * and ? as wildcards
      * @return the list of the Camel routes.
+     * @throws java.lang.Exception can be thrown
      */
-    List<Route> getRoutes(String camelContextName, String filter);
+    List<Route> getRoutes(String camelContextName, String filter) throws Exception;
 
     /**
      * Reset all the route stats for the given Camel context
      *
      * @param camelContextName the Camel context.
+     * @throws java.lang.Exception can be thrown
      */
-    void resetRouteStats(String camelContextName);
+    void resetRouteStats(String camelContextName) throws Exception;
 
     /**
      * Starts the given route
      *
      * @param camelContextName the Camel context.
      * @param routeId          the route ID.
+     * @throws java.lang.Exception can be thrown
      */
-    void startRoute(String camelContextName, String routeId);
+    void startRoute(String camelContextName, String routeId) throws Exception;
 
     /**
      * Stops the given route
      *
      * @param camelContextName the Camel context.
      * @param routeId          the route ID.
+     * @throws java.lang.Exception can be thrown
      */
-    void stopRoute(String camelContextName, String routeId);
+    void stopRoute(String camelContextName, String routeId) throws Exception;
 
     /**
      * Suspends the given route
      *
      * @param camelContextName the Camel context.
      * @param routeId          the route ID.
+     * @throws java.lang.Exception can be thrown
      */
-    void suspendRoute(String camelContextName, String routeId);
+    void suspendRoute(String camelContextName, String routeId) throws Exception;
 
     /**
      * Resumes the given route
      *
      * @param camelContextName the Camel context.
      * @param routeId          the route ID.
+     * @throws java.lang.Exception can be thrown
      */
-    void resumeRoute(String camelContextName, String routeId);
+    void resumeRoute(String camelContextName, String routeId) throws Exception;
 
     /**
      * Return the definition of a route as XML identified by a ID and a Camel context.
@@ -106,8 +115,9 @@ public interface CamelController {
      * @param routeId          the route ID.
      * @param camelContextName the Camel context.
      * @return the route model as XML
+     * @throws java.lang.Exception can be thrown
      */
-    String getRouteModelAsXml(String routeId, String camelContextName);
+    String getRouteModelAsXml(String routeId, String camelContextName) throws Exception;
 
     /**
      * Returns detailed route statistics as XML identified by a ID and a Camel context.
@@ -117,32 +127,36 @@ public interface CamelController {
      * @param fullStats         whether to include verbose stats
      * @param includeProcessors whether to embed per processor stats from the route
      * @return the route statistics as XML
+     * @throws java.lang.Exception can be thrown
      */
-    String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors);
+    String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception;
 
     /**
      * Return the endpoints
      *
      * @param camelContextName the Camel context.
      * @return a list of key/value pairs with endpoint information
+     * @throws java.lang.Exception can be thrown
      */
-    List<Map<String, String>> getEndpoints(String camelContextName);
+    List<Map<String, String>> getEndpoints(String camelContextName) throws Exception;
 
     /**
      * Return the definition of the REST services as XML for the given Camel context.
      *
      * @param camelContextName the Camel context.
      * @return the REST model as xml
+     * @throws java.lang.Exception can be thrown
      */
-    String getRestModelAsXml(String camelContextName);
+    String getRestModelAsXml(String camelContextName) throws Exception;
 
     /**
      * Return the REST services for the given Camel context.
      *
      * @param camelContextName the Camel context.
      * @return a list of key/value pairs with REST information
+     * @throws java.lang.Exception can be thrown
      */
-    List<Map<String, String>> getRestServices(String camelContextName);
+    List<Map<String, String>> getRestServices(String camelContextName) throws Exception;
 
     /**
      * Explains an endpoint uri
@@ -151,7 +165,7 @@ public interface CamelController {
      * @param uri              the endpoint uri
      * @param allOptions       whether to explain all options, or only the explicit configured options from the uri
      * @return a JSON schema with explanation of the options
-     * @throws java.lang.Exception is thrown if error loading resources to explain the endpoint
+     * @throws java.lang.Exception can be thrown
      */
     String explainEndpointAsJSon(String camelContextName, String uri, boolean allOptions) throws Exception;
 
@@ -160,7 +174,7 @@ public interface CamelController {
      *
      * @param camelContextName the Camel context.
      * @return a list of key/value pairs with component information
-     * @throws java.lang.Exception is thrown if error loading resources to gather component information
+     * @throws java.lang.Exception can be thrown
      */
     List<Map<String, String>> listComponents(String camelContextName) throws Exception;
 
@@ -169,7 +183,7 @@ public interface CamelController {
      *
      * @param filter optional filter to filter by labels
      * @return a list of key/value pairs with component information
-     * @throws java.lang.Exception is thrown if error loading resources to gather component information
+     * @throws java.lang.Exception can be thrown
      */
     List<Map<String, String>> listComponentsCatalog(String filter) throws Exception;
 
@@ -177,7 +191,7 @@ public interface CamelController {
      * Lists all the labels from the Camel components catalog
      *
      * @return a map which key is the label, and the set is the component names that has the given label
-     * @throws java.lang.Exception is thrown if error loading resources to gather component information
+     * @throws java.lang.Exception can be thrown
      */
     Map<String, Set<String>> listLabelCatalog() throws Exception;
 


[4/5] camel git commit: CAMEL-8044: Camel commands should be more reusable for remote JVMs

Posted by da...@apache.org.
CAMEL-8044: Camel commands should be more reusable for remote JVMs


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

Branch: refs/heads/master
Commit: 453e40549da1838c4921aeb5a1a49e149bf680cc
Parents: 8048c6c
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 18:44:07 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 18:44:07 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/karaf/commands/EndpointExplain.java    | 2 +-
 .../main/java/org/apache/camel/karaf/commands/EndpointList.java  | 4 ++--
 platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/453e4054/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointExplain.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointExplain.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointExplain.java
index 201f9a1..88e6f56 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointExplain.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointExplain.java
@@ -24,7 +24,7 @@ import org.apache.felix.gogo.commands.Option;
 @Command(scope = "camel", name = "endpoint-explain", description = "Explain all Camel endpoints available in CamelContexts.")
 public class EndpointExplain extends CamelCommandSupport {
 
-    @Argument(index = 0, name = "name", description = "The Camel context name where to look for the endpoints", required = false, multiValued = false)
+    @Argument(index = 0, name = "name", description = "The name of the Camel context", required = true, multiValued = false)
     String name;
 
     @Option(name = "--verbose", aliases = "-v", description = "Verbose output to explain all options",

http://git-wip-us.apache.org/repos/asf/camel/blob/453e4054/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
index 8fe12b4..fdb86d5 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
@@ -21,10 +21,10 @@ import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 import org.apache.felix.gogo.commands.Option;
 
-@Command(scope = "camel", name = "endpoint-list", description = "Lists all Camel endpoints available in CamelContexts.")
+@Command(scope = "camel", name = "endpoint-list", description = "Lists Camel endpoints.")
 public class EndpointList extends CamelCommandSupport {
 
-    @Argument(index = 0, name = "name", description = "The Camel context name where to look for the endpoints", required = false, multiValued = false)
+    @Argument(index = 0, name = "name", description = "The name of the Camel context", required = true, multiValued = false)
     String name;
 
     @Option(name = "--decode", aliases = "-d", description = "Whether to decode the endpoint uri so its human readable",

http://git-wip-us.apache.org/repos/asf/camel/blob/453e4054/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info b/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
index b3df4af..639be83 100644
--- a/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
+++ b/platforms/karaf/commands/src/main/resources/OSGI-INF/bundle.info
@@ -20,7 +20,7 @@
     \u001B[36mcamel:context-stop\u001B[0m Stops a Camel context.
     \u001B[36mcamel:context-suspend\u001B[0m Suspends a Camel context.
     \u001B[36mcamel:endpoint-explain\u001B[0m Explain all Camel endpoints available in Camel Context deployed
-    \u001B[36mcamel:endpoint-list\u001B[0m List all Camel endpoints available in Camel Context deployed
+    \u001B[36mcamel:endpoint-list\u001B[0m List the Camel endpoints.
     \u001B[36mcamel:rest-registry-list\u001B[0m Lists all Camel REST services enlisted in the Rest Registry from all CamelContexts.
     \u001B[36mcamel:rest-show\u001B[0m Display the Camel REST definition in XML..
     \u001B[36mcamel:route-info\u001B[0m Display information about a Camel route.