use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskLogErrByTag.
/**
* Returns the list of standard error outputs (stderr) generated by a set of
* tasks filtered by a given tag.
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskTag
* the tag used to filter the tasks
* @return the list of stderr generated by the set of tasks filtered by the
* given tag or an empty string if the result is not yet available
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/log/err")
@Produces("application/json")
public String taskLogErrByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/log/err");
List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
StringBuffer buf = new StringBuffer();
for (TaskResult tr : trs) {
if (tr.getOutput() != null) {
buf.append(tr.getOutput().getStderrLogs(true));
}
}
return buf.toString();
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getTaskStatesByTag.
@Override
public RestPage<TaskStateData> getTaskStatesByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit, SortSpecifierContainer sortParams) throws NotConnectedRestException, PermissionRestException {
Scheduler s = checkAccess(sessionId, "tasks/tag/" + taskTag);
PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
Page<TaskState> page = null;
// sortParams will be null
if (sortParams == null) {
sortParams = new SortSpecifierContainer();
}
try {
page = s.getTaskStates(taskTag, from, to, mytasks, running, pending, finished, boundaries.getOffset(), boundaries.getLimit(), sortParams);
List<TaskStateData> tasks = map(page.getList(), TaskStateData.class);
return new RestPage<TaskStateData>(tasks, page.getSize());
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method submitFlat.
/**
* Submit job using flat command file
*
* @param sessionId
* valid session id
* @param commandFileContent
* content of a command file: endline separated native commands
* @param jobName
* name of the job to create
* @param selectionScriptContent
* content of a selection script, or null
* @param selectionScriptExtension
* extension of the selectionscript to determine script engine
* ("js", "py", "rb")
* @return Id of the submitted job
* @throws NotConnectedRestException
* @throws IOException
* @throws JobCreationRestException
* @throws PermissionRestException
* @throws SubmissionClosedRestException
*/
@Override
@POST
@Path("submitflat")
@Produces("application/json")
public JobIdData submitFlat(@HeaderParam("sessionid") String sessionId, @FormParam("commandFileContent") String commandFileContent, @FormParam("jobName") String jobName, @FormParam("selectionScriptContent") String selectionScriptContent, @FormParam("selectionScriptExtension") String selectionScriptExtension) throws NotConnectedRestException, IOException, JobCreationRestException, PermissionRestException, SubmissionClosedRestException {
Scheduler s = checkAccess(sessionId, "submitflat");
try {
File command = File.createTempFile("flatsubmit_commands_", ".txt");
command.deleteOnExit();
String selectionPath = null;
File selection = null;
if (selectionScriptContent != null && selectionScriptContent.trim().length() > 0) {
selection = File.createTempFile("flatsubmit_selection_", "." + selectionScriptExtension);
selection.deleteOnExit();
try (PrintWriter pw = new PrintWriter(new FileOutputStream(selection))) {
pw.print(selectionScriptContent);
}
selectionPath = selection.getAbsolutePath();
}
try (PrintWriter pw = new PrintWriter(new FileOutputStream(command))) {
pw.print(commandFileContent);
}
Job j = FlatJobFactory.getFactory().createNativeJobFromCommandsFile(command.getAbsolutePath(), jobName, selectionPath, null);
JobId id = s.submit(j);
command.delete();
if (selection != null) {
selection.delete();
}
return mapper.map(id, JobIdData.class);
} catch (IOException e) {
throw new IOException("I/O Error: " + e.getMessage(), e);
} catch (JobCreationException e) {
throw new JobCreationRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (SubmissionClosedException e) {
throw new SubmissionClosedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getLiveLogJob.
/**
* Stream the output of job identified by the id <code>jobid</code> only
* stream currently available logs, call this method several times to get
* the complete output.
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job to retrieve
* @throws IOException
* @throws LogForwardingRestException
*/
@GET
@GZIP
@Path("jobs/{jobid}/livelog")
@Produces("application/json")
@Override
public String getLiveLogJob(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, LogForwardingRestException, IOException {
try {
Scheduler scheduler = checkAccess(sessionId, "/scheduler/jobs/" + jobId + "/livelog");
Session session = sessionStore.get(sessionId);
JobState jobState = scheduler.getJobState(jobId);
boolean isFinished = jobState != null && jobState.isFinished();
int availableLinesCount = session.getJobsOutputController().availableLinesCount(jobId);
if (!isFinished || availableLinesCount > 0) {
return session.getJobsOutputController().getNewLogs(jobId);
} else {
session.getJobsOutputController().removeAppender(jobId);
return "";
}
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (LogForwardingException e) {
throw new LogForwardingRestException(e);
}
}
use of org.ow2.proactive.resourcemanager.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method listJobs.
/**
* Returns a JobState of the job identified by the id <code>jobid</code>
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job to retrieve
*/
@Override
@GET
@Path("jobs/{jobid}")
@Produces({ "application/json", "application/xml" })
public JobStateData listJobs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "/scheduler/jobs/" + jobId);
JobState js = s.getJobState(jobId);
js = PAFuture.getFutureValue(js);
return mapper.map(js, JobStateData.class);
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
}
}
Aggregations