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/11 10:53:49 UTC
[1/2] camel git commit: CAMEL-8044: Camel commands should be more
reusable for remote JVMs
Repository: camel
Updated Branches:
refs/heads/master a9eb71695 -> f8b97b4c5
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/792ce5c5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/792ce5c5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/792ce5c5
Branch: refs/heads/master
Commit: 792ce5c5cc0af486b39471cf68206a2e95d3a037
Parents: a9eb716
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Dec 11 10:48:25 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Dec 11 10:48:25 2014 +0100
----------------------------------------------------------------------
.../camel/commands/AbstractCamelController.java | 422 -----------------
.../camel/commands/AbstractContextCommand.java | 27 +-
.../commands/AbstractLocalCamelController.java | 456 +++++++++++++++++++
.../apache/camel/commands/CamelController.java | 29 +-
.../camel/commands/ContextListCommand.java | 2 +-
.../camel/commands/LocalCamelController.java | 41 ++
.../camel/commands/DummyCamelController.java | 6 +-
.../completers/CamelCompleterSupport.java | 6 +-
.../completers/CamelContextCompleter.java | 2 +-
.../commands/internal/CamelControllerImpl.java | 12 +-
10 files changed, 538 insertions(+), 465 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/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 df0fb78..deea95d 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
@@ -17,33 +17,16 @@
package org.apache.camel.commands;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
-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.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;
-import org.apache.camel.model.ModelHelper;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.camel.model.rest.RestDefinition;
-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;
/**
@@ -53,389 +36,6 @@ public abstract class AbstractCamelController implements CamelController {
private CamelComponentCatalog catalog = new DefaultCamelComponentCatalog();
- public CamelContext getCamelContext(String name) throws Exception {
- for (CamelContext camelContext : this.getCamelContexts()) {
- if (camelContext.getName().equals(name)) {
- return camelContext;
- }
- }
- 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 String getCamelContextStatsAsXml(String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return null;
- }
-
- ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
- if (agent != null) {
- MBeanServer mBeanServer = agent.getMBeanServer();
- ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=context,*");
- Set<ObjectName> set = mBeanServer.queryNames(query, null);
- for (ObjectName contextMBean : set) {
- String camelId = (String) mBeanServer.getAttribute(contextMBean, "CamelId");
- if (camelId != null && camelId.equals(context.getName())) {
- String xml = (String) mBeanServer.invoke(contextMBean, "dumpRoutesStatsAsXml", new Object[]{fullStats, includeProcessors}, new String[]{"boolean", "boolean"});
- return xml;
- }
- }
- }
- return null;
- }
-
- public void startContext(String camelContextName) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.start();
- }
- }
-
- public void stopContext(String camelContextName) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.stop();
- }
- }
-
- public void suspendContext(String camelContextName) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.suspend();
- }
- }
-
- public void resumeContext(String camelContextName) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.resume();
- }
- }
-
- public List<Map<String, String>> getRoutes(String camelContextName) throws Exception {
- return getRoutes(camelContextName, null);
- }
-
- 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)) {
- 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);
- }
- }
- }
- } else {
- List<Map<String, String>> camelContexts = this.getCamelContexts2();
- for (Map<String, String> row : camelContexts) {
- List<Map<String, String>> routes = getRoutes(row.get("name"), filter);
- answer.addAll(routes);
- }
- }
-
- // sort the list
- Collections.sort(answer, new Comparator<Map<String, String>>() {
- @Override
- public int compare(Map<String, String> o1, Map<String, String> o2) {
- // group by camel context first, then by route name
- 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.get("routeId").compareTo(o2.get("routeId"));
- }
- return answer;
- }
- });
- return answer;
- }
-
- public void resetRouteStats(String camelContextName) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return;
- }
-
- 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"});
- }
- }
- }
- }
-
- public void startRoute(String camelContextName, String routeId) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.startRoute(routeId);
- }
- }
-
- public void stopRoute(String camelContextName, String routeId) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.stopRoute(routeId);
- }
- }
-
- public void suspendRoute(String camelContextName, String routeId) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.suspendRoute(routeId);
- }
- }
-
- public void resumeRoute(String camelContextName, String routeId) throws Exception {
- CamelContext context = getCamelContext(camelContextName);
- if (context != null) {
- context.resumeRoute(routeId);
- }
- }
-
- @SuppressWarnings("deprecation")
- public String getRouteModelAsXml(String routeId, String camelContextName) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return null;
- }
- RouteDefinition route = context.getRouteDefinition(routeId);
- if (route == null) {
- return null;
- }
-
- return ModelHelper.dumpModelAsXml(route);
- }
-
- @Override
- public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return null;
- }
-
- 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;
- }
- }
- }
- return null;
- }
-
- @SuppressWarnings("deprecation")
- public String getRestModelAsXml(String camelContextName) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return null;
- }
-
- List<RestDefinition> rests = context.getRestDefinitions();
- if (rests == null || rests.isEmpty()) {
- return null;
- }
- // use a rests definition to dump the rests
- RestsDefinition def = new RestsDefinition();
- def.setRests(rests);
- return ModelHelper.dumpModelAsXml(def);
- }
-
- public List<Map<String, String>> getEndpoints(String camelContextName) throws Exception {
- List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
-
- if (camelContextName != null) {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context != null) {
- List<Endpoint> endpoints = new ArrayList<Endpoint>(context.getEndpoints());
- // sort routes
- Collections.sort(endpoints, new Comparator<Endpoint>() {
- @Override
- public int compare(Endpoint o1, Endpoint o2) {
- return o1.getEndpointKey().compareTo(o2.getEndpointKey());
- }
- });
- 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;
- }
-
- public List<Map<String, String>> getRestServices(String camelContextName) throws Exception {
- List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
-
- if (camelContextName != null) {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context != null) {
- List<RestRegistry.RestService> services = new ArrayList<RestRegistry.RestService>(context.getRestRegistry().listAllRestServices());
- Collections.sort(services, new Comparator<RestRegistry.RestService>() {
- @Override
- public int compare(RestRegistry.RestService o1, RestRegistry.RestService o2) {
- return o1.getUrl().compareTo(o2.getUrl());
- }
- });
- for (RestRegistry.RestService service : services) {
- Map<String, String> row = new LinkedHashMap<String, String>();
- row.put("basePath", service.getBasePath());
- row.put("baseUrl", service.getBaseUrl());
- row.put("consumes", service.getConsumes());
- row.put("description", service.getDescription());
- row.put("inType", service.getInType());
- row.put("method", service.getMethod());
- row.put("outType", service.getOutType());
- row.put("produces", service.getProduces());
- row.put("routeId", service.getRouteId());
- row.put("state", service.getState());
- row.put("uriTemplate", service.getUriTemplate());
- row.put("url", service.getUrl());
- answer.add(row);
- }
- }
- }
- return answer;
- }
-
- public String explainEndpointAsJSon(String camelContextName, String uri, boolean allOptions) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return null;
- }
- return context.explainEndpointJson(uri, allOptions);
- }
-
- public List<Map<String, String>> listComponents(String camelContextName) throws Exception {
- CamelContext context = this.getCamelContext(camelContextName);
- if (context == null) {
- return null;
- }
-
- List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
-
- // find all components
- Map<String, Properties> components = context.findComponents();
-
- // gather component detail for each component
- for (Map.Entry<String, Properties> entry : components.entrySet()) {
- String name = entry.getKey();
- String description = null;
- String label = null;
- // the status can be:
- // - loaded = in use
- // - classpath = on the classpath
- // - release = available from the Apache Camel release
- String status = context.hasComponent(name) != null ? "in use" : "on classpath";
- String type = null;
- String groupId = null;
- String artifactId = null;
- String version = null;
-
- // load component json data, and parse it to gather the component meta-data
- String json = context.getComponentParameterJsonSchema(name);
- List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("component", json, false);
- for (Map<String, String> row : rows) {
- if (row.containsKey("description")) {
- description = row.get("description");
- } else if (row.containsKey("label")) {
- label = row.get("label");
- } else if (row.containsKey("javaType")) {
- type = row.get("javaType");
- } else if (row.containsKey("groupId")) {
- groupId = row.get("groupId");
- } else if (row.containsKey("artifactId")) {
- artifactId = row.get("artifactId");
- } else if (row.containsKey("version")) {
- version = row.get("version");
- }
- }
-
- Map<String, String> row = new HashMap<String, String>();
- row.put("name", name);
- row.put("status", status);
- if (description != null) {
- row.put("description", description);
- }
- if (label != null) {
- row.put("label", label);
- }
- if (type != null) {
- row.put("type", type);
- }
- if (groupId != null) {
- row.put("groupId", groupId);
- }
- if (artifactId != null) {
- row.put("artifactId", artifactId);
- }
- if (version != null) {
- row.put("version", version);
- }
-
- answer.add(row);
- }
-
- return answer;
- }
-
@Override
public List<Map<String, String>> listComponentsCatalog(String filter) throws Exception {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
@@ -527,26 +127,4 @@ 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();
- }
-
- 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/792ce5c5/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
index 93eb53f..a91d936 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractContextCommand.java
@@ -17,6 +17,8 @@
package org.apache.camel.commands;
import java.io.PrintStream;
+import java.util.List;
+import java.util.Map;
import org.apache.camel.CamelContext;
@@ -36,7 +38,30 @@ public abstract class AbstractContextCommand extends AbstractCamelCommand {
@Override
public Object execute(CamelController camelController, PrintStream out, PrintStream err) throws Exception {
- CamelContext camelContext = camelController.getCamelContext(context);
+ if (camelController instanceof LocalCamelController) {
+ return executeLocal((LocalCamelController) camelController, out, err);
+ } else {
+ boolean found = false;
+ List<Map<String, String>> contexts = camelController.getCamelContexts();
+ for (Map<String, String> entry : contexts) {
+ String name = entry.get("name");
+ if (context.equals(name)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ err.println("Camel context " + context + " not found.");
+ return null;
+ } else {
+ return performContextCommand(camelController, context, out, err);
+ }
+ }
+ }
+
+ protected Object executeLocal(LocalCamelController camelController, PrintStream out, PrintStream err) throws Exception {
+ CamelContext camelContext = camelController.getLocalCamelContext(context);
if (camelContext == null) {
err.println("Camel context " + context + " not found.");
return null;
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
new file mode 100644
index 0000000..fe9be97
--- /dev/null
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
@@ -0,0 +1,456 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.commands;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+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.ServiceStatus;
+import org.apache.camel.StatefulService;
+import org.apache.camel.model.ModelHelper;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+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;
+
+/**
+ * Abstract {@link org.apache.camel.commands.LocalCamelController} that implementators should extend when implemeting
+ * a controller that runs locally in the same JVM as Camel.
+ */
+public abstract class AbstractLocalCamelController extends AbstractCamelController implements LocalCamelController {
+
+ public CamelContext getLocalCamelContext(String name) throws Exception {
+ for (CamelContext camelContext : this.getLocalCamelContexts()) {
+ if (camelContext.getName().equals(name)) {
+ return camelContext;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Map<String, Object> getCamelContextInformation(String name) throws Exception {
+ Map<String, Object> answer = new LinkedHashMap<String, Object>();
+ CamelContext context = getLocalCamelContext(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 String getCamelContextStatsAsXml(String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return null;
+ }
+
+ ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
+ ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=context,*");
+ Set<ObjectName> set = mBeanServer.queryNames(query, null);
+ for (ObjectName contextMBean : set) {
+ String camelId = (String) mBeanServer.getAttribute(contextMBean, "CamelId");
+ if (camelId != null && camelId.equals(context.getName())) {
+ String xml = (String) mBeanServer.invoke(contextMBean, "dumpRoutesStatsAsXml", new Object[]{fullStats, includeProcessors}, new String[]{"boolean", "boolean"});
+ return xml;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void startContext(String camelContextName) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.start();
+ }
+ }
+
+ public void stopContext(String camelContextName) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.stop();
+ }
+ }
+
+ public void suspendContext(String camelContextName) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.suspend();
+ }
+ }
+
+ public void resumeContext(String camelContextName) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.resume();
+ }
+ }
+
+ public List<Map<String, String>> getRoutes(String camelContextName) throws Exception {
+ return getRoutes(camelContextName, null);
+ }
+
+ 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.getLocalCamelContext(camelContextName);
+ if (context != null) {
+ for (Route route : context.getRoutes()) {
+ if (filter == null || route.getId().matches(filter)) {
+ 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);
+ }
+ }
+ }
+ } else {
+ List<Map<String, String>> camelContexts = this.getCamelContexts();
+ for (Map<String, String> row : camelContexts) {
+ List<Map<String, String>> routes = getRoutes(row.get("name"), filter);
+ answer.addAll(routes);
+ }
+ }
+
+ // sort the list
+ Collections.sort(answer, new Comparator<Map<String, String>>() {
+ @Override
+ public int compare(Map<String, String> o1, Map<String, String> o2) {
+ // group by camel context first, then by route name
+ 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.get("routeId").compareTo(o2.get("routeId"));
+ }
+ return answer;
+ }
+ });
+ return answer;
+ }
+
+ public void resetRouteStats(String camelContextName) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return;
+ }
+
+ 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"});
+ }
+ }
+ }
+ }
+
+ public void startRoute(String camelContextName, String routeId) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.startRoute(routeId);
+ }
+ }
+
+ public void stopRoute(String camelContextName, String routeId) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.stopRoute(routeId);
+ }
+ }
+
+ public void suspendRoute(String camelContextName, String routeId) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.suspendRoute(routeId);
+ }
+ }
+
+ public void resumeRoute(String camelContextName, String routeId) throws Exception {
+ CamelContext context = getLocalCamelContext(camelContextName);
+ if (context != null) {
+ context.resumeRoute(routeId);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public String getRouteModelAsXml(String routeId, String camelContextName) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return null;
+ }
+ RouteDefinition route = context.getRouteDefinition(routeId);
+ if (route == null) {
+ return null;
+ }
+
+ return ModelHelper.dumpModelAsXml(route);
+ }
+
+ @Override
+ public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return null;
+ }
+
+ 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;
+ }
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ public String getRestModelAsXml(String camelContextName) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return null;
+ }
+
+ List<RestDefinition> rests = context.getRestDefinitions();
+ if (rests == null || rests.isEmpty()) {
+ return null;
+ }
+ // use a rests definition to dump the rests
+ RestsDefinition def = new RestsDefinition();
+ def.setRests(rests);
+ return ModelHelper.dumpModelAsXml(def);
+ }
+
+ public List<Map<String, String>> getEndpoints(String camelContextName) throws Exception {
+ List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
+
+ if (camelContextName != null) {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context != null) {
+ List<Endpoint> endpoints = new ArrayList<Endpoint>(context.getEndpoints());
+ // sort routes
+ Collections.sort(endpoints, new Comparator<Endpoint>() {
+ @Override
+ public int compare(Endpoint o1, Endpoint o2) {
+ return o1.getEndpointKey().compareTo(o2.getEndpointKey());
+ }
+ });
+ 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;
+ }
+
+ public List<Map<String, String>> getRestServices(String camelContextName) throws Exception {
+ List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
+
+ if (camelContextName != null) {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context != null) {
+ List<RestRegistry.RestService> services = new ArrayList<RestRegistry.RestService>(context.getRestRegistry().listAllRestServices());
+ Collections.sort(services, new Comparator<RestRegistry.RestService>() {
+ @Override
+ public int compare(RestRegistry.RestService o1, RestRegistry.RestService o2) {
+ return o1.getUrl().compareTo(o2.getUrl());
+ }
+ });
+ for (RestRegistry.RestService service : services) {
+ Map<String, String> row = new LinkedHashMap<String, String>();
+ row.put("basePath", service.getBasePath());
+ row.put("baseUrl", service.getBaseUrl());
+ row.put("consumes", service.getConsumes());
+ row.put("description", service.getDescription());
+ row.put("inType", service.getInType());
+ row.put("method", service.getMethod());
+ row.put("outType", service.getOutType());
+ row.put("produces", service.getProduces());
+ row.put("routeId", service.getRouteId());
+ row.put("state", service.getState());
+ row.put("uriTemplate", service.getUriTemplate());
+ row.put("url", service.getUrl());
+ answer.add(row);
+ }
+ }
+ }
+ return answer;
+ }
+
+ public String explainEndpointAsJSon(String camelContextName, String uri, boolean allOptions) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return null;
+ }
+ return context.explainEndpointJson(uri, allOptions);
+ }
+
+ public List<Map<String, String>> listComponents(String camelContextName) throws Exception {
+ CamelContext context = this.getLocalCamelContext(camelContextName);
+ if (context == null) {
+ return null;
+ }
+
+ List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
+
+ // find all components
+ Map<String, Properties> components = context.findComponents();
+
+ // gather component detail for each component
+ for (Map.Entry<String, Properties> entry : components.entrySet()) {
+ String name = entry.getKey();
+ String description = null;
+ String label = null;
+ // the status can be:
+ // - loaded = in use
+ // - classpath = on the classpath
+ // - release = available from the Apache Camel release
+ String status = context.hasComponent(name) != null ? "in use" : "on classpath";
+ String type = null;
+ String groupId = null;
+ String artifactId = null;
+ String version = null;
+
+ // load component json data, and parse it to gather the component meta-data
+ String json = context.getComponentParameterJsonSchema(name);
+ List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("component", json, false);
+ for (Map<String, String> row : rows) {
+ if (row.containsKey("description")) {
+ description = row.get("description");
+ } else if (row.containsKey("label")) {
+ label = row.get("label");
+ } else if (row.containsKey("javaType")) {
+ type = row.get("javaType");
+ } else if (row.containsKey("groupId")) {
+ groupId = row.get("groupId");
+ } else if (row.containsKey("artifactId")) {
+ artifactId = row.get("artifactId");
+ } else if (row.containsKey("version")) {
+ version = row.get("version");
+ }
+ }
+
+ Map<String, String> row = new HashMap<String, String>();
+ row.put("name", name);
+ row.put("status", status);
+ if (description != null) {
+ row.put("description", description);
+ }
+ if (label != null) {
+ row.put("label", label);
+ }
+ if (type != null) {
+ row.put("type", type);
+ }
+ if (groupId != null) {
+ row.put("groupId", groupId);
+ }
+ if (artifactId != null) {
+ row.put("artifactId", artifactId);
+ }
+ if (version != null) {
+ row.put("version", version);
+ }
+
+ answer.add(row);
+ }
+
+ 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();
+ }
+
+ 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/792ce5c5/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 dc696a5..0065fdf 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
@@ -20,37 +20,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.camel.CamelContext;
-
/**
* CamelController interface defines the expected behaviors to manipulate Camel resources (context, route, etc).
*/
public interface CamelController {
- // TODO: migrate camel context commands
- // TODO: fix classloading in karaf for explain-endpoint
- // TODO: AbstractCamelController should have a LocalAbstractCamelController
- // .. and then the AbstractCamelController is pure base, that can be used for remotes
-
- /**
- * Get the list of Camel context.
- *
- * @return the list of Camel contexts.
- * @throws java.lang.Exception can be thrown
- */
- @Deprecated
- 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
- */
- @Deprecated
- CamelContext getCamelContext(String name) throws Exception;
-
/**
* Gets information about a given Camel context by the given name.
*
@@ -66,8 +40,7 @@ public interface CamelController {
* @return a list of key/value pairs with CamelContext information
* @throws java.lang.Exception can be thrown
*/
- // TODO: rename
- List<Map<String, String>> getCamelContexts2() throws Exception;
+ List<Map<String, String>> getCamelContexts() throws Exception;
/**
* Returns detailed CamelContext and route statistics as XML identified by a ID and a Camel context.
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/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 f4f7ecf..4ce3e37 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
@@ -40,7 +40,7 @@ public class ContextListCommand extends AbstractCamelCommand {
@Override
public Object execute(CamelController camelController, PrintStream out, PrintStream err) throws Exception {
- final List<Map<String, String>> camelContexts = camelController.getCamelContexts2();
+ final List<Map<String, String>> camelContexts = camelController.getCamelContexts();
final Map<String, Integer> columnWidths = computeColumnWidths(camelContexts);
final String headerFormat = buildFormatString(columnWidths, true);
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/LocalCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/LocalCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/LocalCamelController.java
new file mode 100644
index 0000000..8352b7e
--- /dev/null
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/LocalCamelController.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.commands;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+
+public interface LocalCamelController extends CamelController{
+
+ /**
+ * Get the list of Camel context.
+ *
+ * @return the list of Camel contexts.
+ * @throws Exception can be thrown
+ */
+ List<CamelContext> getLocalCamelContexts() 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 Exception can be thrown
+ */
+ CamelContext getLocalCamelContext(String name) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/DummyCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/DummyCamelController.java b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/DummyCamelController.java
index 12f2d7d..9d27d0f 100644
--- a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/DummyCamelController.java
+++ b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/DummyCamelController.java
@@ -23,7 +23,7 @@ import java.util.Map;
import org.apache.camel.CamelContext;
-public class DummyCamelController extends AbstractCamelController {
+public class DummyCamelController extends AbstractLocalCamelController {
private CamelContext camelContext;
@@ -32,14 +32,14 @@ public class DummyCamelController extends AbstractCamelController {
}
@Override
- public List<CamelContext> getCamelContexts() {
+ public List<CamelContext> getLocalCamelContexts() {
List<CamelContext> answer = new ArrayList<CamelContext>(1);
answer.add(camelContext);
return answer;
}
@Override
- public List<Map<String, String>> getCamelContexts2() throws Exception {
+ public List<Map<String, String>> getCamelContexts() throws Exception {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>(1);
Map<String, String> row = new LinkedHashMap<String, String>();
row.put("name", camelContext.getName());
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
index 780eb1b..fa5e5cb 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelCompleterSupport.java
@@ -16,7 +16,7 @@
*/
package org.apache.camel.karaf.commands.completers;
-import org.apache.camel.commands.CamelController;
+import org.apache.camel.commands.LocalCamelController;
import org.apache.karaf.shell.console.Completer;
/**
@@ -24,9 +24,9 @@ import org.apache.karaf.shell.console.Completer;
*/
public abstract class CamelCompleterSupport implements Completer {
- protected CamelController camelController;
+ protected LocalCamelController camelController;
- public void setCamelController(CamelController camelController) {
+ public void setCamelController(LocalCamelController camelController) {
this.camelController = camelController;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelContextCompleter.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelContextCompleter.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelContextCompleter.java
index 54ced21..266f25c 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelContextCompleter.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/completers/CamelContextCompleter.java
@@ -30,7 +30,7 @@ public class CamelContextCompleter extends CamelCompleterSupport {
public int complete(String buffer, int cursor, List candidates) {
try {
StringsCompleter delegate = new StringsCompleter();
- List<CamelContext> camelContexts = camelController.getCamelContexts();
+ List<CamelContext> camelContexts = camelController.getLocalCamelContexts();
for (CamelContext camelContext : camelContexts) {
delegate.getStrings().add(camelContext.getName());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/792ce5c5/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 5712137..b026ff0 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
@@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.camel.CamelContext;
-import org.apache.camel.commands.AbstractCamelController;
+import org.apache.camel.commands.AbstractLocalCamelController;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
/**
* Implementation of <code>CamelController</code>.
*/
-public class CamelControllerImpl extends AbstractCamelController {
+public class CamelControllerImpl extends AbstractLocalCamelController {
private static final Logger LOG = LoggerFactory.getLogger(CamelControllerImpl.class);
@@ -44,7 +44,7 @@ public class CamelControllerImpl extends AbstractCamelController {
}
@Override
- public List<CamelContext> getCamelContexts() {
+ public List<CamelContext> getLocalCamelContexts() {
List<CamelContext> camelContexts = new ArrayList<CamelContext>();
try {
ServiceReference<?>[] references = bundleContext.getServiceReferences(CamelContext.class.getName(), null);
@@ -74,10 +74,10 @@ public class CamelControllerImpl extends AbstractCamelController {
}
@Override
- public List<Map<String, String>> getCamelContexts2() throws Exception {
- List<Map<String, String>> answer = new ArrayList<Map<String, String>>(1);
+ public List<Map<String, String>> getCamelContexts() throws Exception {
+ List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
- List<CamelContext> camelContexts = getCamelContexts();
+ List<CamelContext> camelContexts = getLocalCamelContexts();
for (CamelContext camelContext : camelContexts) {
Map<String, String> row = new LinkedHashMap<String, String>();
row.put("name", camelContext.getName());
[2/2] 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/f8b97b4c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f8b97b4c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f8b97b4c
Branch: refs/heads/master
Commit: f8b97b4c5fd849a3cd1897978de2db9b4d51e1eb
Parents: 792ce5c
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Dec 11 10:53:40 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Dec 11 10:53:40 2014 +0100
----------------------------------------------------------------------
.../org/apache/camel/commands/ContextInfoCommand.java | 11 ++++++-----
.../org/apache/camel/commands/RouteInfoCommand.java | 13 +++----------
2 files changed, 9 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f8b97b4c/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 caa085d..6722ab9 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
@@ -90,13 +90,14 @@ public class ContextInfoCommand extends AbstractCamelCommand {
out.println(stringEscape.unescapeJava("\t" + key + " = " + entry.getValue()));
}
}
- out.println("");
- out.println(stringEscape.unescapeJava("\u001B[1mAdvanced\u001B[0m"));
- 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 (verbose) {
+ out.println("");
+ out.println(stringEscape.unescapeJava("\u001B[1mAdvanced\u001B[0m"));
+ out.println(stringEscape.unescapeJava("\tClassResolver: " + row.get("classResolver")));
+ out.println(stringEscape.unescapeJava("\tPackageScanClassResolver: " + row.get("packageScanClassResolver")));
+ out.println(stringEscape.unescapeJava("\tApplicationContextClassLoader: " + row.get("applicationContextClassLoader")));
+
printStatistics(camelController, out);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f8b97b4c/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteInfoCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteInfoCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteInfoCommand.java
index 24c1238..fb016f3 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteInfoCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/RouteInfoCommand.java
@@ -23,7 +23,6 @@ import java.util.Date;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
-import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.RouteStatDump;
import static org.apache.camel.util.ObjectHelper.isEmpty;
@@ -52,8 +51,6 @@ public class RouteInfoCommand extends AbstractRouteCommand {
public void executeOnRoute(CamelController camelController, String contextName, String routeId, PrintStream out, PrintStream err) throws Exception {
out.println(stringEscape.unescapeJava("\u001B[1mCamel Route " + routeId + "\u001B[0m"));
out.println(stringEscape.unescapeJava("\tCamel Context: " + contextName));
- out.println("");
- out.println(stringEscape.unescapeJava("\u001B[1mStatistics\u001B[0m"));
String xml = camelController.getRouteStatsAsXml(routeId, contextName, true, false);
if (xml != null) {
@@ -61,7 +58,10 @@ public class RouteInfoCommand extends AbstractRouteCommand {
Unmarshaller unmarshaller = context.createUnmarshaller();
RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
+ out.println(stringEscape.unescapeJava("\tState: " + route.getState()));
+ out.println("");
+ out.println(stringEscape.unescapeJava("\u001B[1mStatistics\u001B[0m"));
long total = route.getExchangesCompleted() + route.getExchangesFailed();
out.println(stringEscape.unescapeJava("\tExchanges Total: " + total));
out.println(stringEscape.unescapeJava("\tExchanges Completed: " + route.getExchangesCompleted()));
@@ -103,13 +103,6 @@ public class RouteInfoCommand extends AbstractRouteCommand {
String text = new SimpleDateFormat(OUTPUT_TIMESTAMP_FORMAT).format(date);
out.println(stringEscape.unescapeJava("\tLast Exchange Date: " + text));
}
-
- out.println("");
- xml = camelController.getRouteModelAsXml(routeId, contextName);
- if (xml != null) {
- out.println(stringEscape.unescapeJava("\u001B[1mDefinition\u001B[0m"));
- out.println(stringEscape.unescapeJava(xml));
- }
}
}
}