CAMEL-8044: Camel commands useable for remote JVMs using jolokia
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f030c8bf Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f030c8bf Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f030c8bf Branch: refs/heads/master Commit: f030c8bf87160457a92105a80ebf69ac4758fe62 Parents: 636c6fc Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Dec 11 17:03:21 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Dec 11 18:56:10 2014 +0100 ---------------------------------------------------------------------- .../jolokia/JolokiaCamelController.java | 78 ++++++++++++++++++-- .../commands/jolokia/JolokiaRemoteTest.java | 43 +++++++++++ 2 files changed, 113 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f030c8bf/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java b/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java index dd034cc..3dc86d2 100644 --- a/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java +++ b/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java @@ -272,59 +272,121 @@ public class JolokiaCamelController extends AbstractCamelController implements R } @Override - public void startRoute(String s, String s2) throws Exception { + public void startRoute(String camelContextName, String routeId) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); + ObjectName on = ObjectName.getInstance(pattern); + jolokia.execute(new J4pExecRequest(on, "start()")); + } } @Override - public void stopRoute(String s, String s2) throws Exception { + public void stopRoute(String camelContextName, String routeId) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); + ObjectName on = ObjectName.getInstance(pattern); + jolokia.execute(new J4pExecRequest(on, "stop()")); + } } @Override - public void suspendRoute(String s, String s2) throws Exception { + public void suspendRoute(String camelContextName, String routeId) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); + ObjectName on = ObjectName.getInstance(pattern); + jolokia.execute(new J4pExecRequest(on, "suspend()")); + } } @Override - public void resumeRoute(String s, String s2) throws Exception { + public void resumeRoute(String camelContextName, String routeId) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); + ObjectName on = ObjectName.getInstance(pattern); + jolokia.execute(new J4pExecRequest(on, "resume()")); + } } @Override - public String getRouteModelAsXml(String s, String s2) throws Exception { + public String getRouteModelAsXml(String camelContextName, String routeId) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); + ObjectName on = ObjectName.getInstance(pattern); + J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "dumpRouteAsXml()")); + if (response != null) { + String xml = response.getValue(); + return xml; + } + } + return null; } @Override - public String getRouteStatsAsXml(String s, String s2, boolean b, boolean b2) throws Exception { + public String getRouteStatsAsXml(String camelContextName, String routeId, boolean fullStats, boolean includeProcessors) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); + ObjectName on = ObjectName.getInstance(pattern); + J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "dumpRouteStatsAsXml(boolean,boolean)", fullStats, includeProcessors)); + if (response != null) { + String xml = response.getValue(); + return xml; + } + } + return null; } @Override - public List<Map<String, String>> getEndpoints(String s) throws Exception { + public String getRestModelAsXml(String camelContextName) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } + + ObjectName found = lookupCamelContext(camelContextName); + if (found != null) { + J4pExecResponse response = jolokia.execute(new J4pExecRequest(found, "dumpRestsAsXml()")); + if (response != null) { + String xml = response.getValue(); + return xml; + } + } + return null; } @Override - public String getRestModelAsXml(String s) throws Exception { + public List<Map<String, String>> getEndpoints(String s) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } http://git-wip-us.apache.org/repos/asf/camel/blob/f030c8bf/platforms/commands/commands-jolokia/src/test/java/org/apache/camel/commands/jolokia/JolokiaRemoteTest.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-jolokia/src/test/java/org/apache/camel/commands/jolokia/JolokiaRemoteTest.java b/platforms/commands/commands-jolokia/src/test/java/org/apache/camel/commands/jolokia/JolokiaRemoteTest.java index 52048b4..86656be 100644 --- a/platforms/commands/commands-jolokia/src/test/java/org/apache/camel/commands/jolokia/JolokiaRemoteTest.java +++ b/platforms/commands/commands-jolokia/src/test/java/org/apache/camel/commands/jolokia/JolokiaRemoteTest.java @@ -107,4 +107,47 @@ public class JolokiaRemoteTest { controller.resetRouteStats("myCamel"); } + @Test + public void testRemoteRouteControl() throws Exception { + controller = new JolokiaCamelController(); + controller.connect(url, null, null); + + controller.suspendRoute("myCamel", "route2"); + List<Map<String, String>> data = controller.getRoutes("myCamel", "route2"); + System.out.println(data); + + Thread.sleep(500); + + controller.resumeRoute("myCamel", "route2"); + data = controller.getRoutes("myCamel", "route2"); + System.out.println(data); + } + + @Test + public void testRouteModel() throws Exception { + controller = new JolokiaCamelController(); + controller.connect(url, null, null); + + String data = controller.getRouteModelAsXml("myCamel", "route2"); + System.out.println(data); + } + + @Test + public void testRouteStats() throws Exception { + controller = new JolokiaCamelController(); + controller.connect(url, null, null); + + String data = controller.getRouteStatsAsXml("myCamel", "route2", true, true); + System.out.println(data); + } + + @Test + public void testRestsModel() throws Exception { + controller = new JolokiaCamelController(); + controller.connect(url, null, null); + + String data = controller.getRestModelAsXml("myCamel"); + System.out.println(data); + } + }