Search in sources :

Example 16 with J4pExecRequest

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

the class DefaultJolokiaCamelController method suspendRoute.

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

Example 17 with J4pExecRequest

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

the class DefaultJolokiaCamelController method getTransformers.

@Override
public List<Map<String, String>> getTransformers(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=DefaultTransformerRegistry", found.getDomain(), found.getKeyProperty("context"));
        ObjectName on = ObjectName.getInstance(pattern);
        J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "listTransformers()"));
        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("scheme", asString(service.get("scheme")));
                    row.put("from", asString(service.get("from")));
                    row.put("to", asString(service.get("to")));
                    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 scheme1 = service1.get("scheme");
                String scheme2 = service2.get("scheme");
                if (scheme1 != null && scheme2 != null) {
                    return scheme1.compareTo(scheme2);
                } else if (scheme1 != null) {
                    return -1;
                } else if (scheme2 != null) {
                    return 1;
                } else {
                    String from1 = service1.get("from");
                    String from2 = service2.get("from");
                    if (from1.equals(from2)) {
                        String to1 = service1.get("to");
                        String to2 = service2.get("to");
                        return to1.compareTo(to2);
                    }
                    return from1.compareTo(from2);
                }
            }
        });
    }
    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 18 with J4pExecRequest

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

the class DefaultJolokiaCamelController method browseInflightExchanges.

@Override
public List<Map<String, Object>> browseInflightExchanges(String camelContextName, String route, int limit, boolean sortByLongestDuration) throws Exception {
    if (jolokia == null) {
        throw new IllegalStateException("Need to connect to remote jolokia first");
    }
    List<Map<String, Object>> answer = new ArrayList<Map<String, Object>>();
    ObjectName found = lookupCamelContext(camelContextName);
    if (found != null) {
        String pattern = String.format("%s:context=%s,type=services,name=DefaultInflightRepository", found.getDomain(), found.getKeyProperty("context"));
        ObjectName on = ObjectName.getInstance(pattern);
        J4pExecResponse er = jolokia.execute(new J4pExecRequest(on, "browse(String,int,boolean)", route, limit, sortByLongestDuration));
        if (er != null) {
            JSONObject data = er.getValue();
            if (data != null) {
                for (Object obj : data.values()) {
                    JSONObject inflight = (JSONObject) obj;
                    Map<String, Object> row = new LinkedHashMap<String, Object>();
                    row.put("exchangeId", asString(inflight.get("exchangeId")));
                    row.put("fromRouteId", asString(inflight.get("fromRouteId")));
                    row.put("routeId", asString(inflight.get("routeId")));
                    row.put("nodeId", asString(inflight.get("nodeId")));
                    row.put("elapsed", asString(inflight.get("elapsed")));
                    row.put("duration", asString(inflight.get("duration")));
                    answer.add(row);
                }
            }
        }
    }
    return answer;
}
Also used : JSONObject(org.json.simple.JSONObject) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) J4pExecResponse(org.jolokia.client.request.J4pExecResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectName(javax.management.ObjectName) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with J4pExecRequest

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

the class DefaultJolokiaCamelController method resumeRoute.

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

Example 20 with J4pExecRequest

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

the class DefaultJolokiaCamelController method getRestApiDocAsJson.

@Override
public String getRestApiDocAsJson(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=services,name=DefaultRestRegistry", found.getDomain(), found.getKeyProperty("context"));
        ObjectName on = ObjectName.getInstance(pattern);
        J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "apiDocAsJson()"));
        if (response != null) {
            String json = response.getValue();
            return json;
        }
    }
    return null;
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pExecResponse(org.jolokia.client.request.J4pExecResponse) 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