Search in sources :

Example 6 with HttpResponseWrapper

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

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

the class GetNodeInfoCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpGet request = new HttpGet(currentContext.getResourceUrl("monitoring"));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        RmStateView state = readValue(response, RmStateView.class, currentContext);
        NodeEventView[] nodeEvents = state.getNodesEvents();
        NodeEventView target = null;
        for (NodeEventView nodeEvent : nodeEvents) {
            if (nodeUrl.equals(nodeEvent.getNodeUrl())) {
                target = nodeEvent;
                break;
            }
        }
        if (target == null) {
            writeLine(currentContext, "Cannot find node: '%s'", nodeUrl);
            return;
        }
        resultStack(currentContext).push(target);
        writeLine(currentContext, "%s", target.getNodeInfo());
    } else {
        handleError("An error occurred while retrieving node info.", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) NodeEventView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeEventView) RmStateView(org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)

Example 8 with HttpResponseWrapper

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

the class ListInfrastructureCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    Map<String, PluginView> infrastructures = currentContext.getInfrastructures();
    if (infrastructures == null) {
        HttpGet request = new HttpGet(currentContext.getResourceUrl("infrastructures"));
        HttpResponseWrapper response = execute(request, currentContext);
        if (statusCode(OK) == statusCode(response)) {
            infrastructures = new HashMap<>();
            List<PluginView> pluginViewList = readValue(response, new TypeReference<List<PluginView>>() {
            }, currentContext);
            resultStack(currentContext).push(pluginViewList);
            for (PluginView pluginView : pluginViewList) {
                infrastructures.put(pluginView.getPluginName(), pluginView);
            }
            currentContext.setInfrastructures(infrastructures);
        } else {
            handleError("An error occurred while retrieving supported infrastructure types:", response, currentContext);
        }
    }
    if (infrastructures != null) {
        writeLine(currentContext, "%n%s:%n", "Supported infrastructure types");
        for (PluginView pluginView : infrastructures.values()) {
            writeLine(currentContext, "%s%n", pluginView.toString());
        }
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) PluginView(org.ow2.proactive_grid_cloud_portal.cli.json.PluginView) List(java.util.List)

Example 9 with HttpResponseWrapper

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

the class ListNodeSourceCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpGet request = new HttpGet(currentContext.getResourceUrl("monitoring"));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        RmStateView state = readValue(response, RmStateView.class, currentContext);
        NodeSourceView[] nodeSources = state.getNodeSource();
        // filter out all node source events that was removed
        // so rm client does not display them
        List<NodeSourceView> filtered = new ArrayList<>(nodeSources.length);
        for (NodeSourceView nodeSourceEvent : nodeSources) {
            if (!nodeSourceEvent.isRemoved()) {
                filtered.add(nodeSourceEvent);
            }
        }
        NodeSourceView[] result = new NodeSourceView[filtered.size()];
        result = filtered.toArray(result);
        resultStack(currentContext).push(result);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.string(result));
        }
    } else {
        handleError("An error occurred while retrieving node sources:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) NodeSourceView(org.ow2.proactive_grid_cloud_portal.cli.json.NodeSourceView) ArrayList(java.util.ArrayList) RmStateView(org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)

Example 10 with HttpResponseWrapper

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

the class RemoveNodeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPost request = new HttpPost(currentContext.getResourceUrl("node/remove"));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("url", nodeUrl);
    if (currentContext.isForced()) {
        preempt = true;
    }
    if (preempt) {
        queryStringBuilder.add("preempt", TRUE.toString());
    }
    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') successfully removed.", nodeUrl);
        } else {
            writeLine(currentContext, "Cannot remove node: '%s'", nodeUrl);
        }
    } else {
        handleError("An error occurred while removing 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)

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