camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1173266 - in /camel/branches/camel-2.8.x: ./ platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/ platforms/karaf/commands/src/main/resourc...
Date Tue, 20 Sep 2011 17:25:10 GMT
Author: dkulp
Date: Tue Sep 20 17:25:09 2011
New Revision: 1173266

URL: http://svn.apache.org/viewvc?rev=1173266&view=rev
Log:
Merged revisions 1171210 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1171210 | davsclaus | 2011-09-15 14:24:14 -0400 (Thu, 15 Sep 2011) | 1 line
  
  CAMEL-4450: Improved Camel Karaf commands. Thanks to Ioannis for the patch.
........

Added:
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ResumeRouteCommand.java
      - copied unchanged from r1171210, camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ResumeRouteCommand.java
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/SuspendRouteCommand.java
      - copied unchanged from r1171210, camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/SuspendRouteCommand.java
Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ListRoutesCommand.java
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/StartRouteCommand.java
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
    camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java?rev=1173266&r1=1173265&r2=1173266&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
(original)
+++ camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/CamelController.java
Tue Sep 20 17:25:09 2011
@@ -51,6 +51,14 @@ public interface CamelController {
     List<Route> getRoutes(String camelContextName);
 
     /**
+     * Get all route definitions. If Camel context name is null, all route definitions from
all contexts are listed.
+     *
+     * @param camelContextName the Camel context name. If null, all contexts are considered.
+     * @return the list of the Camel route definitions.
+     */
+    List<RouteDefinition> getRouteDefinitions(String camelContextName);
+
+    /**
      * Return the route with the given route ID.
      *
      * @param routeId the route ID.

Modified: camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ListRoutesCommand.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ListRoutesCommand.java?rev=1173266&r1=1173265&r2=1173266&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ListRoutesCommand.java
(original)
+++ camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ListRoutesCommand.java
Tue Sep 20 17:25:09 2011
@@ -16,9 +16,11 @@
  */
 package org.apache.camel.karaf.commands;
 
+import java.util.LinkedList;
 import java.util.List;
 
-import org.apache.camel.Route;
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -29,7 +31,12 @@ import org.apache.karaf.shell.console.Os
 @Command(scope = "camel", name = "list-routes", description = "List all Camel routes.")
 public class ListRoutesCommand extends OsgiCommandSupport {
 
-    protected static final String OUTPUT_FORMAT = "[%-20s]";
+    protected static final String HEADER_FORMAT = "%-20s %-20s %-20s";
+    protected static final String OUTPUT_FORMAT = "[%-18s] [%-18s] [%-18s]";
+    protected static final String UNKNOWN = "Unknown";
+    protected static final String ROUTE_ID = "Route Id";
+    protected static final String CONTEXT_ID = "Context Name";
+    protected static final String STATUS = "Status";
 
     @Argument(index = 0, name = "name", description = "The Camel context name where to look
for the route", required = false, multiValued = false)
     String name;
@@ -41,10 +48,26 @@ public class ListRoutesCommand extends O
     }
 
     protected Object doExecute() throws Exception {
-        List<Route> routes = camelController.getRoutes(name);
-        for (Route route : routes) {
-            System.out.println(String.format(OUTPUT_FORMAT, route.getId()));
+        System.out.println(String.format(HEADER_FORMAT, ROUTE_ID, CONTEXT_ID, STATUS));
+
+        List<CamelContext> camelContexts = new LinkedList<CamelContext>();
+        if (name != null && camelController.getCamelContext(name) != null) {
+            camelContexts.add(camelController.getCamelContext(name));
+        } else {
+            camelContexts = camelController.getCamelContexts();
+        }
+
+        for (CamelContext camelContext : camelContexts) {
+            List<RouteDefinition> routeDefinitions = camelController.getRouteDefinitions(camelContext.getName());
+            if (routeDefinitions != null && !routeDefinitions.isEmpty()) {
+                for (RouteDefinition routeDefinition : routeDefinitions) {
+                    String contextName = camelContext.getName();
+                    String status = camelContext.getRouteStatus(routeDefinition.getId()).name();
+                    System.out.println(String.format(OUTPUT_FORMAT, routeDefinition.getId(),
contextName, status));
+                }
+            }
         }
+
         return null;
     }
 

Modified: camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/StartRouteCommand.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/StartRouteCommand.java?rev=1173266&r1=1173265&r2=1173266&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/StartRouteCommand.java
(original)
+++ camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/StartRouteCommand.java
Tue Sep 20 17:25:09 2011
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.karaf.commands;
 
+import java.util.List;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -43,11 +46,20 @@ public class StartRouteCommand extends O
     public Object doExecute() throws Exception {
         Route camelRoute = camelController.getRoute(route, context);
         if (camelRoute == null) {
+            List<CamelContext> camelContexts = camelController.getCamelContexts();
+            for (CamelContext camelContext : camelContexts) {
+                RouteDefinition routeDefinition = camelContext.getRouteDefinition(route);
+                if (routeDefinition != null) {
+                    camelContext.startRoute(routeDefinition.getId());
+                    return null;
+                }
+            }
             System.err.println("Camel route " + route + " not found.");
             return null;
+        } else {
+            CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
+            camelContext.startRoute(route);
         }
-        CamelContext camelContext = camelRoute.getRouteContext().getCamelContext();
-        camelContext.startRoute(route);
         return null;
     }
 

Modified: camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java?rev=1173266&r1=1173265&r2=1173266&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
(original)
+++ camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java
Tue Sep 20 17:25:09 2011
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
 
 
 /**
- * Implementation of <code>CamelConrtoller</code>.
+ * Implementation of <code>CamelController</code>.
  */
 public class CamelControllerImpl implements CamelController {
 
@@ -90,6 +90,26 @@ public class CamelControllerImpl impleme
         return null;
     }
 
+
+    public List<RouteDefinition> getRouteDefinitions(String camelContextName) {
+        if (camelContextName != null) {
+            CamelContext context = this.getCamelContext(camelContextName);
+            if (context != null) {
+                return context.getRouteDefinitions();
+            }
+        } else {
+            ArrayList<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
+            List<CamelContext> camelContexts = this.getCamelContexts();
+            for (CamelContext camelContext : camelContexts) {
+                for (RouteDefinition routeDefinition : camelContext.getRouteDefinitions())
{
+                    routeDefinitions.add(routeDefinition);
+                }
+            }
+            return routeDefinitions;
+        }
+        return null;
+    }
+
     public Route getRoute(String routeId, String camelContextName) {
         List<Route> routes = this.getRoutes(camelContextName);
         for (Route route : routes) {

Modified: camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml?rev=1173266&r1=1173265&r2=1173266&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
(original)
+++ camel/branches/camel-2.8.x/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
Tue Sep 20 17:25:09 2011
@@ -95,6 +95,24 @@
                 <null/>
             </completers>
         </command>
+        <command name="camel/resume-route">
+            <action class="org.apache.camel.karaf.commands.ResumeRouteCommand">
+                <property name="camelController" ref="camelController"/>
+            </action>
+            <completers>
+                <ref component-id="routeCompleter"/>
+                <null/>
+            </completers>
+        </command>
+        <command name="camel/suspend-route">
+            <action class="org.apache.camel.karaf.commands.SuspendRouteCommand">
+                <property name="camelController" ref="camelController"/>
+            </action>
+            <completers>
+                <ref component-id="routeCompleter"/>
+                <null/>
+            </completers>
+        </command>
     </command-bundle>
 
     <bean id="camelContextCompleter" class="org.apache.camel.karaf.commands.completers.CamelContextCompleter">



Mime
View raw message