use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobLogs.
/**
* Returns all the logs generated by the job (either stdout and stderr)
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @return all the logs generated by the job (either stdout and stderr) or
* an empty string if the result is not yet available
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/log/all")
@Produces("application/json")
public String jobLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/log/all");
JobResult jobResult = s.getJobResult(jobId);
if (jobResult == null) {
return "";
}
StringBuilder jobOutput = new StringBuilder();
for (TaskResult tr : jobResult.getAllResults().values()) {
if ((tr != null) && (tr.getOutput() != null)) {
jobOutput.append(tr.getOutput().getAllLogs(true));
}
}
return jobOutput.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.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getSchedulerPropertiesFromSessionId.
@GET
@Override
@Path("properties")
@Produces("application/json")
public Map<String, Object> getSchedulerPropertiesFromSessionId(@HeaderParam("sessionid") final String sessionId) throws NotConnectedRestException, PermissionRestException {
SchedulerProxyUserInterface scheduler = checkAccess(sessionId, "properties");
Map<String, Object> schedulerProperties = new HashMap<String, Object>();
try {
schedulerProperties = scheduler.getSchedulerProperties();
} catch (NotConnectedException e) {
logger.warn("Attempt to retrieve scheduler properties but failed because connection exception", e);
throw new PermissionRestException(e);
} catch (PermissionException e) {
logger.warn("Attempt to retrieve scheduler properties but failed because permission exception", e);
throw new NotConnectedRestException(e);
}
return schedulerProperties;
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskLogErr.
/**
* Returns the standard error output (stderr) generated by the task
*
* @param sessionId
* a valid session id
* @param jobId
* the id of the job
* @param taskname
* the name of the task
* @return the stderr generated by the task or an empty string if the result
* is not yet available
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/log/err")
@Produces("application/json")
public String taskLogErr(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/log/err");
TaskResult tr = s.getTaskResult(jobId, taskname);
if ((tr != null) && (tr.getOutput() != null)) {
return tr.getOutput().getStderrLogs(true);
} else {
return "";
}
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (UnknownTaskException e) {
throw new UnknownTaskRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getTaskIdsByTag.
@Override
public RestPage<String> getTaskIdsByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit) throws NotConnectedRestException, PermissionRestException {
Scheduler s = checkAccess(sessionId, "tasks");
PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
Page<TaskId> page = null;
try {
page = s.getTaskIds(taskTag, from, to, mytasks, running, pending, finished, boundaries.getOffset(), boundaries.getLimit());
List<TaskId> taskIds = page.getList();
List<String> taskNames = new ArrayList<>(taskIds.size());
for (TaskId taskId : taskIds) {
taskNames.add(taskId.getReadableName());
}
return new RestPage<String>(taskNames, page.getSize());
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (PermissionException e) {
throw new PermissionRestException(e);
}
}
use of org.ow2.proactive.scheduler.common.exception.NotConnectedException in project scheduling by ow2-proactive.
the class SchedulerStateRest method taskLogoutByTag.
/**
* Returns the standard output (stdout) 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 stdout generated by the task or an empty string if the result
* is not yet available
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/log/out")
@Produces("application/json")
public String taskLogoutByTag(@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/out");
List<TaskResult> trs = s.getTaskResultsByTag(jobId, taskTag);
StringBuffer result = new StringBuffer();
for (TaskResult tr : trs) {
if (tr.getOutput() != null) {
result.append(tr.getOutput().getStdoutLogs(true));
}
}
return result.toString();
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
Aggregations