Search in sources :

Example 6 with JobIdData

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());
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Job(org.ow2.proactive.scheduler.common.job.Job) Test(org.junit.Test)

Example 7 with JobIdData

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());
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Job(org.ow2.proactive.scheduler.common.job.Job) Test(org.junit.Test)

Example 8 with JobIdData

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TaskStatus.statusesToString(org.ow2.proactive.scheduler.common.task.TaskStatus.statusesToString) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) URLConnection(java.net.URLConnection) KeyStoreException(java.security.KeyStoreException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException)

Example 9 with 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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) KeyStoreException(java.security.KeyStoreException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) TimeoutException(java.util.concurrent.TimeoutException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) SignalApiException(org.ow2.proactive.scheduler.signal.SignalApiException)

Example 10 with 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);
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

JobIdData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData)9 IOException (java.io.IOException)7 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)4 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)4 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)4 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)4 FileOutputStream (java.io.FileOutputStream)3 InputStream (java.io.InputStream)3 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ArrayList (java.util.ArrayList)3 TimeoutException (java.util.concurrent.TimeoutException)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Test (org.junit.Test)3 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)3