Search in sources :

Example 1 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest in project camel by apache.

the class DefaultJolokiaCamelController method startRoute.

@Override
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()"));
    }
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ObjectName(javax.management.ObjectName)

Example 2 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest in project camel by apache.

the class DefaultJolokiaCamelController method getRouteModelAsXml.

@Override
public String getRouteModelAsXml(String routeId, String camelContextName) 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;
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pExecResponse(org.jolokia.client.request.J4pExecResponse) ObjectName(javax.management.ObjectName)

Example 3 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest in project camel by apache.

the class DefaultJolokiaCamelController method getEndpointRuntimeStatistics.

@Override
public List<Map<String, String>> getEndpointRuntimeStatistics(String camelContextName) throws Exception {
    if (jolokia == null) {
        throw new IllegalStateException("Need to connect to remote jolokia first");
    }
    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=DefaultRuntimeEndpointRegistry", found.getDomain(), found.getKeyProperty("context"));
        ObjectName on = ObjectName.getInstance(pattern);
        J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "endpointStatistics()"));
        if (response != null) {
            JSONObject data = response.getValue();
            for (Object obj : data.values()) {
                JSONObject data2 = (JSONObject) obj;
                JSONObject service = (JSONObject) data2.values().iterator().next();
                Map<String, String> row = new LinkedHashMap<String, String>();
                row.put("index", asString(service.get("index")));
                row.put("url", asString(service.get("url")));
                row.put("routeId", asString(service.get("routeId")));
                row.put("direction", asString(service.get("direction")));
                row.put("static", asString(service.get("static")));
                row.put("dynamic", asString(service.get("dynamic")));
                row.put("hits", asString(service.get("hits")));
                answer.add(row);
            }
        }
        // sort the list
        Collections.sort(answer, new Comparator<Map<String, String>>() {

            @Override
            public int compare(Map<String, String> endpoint1, Map<String, String> endpoint2) {
                // sort by route id
                String route1 = endpoint1.get("routeId");
                String route2 = endpoint2.get("routeId");
                int num = route1.compareTo(route2);
                if (num == 0) {
                    // we want in before out
                    String dir1 = endpoint1.get("direction");
                    String dir2 = endpoint2.get("direction");
                    num = dir1.compareTo(dir2);
                }
                return num;
            }
        });
    }
    return answer;
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) J4pExecResponse(org.jolokia.client.request.J4pExecResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest in project camel by apache.

the class DefaultJolokiaCamelController method getValidators.

@Override
public List<Map<String, String>> getValidators(String camelContextName) throws Exception {
    if (jolokia == null) {
        throw new IllegalStateException("Need to connect to remote jolokia first");
    }
    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=DefaultValidatorRegistry", found.getDomain(), found.getKeyProperty("context"));
        ObjectName on = ObjectName.getInstance(pattern);
        J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "listValidators()"));
        if (response != null) {
            JSONObject data = response.getValue();
            if (data != null) {
                for (Object obj : data.values()) {
                    JSONObject data2 = (JSONObject) obj;
                    JSONObject service = (JSONObject) data2.values().iterator().next();
                    Map<String, String> row = new LinkedHashMap<String, String>();
                    row.put("type", asString(service.get("type")));
                    row.put("static", asString(service.get("static")));
                    row.put("dynamic", asString(service.get("dynamic")));
                    row.put("description", asString(service.get("description")));
                    answer.add(row);
                }
            }
        }
        // sort the list
        Collections.sort(answer, new Comparator<Map<String, String>>() {

            @Override
            public int compare(Map<String, String> service1, Map<String, String> service2) {
                String type1 = service1.get("type");
                String type2 = service2.get("type");
                return type1.compareTo(type2);
            }
        });
    }
    return answer;
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) J4pExecResponse(org.jolokia.client.request.J4pExecResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest in project camel by apache.

the class DefaultJolokiaCamelController method stopRoute.

@Override
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()"));
    }
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ObjectName(javax.management.ObjectName)

Aggregations

J4pExecRequest (org.jolokia.client.request.J4pExecRequest)24 ObjectName (javax.management.ObjectName)17 J4pExecResponse (org.jolokia.client.request.J4pExecResponse)12 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 JSONObject (org.json.simple.JSONObject)7 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 J4pException (org.jolokia.client.exception.J4pException)5 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)3 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)3 List (java.util.List)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 AbtractJ4pMBeanRequest (org.jolokia.client.request.AbtractJ4pMBeanRequest)2 J4pResponse (org.jolokia.client.request.J4pResponse)2 J4pWriteRequest (org.jolokia.client.request.J4pWriteRequest)2 DeployResults (io.fabric8.deployer.dto.DeployResults)1 IOException (java.io.IOException)1 Override (java.lang.Override)1