Search in sources :

Example 1 with HttpResponseWrapper

use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.

the class UnlockNodeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPost request = new HttpPost(currentContext.getResourceUrl("node/unlock"));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    for (String nodeUrl : nodeUrls) {
        queryStringBuilder.add("nodeurls", nodeUrl);
    }
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        boolean success = readValue(response, Boolean.TYPE, currentContext);
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "Node(s) unlocked successfully.");
        } else {
            writeLine(currentContext, "Cannot unlock node(s).");
        }
    } else {
        handleError("An error occurred while unlocking nodes:", response, currentContext);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)

Example 2 with HttpResponseWrapper

use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.

the class AbstractCommand method buildCLIException.

protected CLIException buildCLIException(int reason, HttpResponseWrapper response, ApplicationContext currentContext) {
    String responseContent = StringUtility.responseAsString(response);
    ErrorView errorView = errorView(responseContent, currentContext);
    if (errorView != null) {
        throw new CLIException(reason, errorView.getErrorMessage(), errorView.getStackTrace());
    } else {
        HttpErrorView httpErrorView = errorView(responseContent);
        throw new CLIException(reason, httpErrorView.errorMessage, httpErrorView.stackTrace);
    }
}
Also used : CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) ErrorView(org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString)

Example 3 with HttpResponseWrapper

use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.

the class AbstractCommand method handleError.

@SuppressWarnings("unchecked")
protected void handleError(String errorMessage, HttpResponseWrapper response, ApplicationContext currentContext) {
    String responseContent = StringUtility.responseAsString(response);
    Stack resultStack = resultStack(currentContext);
    ErrorView errorView = errorView(responseContent, currentContext);
    if (errorView != null) {
        resultStack.push(errorView);
    } else {
        resultStack.push(responseContent);
    }
    if (errorView != null) {
        writeError(errorMessage, errorView, currentContext);
    } else {
        writeError(errorMessage, responseContent, currentContext);
    }
}
Also used : ErrorView(org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) Stack(java.util.Stack)

Example 4 with HttpResponseWrapper

use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.

the class AddNodeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPost request = new HttpPost(currentContext.getResourceUrl("node"));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("nodeurl", nodeUrl);
    if (currentContext.getProperty(SET_NODE_SOURCE, String.class) != null) {
        nodeSource = currentContext.getProperty(SET_NODE_SOURCE, String.class);
    }
    if (nodeSource != null) {
        queryStringBuilder.add("nodesource", nodeSource);
    }
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        boolean successful = readValue(response, Boolean.TYPE, currentContext);
        currentContext.resultStack().push(successful);
        if (successful) {
            writeLine(currentContext, "Node('%s') added successfully.", nodeUrl);
        } else {
            writeLine(currentContext, "Cannot add node('%s').", nodeUrl);
        }
    } else {
        handleError("An error occurred while adding the node:", response, currentContext);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)

Example 5 with HttpResponseWrapper

use of org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper in project scheduling by ow2-proactive.

the class CreateNodeSourceCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    QueryStringBuilder infrastructure = currentContext.getProperty(SET_INFRASTRUCTURE, QueryStringBuilder.class);
    QueryStringBuilder policy = currentContext.getProperty(SET_POLICY, QueryStringBuilder.class);
    if (infrastructure == null) {
        throw new CLIException(REASON_INVALID_ARGUMENTS, "Infrastructure not specified");
    }
    if (policy == null) {
        throw new CLIException(REASON_INVALID_ARGUMENTS, "Policy not specified");
    }
    if (currentContext.getProperty(SET_NODE_SOURCE, String.class) != null) {
        nodeSource = currentContext.getProperty(SET_NODE_SOURCE, String.class);
    }
    HttpPost request = new HttpPost(currentContext.getResourceUrl("nodesource/create/recovery"));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("nodeSourceName", nodeSource).addAll(infrastructure).addAll(policy).add("nodesRecoverable", nodesRecoverable);
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        NSStateView nsState = readValue(response, NSStateView.class, currentContext);
        boolean success = nsState.isResult();
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "Node source successfully created.");
        } else {
            writeLine(currentContext, "%s %s", "Cannot create node source:", nodeSource);
        }
    } else {
        handleError("An error occurred while creating node source:", response, currentContext);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) NSStateView(org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)

Aggregations

HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)22 QueryStringBuilder (org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)12 HttpGet (org.apache.http.client.methods.HttpGet)10 HttpPost (org.apache.http.client.methods.HttpPost)9 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)7 List (java.util.List)5 NSStateView (org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView)4 PluginView (org.ow2.proactive_grid_cloud_portal.cli.json.PluginView)4 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)3 File (java.io.File)3 RmStateView (org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)3 ArrayList (java.util.ArrayList)2 HttpPut (org.apache.http.client.methods.HttpPut)2 ConfigurableFieldView (org.ow2.proactive_grid_cloud_portal.cli.json.ConfigurableFieldView)2 ErrorView (org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView)2 Type (org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type)2 NodeEventView (org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView)2 IOException (java.io.IOException)1 Stack (java.util.Stack)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1