Search in sources :

Example 1 with NSStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView 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)

Example 2 with NSStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView in project scheduling by ow2-proactive.

the class DeployNodeSourceCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPut request = new HttpPut(currentContext.getResourceUrl(RM_REST_ENDPOINT));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("nodeSourceName", nodeSourceName);
    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 deployed.");
        } else {
            writeLine(currentContext, "%s %s", "Cannot deploy node source:", nodeSourceName);
        }
    } else {
        handleError("An error occurred while deploying node source:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) NSStateView(org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder) HttpPut(org.apache.http.client.methods.HttpPut)

Example 3 with NSStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView in project scheduling by ow2-proactive.

the class DefineNodeSourceCommand 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(RM_REST_ENDPOINT));
    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 defined.");
        } else {
            writeLine(currentContext, "%s %s", "Cannot define node source:", nodeSource);
        }
    } else {
        handleError("An error occurred while defining 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)

Example 4 with NSStateView

use of org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView in project scheduling by ow2-proactive.

the class UndeployNodeSourceCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPut request = new HttpPut(currentContext.getResourceUrl(RM_REST_ENDPOINT));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("nodeSourceName", this.nodeSourceName).add("preempt", Boolean.toString(this.preempt));
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = this.execute(request, currentContext);
    if (this.statusCode(OK) == this.statusCode(response)) {
        NSStateView nsState = this.readValue(response, NSStateView.class, currentContext);
        boolean success = nsState.isResult();
        this.resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "Node source successfully undeployed.");
        } else {
            writeLine(currentContext, "%s %s", "Cannot undeploy node source:", this.nodeSourceName);
        }
    } else {
        this.handleError("An error occurred while undeploying node source:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) NSStateView(org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder) HttpPut(org.apache.http.client.methods.HttpPut)

Aggregations

NSStateView (org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView)4 HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)4 QueryStringBuilder (org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)4 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpPut (org.apache.http.client.methods.HttpPut)2 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)2