use of org.jolokia.client.request.J4pSearchRequest 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;
}
use of org.jolokia.client.request.J4pSearchRequest in project fabric8 by jboss-fuse.
the class DeployToProfileMojo method getMavenUploadUri.
protected String getMavenUploadUri(J4pClient client) throws MalformedObjectNameException, J4pException, MojoExecutionException {
Exception exception = null;
try {
J4pSearchResponse searchResponse = client.execute(new J4pSearchRequest(FABRIC_MBEAN));
List<String> mbeanNames = searchResponse.getMBeanNames();
if (mbeanNames == null || mbeanNames.isEmpty()) {
getLog().warn("No MBean " + FABRIC_MBEAN + " found, are you sure you have created a fabric in this JVM?");
return null;
}
J4pResponse<J4pReadRequest> request = client.execute(new J4pReadRequest(FABRIC_MBEAN, "MavenRepoUploadURI"));
Object value = request.getValue();
if (value != null) {
String uri = value.toString();
if (uri.startsWith("http")) {
return uri;
} else {
getLog().warn("Could not find the Maven upload URI. Got: " + value);
}
} else {
getLog().warn("Could not find the Maven upload URI");
}
} catch (J4pConnectException e) {
String message = "Could not connect to jolokia on " + jolokiaUrl + " using user: " + fabricServer.getUsername() + ".\nAre you sure you are running a fabric8 container?";
getLog().error(message);
throw new MojoExecutionException(message, e);
} catch (J4pRemoteException e) {
int status = e.getStatus();
if (status == 401) {
String message = "Status 401: Unauthorized to access: " + jolokiaUrl + " using user: " + fabricServer.getUsername();
if (!customUsernameAndPassword) {
message += ".\nHave you created a Fabric?\nHave you setup your ~/.m2/settings.xml with the correct user and password for server ID: " + serverId + " and do the user/password match the server " + jolokiaUrl + "?";
}
getLog().error(message);
throw new MojoExecutionException(message, e);
} else if (status == 404) {
String message = "Status 404: Resource not found: " + jolokiaUrl + ".\nHave you created a Fabric?";
getLog().error(message);
throw new MojoExecutionException(message, e);
} else {
exception = e;
}
} catch (J4pException e) {
// it may be an empty response which is like a 404
boolean is404 = "Could not parse answer: Unexpected token END OF FILE at position 0.".equals(e.getMessage());
if (is404) {
String message = "Status 404: Resource not found: " + jolokiaUrl + ".\nHave you created a Fabric?";
getLog().error(message);
throw new MojoExecutionException(message, e);
} else {
exception = e;
}
}
if (exception != null) {
getLog().error("Failed to get maven repository URI from " + jolokiaUrl + ". " + exception, exception);
throw new MojoExecutionException("Could not find the Maven Upload Repository URI");
} else {
throw new MojoExecutionException("Could not find the Maven Upload Repository URI");
}
}
use of org.jolokia.client.request.J4pSearchRequest in project syndesis by syndesisio.
the class PodMetricsReader method lookupCamelContext.
/**
* Code borrowed from the DefaultCamelController: https://github.com/apache/camel/blob/master/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/DefaultJolokiaCamelController.java
* Slight modifications have been applied.
* Credits to: Claus & Tomo
*/
private ObjectName lookupCamelContext(String camelContextName) throws Exception {
ObjectName on = cache.get(camelContextName);
if (on == null) {
ObjectName found = null;
J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest("org.apache.camel: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;
}
Aggregations