Search in sources :

Example 26 with CLIException

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

the class AbstractIModeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    currentContext.setProperty(IMODE, true);
    ScriptEngine engine = currentContext.getEngine();
    try {
        // load supported functions
        engine.eval(new InputStreamReader(script()));
    } catch (ScriptException error) {
        throw new CLIException(CLIException.REASON_OTHER, error);
    }
    while (!currentContext.getProperty(TERMINATE, Boolean.TYPE, false)) {
        try {
            String command = readLine(currentContext, "> ");
            if (command == null) {
                // EOF, exit interactive shell
                break;
            }
            engine.eval(command);
        } catch (ScriptException se) {
            handleError(String.format("An error occurred while executing the script:"), se, currentContext);
        }
    }
}
Also used : ScriptException(javax.script.ScriptException) InputStreamReader(java.io.InputStreamReader) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) ScriptEngine(javax.script.ScriptEngine)

Example 27 with CLIException

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

the class OutputCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    File outFile = new File(pathname);
    if (outFile.exists()) {
        outFile.delete();
    }
    Stack resultStack = resultStack(currentContext);
    if (!resultStack.isEmpty()) {
        Object result = resultStack.peek();
        if (result instanceof String) {
            FileUtility.writeStringToFile(outFile, (String) result);
        } else if (result instanceof TaskResultData) {
            FileUtility.writeByteArrayToFile(ObjectByteConverter.base64StringToByteArray(((TaskResultData) result).getSerializedValue()), outFile);
        } else {
            FileUtility.writeObjectToFile(result, outFile);
        }
    } else {
        writeLine(currentContext, "No result available to write.");
    }
}
Also used : TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) File(java.io.File) Stack(java.util.Stack)

Example 28 with CLIException

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

the class AddNodeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    HttpPost request = new HttpPost(currentContext.getResourceUrl("node"));
    QueryStringBuilder queryStringBuilder = new QueryStringBuilder();
    queryStringBuilder.add("nodeurl", nodeUrl);
    if (currentContext.getProperty(SET_NODE_SOURCE, String.class) != null) {
        nodeSource = currentContext.getProperty(SET_NODE_SOURCE, String.class);
    }
    if (nodeSource != null) {
        queryStringBuilder.add("nodesource", nodeSource);
    }
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = execute(request, currentContext);
    if (statusCode(OK) == statusCode(response)) {
        boolean successful = readValue(response, Boolean.TYPE, currentContext);
        currentContext.resultStack().push(successful);
        if (successful) {
            writeLine(currentContext, "Node('%s') added successfully.", nodeUrl);
        } else {
            writeLine(currentContext, "Cannot add node('%s').", nodeUrl);
        }
    } else {
        handleError("An error occurred while adding the 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 29 with CLIException

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

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

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