Search in sources :

Example 1 with JobIdData

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData 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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) IOException(java.io.IOException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) FileOutputStream(java.io.FileOutputStream) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) Job(org.ow2.proactive.scheduler.common.job.Job) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) PrintWriter(java.io.PrintWriter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with JobIdData

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData 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);
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with JobIdData

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.

the class SchedulerRestClient method submit.

private JobIdData submit(String sessionId, InputStream job, MediaType mediaType, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException {
    String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/submit";
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl);
    // Generic infos
    if (genericInfos != null) {
        for (String key : genericInfos.keySet()) {
            target = target.queryParamNoTemplate(key, genericInfos.get(key));
        }
    }
    // Multipart form
    MultipartFormDataOutput formData = new MultipartFormDataOutput();
    // Add job to multipart
    formData.addFormData(FILE_KEY, job, mediaType);
    // Add variables to multipart
    if (variables != null && variables.size() > 0) {
        formData.addFormData(VARIABLES_KEY, variables, MediaType.APPLICATION_JSON_TYPE);
    }
    // Multipart form entity
    GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(formData) {
    };
    Response response = target.request().header("sessionid", sessionId).post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
    if (response.getStatus() != HttpURLConnection.HTTP_OK) {
        if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
            throw new NotConnectedRestException("User not authenticated or session timeout.");
        } else {
            throwException(String.format("Job submission failed status code: %d", response.getStatus()), response);
        }
    }
    return response.readEntity(JobIdData.class);
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) MultipartFormDataOutput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)

Example 4 with JobIdData

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.

the class SchedulerRestClient method reSubmit.

public JobIdData reSubmit(String sessionId, String jobId, Map<String, String> variables, Map<String, String> genericInfos) throws NotConnectedRestException {
    String uriTmpl = restEndpointURL + addSlashIfMissing(restEndpointURL) + "scheduler/jobs/" + jobId + "/resubmit";
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl);
    // Variables
    if (variables != null) {
        for (String key : variables.keySet()) {
            target = target.matrixParam(key, variables.get(key));
        }
    }
    // Generic infos
    if (genericInfos != null) {
        for (String key : genericInfos.keySet()) {
            target = target.queryParam(key, genericInfos.get(key));
        }
    }
    Response response = target.request().header("sessionid", sessionId).get();
    if (response.getStatus() != HttpURLConnection.HTTP_OK) {
        if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
            throw new NotConnectedRestException("User not authenticated or session timeout.");
        } else {
            throwException(String.format("Job submission failed status code: %d", response.getStatus()), response);
        }
    }
    return response.readEntity(JobIdData.class);
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 5 with JobIdData

use of org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData in project scheduling by ow2-proactive.

the class SchedulerClientExample method main.

public static void main(String[] args) throws Exception {
    // LOGIN IN
    SchedulerRestClient client = new SchedulerRestClient("http://localhost:8080/rest/");
    SchedulerRestInterface scheduler = client.getScheduler();
    String sessionId = scheduler.login("admin", "admin");
    // JOB SUBMISSION
    File xmlJobFile = new File("/path/to/some/existing/job/job_1.xml");
    JobIdData xmlJob;
    try (FileInputStream inputStream = new FileInputStream(xmlJobFile)) {
        xmlJob = client.submitXml(sessionId, inputStream);
    }
    System.out.println(xmlJob.getReadableName() + " " + xmlJob.getId());
    // FLAT JOB SUBMISSION
    JobIdData flatJob = scheduler.submitFlat(sessionId, "echo hello", "test-hello", null, null);
    System.out.println("Jobid=" + flatJob);
    String serverlog = scheduler.jobServerLog(sessionId, Long.toString(flatJob.getId()));
    System.out.println(serverlog);
    while (true) {
        JobStateData jobState2 = scheduler.listJobs(sessionId, Long.toString(flatJob.getId()));
        System.out.println(jobState2);
        if (jobState2.getJobInfo().getStatus().name().equals("FINISHED")) {
            break;
        }
        Thread.sleep(100);
    }
    JobResultData jobResultData = scheduler.jobResult(sessionId, Long.toString(flatJob.getId()));
    System.out.println(jobResultData);
    TaskResultData taskresult = scheduler.taskResult(sessionId, Long.toString(flatJob.getId()), "task_1");
    System.out.println(taskresult);
    List<TaskStateData> jobTaskStates = scheduler.getJobTaskStates(sessionId, Long.toString(flatJob.getId())).getList();
    System.out.println(jobTaskStates);
    TaskStateData task_1 = scheduler.jobTask(sessionId, Long.toString(flatJob.getId()), "task_1");
    System.out.println(task_1);
    // OTHER CALLS
    List<SchedulerUserData> users = scheduler.getUsers(sessionId);
    System.out.println(users);
    System.out.println(users.size());
    RestMapPage<Long, ArrayList<UserJobData>> page = scheduler.revisionAndJobsInfo(sessionId, 0, 50, true, true, true, true, true, null, null, null, null, null);
    Map<Long, ArrayList<UserJobData>> map = page.getMap();
    System.out.println(map);
    System.out.println(scheduler.getSchedulerStatus(sessionId));
    System.out.println(scheduler.getUsageOnMyAccount(sessionId, new Date(), new Date()));
    // FAILING CALL
    try {
        JobStateData jobState = scheduler.listJobs(sessionId, "601");
        System.out.println(jobState);
    } catch (UnknownJobRestException e) {
        System.err.println("exception! " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : JobIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobIdData) JobResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobResultData) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) JobStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobStateData) SchedulerUserData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.SchedulerUserData) FileInputStream(java.io.FileInputStream) Date(java.util.Date) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) File(java.io.File)

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