camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/4] camel git commit: CAMEL-8044: Camel commands should be more reusable for remote JVMs
Date Thu, 11 Dec 2014 09:15:19 GMT
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/5e774fac
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5e774fac
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5e774fac

Branch: refs/heads/master
Commit: 5e774fac8f832f02cfba5464cfecadc1059de05f
Parents: 7970f83
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Dec 11 09:09:12 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Dec 11 09:09:12 2014 +0100

----------------------------------------------------------------------
 .../camel/commands/AbstractCamelController.java | 29 +++++++
 .../apache/camel/commands/CamelController.java  |  9 +++
 .../camel/commands/ContextInfoCommand.java      | 85 +++++++-------------
 .../camel/commands/ContextListCommand.java      |  2 +-
 .../commands/internal/CamelControllerImpl.java  | 19 +++++
 5 files changed, 86 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5e774fac/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 98290d1..51c2f7c 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,6 +62,35 @@ public abstract class AbstractCamelController implements CamelController
{
         return null;
     }
 
+    @Override
+    public Map<String, Object> getCamelContextInformation(String name) throws Exception
{
+        Map<String, Object> answer = new LinkedHashMap<String, Object>();
+        CamelContext context = getCamelContext(name);
+        if (context != null) {
+            answer.put("name", context.getName());
+            answer.put("managementName", context.getManagementName());
+            answer.put("version", context.getVersion());
+            answer.put("status", context.getStatus().name());
+            answer.put("uptime", context.getUptime());
+            answer.put("autoStartup", context.isAutoStartup());
+            answer.put("startingRoutes", context.isStartingRoutes());
+            answer.put("suspended", context.getStatus().isSuspended());
+            answer.put("allowUseOriginalMessage", context.isAllowUseOriginalMessage());
+            answer.put("messageHistory", context.isMessageHistory());
+            answer.put("tracing", context.isTracing());
+            answer.put("shutdownTimeout", context.getShutdownStrategy().getTimeUnit().toSeconds(context.getShutdownStrategy().getTimeout()));
+            answer.put("classResolver", context.getClassResolver().toString());
+            answer.put("packageScanClassResolver", context.getPackageScanClassResolver().toString());
+            answer.put("applicationContextClassLoader", context.getApplicationContextClassLoader().toString());
+
+            for (Map.Entry<String, String> entry : context.getProperties().entrySet())
{
+                answer.put("property." + entry.getKey(), entry.getValue());
+            }
+        }
+
+        return answer;
+    }
+
     public void startContext(String camelContextName) throws Exception {
         CamelContext context = getCamelContext(camelContextName);
         if (context != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/5e774fac/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 7929f88..6f781a0 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
@@ -52,6 +52,15 @@ public interface CamelController {
     CamelContext getCamelContext(String name) throws Exception;
 
     /**
+     * Gets information about a given Camel context by the given name.
+     *
+     * @param name the Camel context name.
+     * @return a list of key/value pairs with CamelContext information
+     * @throws java.lang.Exception can be thrown
+     */
+    Map<String, Object> getCamelContextInformation(String name) throws Exception;
+
+    /**
      * Get the list of Camel context.
      *
      * @return a list of key/value pairs with CamelContext information

http://git-wip-us.apache.org/repos/asf/camel/blob/5e774fac/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
index 3a83bec..e85bceb 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
@@ -27,7 +27,6 @@ import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
 import org.apache.camel.spi.ManagementAgent;
 
@@ -61,75 +60,47 @@ public class ContextInfoCommand extends AbstractCamelCommand {
 
     @Override
     public Object execute(CamelController camelController, PrintStream out, PrintStream err)
throws Exception {
-        CamelContext camelContext = camelController.getCamelContext(context);
-        if (camelContext == null) {
+        Map<String, Object> row = camelController.getCamelContextInformation(context);
+        if (row == null || row.isEmpty()) {
             err.println("Camel context " + context + " not found.");
             return null;
         }
 
-        out.println(stringEscape.unescapeJava("\u001B[1m\u001B[33mCamel Context " + context
+ "\u001B[0m"));
-        out.println(stringEscape.unescapeJava("\tName: " + camelContext.getName()));
-        out.println(stringEscape.unescapeJava("\tManagementName: " + camelContext.getManagementName()));
-        out.println(stringEscape.unescapeJava("\tVersion: " + camelContext.getVersion()));
-        out.println(stringEscape.unescapeJava("\tStatus: " + camelContext.getStatus()));
-        out.println(stringEscape.unescapeJava("\tUptime: " + camelContext.getUptime()));
-
-        // the statistics are in the mbeans
-        printCamelManagedBeansStatus(camelContext, out);
+        out.println("");
+        out.println(stringEscape.unescapeJava("\u001B[1mCamel Context " + context + "\u001B[0m"));
+        out.println(stringEscape.unescapeJava("\tName: " + row.get("name")));
+        out.println(stringEscape.unescapeJava("\tManagementName: " + row.get("managementName")));
+        out.println(stringEscape.unescapeJava("\tVersion: " + row.get("version")));
+        out.println(stringEscape.unescapeJava("\tStatus: " + row.get("status")));
+        out.println(stringEscape.unescapeJava("\tUptime: " + row.get("uptime")));
 
         out.println("");
         out.println(stringEscape.unescapeJava("\u001B[1mMiscellaneous\u001B[0m"));
-        out.println(stringEscape.unescapeJava("\tAuto Startup: " + camelContext.isAutoStartup()));
-        out.println(stringEscape.unescapeJava("\tStarting Routes: " + camelContext.isStartingRoutes()));
-        out.println(stringEscape.unescapeJava("\tSuspended: " + camelContext.isSuspended()));
-        out.println(stringEscape.unescapeJava("\tShutdown timeout: "
-                + camelContext.getShutdownStrategy().getTimeUnit().toSeconds(camelContext.getShutdownStrategy().getTimeout())
+ " sec."));
-        out.println(stringEscape.unescapeJava("\tAllow UseOriginalMessage: " + camelContext.isAllowUseOriginalMessage()));
-        out.println(stringEscape.unescapeJava("\tMessage History: " + camelContext.isMessageHistory()));
-        out.println(stringEscape.unescapeJava("\tTracing: " + camelContext.isTracing()));
+        out.println(stringEscape.unescapeJava("\tAuto Startup: " + row.get("autoStartup")));
+        out.println(stringEscape.unescapeJava("\tStarting Routes: " + row.get("startingRoutes")));
+        out.println(stringEscape.unescapeJava("\tSuspended: " + row.get("suspended")));
+        out.println(stringEscape.unescapeJava("\tShutdown Timeout: " + row.get("shutdownTimeout")
+ " sec."));
+        out.println(stringEscape.unescapeJava("\tAllow UseOriginalMessage: " + row.get("allowUseOriginalMessage")));
+        out.println(stringEscape.unescapeJava("\tMessage History: " + row.get("messageHistory")));
+        out.println(stringEscape.unescapeJava("\tTracing: " + row.get("tracing")));
         out.println("");
         out.println(stringEscape.unescapeJava("\u001B[1mProperties\u001B[0m"));
-        for (Map.Entry<String, String> entry : camelContext.getProperties().entrySet())
{
-            out.println(stringEscape.unescapeJava("\t" + entry.getKey() + " = " + entry.getValue()));
+        for (Map.Entry<String, Object> entry : row.entrySet()) {
+            String key = entry.getKey();
+            if (key.startsWith("property.")) {
+                key = key.substring(9);
+                out.println(stringEscape.unescapeJava("\t" + key + " = " + entry.getValue()));
+            }
         }
-
         out.println("");
         out.println(stringEscape.unescapeJava("\u001B[1mAdvanced\u001B[0m"));
-        out.println(stringEscape.unescapeJava("\tClassResolver: " + camelContext.getClassResolver()));
-        out.println(stringEscape.unescapeJava("\tPackageScanClassResolver: " + camelContext.getPackageScanClassResolver()));
-        out.println(stringEscape.unescapeJava("\tApplicationContextClassLoader: " + camelContext.getApplicationContextClassLoader()));
-
-        out.println("");
-        out.println(stringEscape.unescapeJava("\u001B[1mComponents\u001B[0m"));
-        for (String component : camelContext.getComponentNames()) {
-            System.out.println(stringEscape.unescapeJava("\t" + component));
-        }
-
-        out.println("");
-        out.println(stringEscape.unescapeJava("\u001B[1mDataformats\u001B[0m"));
-        for (String name : camelContext.getDataFormats().keySet()) {
-            out.println(stringEscape.unescapeJava("\t" + name));
-        }
+        out.println(stringEscape.unescapeJava("\tClassResolver: " + row.get("classResolver")));
+        out.println(stringEscape.unescapeJava("\tPackageScanClassResolver: " + row.get("packageScanClassResolver")));
+        out.println(stringEscape.unescapeJava("\tApplicationContextClassLoader: " + row.get("applicationContextClassLoader")));
 
-        if (mode != null && mode.equals("--verbose")) {
-            out.println("");
-            out.println(stringEscape.unescapeJava("\u001B[1mLanguages\u001B[0m"));
-            for (String language : camelContext.getLanguageNames()) {
-                out.println(stringEscape.unescapeJava("\t" + language));
-            }
-
-            out.println("");
-            out.println(stringEscape.unescapeJava("\u001B[1mEndpoints\u001B[0m"));
-            for (Endpoint endpoint : camelContext.getEndpoints()) {
-                out.println(stringEscape.unescapeJava("\t" + endpoint.getEndpointUri()));
-            }
-        }
-
-        out.println("");
-        out.println(stringEscape.unescapeJava("\u001B[1mRoutes\u001B[0m"));
-        for (Route route : camelContext.getRoutes()) {
-            out.println(stringEscape.unescapeJava("\t" + route.getId()));
-        }
+        // the statistics are in the mbeans
+        // TODO: use dump stats as xml
+        // printCamelManagedBeansStatus(camelContext, out);
 
         return null;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5e774fac/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
index 6b66ecd..f4f7ecf 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextListCommand.java
@@ -50,7 +50,7 @@ public class ContextListCommand extends AbstractCamelCommand {
             out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, STATUS_COLUMN_LABEL,
UPTIME_COLUMN_LABEL));
             out.println(String.format(headerFormat, "-------", "------", "------"));
             for (Map<String, String> row : camelContexts) {
-                out.println(String.format(rowFormat, row.get("name"), row.get("state"), row.get("updtime")));
+                out.println(String.format(rowFormat, row.get("name"), row.get("state"), row.get("uptime")));
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5e774fac/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
index e0d7d6f..5712137 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
@@ -19,7 +19,9 @@ package org.apache.camel.karaf.commands.internal;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.commands.AbstractCamelController;
@@ -41,6 +43,7 @@ public class CamelControllerImpl extends AbstractCamelController {
         this.bundleContext = bundleContext;
     }
 
+    @Override
     public List<CamelContext> getCamelContexts() {
         List<CamelContext> camelContexts = new ArrayList<CamelContext>();
         try {
@@ -70,4 +73,20 @@ public class CamelControllerImpl extends AbstractCamelController {
         return camelContexts;
     }
 
+    @Override
+    public List<Map<String, String>> getCamelContexts2() throws Exception {
+        List<Map<String, String>> answer = new ArrayList<Map<String, String>>(1);
+
+        List<CamelContext> camelContexts = getCamelContexts();
+        for (CamelContext camelContext : camelContexts) {
+            Map<String, String> row = new LinkedHashMap<String, String>();
+            row.put("name", camelContext.getName());
+            row.put("state", camelContext.getStatus().name());
+            row.put("uptime", camelContext.getUptime());
+            answer.add(row);
+        }
+
+        return answer;
+    }
+
 }


Mime
View raw message