Search in sources :

Example 66 with CLIException

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

the class SchedStatsCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        Map<String, String> stats = scheduler.getStatistics(currentContext.getSessionId());
        resultStack(currentContext).push(stats);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.statsAsString(stats));
        }
    } catch (Exception e) {
        handleError("An error occurred while retrieving stats:", e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 67 with CLIException

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

the class SubmitJobCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    try {
        validateFilePath(currentContext);
        File jobFile = new File(pathname);
        String contentType = URLConnection.getFileNameMap().getContentTypeFor(pathname);
        JobIdData jobId;
        try (FileInputStream inputStream = new FileInputStream(jobFile)) {
            if (APPLICATION_XML.getMimeType().equals(contentType)) {
                jobId = currentContext.getRestClient().submitXml(currentContext.getSessionId(), inputStream, map(this.variables));
            } else {
                jobId = currentContext.getRestClient().submitJobArchive(currentContext.getSessionId(), inputStream, map(this.variables));
            }
        }
        writeLine(currentContext, "Job('%s') successfully submitted: job('%d')", pathname, jobId.getId());
        resultStack(currentContext).push(jobId);
    } catch (Exception e) {
        handleError(String.format("An error occurred while attempting to submit job('%s'):", pathname), e, currentContext);
    }
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) InvalidPathException(java.nio.file.InvalidPathException)

Example 68 with CLIException

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

the class UploadFileCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    try (FileInputStream fileStream = new FileInputStream(localFile)) {
        boolean uploaded = currentContext.getRestClient().pushFile(currentContext.getSessionId(), spaceName, filePath, fileName, fileStream);
        resultStack(currentContext).push(uploaded);
        if (uploaded) {
            writeLine(currentContext, "%s successfully uploaded.", localFile);
        } else {
            writeLine(currentContext, "Cannot upload the file: %s.", localFile);
        }
    } catch (Exception error) {
        handleError(String.format("An error occurred when uploading the file %s. ", localFile), error, currentContext);
    }
}
Also used : FileInputStream(java.io.FileInputStream) 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