Search in sources :

Example 56 with CLIException

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

the class KillCommand method execute.

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

Example 57 with CLIException

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

the class ListTaskStatesCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        List<TaskStateData> tasks = null;
        if (this.tag == null) {
            if (this.limit == 0) {
                tasks = scheduler.getJobTaskStates(currentContext.getSessionId(), jobId).getList();
            } else {
                tasks = scheduler.getJobTaskStatesPaginated(currentContext.getSessionId(), jobId, offset, limit).getList();
            }
        } else {
            if (this.limit == 0) {
                tasks = scheduler.getJobTaskStatesByTag(currentContext.getSessionId(), jobId, tag).getList();
            } else {
                tasks = scheduler.getJobTaskStatesByTagPaginated(currentContext.getSessionId(), jobId, tag, offset, limit).getList();
            }
        }
        resultStack(currentContext).push(tasks);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.taskStatesAsString(tasks, false));
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while retrieving %s state:", job()), e, currentContext);
    }
}
Also used : TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 58 with CLIException

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

the class LiveLogCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    writeLine(currentContext, "Displaying live log for job %s. Press 'q' to stop.", jobId);
    try {
        LogReader reader = new LogReader(currentContext);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.submit(reader);
        String line = readLine(currentContext, "> ");
        while (Strings.isNullOrEmpty(line) || !line.trim().equals("q")) {
            line = readLine(currentContext, "> ");
        }
        reader.terminate();
        executor.shutdownNow();
    } catch (Exception e) {
        handleError("An error occurred while displaying live log", e, currentContext);
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 59 with CLIException

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

the class LoginSchedCommand method login.

@Override
protected String login(ApplicationContext currentContext) throws CLIException {
    String password = currentContext.getProperty(PASSWORD, String.class);
    if (password == null) {
        password = new String(readPassword(currentContext, "password:"));
    }
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        return scheduler.login(username, password);
    } catch (Exception e) {
        throw new CLIException(REASON_OTHER, "An error occurred while logging.", e);
    }
}
Also used : CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 60 with CLIException

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

the class PauseJobCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        boolean success = scheduler.pauseJob(currentContext.getSessionId(), jobId);
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "%s successfully paused.", job());
        } else {
            writeLine(currentContext, "Cannot pause %s.", job());
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while attempting to pause %s:", job()), 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