Search in sources :

Example 51 with CLIException

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

the class UndeployNodeSourceCommand 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", this.nodeSourceName).add("preempt", Boolean.toString(this.preempt));
    request.setEntity(queryStringBuilder.buildEntity(APPLICATION_FORM_URLENCODED));
    HttpResponseWrapper response = this.execute(request, currentContext);
    if (this.statusCode(OK) == this.statusCode(response)) {
        NSStateView nsState = this.readValue(response, NSStateView.class, currentContext);
        boolean success = nsState.isResult();
        this.resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "Node source successfully undeployed.");
        } else {
            writeLine(currentContext, "%s %s", "Cannot undeploy node source:", this.nodeSourceName);
        }
    } else {
        this.handleError("An error occurred while undeploying 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 52 with CLIException

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

the class ChangeJobPriorityCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        scheduler.schedulerChangeJobPriorityByValue(currentContext.getSessionId(), jobId, priorityValue);
        resultStack(currentContext).push(Boolean.TRUE);
        writeLine(currentContext, "%s priority changed successfully.", job());
    } catch (Exception e) {
        handleError(String.format("An error occurred while changing %s priority:", job()), e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 53 with CLIException

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

the class DownloadFileCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    InputStream in = null;
    OutputStream out = null;
    try {
        in = currentContext.getRestClient().getScheduler().pullFile(currentContext.getSessionId(), spaceName, pathName);
        out = buildOutputStream(new File(localFile));
        copy(in, out);
        resultStack(currentContext).push(true);
        writeLine(currentContext, "%s successfully downloaded to %s.", pathName, localFile);
    } catch (Exception error) {
        handleError("An error occurred while pulling the file from the server. " + localFile, error, currentContext);
    } finally {
        if (in != null) {
            closeQuietly(in);
        }
        if (out != null) {
            closeQuietly(out);
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileUtility.buildOutputStream(org.ow2.proactive_grid_cloud_portal.cli.utils.FileUtility.buildOutputStream) File(java.io.File) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 54 with CLIException

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

the class GetJobResultCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        if (this.tag == null) {
            JobResultData results = scheduler.jobResult(currentContext.getSessionId(), jobId);
            resultStack(currentContext).push(results);
            if (!currentContext.isForced()) {
                writeLine(currentContext, "%s", StringUtility.jobResultAsString(job(), results));
            }
        } else {
            List<TaskResultData> results = scheduler.taskResultByTag(currentContext.getSessionId(), jobId, tag);
            resultStack(currentContext).push(results);
            if (!currentContext.isForced()) {
                writeLine(currentContext, "%s", StringUtility.taskResultsAsString(results));
            }
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while retrieving %s result:", job()), e, currentContext);
    }
}
Also used : JobResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobResultData) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 55 with CLIException

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

the class GetJobStateCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        JobStateData jobState = scheduler.listJobs(currentContext.getSessionId(), jobId);
        resultStack(currentContext).push(jobState);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.jobStateAsString(job(), jobState));
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while retrieving %s state:", job()), e, currentContext);
    }
}
Also used : JobStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobStateData) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

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