Search in sources :

Example 1 with J4pSearchRequest

use of org.jolokia.client.request.J4pSearchRequest 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 J4pSearchRequest

use of org.jolokia.client.request.J4pSearchRequest 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 J4pSearchRequest

use of org.jolokia.client.request.J4pSearchRequest 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 J4pSearchRequest

use of org.jolokia.client.request.J4pSearchRequest in project syndesis by syndesisio.

the class PodMetricsReader method getRoutes.

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, ROUTE_ID, RESET_TIMESTAMP, EXCHANGES_TOTAL, EXCHANGES_FAILED, LAST_COMPLETED_TIMESTAMP, LAST_FAILED_TIMESTAMP, START_TIMESTAMP));
        }
        List<J4pReadResponse> lrr = jolokia.execute(list);
        for (J4pReadResponse rr : lrr) {
            String routeId = rr.getValue(ROUTE_ID).toString();
            if (filter == null || routeId.matches(filter)) {
                Map<String, String> row = new LinkedHashMap<String, String>();
                for (String attribute : rr.getAttributes()) {
                    if (rr.getValue(attribute) != null) {
                        row.put(attribute, rr.getValue(attribute).toString());
                    }
                }
                answer.add(row);
            }
        }
    }
    // 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 5 with J4pSearchRequest

use of org.jolokia.client.request.J4pSearchRequest 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)

Aggregations

J4pSearchRequest (org.jolokia.client.request.J4pSearchRequest)8 J4pSearchResponse (org.jolokia.client.request.J4pSearchResponse)8 ObjectName (javax.management.ObjectName)7 ArrayList (java.util.ArrayList)5 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 J4pReadResponse (org.jolokia.client.request.J4pReadResponse)4 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ArtifactDeploymentException (org.apache.maven.artifact.deployer.ArtifactDeploymentException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 J4pConnectException (org.jolokia.client.exception.J4pConnectException)1 J4pException (org.jolokia.client.exception.J4pException)1 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)1 J4pExecRequest (org.jolokia.client.request.J4pExecRequest)1