use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerRestWorkflowFromCatalogExecutionTest method testWhenSubmittingAValidTemplateWithVariablesThenTheProvidedJobVariableIsUsed.
@Test
public void testWhenSubmittingAValidTemplateWithVariablesThenTheProvidedJobVariableIsUsed() throws Exception {
when(scheduler.submit(Matchers.<Job>any())).thenReturn(new JobIdImpl(99L, "job"));
ArgumentCaptor<Job> argumentCaptor = ArgumentCaptor.forClass(Job.class);
String workflowUrl = getBaseUriTestWorkflowsServer() + "/workflow";
JobIdData response = schedulerRest.submitFromUrl(sessionId, workflowUrl, getOneVariablePathSegment("var1", "value1"), null);
verify(scheduler).submit(argumentCaptor.capture());
Job interceptedJob = argumentCaptor.getValue();
Assert.assertEquals(1, interceptedJob.getVariables().size());
Assert.assertEquals("value1", interceptedJob.getVariables().get("var1").getValue());
Assert.assertEquals(99L, response.getId());
Assert.assertEquals("job", response.getReadableName());
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerRestWorkflowFromCatalogExecutionTest method testWhenSubmittingAValidTemplateWithoutVariablesThenTheDefaultJobVariableIsUsed.
@Test
public void testWhenSubmittingAValidTemplateWithoutVariablesThenTheDefaultJobVariableIsUsed() throws Exception {
when(scheduler.submit(Matchers.<Job>any())).thenReturn(new JobIdImpl(88L, "job"));
ArgumentCaptor<Job> argumentCaptor = ArgumentCaptor.forClass(Job.class);
String workflowUrl = getBaseUriTestWorkflowsServer() + "/workflow";
JobIdData response = schedulerRest.submitFromUrl(sessionId, workflowUrl, getEmptyPathSegment(), null);
verify(scheduler).submit(argumentCaptor.capture());
Job interceptedJob = argumentCaptor.getValue();
Assert.assertEquals(1, interceptedJob.getVariables().size());
Assert.assertEquals("defaultvalue", interceptedJob.getVariables().get("var1").getValue());
Assert.assertEquals(88L, response.getId());
Assert.assertEquals("job", response.getReadableName());
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerClient method submit.
@Override
public JobId submit(URL job, Map<String, String> variables, Map<String, String> genericInfos, Map<String, String> requestHeaderParams) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
JobIdData jobIdData = null;
try {
URLConnection urlConnection = job.openConnection();
if (requestHeaderParams != null) {
for (Map.Entry<String, String> requestHeaderEntry : requestHeaderParams.entrySet()) {
urlConnection.addRequestProperty(requestHeaderEntry.getKey(), requestHeaderEntry.getValue());
}
}
InputStream is = urlConnection.getInputStream();
jobIdData = restApiClient().submitXml(sid, is, variables, genericInfos);
} catch (Exception e) {
throwNCEOrPEOrSCEOrJCE(e);
}
return jobId(jobIdData);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerClient method submitFromCatalog.
private JobId submitFromCatalog(HttpGet httpGet, Map<String, String> variables, Map<String, String> genericInfos) throws SubmissionClosedException, JobCreationException, NotConnectedException, PermissionException {
JobIdData jobIdData = null;
httpGet.addHeader("sessionid", sid);
try (CloseableHttpClient httpclient = getHttpClientBuilder().build();
CloseableHttpResponse response = httpclient.execute(httpGet)) {
jobIdData = restApiClient().submitXml(sid, response.getEntity().getContent(), variables, genericInfos);
} catch (Exception e) {
throwNCEOrPEOrSCEOrJCE(e);
}
return jobId(jobIdData);
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.
the class SchedulerStateRest method submit.
/**
* Submits a job to the scheduler
*
* @param sessionId
* a valid session id
* @return the <code>jobid</code> of the newly created job
* @throws IOException
* if the job was not correctly uploaded/stored
*/
@Override
@POST
@Path("{path:submit}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public JobIdData submit(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment, MultipartFormDataInput multipart) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
try {
Scheduler scheduler = checkAccess(sessionId, "submit");
Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
String name = formDataMap.keySet().iterator().next();
File tmpJobFile = null;
try {
// "file"
InputPart part1 = multipart.getFormDataMap().get(name).get(0);
String fileType = part1.getMediaType().toString().toLowerCase();
if (!fileType.contains(MediaType.APPLICATION_XML.toLowerCase())) {
throw new JobCreationRestException("Unknown job descriptor type: " + fileType);
}
// is the name of the browser's input field
InputStream is = part1.getBody(new GenericType<InputStream>() {
});
tmpJobFile = File.createTempFile("job", "d");
JobId jobId;
try (OutputStream outputStream = new FileOutputStream(tmpJobFile)) {
IOUtils.copy(is, outputStream);
Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(scheduler);
jobId = workflowSubmitter.submit(tmpJobFile, jobVariables);
}
return mapper.map(jobId, JobIdData.class);
} finally {
if (tmpJobFile != null) {
// clean the temporary file
FileUtils.deleteQuietly(tmpJobFile);
}
}
} catch (IOException e) {
throw new IOException("I/O Error: " + e.getMessage(), e);
}
}
Aggregations