Search in sources :

Example 31 with CLIException

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

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

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

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

Example 35 with CLIException

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

Aggregations

CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)49 SchedulerRestInterface (org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)30 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 IOException (java.io.IOException)8 File (java.io.File)6 List (java.util.List)5 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)4 NSStateView (org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView)4 PluginView (org.ow2.proactive_grid_cloud_portal.cli.json.PluginView)4 ArrayList (java.util.ArrayList)3 RmStateView (org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)3 FileInputStream (java.io.FileInputStream)2 Stack (java.util.Stack)2 HttpPut (org.apache.http.client.methods.HttpPut)2 ConfigurableFieldView (org.ow2.proactive_grid_cloud_portal.cli.json.ConfigurableFieldView)2 TaskResultData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData)2 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)2