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()"));
}
}
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;
}
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;
}
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()"));
}
}
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;
}
Aggregations