Search in sources :

Example 6 with CLIException

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

the class InstallPackageCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    ScriptResult scriptResult;
    Map<String, Object> schedulerProperties;
    String packageDirPath;
    try {
        packageDirPath = retrievePackagePath();
        schedulerProperties = retrieveSchedulerProperties(currentContext, scheduler);
        addSessionIdToSchedulerProperties(currentContext, schedulerProperties);
        scriptResult = executeScript(schedulerProperties, packageDirPath);
        if (scriptResult.errorOccured()) {
            logger.error("Failed to execute script: " + SCRIPT_PATH);
            throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException());
        } else {
            writeLine(currentContext, "Package('%s') successfully installed in the catalog", SOURCE_PACKAGE);
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while attempting to install package('%s') in the catalog", SOURCE_PACKAGE), e, currentContext);
    }
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) IOException(java.io.IOException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 7 with CLIException

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

the class JobKeyValueTransformer method transformVariablesToMap.

public Map<String, String> transformVariablesToMap(String jsonVariables) {
    Map<String, String> jobVariables = Maps.newHashMap();
    if (jsonVariables != null) {
        try {
            jobVariables = (JSONObject) new JSONParser().parse(jsonVariables);
            validateJSONVariables(jobVariables);
        } catch (ParseException | IllegalArgumentException e) {
            throw new CLIException(REASON_INVALID_ARGUMENTS, e.getMessage() + USAGE);
        }
    }
    return jobVariables;
}
Also used : CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 8 with CLIException

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

the class KillJobCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        boolean success = scheduler.killJob(currentContext.getSessionId(), jobId);
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "%s successfully killed.", job());
        } else {
            writeLine(currentContext, "Cannot kill %s:", job());
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while attempting to kill %s:", job()), e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 9 with CLIException

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

the class LinkRmCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        boolean success = scheduler.linkRm(currentContext.getSessionId(), rmUrl);
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "New resource manager relinked successfully.");
        } else {
            writeLine(currentContext, "Cannot relink '%s'.", rmUrl);
        }
    } catch (Exception e) {
        handleError("An error occurred while relinking:", e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 10 with CLIException

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

the class ListJobTasksCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        List<String> tasks = null;
        if (this.tag != null) {
            if (this.limit == 0) {
                tasks = scheduler.getJobTasksIdsByTag(currentContext.getSessionId(), jobId, tag).getList();
            } else {
                tasks = scheduler.getJobTasksIdsByTagPaginated(currentContext.getSessionId(), jobId, tag, offset, limit).getList();
            }
        } else {
            if (this.limit == 0) {
                tasks = scheduler.getTasksNames(currentContext.getSessionId(), jobId).getList();
            } else {
                tasks = scheduler.getTasksNamesPaginated(currentContext.getSessionId(), jobId, offset, limit).getList();
            }
        }
        resultStack(currentContext).push(tasks);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", tasks);
        }
    } catch (Exception e) {
        String message = null;
        if (this.tag == null) {
            message = String.format("An error occurred while retrieving %s tasks:", job());
        } else {
            message = String.format("An error occurred while retrieving %s tasks filtered by tag %s:", job(), tag);
        }
        handleError(message, e, currentContext);
    }
}
Also used : 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