Search in sources :

Example 6 with WildflyClientException

use of org.guvnor.ala.wildfly.access.exceptions.WildflyClientException in project kie-wb-common by kiegroup.

the class WildflyRuntimeManager method pause.

@Override
public void pause(RuntimeId runtimeId) throws RuntimeOperationException {
    WildflyRuntime runtime = (WildflyRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        wildfly.getWildflyClient(runtime.getProviderId()).stop(runtime.getId());
        refresh(runtimeId);
    } catch (WildflyClientException ex) {
        throw new RuntimeOperationException("Error Pausing container: " + runtimeId.getId() + "\n\t There as a problem with stopping your application, please check into the Wildfly Logs for more information.", ex);
    }
}
Also used : WildflyRuntime(org.guvnor.ala.wildfly.model.WildflyRuntime) WildflyClientException(org.guvnor.ala.wildfly.access.exceptions.WildflyClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException)

Example 7 with WildflyClientException

use of org.guvnor.ala.wildfly.access.exceptions.WildflyClientException in project kie-wb-common by kiegroup.

the class WildflyRuntimeManager method restart.

@Override
public void restart(RuntimeId runtimeId) {
    WildflyRuntime runtime = (WildflyRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        wildfly.getWildflyClient(runtime.getProviderId()).restart(runtime.getId());
        refresh(runtimeId);
    } catch (WildflyClientException ex) {
        throw new RuntimeOperationException("Error Restarting container: " + runtimeId.getId() + "\n\t There as a problem with restarting your application, please check into the Wildfly Logs for more information.", ex);
    }
}
Also used : WildflyRuntime(org.guvnor.ala.wildfly.model.WildflyRuntime) WildflyClientException(org.guvnor.ala.wildfly.access.exceptions.WildflyClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException)

Example 8 with WildflyClientException

use of org.guvnor.ala.wildfly.access.exceptions.WildflyClientException in project kie-wb-common by kiegroup.

the class WildflyClient method start.

/*
     * Start the application specified by the deploymentName
     * @param String deploymentName
     * @return the 200 on successful start
     * @throw a WildflyClientException with the status code on failure
     * @throw a WildflyClientException with the throwable in case of an internal exception
     */
public int start(String deploymentName) throws WildflyClientException {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(host, managementPort), new UsernamePasswordCredentials(user, password));
    CloseableHttpClient httpclient = custom().setDefaultCredentialsProvider(credsProvider).build();
    final HttpPost post = new HttpPost("http://" + host + ":" + managementPort + "/management");
    post.addHeader("X-Management-Client-Name", "GUVNOR-ALA");
    // the DMR operation
    ModelNode operation = new ModelNode();
    operation.get("operation").set("deploy");
    operation.get("address").add("deployment", deploymentName);
    post.setEntity(new StringEntity(operation.toJSONString(true), APPLICATION_JSON));
    try {
        HttpResponse response = httpclient.execute(post);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            throw new WildflyClientException("Error Starting App Status Code: " + statusCode);
        }
        return statusCode;
    } catch (IOException ex) {
        getLogger(WildflyClient.class.getName()).log(SEVERE, null, ex);
        throw new WildflyClientException("Error Starting App : " + ex.getMessage(), ex);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) WildflyClientException(org.guvnor.ala.wildfly.access.exceptions.WildflyClientException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) IOException(java.io.IOException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) StringEntity(org.apache.http.entity.StringEntity) AuthScope(org.apache.http.auth.AuthScope) ModelNode(org.jboss.dmr.ModelNode)

Example 9 with WildflyClientException

use of org.guvnor.ala.wildfly.access.exceptions.WildflyClientException in project kie-wb-common by kiegroup.

the class WildflyClient method stop.

/*
     * Stop the application specified by the deploymentName
     * @param String deploymentName
     * @return the 200 on successful stop
     * @throw a WildflyClientException with the status code on failure
     * @throw a WildflyClientException with the throwable in case of an internal exception
     */
public int stop(String deploymentName) throws WildflyClientException {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(host, managementPort), new UsernamePasswordCredentials(user, password));
    CloseableHttpClient httpclient = custom().setDefaultCredentialsProvider(credsProvider).build();
    final HttpPost post = new HttpPost("http://" + host + ":" + managementPort + "/management");
    post.addHeader("X-Management-Client-Name", "GUVNOR-ALA");
    // the DMR operation
    ModelNode operation = new ModelNode();
    operation.get("operation").set("undeploy");
    operation.get("address").add("deployment", deploymentName);
    post.setEntity(new StringEntity(operation.toJSONString(true), APPLICATION_JSON));
    try {
        HttpResponse response = httpclient.execute(post);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            throw new WildflyClientException("Error Stopping App Status Code: " + statusCode);
        }
        return statusCode;
    } catch (IOException ex) {
        LOG.error("Error Stopping App : " + ex.getMessage(), ex);
        throw new WildflyClientException("Error Stopping App : " + ex.getMessage(), ex);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) WildflyClientException(org.guvnor.ala.wildfly.access.exceptions.WildflyClientException) AuthScope(org.apache.http.auth.AuthScope) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 10 with WildflyClientException

use of org.guvnor.ala.wildfly.access.exceptions.WildflyClientException in project kie-wb-common by kiegroup.

the class WildflyRuntimeManager method stop.

@Override
public void stop(RuntimeId runtimeId) throws RuntimeOperationException {
    WildflyRuntime runtime = (WildflyRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        wildfly.getWildflyClient(runtime.getProviderId()).stop(runtime.getId());
        refresh(runtimeId);
    } catch (WildflyClientException ex) {
        throw new RuntimeOperationException("Error Stopping container: " + runtimeId.getId() + "\n\t There as a problem with stopping your application, please check into the Wildfly Logs for more information.", ex);
    }
}
Also used : WildflyRuntime(org.guvnor.ala.wildfly.model.WildflyRuntime) WildflyClientException(org.guvnor.ala.wildfly.access.exceptions.WildflyClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException)

Aggregations

WildflyClientException (org.guvnor.ala.wildfly.access.exceptions.WildflyClientException)11 IOException (java.io.IOException)6 AuthScope (org.apache.http.auth.AuthScope)6 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 HttpPost (org.apache.http.client.methods.HttpPost)6 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 ModelNode (org.jboss.dmr.ModelNode)6 HttpResponse (org.apache.http.HttpResponse)5 CredentialsProvider (org.apache.http.client.CredentialsProvider)5 StringEntity (org.apache.http.entity.StringEntity)5 RuntimeOperationException (org.guvnor.ala.exceptions.RuntimeOperationException)4 WildflyRuntime (org.guvnor.ala.wildfly.model.WildflyRuntime)4 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1 HttpEntity (org.apache.http.HttpEntity)1