use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method getJobTaskStatesByTag.
/**
* Returns a list of taskState of the tasks filtered by a given tag.
*
* @param sessionId
* a valid session id
* @param jobId
* the job id
* @param taskTag
* the tag used to filter the tasks
* @return a list of task' states of the job <code>jobId</code> filtered by
* a given tag.
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/taskstates/{tasktag}")
@Produces("application/json")
public RestPage<TaskStateData> getJobTaskStatesByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/taskstates/" + taskTag);
JobState jobState = s.getJobState(jobId);
TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, 0, TASKS_PAGE_SIZE);
List<TaskStateData> tasks = map(page.getTaskStates(), TaskStateData.class);
return new RestPage<TaskStateData>(tasks, page.getSize());
} 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_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method revisionAndJobsInfo.
/**
* Returns a map containing one entry with the revision id as key and the
* list of UserJobData as value. each jobs is described using - its id - its
* owner - the JobInfo class
*
* @param sessionId
* a valid session id
* @param index
* optional, if a sublist has to be returned the index of the
* sublist
* @param limit
* optional, if a sublist has to be returned, the limit of the
* sublist
* @param myJobs
* fetch only the jobs for the user making the request
* @param pending
* fetch pending jobs
* @param running
* fetch running jobs
* @param finished
* fetch finished jobs
* @return a map containing one entry with the revision id as key and the
* list of UserJobData as value.
*/
@Override
@GET
@GZIP
@Path("revisionjobsinfo")
@Produces({ "application/json", "application/xml" })
public RestMapPage<Long, ArrayList<UserJobData>> revisionAndJobsInfo(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit, @QueryParam("myjobs") @DefaultValue("false") boolean myJobs, @QueryParam("pending") @DefaultValue("true") boolean pending, @QueryParam("running") @DefaultValue("true") boolean running, @QueryParam("finished") @DefaultValue("true") boolean finished) throws PermissionRestException, NotConnectedRestException {
try {
Scheduler s = checkAccess(sessionId, "revisionjobsinfo?index=" + index + "&limit=" + limit);
String user = sessionStore.get(sessionId).getUserName();
boolean onlyUserJobs = (myJobs && user != null && user.trim().length() > 0);
Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(onlyUserJobs, pending, running, finished), DEFAULT_JOB_SORT_PARAMS);
List<JobInfo> jobsInfo = page.getList();
ArrayList<UserJobData> jobs = new ArrayList<>(jobsInfo.size());
for (JobInfo jobInfo : jobsInfo) {
jobs.add(new UserJobData(mapper.map(jobInfo, JobInfoData.class)));
}
HashMap<Long, ArrayList<UserJobData>> map = new HashMap<Long, ArrayList<UserJobData>>(1);
map.put(SchedulerStateListener.getInstance().getSchedulerStateRevision(), jobs);
RestMapPage<Long, ArrayList<UserJobData>> restMapPage = new RestMapPage<Long, ArrayList<UserJobData>>();
restMapPage.setMap(map);
restMapPage.setSize(page.getSize());
return restMapPage;
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method validateFromUrl.
@Override
public JobValidationData validateFromUrl(String sessionId, String url, PathSegment pathSegment) throws NotConnectedRestException {
File tmpWorkflowFile = null;
try {
checkAccess(sessionId);
String jobXml = downloadWorkflowContent(sessionId, url);
tmpWorkflowFile = File.createTempFile("job", "d");
Map<String, String> jobVariables;
try (OutputStream outputStream = new FileOutputStream(tmpWorkflowFile)) {
IOUtils.write(jobXml, outputStream);
jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
}
return jobValidator.validateJobDescriptor(tmpWorkflowFile, jobVariables);
} catch (JobCreationRestException | IOException e) {
JobValidationData validation = new JobValidationData();
validation.setErrorMessage("Error while reading workflow at url: " + url);
validation.setStackTrace(getStackTrace(e));
return validation;
} finally {
FileUtils.deleteQuietly(tmpWorkflowFile);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerStateRest method submitFromUrl.
/**
* Submits a workflow to the scheduler from a workflow URL, creating hence a
* new job resource.
*
* @param sessionId
* a valid session id
* @param url
* url to the workflow content
* @param pathSegment
* variables of the workflow
* @return the <code>jobid</code> of the newly created job
* @throws NotConnectedRestException
* @throws IOException
* @throws JobCreationRestException
* @throws PermissionRestException
* @throws SubmissionClosedRestException
*/
@Override
@POST
@Path("{path:jobs}")
@Produces("application/json")
public JobIdData submitFromUrl(@HeaderParam("sessionid") String sessionId, @HeaderParam("link") String url, @PathParam("path") PathSegment pathSegment) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
Scheduler s = checkAccess(sessionId, "jobs");
File tmpWorkflowFile = null;
try {
String jobXml = downloadWorkflowContent(sessionId, url);
tmpWorkflowFile = File.createTempFile("job", "d");
JobId jobId;
try (OutputStream outputStream = new FileOutputStream(tmpWorkflowFile)) {
IOUtils.write(jobXml, outputStream);
WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(s);
jobId = workflowSubmitter.submit(tmpWorkflowFile, workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment));
}
return mapper.map(jobId, JobIdData.class);
} catch (IOException e) {
throw new IOException("Cannot save temporary job file on submission: " + e.getMessage(), e);
} finally {
FileUtils.deleteQuietly(tmpWorkflowFile);
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SessionSharingTest method sessions_are_shared_rm_login.
@Test
public void sessions_are_shared_rm_login() throws Exception {
String sessionId = rmRest.rmConnect("login", "pw");
assertTrue(studioRest.getWorkflows(sessionId).isEmpty());
when(schedulerMock.freeze()).thenReturn(true);
boolean frozen = schedulerRest.freezeScheduler(sessionId);
assertTrue(frozen);
when(rmMock.getState()).thenReturn(new RMState(new RMStateNodeUrls(new HashSet<String>(), new HashSet<String>(), new HashSet<String>()), Long.valueOf(-1)));
RMState rmState = rmRest.getState(sessionId);
assertNotNull(rmState);
rmRest.rmDisconnect(sessionId);
try {
rmRest.getState(sessionId);
fail();
} catch (NotConnectedException expected) {
// expected
}
try {
schedulerRest.freezeScheduler(sessionId);
fail();
} catch (NotConnectedRestException expected) {
// expected
}
}
Aggregations