Search in sources :

Example 1 with J4pSearchResponse

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

the class DefaultJolokiaCamelController method getCamelContexts.

@Override
public List<Map<String, String>> getCamelContexts() 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>>();
    J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest("*:type=context,*"));
    List<J4pReadRequest> list = new ArrayList<J4pReadRequest>();
    for (ObjectName on : sr.getObjectNames()) {
        list.add(new J4pReadRequest(on, "CamelId", "State", "Uptime", "ExchangesTotal", "ExchangesInflight", "ExchangesFailed"));
    }
    List<J4pReadResponse> lrr = jolokia.execute(list);
    for (J4pReadResponse rr : lrr) {
        Map<String, String> row = new LinkedHashMap<String, String>();
        row.put("name", rr.getValue("CamelId").toString());
        row.put("state", rr.getValue("State").toString());
        row.put("uptime", rr.getValue("Uptime").toString());
        row.put("exchangesTotal", rr.getValue("ExchangesTotal").toString());
        row.put("exchangesInflight", rr.getValue("ExchangesInflight").toString());
        row.put("exchangesFailed", rr.getValue("ExchangesFailed").toString());
        answer.add(row);
    }
    return answer;
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) ArrayList(java.util.ArrayList) J4pSearchRequest(org.jolokia.client.request.J4pSearchRequest) J4pSearchResponse(org.jolokia.client.request.J4pSearchResponse) ObjectName(javax.management.ObjectName) LinkedHashMap(java.util.LinkedHashMap) J4pReadResponse(org.jolokia.client.request.J4pReadResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with J4pSearchResponse

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

the class DefaultJolokiaCamelController method lookupCamelContext.

private ObjectName lookupCamelContext(String camelContextName) throws Exception {
    ObjectName on = cache.get(camelContextName);
    if (on == null) {
        ObjectName found = null;
        J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest("*:type=context,*"));
        if (sr != null) {
            for (ObjectName name : sr.getObjectNames()) {
                String id = name.getKeyProperty("name");
                id = removeLeadingAndEndingQuotes(id);
                if (camelContextName.equals(id)) {
                    found = name;
                    break;
                }
            }
        }
        if (found != null) {
            on = found;
            cache.put(camelContextName, on);
        }
    }
    return on;
}
Also used : J4pSearchRequest(org.jolokia.client.request.J4pSearchRequest) ObjectName(javax.management.ObjectName) J4pSearchResponse(org.jolokia.client.request.J4pSearchResponse)

Example 3 with J4pSearchResponse

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

the class DefaultJolokiaCamelController method getRoutes.

@Override
public List<Map<String, String>> getRoutes(String camelContextName, String filter) 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 = camelContextName != null ? lookupCamelContext(camelContextName) : null;
    if (found != null) {
        String pattern = String.format("%s:context=%s,type=routes,*", found.getDomain(), found.getKeyProperty("context"));
        J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest(pattern));
        List<J4pReadRequest> list = new ArrayList<J4pReadRequest>();
        for (ObjectName on : sr.getObjectNames()) {
            list.add(new J4pReadRequest(on, "CamelId", "RouteId", "State", "Uptime", "ExchangesTotal", "ExchangesInflight", "ExchangesFailed"));
        }
        List<J4pReadResponse> lrr = jolokia.execute(list);
        for (J4pReadResponse rr : lrr) {
            String routeId = rr.getValue("RouteId").toString();
            if (filter == null || routeId.matches(filter)) {
                Map<String, String> row = new LinkedHashMap<String, String>();
                row.put("camelContextName", rr.getValue("CamelId").toString());
                row.put("routeId", routeId);
                row.put("state", rr.getValue("State").toString());
                row.put("uptime", rr.getValue("Uptime").toString());
                row.put("exchangesTotal", rr.getValue("ExchangesTotal").toString());
                row.put("exchangesInflight", rr.getValue("ExchangesInflight").toString());
                row.put("exchangesFailed", rr.getValue("ExchangesFailed").toString());
                answer.add(row);
            }
        }
    } else {
        List<Map<String, String>> camelContexts = this.getCamelContexts();
        for (Map<String, String> row : camelContexts) {
            List<Map<String, String>> routes = getRoutes(row.get("name"), filter);
            answer.addAll(routes);
        }
    }
    // sort the list
    Collections.sort(answer, new Comparator<Map<String, String>>() {

        @Override
        public int compare(Map<String, String> o1, Map<String, String> o2) {
            // group by camel context first, then by route name
            String c1 = o1.get("camelContextName");
            String c2 = o2.get("camelContextName");
            int answer = c1.compareTo(c2);
            if (answer == 0) {
                // okay from same camel context, then sort by route id
                answer = o1.get("routeId").compareTo(o2.get("routeId"));
            }
            return answer;
        }
    });
    return answer;
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) ArrayList(java.util.ArrayList) J4pSearchRequest(org.jolokia.client.request.J4pSearchRequest) ObjectName(javax.management.ObjectName) J4pSearchResponse(org.jolokia.client.request.J4pSearchResponse) LinkedHashMap(java.util.LinkedHashMap) J4pReadResponse(org.jolokia.client.request.J4pReadResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with J4pSearchResponse

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

the class DefaultJolokiaCamelController method resetRouteStats.

@Override
public void resetRouteStats(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=*", found.getDomain(), found.getKeyProperty("context"));
        J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest(pattern));
        List<J4pExecRequest> list = new ArrayList<J4pExecRequest>();
        for (ObjectName on : sr.getObjectNames()) {
            list.add(new J4pExecRequest(on, "reset(boolean)", true));
        }
        jolokia.execute(list);
    }
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ArrayList(java.util.ArrayList) J4pSearchRequest(org.jolokia.client.request.J4pSearchRequest) ObjectName(javax.management.ObjectName) J4pSearchResponse(org.jolokia.client.request.J4pSearchResponse)

Example 5 with J4pSearchResponse

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

the class DefaultJolokiaCamelController method getEndpoints.

@Override
public List<Map<String, String>> getEndpoints(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=endpoints,*", found.getDomain(), found.getKeyProperty("context"));
        J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest(pattern));
        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;
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) ArrayList(java.util.ArrayList) J4pSearchRequest(org.jolokia.client.request.J4pSearchRequest) ObjectName(javax.management.ObjectName) J4pSearchResponse(org.jolokia.client.request.J4pSearchResponse) LinkedHashMap(java.util.LinkedHashMap) J4pReadResponse(org.jolokia.client.request.J4pReadResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ObjectName (javax.management.ObjectName)5 J4pSearchRequest (org.jolokia.client.request.J4pSearchRequest)5 J4pSearchResponse (org.jolokia.client.request.J4pSearchResponse)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)3 J4pReadResponse (org.jolokia.client.request.J4pReadResponse)3 J4pExecRequest (org.jolokia.client.request.J4pExecRequest)1