Search in sources :

Example 6 with QueryStringBuilder

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

the class RemoveNodeSourceCommand method execute.

public void execute(ApplicationContext currentContext) throws CLIException {
    if (currentContext.isForced()) {
        preempt = true;
    }
    HttpPost request = new HttpPost(currentContext.getResourceUrl("nodesource/remove"));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("name", nodeSource).add("preempt", Boolean.toString(preempt));
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(response) == statusCode(OK)) {
        boolean success = readValue(response, Boolean.TYPE, currentContext);
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "Node source '%s' deleted successfully.", nodeSource);
        } else {
            writeLine(currentContext, "Cannot delete node source: %s.", nodeSource);
        }
    } else {
        handleError(String.format("An error occurred while deleting node source: %s", nodeSource), 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 7 with QueryStringBuilder

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

the class SetPolicyCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    Map<String, PluginView> knownPolicies = currentContext.getPolicies();
    if (knownPolicies == null) {
        HttpGet request = new HttpGet(currentContext.getResourceUrl("policies"));
        HttpResponseWrapper response = execute(request, currentContext);
        if (statusCode(OK) == statusCode(response)) {
            knownPolicies = new HashMap<>();
            List<PluginView> pluginViewList = readValue(response, new TypeReference<List<PluginView>>() {
            }, currentContext);
            for (PluginView pluginView : pluginViewList) {
                knownPolicies.put(pluginView.getPluginName(), pluginView);
            }
            currentContext.setPolicies(knownPolicies);
        } else {
            handleError("Unable to retrieve known policy types:", response, currentContext);
        }
    }
    if (knownPolicies != null) {
        PluginView pluginView = knownPolicies.get(policyType);
        if (pluginView == null) {
            throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("Unknown policy type: %s", policyType));
        }
        ConfigurableFieldView[] configurableFields = pluginView.getConfigurableFields();
        if (configurableFields.length != policyArgs.length) {
            throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("Invalid number of arguments specified for '%s' type.", policyType));
        }
        QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
        queryStringBuilder.add("policyType", policyType);
        for (int index = 0; index < configurableFields.length; index++) {
            ConfigurableFieldView cf = configurableFields[index];
            Type ft = cf.getMeta().type();
            if (FILEBROWSER.equals(ft) || CREDENTIAL.equals(ft)) {
                String contents = FileUtility.readFileToString(new File(policyArgs[index]));
                queryStringBuilder.add("policyFileParameters", contents);
            } else {
                queryStringBuilder.add("policyParameters", policyArgs[index]);
            }
        }
        currentContext.setProperty(SET_POLICY, queryStringBuilder);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) ConfigurableFieldView(org.ow2.proactive_grid_cloud_portal.cli.json.ConfigurableFieldView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder) Type(org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type) PluginView(org.ow2.proactive_grid_cloud_portal.cli.json.PluginView) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) List(java.util.List) File(java.io.File)

Example 8 with QueryStringBuilder

use of org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder 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 9 with QueryStringBuilder

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

the class LockNodeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPost request = new HttpPost(currentContext.getResourceUrl("node/lock"));
    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 successful = readValue(response, Boolean.TYPE, currentContext);
        resultStack(currentContext).push(successful);
        if (successful) {
            writeLine(currentContext, "Node(s) locked successfully.");
        } else {
            writeLine(currentContext, "Cannot lock node(s).");
        }
    } else {
        handleError("An error occurred while locking 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 10 with QueryStringBuilder

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

the class RmStatsCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    StringBuilder url = new StringBuilder();
    url.append("info/ProActiveResourceManager:name=RuntimeData?");
    QueryStringBuilder builder = new QueryStringBuilder();
    for (String attr : RUNTIME_DATA_ATTR) {
        builder.add("attr", attr);
    }
    url.append(builder.buildString());
    HttpGet request = new HttpGet(currentContext.getResourceUrl(url.toString()));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        List<MBeanInfoView> infoList = readValue(response, new TypeReference<List<MBeanInfoView>>() {
        }, currentContext);
        MBeanInfoView[] stats = infoList.toArray(new MBeanInfoView[infoList.size()]);
        resultStack(currentContext).push(stats);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.mBeanInfoAsString(stats));
        }
    } else {
        handleError("An error occurred while retrieving stats:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) MBeanInfoView(org.ow2.proactive_grid_cloud_portal.cli.json.MBeanInfoView) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder) HttpGet(org.apache.http.client.methods.HttpGet) List(java.util.List) QueryStringBuilder(org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)

Aggregations

HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)12 QueryStringBuilder (org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)12 HttpPost (org.apache.http.client.methods.HttpPost)7 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)4 NSStateView (org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView)4 List (java.util.List)3 HttpGet (org.apache.http.client.methods.HttpGet)3 File (java.io.File)2 HttpPut (org.apache.http.client.methods.HttpPut)2 ConfigurableFieldView (org.ow2.proactive_grid_cloud_portal.cli.json.ConfigurableFieldView)2 Type (org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type)2 PluginView (org.ow2.proactive_grid_cloud_portal.cli.json.PluginView)2 MBeanInfoView (org.ow2.proactive_grid_cloud_portal.cli.json.MBeanInfoView)1