Search in sources :

Example 46 with CLIException

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

the class ListPolicyCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    Map<String, PluginView> knownPolicyMap = currentContext.getPolicies();
    if (knownPolicyMap == null) {
        HttpGet request = new HttpGet(currentContext.getResourceUrl("policies"));
        HttpResponseWrapper response = execute(request, currentContext);
        if (statusCode(OK) == statusCode(response)) {
            List<PluginView> pluginViewList = readValue(response, new TypeReference<List<PluginView>>() {
            }, currentContext);
            resultStack(currentContext).push(pluginViewList.toArray(new PluginView[pluginViewList.size()]));
            knownPolicyMap = new HashMap<>();
            for (PluginView pluginView : pluginViewList) {
                knownPolicyMap.put(pluginView.getPluginName(), pluginView);
            }
            currentContext.setPolicies(knownPolicyMap);
        } else {
            handleError("An error occurred while retrieving supported policy types:", response, currentContext);
        }
    }
    if (!currentContext.isSilent()) {
        if (knownPolicyMap != null) {
            writeLine(currentContext, "%n%s:%n", "Supported policy types");
            for (PluginView policy : knownPolicyMap.values()) {
                writeLine(currentContext, "%s%n", policy.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 47 with CLIException

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

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

Example 49 with CLIException

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

the class SetInfrastructureCommand 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);
            for (PluginView pluginView : pluginViewList) {
                infrastructures.put(pluginView.getPluginName(), pluginView);
            }
            currentContext.setInfrastructures(infrastructures);
        } else {
            handleError("Unable to retrieve known infrastructure types:", response, currentContext);
        }
    }
    if (infrastructures != null) {
        PluginView pluginView = infrastructures.get(infrastructureType);
        if (pluginView == null) {
            throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("Unknown infrastructure type: %s", infrastructureType));
        }
        ConfigurableFieldView[] configurableFields = pluginView.getConfigurableFields();
        if (configurableFields.length != infrastructureArgs.length) {
            throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("Invalid number of arguments specified for '%s' type.", infrastructureType));
        }
        QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
        queryStringBuilder.add("infrastructureType", infrastructureType);
        for (int index = 0; index < configurableFields.length; index++) {
            ConfigurableFieldView cf = configurableFields[index];
            Type ft = cf.getMeta().type();
            if (FILEBROWSER.equals(ft) || CREDENTIAL.equals(ft)) {
                if ("".equals(infrastructureArgs[index])) {
                    String contents = "";
                    queryStringBuilder.add("infrastructureFileParameters", contents);
                } else {
                    String contents = FileUtility.readFileToString(new File(infrastructureArgs[index]));
                    queryStringBuilder.add("infrastructureFileParameters", contents);
                }
            } else {
                queryStringBuilder.add("infrastructureParameters", infrastructureArgs[index]);
            }
        }
        currentContext.setProperty(SET_INFRASTRUCTURE, 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 50 with CLIException

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

the class ShutdownCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpGet request = new HttpGet(currentContext.getResourceUrl("shutdown"));
    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, "%s", "Resource manager shutdown successfully.");
        } else {
            writeLine(currentContext, "%s", "Cannot shutdown resource manager.");
        }
    } else {
        handleError("An error occurred while shutting down:", response, currentContext);
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet)

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