This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new 6beb3700f Make camel context optional in most of camel:* shell
commands (#615)
6beb3700f is described below
commit 6beb3700fdd53703ffee0a5264819d99494261ba
Author: JB Onofré <[email protected]>
AuthorDate: Sun Apr 13 21:03:35 2025 +0200
Make camel context optional in most of camel:* shell commands (#615)
---
.../camel/karaf/shell/CamelCommandSupport.java | 7 ++-
.../apache/camel/karaf/shell/ContextInflight.java | 45 ++++++++-------
.../apache/camel/karaf/shell/ContextResume.java | 8 ++-
.../org/apache/camel/karaf/shell/ContextStart.java | 8 ++-
.../org/apache/camel/karaf/shell/ContextStop.java | 8 ++-
.../apache/camel/karaf/shell/ContextSuspend.java | 8 ++-
.../org/apache/camel/karaf/shell/EndpointList.java | 43 +++++++-------
.../apache/camel/karaf/shell/EndpointStats.java | 66 +++++++++++-----------
.../org/apache/camel/karaf/shell/RestApiDoc.java | 10 ++--
.../apache/camel/karaf/shell/RestRegistryList.java | 6 +-
.../org/apache/camel/karaf/shell/RouteList.java | 44 +++++++--------
.../apache/camel/karaf/shell/RouteResetStats.java | 29 +++++-----
.../org/apache/camel/karaf/shell/RouteResume.java | 14 ++---
.../org/apache/camel/karaf/shell/RouteStart.java | 14 ++---
.../org/apache/camel/karaf/shell/RouteStop.java | 14 ++---
.../org/apache/camel/karaf/shell/RouteSuspend.java | 14 ++---
.../karaf/shell/completers/RouteCompleter.java | 7 ++-
17 files changed, 178 insertions(+), 167 deletions(-)
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/CamelCommandSupport.java
b/shell/src/main/java/org/apache/camel/karaf/shell/CamelCommandSupport.java
index b45502063..a18d192c6 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/CamelCommandSupport.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/CamelCommandSupport.java
@@ -62,10 +62,13 @@ public abstract class CamelCommandSupport {
}
- public CamelContext getCamelContext(String name) throws Exception {
+ public List<CamelContext> getCamelContext(String name) throws Exception {
+ if (name == null) {
+ return getCamelContexts();
+ }
for (CamelContext camelContext : getCamelContexts()) {
if (camelContext.getName().equals(name)) {
- return camelContext;
+ return List.of(camelContext);
}
}
return null;
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/ContextInflight.java
b/shell/src/main/java/org/apache/camel/karaf/shell/ContextInflight.java
index 55c45c0ab..07c96b2e1 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/ContextInflight.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/ContextInflight.java
@@ -30,13 +30,14 @@ import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
import java.util.Collection;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
@Command(scope = "camel", name = "context-inflight", description = "List
inflight exchanges")
@Service
public class ContextInflight extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The Camel context
name", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The Camel context
name", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String name;
@@ -52,37 +53,35 @@ public class ContextInflight extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
-
- if (camelContext == null) {
- System.err.println("Camel context " + name + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(name);
ShellTable table = new ShellTable();
table.column("ExchangeId");
table.column("From Route");
+ table.column("Context");
table.column("Route");
table.column("Node");
table.column("Elapsed (ms)");
table.column("Duration (ms)");
- ManagementAgent agent =
camelContext.getManagementStrategy().getManagementAgent();
- if (agent != null) {
- MBeanServer mBeanServer = agent.getMBeanServer();
- ObjectName on = new ObjectName(agent.getMBeanObjectDomainName() +
":type=services,name=DefaultInflightRepository,context=" +
camelContext.getManagementName());
- if (mBeanServer.isRegistered(on)) {
- TabularData list = (TabularData) mBeanServer.invoke(on,
"browse", new Object[]{route, limit, sortByLongestDuration}, new
String[]{"java.lang.String", "int", "boolean"});
- Collection<CompositeData> values = (Collection<CompositeData>)
list.values();
- for (CompositeData data : values) {
- Map<String, Object> row = new LinkedHashMap<>();
- Object exchangeId = data.get("exchangeId");
- Object fromRouteId = data.get("fromRouteId");
- Object routeId = data.get("routeId");
- Object nodeId = data.get("nodeId");
- Object elapsed = data.get("elapsed");
- Object duration = data.get("duration");
- table.addRow().addContent(exchangeId, fromRouteId,
routeId, nodeId, elapsed, duration);
+ for (CamelContext camelContext : camelContexts) {
+ ManagementAgent agent =
camelContext.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
+ ObjectName on = new
ObjectName(agent.getMBeanObjectDomainName() +
":type=services,name=DefaultInflightRepository,context=" +
camelContext.getManagementName());
+ if (mBeanServer.isRegistered(on)) {
+ TabularData list = (TabularData) mBeanServer.invoke(on,
"browse", new Object[]{route, limit, sortByLongestDuration}, new
String[]{"java.lang.String", "int", "boolean"});
+ Collection<CompositeData> values =
(Collection<CompositeData>) list.values();
+ for (CompositeData data : values) {
+ Map<String, Object> row = new LinkedHashMap<>();
+ Object exchangeId = data.get("exchangeId");
+ Object fromRouteId = data.get("fromRouteId");
+ Object routeId = data.get("routeId");
+ Object nodeId = data.get("nodeId");
+ Object elapsed = data.get("elapsed");
+ Object duration = data.get("duration");
+ table.addRow().addContent(exchangeId, fromRouteId,
camelContext.getName(), routeId, nodeId, elapsed, duration);
+ }
}
}
}
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/ContextResume.java
b/shell/src/main/java/org/apache/camel/karaf/shell/ContextResume.java
index 647b39fd9..9705b1fe4 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/ContextResume.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/ContextResume.java
@@ -24,6 +24,8 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "context-resume", description = "Resumes a
Camel context")
@Service
public class ContextResume extends CamelCommandSupport implements Action {
@@ -34,14 +36,14 @@ public class ContextResume extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
- if (camelContext == null) {
+ if (camelContexts.size() != 1) {
System.err.println("Camel context " + name + " not found");
return null;
}
- camelContext.resume();
+ camelContexts.get(0).resume();
return null;
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/ContextStart.java
b/shell/src/main/java/org/apache/camel/karaf/shell/ContextStart.java
index 1f4e7ca62..cbb76b4d4 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/ContextStart.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/ContextStart.java
@@ -25,6 +25,8 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "context-start", description = "Starts a
Camel context")
@Service
public class ContextStart extends CamelCommandSupport implements Action {
@@ -35,13 +37,15 @@ public class ContextStart extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
- if (camelContext == null) {
+ if (camelContexts.size() != 1) {
System.err.println("Camel context " + name + " not found");
return null;
}
+ CamelContext camelContext = camelContexts.get(0);
+
if (camelContext.getStatus().equals(ServiceStatus.Suspended)) {
camelContext.resume();
} else {
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/ContextStop.java
b/shell/src/main/java/org/apache/camel/karaf/shell/ContextStop.java
index d78e55fe2..287c064d2 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/ContextStop.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/ContextStop.java
@@ -24,6 +24,8 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "context-stop", description = "Stop a Camel
context, it becomes unavailable and can not be started again")
@Service
public class ContextStop extends CamelCommandSupport implements Action {
@@ -34,14 +36,14 @@ public class ContextStop extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
- if (camelContext == null) {
+ if (camelContexts.size() != 1) {
System.err.println("Camel context " + name + " not found");
return null;
}
- camelContext.stop();
+ camelContexts.get(0).stop();
return null;
}
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/ContextSuspend.java
b/shell/src/main/java/org/apache/camel/karaf/shell/ContextSuspend.java
index 5b8b672ad..c94bcc072 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/ContextSuspend.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/ContextSuspend.java
@@ -24,6 +24,8 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "context-suspend", description = "Suspends a
Camel context")
@Service
public class ContextSuspend extends CamelCommandSupport implements Action {
@@ -34,14 +36,14 @@ public class ContextSuspend extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
- if (camelContext == null) {
+ if (camelContexts.size() != 1) {
System.err.println("Camel context " + name + " not found");
return null;
}
- camelContext.suspend();
+ camelContexts.get(0).suspend();
return null;
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/EndpointList.java
b/shell/src/main/java/org/apache/camel/karaf/shell/EndpointList.java
index 76e9bee5a..ff8a57c3b 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/EndpointList.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/EndpointList.java
@@ -36,7 +36,7 @@ import java.util.List;
@Service
public class EndpointList extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The name of the
Camel context (support wildcard)", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The name of the
Camel context (support wildcard)", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String name;
@@ -51,30 +51,27 @@ public class EndpointList extends CamelCommandSupport
implements Action {
table.column("Uri");
table.column("Status");
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
- if (camelContext == null) {
- System.err.println("Camel context " + name + " not found");
- return null;
- }
-
- List<Endpoint> endpoints = new
ArrayList<>(camelContext.getEndpoints());
- // sort routes
- Collections.sort(endpoints, new Comparator<Endpoint>() {
- @Override
- public int compare(Endpoint e1, Endpoint e2) {
- return e1.getEndpointKey().compareTo(e2.getEndpointKey());
- }
- });
- for (Endpoint endpoint : endpoints) {
- String uri = endpoint.getEndpointUri();
- if (decode) {
- // decode uri so its more human readable
- uri = URLDecoder.decode(uri, "UTF-8");
+ for (CamelContext camelContext : camelContexts) {
+ List<Endpoint> endpoints = new
ArrayList<>(camelContext.getEndpoints());
+ // sort routes
+ Collections.sort(endpoints, new Comparator<Endpoint>() {
+ @Override
+ public int compare(Endpoint e1, Endpoint e2) {
+ return e1.getEndpointKey().compareTo(e2.getEndpointKey());
+ }
+ });
+ for (Endpoint endpoint : endpoints) {
+ String uri = endpoint.getEndpointUri();
+ if (decode) {
+ // decode uri so its more human readable
+ uri = URLDecoder.decode(uri, "UTF-8");
+ }
+ // sanitize and mask uri so we don't see passwords
+ uri = URISupport.sanitizeUri(uri);
+ table.addRow().addContent(camelContext.getName(), uri,
getEndpointState(endpoint));
}
- // sanitize and mask uri so we don't see passwords
- uri = URISupport.sanitizeUri(uri);
- table.addRow().addContent(camelContext.getName(), uri,
getEndpointState(endpoint));
}
table.print(System.out);
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/EndpointStats.java
b/shell/src/main/java/org/apache/camel/karaf/shell/EndpointStats.java
index 9720569a3..5b6fbb805 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/EndpointStats.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/EndpointStats.java
@@ -26,12 +26,13 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.support.table.ShellTable;
import java.net.URLDecoder;
+import java.util.List;
@Command(scope = "camel", name = "endpoint-stats", description = "List the
statistics of the Camel endpoints")
@Service
public class EndpointStats extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The name of the
Camel context (support wildcard)", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The name of the
Camel context (support wildcard)", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String name;
@@ -52,41 +53,38 @@ public class EndpointStats extends CamelCommandSupport
implements Action {
table.column("Dynamic");
table.column("Total #");
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
+
+ for (CamelContext camelContext : camelContexts) {
+ if (camelContext.getRuntimeEndpointRegistry() != null) {
+ EndpointRegistry endpointRegistry =
camelContext.getEndpointRegistry();
+ for (RuntimeEndpointRegistry.Statistic stat :
camelContext.getRuntimeEndpointRegistry().getEndpointStatistics()) {
+ String uri = stat.getUri();
+ String routeId = stat.getRouteId();
+ String direction = stat.getDirection();
+ boolean isStatic = endpointRegistry.isStatic(uri);
+ boolean isDynamic = endpointRegistry.isDynamic(uri);
+ long hits = stat.getHits();
+
+ if (decode) {
+ // decode uri so it's more human readable
+ uri = URLDecoder.decode(uri, "UTF-8");
+ }
+ // sanitize and mask uri so we don't see passwords
+ uri = URISupport.sanitizeUri(uri);
+
+ // should we filter ?
+ if (isValidRow(direction, Boolean.toString(isStatic),
Boolean.toString(isDynamic))) {
+ table.addRow().addContent(camelContext.getName(),
+ uri,
+ routeId,
+ direction,
+ isStatic,
+ isDynamic,
+ hits);
+ }
- if (camelContext == null) {
- System.err.println("Camel context " + name + " not found");
- return null;
- }
-
- if (camelContext.getRuntimeEndpointRegistry() != null) {
- EndpointRegistry endpointRegistry =
camelContext.getEndpointRegistry();
- for (RuntimeEndpointRegistry.Statistic stat :
camelContext.getRuntimeEndpointRegistry().getEndpointStatistics()) {
- String uri = stat.getUri();
- String routeId = stat.getRouteId();
- String direction = stat.getDirection();
- boolean isStatic = endpointRegistry.isStatic(uri);
- boolean isDynamic = endpointRegistry.isDynamic(uri);
- long hits = stat.getHits();
-
- if (decode) {
- // decode uri so it's more human readable
- uri = URLDecoder.decode(uri, "UTF-8");
}
- // sanitize and mask uri so we don't see passwords
- uri = URISupport.sanitizeUri(uri);
-
- // should we filter ?
- if (isValidRow(direction, Boolean.toString(isStatic),
Boolean.toString(isDynamic))) {
- table.addRow().addContent(camelContext.getName(),
- uri,
- routeId,
- direction,
- isStatic,
- isDynamic,
- hits);
- }
-
}
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/RestApiDoc.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RestApiDoc.java
index 789a334c9..7ab111df6 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RestApiDoc.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RestApiDoc.java
@@ -24,24 +24,26 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "rest-api-doc", description = "List the Camel
REST services API documentation (requires camel-swagger-java on classpath)")
@Service
public class RestApiDoc extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The Camel context
name where to look for the REST services", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The Camel context
name where to look for the REST services", required = false, multiValued =
false)
@Completion(CamelContextCompleter.class)
String name;
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
+ List<CamelContext> camelContexts = getCamelContext(name);
- if (camelContext == null) {
+ if (camelContexts.size() != 1) {
System.err.println("Camel context " + name + " not found");
return null;
}
- String json = camelContext.getRestRegistry().apiDocAsJson();
+ String json = camelContexts.get(0).getRestRegistry().apiDocAsJson();
if (json != null) {
System.out.println(json);
} else {
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/RestRegistryList.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RestRegistryList.java
index a4cc16ded..b1beffdb3 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RestRegistryList.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RestRegistryList.java
@@ -50,13 +50,13 @@ public class RestRegistryList extends CamelCommandSupport
implements Action {
table.column("Method");
table.column("State");
- CamelContext camelContext = getCamelContext(name);
- if (camelContext == null) {
+ List<CamelContext> camelContexts = getCamelContext(name);
+ if (camelContexts.size() != 1) {
System.err.println("Camel context " + name + " not found");
return null;
}
- List<RestRegistry.RestService> services = new
ArrayList<>(camelContext.getRestRegistry().listAllRestServices());
+ List<RestRegistry.RestService> services = new
ArrayList<>(camelContexts.get(0).getRestRegistry().listAllRestServices());
Collections.sort(services, new Comparator<RestRegistry.RestService>() {
@Override
public int compare(RestRegistry.RestService s1,
RestRegistry.RestService s2) {
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/RouteList.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RouteList.java
index 149bb856f..6af7e4cf1 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RouteList.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RouteList.java
@@ -29,6 +29,8 @@ import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.apache.karaf.shell.support.table.ShellTable;
+import java.util.List;
+
@Command(scope = "camel", name = "route-list", description = "List Camel
routes")
@Service
public class RouteList extends CamelCommandSupport implements Action {
@@ -48,30 +50,28 @@ public class RouteList extends CamelCommandSupport
implements Action {
table.column("Inflight #");
table.column("Uptime");
- CamelContext camelContext = getCamelContext(name);
- if (camelContext == null) {
- System.err.println("Camel context " + name + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(name);
- for (Route route : camelContext.getRoutes()) {
- ManagedCamelContext mcc =
camelContext.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class);
- long exchangesTotal = 0;
- long exchangesInflight = 0;
- long exchangesFailed = 0;
- if (mcc != null && mcc.getManagedCamelContext() != null) {
- ManagedRouteMBean mr = mcc.getManagedRoute(route.getId());
- exchangesFailed = mr.getExchangesFailed();
- exchangesInflight = mr.getExchangesInflight();
- exchangesTotal = mr.getExchangesTotal();
+ for (CamelContext camelContext : camelContexts) {
+ for (Route route : camelContext.getRoutes()) {
+ ManagedCamelContext mcc =
camelContext.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class);
+ long exchangesTotal = 0;
+ long exchangesInflight = 0;
+ long exchangesFailed = 0;
+ if (mcc != null && mcc.getManagedCamelContext() != null) {
+ ManagedRouteMBean mr = mcc.getManagedRoute(route.getId());
+ exchangesFailed = mr.getExchangesFailed();
+ exchangesInflight = mr.getExchangesInflight();
+ exchangesTotal = mr.getExchangesTotal();
+ }
+ table.addRow().addContent(route.getCamelContext().getName(),
+ route.getId(),
+ getRouteState(route),
+ exchangesTotal,
+ exchangesFailed,
+ exchangesInflight,
+ route.getUptime());
}
- table.addRow().addContent(route.getCamelContext().getName(),
- route.getId(),
- getRouteState(route),
- exchangesTotal,
- exchangesFailed,
- exchangesInflight,
- route.getUptime());
}
table.print(System.out);
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/RouteResetStats.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RouteResetStats.java
index ad44adfad..562174e77 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RouteResetStats.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RouteResetStats.java
@@ -27,6 +27,7 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+import java.util.List;
import java.util.Set;
@Command(scope = "camel", name = "route-reset-stats", description = "Reset
route performance stats from a Camel context")
@@ -40,23 +41,21 @@ public class RouteResetStats extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(name);
- if (camelContext == null) {
- System.err.println("Camel context " + name + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(name);
- ManagementAgent agent =
camelContext.getManagementStrategy().getManagementAgent();
- if (agent != null) {
- MBeanServer mBeanServer = agent.getMBeanServer();
+ for (CamelContext camelContext : camelContexts) {
+ ManagementAgent agent =
camelContext.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
- // reset route mbeans
- ObjectName query =
ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
- Set<ObjectName> mBeans = mBeanServer.queryNames(query, null);
- for (ObjectName routeMBean : mBeans) {
- String camelId = (String) mBeanServer.getAttribute(routeMBean,
"CamelId");
- if (camelId != null && camelId.equals(camelContext.getName()))
{
- mBeanServer.invoke(routeMBean, "reset", new
Object[]{true}, new String[]{"boolean"});
+ // reset route mbeans
+ ObjectName query =
ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
+ Set<ObjectName> mBeans = mBeanServer.queryNames(query, null);
+ for (ObjectName routeMBean : mBeans) {
+ String camelId = (String)
mBeanServer.getAttribute(routeMBean, "CamelId");
+ if (camelId != null &&
camelId.equals(camelContext.getName())) {
+ mBeanServer.invoke(routeMBean, "reset", new
Object[]{true}, new String[]{"boolean"});
+ }
}
}
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/RouteResume.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RouteResume.java
index 24984b2be..f61676b36 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RouteResume.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RouteResume.java
@@ -25,11 +25,13 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "route-resume", description = "Resume a Camel
route")
@Service
public class RouteResume extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The Camel context
name", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The Camel context
name", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String context;
@@ -39,13 +41,11 @@ public class RouteResume extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(context);
- if (camelContext == null) {
- System.err.println("Camel context " + context + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(context);
- camelContext.getRouteController().resumeRoute(route);
+ for (CamelContext camelContext : camelContexts) {
+ camelContext.getRouteController().resumeRoute(route);
+ }
return null;
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/RouteStart.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RouteStart.java
index f1e1837e3..eab1d02e9 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RouteStart.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RouteStart.java
@@ -25,11 +25,13 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "route-start", description = "Start a Camel
route")
@Service
public class RouteStart extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The Camel context
name", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The Camel context
name", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String context;
@@ -39,13 +41,11 @@ public class RouteStart extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(context);
- if (camelContext == null) {
- System.err.println("Camel context " + context + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(context);
- camelContext.getRouteController().startRoute(route);
+ for (CamelContext camelContext : camelContexts) {
+ camelContext.getRouteController().startRoute(route);
+ }
return null;
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/RouteStop.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RouteStop.java
index 61bd47435..dd046a15a 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RouteStop.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RouteStop.java
@@ -25,11 +25,13 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "route-stop", description = "Stop a Camel
route")
@Service
public class RouteStop extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The Camel context
name", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The Camel context
name", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String context;
@@ -39,13 +41,11 @@ public class RouteStop extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(context);
- if (camelContext == null) {
- System.err.println("Camel context " + context + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(context);
- camelContext.getRouteController().stopRoute(route);
+ for (CamelContext camelContext : camelContexts) {
+ camelContext.getRouteController().stopRoute(route);
+ }
return null;
}
diff --git a/shell/src/main/java/org/apache/camel/karaf/shell/RouteSuspend.java
b/shell/src/main/java/org/apache/camel/karaf/shell/RouteSuspend.java
index 57d8d7233..3931d8d98 100644
--- a/shell/src/main/java/org/apache/camel/karaf/shell/RouteSuspend.java
+++ b/shell/src/main/java/org/apache/camel/karaf/shell/RouteSuspend.java
@@ -25,11 +25,13 @@ import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import java.util.List;
+
@Command(scope = "camel", name = "route-suspend", description = "Suspend a
Camel route")
@Service
public class RouteSuspend extends CamelCommandSupport implements Action {
- @Argument(index = 0, name = "context", description = "The Camel context
name", required = true, multiValued = false)
+ @Argument(index = 0, name = "context", description = "The Camel context
name", required = false, multiValued = false)
@Completion(CamelContextCompleter.class)
String context;
@@ -39,13 +41,11 @@ public class RouteSuspend extends CamelCommandSupport
implements Action {
@Override
public Object execute() throws Exception {
- CamelContext camelContext = getCamelContext(context);
- if (camelContext == null) {
- System.err.println("Camel context " + context + " not found");
- return null;
- }
+ List<CamelContext> camelContexts = getCamelContext(context);
- camelContext.getRouteController().suspendRoute(route);
+ for (CamelContext camelContext : camelContexts) {
+ camelContext.getRouteController().suspendRoute(route);
+ }
return null;
}
diff --git
a/shell/src/main/java/org/apache/camel/karaf/shell/completers/RouteCompleter.java
b/shell/src/main/java/org/apache/camel/karaf/shell/completers/RouteCompleter.java
index 6018ce7d8..11dd3d9cc 100644
---
a/shell/src/main/java/org/apache/camel/karaf/shell/completers/RouteCompleter.java
+++
b/shell/src/main/java/org/apache/camel/karaf/shell/completers/RouteCompleter.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.karaf.shell.completers;
+import org.apache.camel.CamelContext;
import org.apache.camel.Route;
import org.apache.camel.karaf.shell.CamelCommandSupport;
import org.apache.karaf.shell.api.action.lifecycle.Service;
@@ -42,8 +43,10 @@ public class RouteCompleter extends CamelCommandSupport
implements Completer {
try {
StringsCompleter delegate = new StringsCompleter();
- for (Route route : getCamelContext(contextName).getRoutes()) {
- delegate.getStrings().add(route.getRouteId());
+ for (CamelContext camelContext : getCamelContext(contextName)) {
+ for (Route route : camelContext.getRoutes()) {
+ delegate.getStrings().add(route.getRouteId());
+ }
}
return delegate.complete(session, commandLine, candidates);
} catch (Exception e) {