Search in sources :

Example 11 with J4pExecRequest

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;
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pException(org.jolokia.client.exception.J4pException)

Example 12 with J4pExecRequest

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;
        }
    }
}
Also used : J4pRemoteException(org.jolokia.client.exception.J4pRemoteException) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ObjectName(javax.management.ObjectName)

Example 13 with J4pExecRequest

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);
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) Matchers.anyString(org.mockito.Matchers.anyString)

Example 14 with J4pExecRequest

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;
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pExecResponse(org.jolokia.client.request.J4pExecResponse) ObjectName(javax.management.ObjectName)

Example 15 with J4pExecRequest

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

J4pExecRequest (org.jolokia.client.request.J4pExecRequest)24 ObjectName (javax.management.ObjectName)17 J4pExecResponse (org.jolokia.client.request.J4pExecResponse)12 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 JSONObject (org.json.simple.JSONObject)7 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 J4pException (org.jolokia.client.exception.J4pException)5 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)3 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)3 List (java.util.List)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 AbtractJ4pMBeanRequest (org.jolokia.client.request.AbtractJ4pMBeanRequest)2 J4pResponse (org.jolokia.client.request.J4pResponse)2 J4pWriteRequest (org.jolokia.client.request.J4pWriteRequest)2 DeployResults (io.fabric8.deployer.dto.DeployResults)1 IOException (java.io.IOException)1 Override (java.lang.Override)1