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