camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [6/6] camel git commit: CAMEL-8044: Camel commands useable for remote JVMs using jolokia
Date Thu, 11 Dec 2014 17:56:28 GMT
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/3636e302
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3636e302
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3636e302

Branch: refs/heads/master
Commit: 3636e302ecd9f67f758dae644e474c13ae06a07a
Parents: f030c8b
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Dec 11 17:24:22 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Dec 11 18:56:10 2014 +0100

----------------------------------------------------------------------
 .../jolokia/JolokiaCamelController.java         | 89 ++++++++++++++++++--
 .../commands/jolokia/JolokiaRemoteTest.java     | 27 ++++++
 2 files changed, 110 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3636e302/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 3dc86d2..730c913 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
@@ -34,6 +34,7 @@ import org.jolokia.client.request.J4pReadRequest;
 import org.jolokia.client.request.J4pReadResponse;
 import org.jolokia.client.request.J4pSearchRequest;
 import org.jolokia.client.request.J4pSearchResponse;
+import org.json.simple.JSONObject;
 
 /**
  * A {@link org.apache.camel.commands.CamelController} that uses Jolokia Client to connect
to remote JVMs which
@@ -386,34 +387,110 @@ public class JolokiaCamelController extends AbstractCamelController
implements R
     }
 
     @Override
-    public List<Map<String, String>> getEndpoints(String s) throws Exception
{
+    public List<Map<String, String>> getEndpoints(String camelContextName) throws
Exception {
         if (jolokia == null) {
             throw new IllegalStateException("Need to connect to remote jolokia first");
         }
-        return null;
+
+        List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
+
+        ObjectName found = lookupCamelContext(camelContextName);
+        if (found != null) {
+            J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest("*:type=endpoints,*"));
+
+            List<J4pReadRequest> list = new ArrayList<J4pReadRequest>();
+            for (ObjectName on : sr.getObjectNames()) {
+                list.add(new J4pReadRequest(on, "CamelId", "EndpointUri", "State"));
+            }
+
+            List<J4pReadResponse> lrr = jolokia.execute(list);
+            for (J4pReadResponse rr : lrr) {
+                Map<String, String> row = new LinkedHashMap<String, String>();
+                row.put("camelContextName", rr.getValue("CamelId").toString());
+                row.put("uri", rr.getValue("EndpointUri").toString());
+                row.put("state", rr.getValue("State").toString());
+                answer.add(row);
+            }
+        }
+
+        return answer;
     }
 
     @Override
-    public List<Map<String, String>> getRestServices(String s) throws Exception
{
+    public List<Map<String, String>> getRestServices(String camelContextName)
throws Exception {
         if (jolokia == null) {
             throw new IllegalStateException("Need to connect to remote jolokia first");
         }
-        return null;
+
+        List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
+
+        ObjectName found = lookupCamelContext(camelContextName);
+        if (found != null) {
+            String pattern = String.format("%s:context=%s,type=services,name=DefaultRestRegistry",
found.getDomain(), found.getKeyProperty("context"));
+            ObjectName on = ObjectName.getInstance(pattern);
+
+            J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "listRestServices()"));
+            if (response != null) {
+                JSONObject data = response.asJSONObject();
+                // TODO: parse the open data type
+            }
+
+            /*
+                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;
     }
 
     @Override
-    public String explainEndpointAsJSon(String s, String s2, boolean b) throws Exception
{
+    public String explainEndpointAsJSon(String camelContextName, String uri, boolean allOptions)
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, "explainEndpointJson(java.lang.String,boolean)",
uri, allOptions));
+            if (response != null) {
+                String json = response.getValue();
+                return json;
+            }
+        }
+
         return null;
     }
 
     @Override
-    public List<Map<String, String>> listComponents(String s) throws Exception
{
+    public List<Map<String, String>> listComponents(String camelContextName)
throws Exception {
         if (jolokia == null) {
             throw new IllegalStateException("Need to connect to remote jolokia first");
         }
+
+        // TODO: implement me
+
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3636e302/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 86656be..2afc2c2 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
@@ -150,4 +150,31 @@ public class JolokiaRemoteTest {
         System.out.println(data);
     }
 
+    @Test
+    public void testGetEndpoints() throws Exception {
+        controller = new JolokiaCamelController();
+        controller.connect(url, null, null);
+
+        List<Map<String, String>> data = controller.getEndpoints("myCamel");
+        System.out.println(data);
+    }
+
+    @Test
+    public void testGetRestServices() throws Exception {
+        controller = new JolokiaCamelController();
+        controller.connect(url, null, null);
+
+        List<Map<String, String>> data = controller.getRestServices("myCamel");
+        System.out.println(data);
+    }
+
+    @Test
+    public void testExplainEndpointJson() throws Exception {
+        controller = new JolokiaCamelController();
+        controller.connect(url, null, null);
+
+        String data = controller.explainEndpointAsJSon("myCamel", "log:foo", true);
+        System.out.println(data);
+    }
+
 }


Mime
View raw message