You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/10 18:56:58 UTC
[2/5] camel git commit: CAMEL-8044: Camel commands should be more
reusable for remote JVMs
CAMEL-8044: Camel commands should be more reusable for remote JVMs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b33acc35
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b33acc35
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b33acc35
Branch: refs/heads/master
Commit: b33acc35bf763094b4ac932bc6b3ddc07623649e
Parents: 288ea67
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 18:25:59 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 18:25:59 2014 +0100
----------------------------------------------------------------------
.../camel/commands/AbstractCamelController.java | 124 +++++++------------
.../apache/camel/commands/CamelController.java | 50 +++++---
2 files changed, 75 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b33acc35/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
index 7837d51..eaf42c5 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java
@@ -29,7 +29,6 @@ import java.util.Properties;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import javax.xml.bind.JAXBException;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
@@ -46,7 +45,6 @@ import org.apache.camel.model.rest.RestsDefinition;
import org.apache.camel.spi.ManagementAgent;
import org.apache.camel.spi.RestRegistry;
import org.apache.camel.util.JsonSchemaHelper;
-import org.apache.camel.util.ObjectHelper;
/**
* Abstract {@link org.apache.camel.commands.CamelController} that implementators should extend.
@@ -55,7 +53,7 @@ public abstract class AbstractCamelController implements CamelController {
private CamelComponentCatalog catalog = new DefaultCamelComponentCatalog();
- public CamelContext getCamelContext(String name) {
+ public CamelContext getCamelContext(String name) throws Exception {
for (CamelContext camelContext : this.getCamelContexts()) {
if (camelContext.getName().equals(name)) {
return camelContext;
@@ -64,11 +62,11 @@ public abstract class AbstractCamelController implements CamelController {
return null;
}
- public List<Route> getRoutes(String camelContextName) {
+ public List<Route> getRoutes(String camelContextName) throws Exception {
return getRoutes(camelContextName, null);
}
- public List<Route> getRoutes(String camelContextName, String filter) {
+ public List<Route> getRoutes(String camelContextName, String filter) throws Exception {
List<Route> routes = new ArrayList<Route>();
if (camelContextName != null) {
@@ -110,78 +108,58 @@ public abstract class AbstractCamelController implements CamelController {
return routes;
}
- public void resetRouteStats(String camelContextName) {
+ public void resetRouteStats(String camelContextName) throws Exception{
CamelContext context = this.getCamelContext(camelContextName);
if (context == null) {
return;
}
- try {
- ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
- if (agent != null) {
- MBeanServer mBeanServer = agent.getMBeanServer();
-
- // reset route mbeans
- ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
- Set<ObjectName> set = mBeanServer.queryNames(query, null);
- for (ObjectName routeMBean : set) {
- String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
- if (camelId != null && camelId.equals(context.getName())) {
- mBeanServer.invoke(routeMBean, "reset", new Object[]{true}, new String[]{"boolean"});
- }
+ ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
+
+ // reset route mbeans
+ ObjectName query = ObjectName.getInstance(agent.getMBeanObjectDomainName() + ":type=routes,*");
+ Set<ObjectName> set = mBeanServer.queryNames(query, null);
+ for (ObjectName routeMBean : set) {
+ String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
+ if (camelId != null && camelId.equals(context.getName())) {
+ mBeanServer.invoke(routeMBean, "reset", new Object[]{true}, new String[]{"boolean"});
}
}
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
- public void startRoute(String camelContextName, String routeId) {
+ public void startRoute(String camelContextName, String routeId) throws Exception {
CamelContext context = getCamelContext(camelContextName);
if (context != null) {
- try {
- context.startRoute(routeId);
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
+ context.startRoute(routeId);
}
}
- public void stopRoute(String camelContextName, String routeId) {
+ public void stopRoute(String camelContextName, String routeId) throws Exception {
CamelContext context = getCamelContext(camelContextName);
if (context != null) {
- try {
- context.stopRoute(routeId);
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
+ context.stopRoute(routeId);
}
}
- public void suspendRoute(String camelContextName, String routeId) {
+ public void suspendRoute(String camelContextName, String routeId) throws Exception {
CamelContext context = getCamelContext(camelContextName);
if (context != null) {
- try {
- context.suspendRoute(routeId);
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
+ context.suspendRoute(routeId);
}
}
- public void resumeRoute(String camelContextName, String routeId) {
+ public void resumeRoute(String camelContextName, String routeId) throws Exception {
CamelContext context = getCamelContext(camelContextName);
if (context != null) {
- try {
- context.resumeRoute(routeId);
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
+ context.resumeRoute(routeId);
}
}
@SuppressWarnings("deprecation")
- public String getRouteModelAsXml(String routeId, String camelContextName) {
+ public String getRouteModelAsXml(String routeId, String camelContextName) throws Exception {
CamelContext context = this.getCamelContext(camelContextName);
if (context == null) {
return null;
@@ -191,47 +169,37 @@ public abstract class AbstractCamelController implements CamelController {
return null;
}
- String xml;
- try {
- xml = ModelHelper.dumpModelAsXml(route);
- } catch (JAXBException e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
- return xml;
+ return ModelHelper.dumpModelAsXml(route);
}
@Override
- public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) {
+ public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception {
CamelContext context = this.getCamelContext(camelContextName);
if (context == null) {
return null;
}
- try {
- ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
- if (agent != null) {
- MBeanServer mBeanServer = agent.getMBeanServer();
- Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" + routeId + "\",*"), null);
- Iterator<ObjectName> iterator = set.iterator();
- if (iterator.hasNext()) {
- ObjectName routeMBean = iterator.next();
-
- // the route must be part of the camel context
- String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
- if (camelId != null && camelId.equals(camelContextName)) {
- String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml", new Object[]{fullStats, includeProcessors}, new String[]{"boolean", "boolean"});
- return xml;
- }
+ ManagementAgent agent = context.getManagementStrategy().getManagementAgent();
+ if (agent != null) {
+ MBeanServer mBeanServer = agent.getMBeanServer();
+ Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(agent.getMBeanObjectDomainName() + ":type=routes,name=\"" + routeId + "\",*"), null);
+ Iterator<ObjectName> iterator = set.iterator();
+ if (iterator.hasNext()) {
+ ObjectName routeMBean = iterator.next();
+
+ // the route must be part of the camel context
+ String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
+ if (camelId != null && camelId.equals(camelContextName)) {
+ String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml", new Object[]{fullStats, includeProcessors}, new String[]{"boolean", "boolean"});
+ return xml;
}
}
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
}
return null;
}
@SuppressWarnings("deprecation")
- public String getRestModelAsXml(String camelContextName) {
+ public String getRestModelAsXml(String camelContextName) throws Exception {
CamelContext context = this.getCamelContext(camelContextName);
if (context == null) {
return null;
@@ -244,16 +212,10 @@ public abstract class AbstractCamelController implements CamelController {
// use a rests definition to dump the rests
RestsDefinition def = new RestsDefinition();
def.setRests(rests);
- String xml;
- try {
- xml = ModelHelper.dumpModelAsXml(def);
- } catch (JAXBException e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
- return xml;
+ return ModelHelper.dumpModelAsXml(def);
}
- public List<Map<String, String>> getEndpoints(String camelContextName) {
+ public List<Map<String, String>> getEndpoints(String camelContextName) throws Exception {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
if (camelContextName != null) {
@@ -279,7 +241,7 @@ public abstract class AbstractCamelController implements CamelController {
return answer;
}
- public List<Map<String, String>> getRestServices(String camelContextName) {
+ public List<Map<String, String>> getRestServices(String camelContextName) throws Exception {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
if (camelContextName != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/b33acc35/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
index f6e150e..5f61140 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java
@@ -33,24 +33,27 @@ public interface CamelController {
* Get the list of Camel context.
*
* @return the list of Camel contexts.
+ * @throws java.lang.Exception can be thrown
*/
- List<CamelContext> getCamelContexts();
+ List<CamelContext> getCamelContexts() throws Exception;
/**
* Get a Camel context identified by the given name.
*
* @param name the Camel context name.
* @return the Camel context or null if not found.
+ * @throws java.lang.Exception can be thrown
*/
- CamelContext getCamelContext(String name);
+ CamelContext getCamelContext(String name) throws Exception;
/**
* Get all routes. If Camel context name is null, all routes from all contexts are listed.
*
* @param camelContextName the Camel context name. If null, all contexts are considered.
* @return the list of the Camel routes.
+ * @throws java.lang.Exception can be thrown
*/
- List<Route> getRoutes(String camelContextName);
+ List<Route> getRoutes(String camelContextName) throws Exception;
/**
* Get all routes filtered by the regex.
@@ -58,47 +61,53 @@ public interface CamelController {
* @param camelContextName the Camel context name. If null, all contexts are considered.
* @param filter the filter which supports * and ? as wildcards
* @return the list of the Camel routes.
+ * @throws java.lang.Exception can be thrown
*/
- List<Route> getRoutes(String camelContextName, String filter);
+ List<Route> getRoutes(String camelContextName, String filter) throws Exception;
/**
* Reset all the route stats for the given Camel context
*
* @param camelContextName the Camel context.
+ * @throws java.lang.Exception can be thrown
*/
- void resetRouteStats(String camelContextName);
+ void resetRouteStats(String camelContextName) throws Exception;
/**
* Starts the given route
*
* @param camelContextName the Camel context.
* @param routeId the route ID.
+ * @throws java.lang.Exception can be thrown
*/
- void startRoute(String camelContextName, String routeId);
+ void startRoute(String camelContextName, String routeId) throws Exception;
/**
* Stops the given route
*
* @param camelContextName the Camel context.
* @param routeId the route ID.
+ * @throws java.lang.Exception can be thrown
*/
- void stopRoute(String camelContextName, String routeId);
+ void stopRoute(String camelContextName, String routeId) throws Exception;
/**
* Suspends the given route
*
* @param camelContextName the Camel context.
* @param routeId the route ID.
+ * @throws java.lang.Exception can be thrown
*/
- void suspendRoute(String camelContextName, String routeId);
+ void suspendRoute(String camelContextName, String routeId) throws Exception;
/**
* Resumes the given route
*
* @param camelContextName the Camel context.
* @param routeId the route ID.
+ * @throws java.lang.Exception can be thrown
*/
- void resumeRoute(String camelContextName, String routeId);
+ void resumeRoute(String camelContextName, String routeId) throws Exception;
/**
* Return the definition of a route as XML identified by a ID and a Camel context.
@@ -106,8 +115,9 @@ public interface CamelController {
* @param routeId the route ID.
* @param camelContextName the Camel context.
* @return the route model as XML
+ * @throws java.lang.Exception can be thrown
*/
- String getRouteModelAsXml(String routeId, String camelContextName);
+ String getRouteModelAsXml(String routeId, String camelContextName) throws Exception;
/**
* Returns detailed route statistics as XML identified by a ID and a Camel context.
@@ -117,32 +127,36 @@ public interface CamelController {
* @param fullStats whether to include verbose stats
* @param includeProcessors whether to embed per processor stats from the route
* @return the route statistics as XML
+ * @throws java.lang.Exception can be thrown
*/
- String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors);
+ String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception;
/**
* Return the endpoints
*
* @param camelContextName the Camel context.
* @return a list of key/value pairs with endpoint information
+ * @throws java.lang.Exception can be thrown
*/
- List<Map<String, String>> getEndpoints(String camelContextName);
+ List<Map<String, String>> getEndpoints(String camelContextName) throws Exception;
/**
* Return the definition of the REST services as XML for the given Camel context.
*
* @param camelContextName the Camel context.
* @return the REST model as xml
+ * @throws java.lang.Exception can be thrown
*/
- String getRestModelAsXml(String camelContextName);
+ String getRestModelAsXml(String camelContextName) throws Exception;
/**
* Return the REST services for the given Camel context.
*
* @param camelContextName the Camel context.
* @return a list of key/value pairs with REST information
+ * @throws java.lang.Exception can be thrown
*/
- List<Map<String, String>> getRestServices(String camelContextName);
+ List<Map<String, String>> getRestServices(String camelContextName) throws Exception;
/**
* Explains an endpoint uri
@@ -151,7 +165,7 @@ public interface CamelController {
* @param uri the endpoint uri
* @param allOptions whether to explain all options, or only the explicit configured options from the uri
* @return a JSON schema with explanation of the options
- * @throws java.lang.Exception is thrown if error loading resources to explain the endpoint
+ * @throws java.lang.Exception can be thrown
*/
String explainEndpointAsJSon(String camelContextName, String uri, boolean allOptions) throws Exception;
@@ -160,7 +174,7 @@ public interface CamelController {
*
* @param camelContextName the Camel context.
* @return a list of key/value pairs with component information
- * @throws java.lang.Exception is thrown if error loading resources to gather component information
+ * @throws java.lang.Exception can be thrown
*/
List<Map<String, String>> listComponents(String camelContextName) throws Exception;
@@ -169,7 +183,7 @@ public interface CamelController {
*
* @param filter optional filter to filter by labels
* @return a list of key/value pairs with component information
- * @throws java.lang.Exception is thrown if error loading resources to gather component information
+ * @throws java.lang.Exception can be thrown
*/
List<Map<String, String>> listComponentsCatalog(String filter) throws Exception;
@@ -177,7 +191,7 @@ public interface CamelController {
* Lists all the labels from the Camel components catalog
*
* @return a map which key is the label, and the set is the component names that has the given label
- * @throws java.lang.Exception is thrown if error loading resources to gather component information
+ * @throws java.lang.Exception can be thrown
*/
Map<String, Set<String>> listLabelCatalog() throws Exception;