use of org.jolokia.client.request.J4pExecRequest in project fabric8 by jboss-fuse.
the class DeployToProfileMojo method uploadProfileConfigFile.
protected void uploadProfileConfigFile(J4pClient client, DeployResults results, File rootDir, File configFile) throws MojoExecutionException, J4pException, IOException, MalformedObjectNameException {
String profileId = results.getProfileId();
String versionId = results.getVersionId();
if (Strings.isNullOrBlank(profileId)) {
throw new MojoExecutionException("Cannot upload configuration file " + configFile + " to profile as the profileId was not returned");
}
if (Strings.isNullOrBlank(versionId)) {
throw new MojoExecutionException("Cannot upload configuration file " + configFile + " to profile as the versionId was not returned");
}
String relativePath = Files.getRelativePath(rootDir, configFile);
if (relativePath.startsWith("/"))
relativePath = relativePath.substring(1);
// the path should use forward slash only as we use forward slashes in fabric profiles
relativePath = Files.normalizePath(relativePath, '\\', '/');
String configFileContents = loadFilteredConfigFile(configFile);
if (configFileContents == null) {
getLog().debug(String.format("Filtered copy of the config file %s not found. Using the original file.", configFile));
configFileContents = Files.toString(configFile);
}
String expandedConfig = expandPlaceholders(configFileContents);
String data = Base64Encoder.encode(expandedConfig);
String mbeanName = "io.fabric8:type=Fabric";
getLog().info("Uploading file " + relativePath + " to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername());
try {
J4pExecRequest request = new J4pExecRequest(mbeanName, "setConfigurationFile", versionId, profileId, relativePath, data);
J4pResponse<J4pExecRequest> response = client.execute(request, "POST");
Object value = response.getValue();
if (value != null) {
getLog().info("Upload returned result: " + value);
}
} catch (J4pException e) {
if (e.getMessage().contains(".InstanceNotFoundException")) {
throw new MojoExecutionException("Could not find the mbean " + mbeanName + " in the JVM for " + jolokiaUrl + ". Are you sure this JVM is running the Fabric8 console?");
} else {
throw e;
}
}
}
use of org.jolokia.client.request.J4pExecRequest in project fabric8 by jboss-fuse.
the class DeployToProfileMojo method refreshProfile.
protected void refreshProfile(J4pClient client, DeployResults results) throws Exception {
String profileId = results.getProfileId();
String versionId = results.getVersionId();
ObjectName mbeanName = new ObjectName(FABRIC_MBEAN);
if (!Strings.isNullOrBlank(profileId) && !Strings.isNullOrBlank(versionId)) {
getLog().info("Performing profile refresh on mbean: " + mbeanName + " version: " + versionId + " profile: " + profileId);
try {
J4pExecRequest request = new J4pExecRequest(mbeanName, "refreshProfile", versionId, profileId);
J4pResponse<J4pExecRequest> response = client.execute(request, "POST");
response.getValue();
} catch (J4pRemoteException e) {
getLog().error("Failed to refresh profile " + profileId + " on mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername() + ". Error: " + e.getErrorType());
getLog().error("Stack: " + e.getRemoteStackTrace());
throw e;
}
}
}
use of org.jolokia.client.request.J4pExecRequest in project fabric8 by jboss-fuse.
the class DeployToProfileMojoTest method decodeSentConfig.
// Helpers
private String decodeSentConfig() throws J4pException {
verify(jolokiaClient).execute(jolokiaRequest.capture(), anyString());
J4pExecRequest capturedRequest = jolokiaRequest.getValue();
String encodedConfig = (String) capturedRequest.getArguments().get(3);
return decode(encodedConfig);
}
use of org.jolokia.client.request.J4pExecRequest in project camel by apache.
the class DefaultJolokiaCamelController method getRouteStatsAsXml.
@Override
public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) 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);
J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "dumpRouteStatsAsXml(boolean,boolean)", fullStats, includeProcessors));
if (response != null) {
String xml = response.getValue();
return xml;
}
}
return null;
}
use of org.jolokia.client.request.J4pExecRequest 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);
}
}
Aggregations