Search in sources :

Example 36 with PermissionRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobFullLogs.

@Override
@GET
@GZIP
@Path("jobs/{jobid}/log/full")
@Produces("application/json")
public InputStream jobFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
    if (sessionId == null) {
        sessionId = session;
    }
    try {
        Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/log/full");
        JobState jobState = scheduler.getJobState(jobId);
        List<TaskState> tasks = jobState.getTasks();
        List<InputStream> streams = new ArrayList<>(tasks.size());
        Collections.sort(tasks, TaskState.COMPARE_BY_FINISHED_TIME_ASC);
        for (TaskState taskState : tasks) {
            InputStream inputStream = null;
            try {
                if (taskState.isPreciousLogs()) {
                    inputStream = retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskState.getId());
                } else {
                    String taskLogs = retrieveTaskLogsUsingDatabase(sessionId, jobId, taskState.getName());
                    if (!taskLogs.isEmpty()) {
                        inputStream = IOUtils.toInputStream(taskLogs);
                    }
                    logger.warn("Retrieving truncated logs for task '" + taskState.getId() + "'");
                }
            } catch (Exception e) {
                logger.info("Could not retrieve logs for task " + taskState.getId() + " (could be a non finished or killed task)", e);
            }
            if (inputStream != null) {
                streams.add(inputStream);
            }
        }
        if (streams.isEmpty()) {
            // will produce HTTP 204 code
            return null;
        } else {
            return new SequenceInputStream(Collections.enumeration(streams));
        }
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) LogForwardingRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.LogForwardingRestException) NodeException(org.objectweb.proactive.core.node.NodeException) 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) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) URISyntaxException(java.net.URISyntaxException) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobAlreadyFinishedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobAlreadyFinishedRestException) SubmissionClosedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SubmissionClosedRestException) SequenceInputStream(java.io.SequenceInputStream) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 37 with PermissionRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException 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)

Example 38 with PermissionRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method taskResult.

/**
 * Returns the task result of the task <code>taskName</code> of the job
 * <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return the task result of the task <code>taskName</code>
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result")
@Produces("application/json")
public TaskResultData taskResult(@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");
        TaskResult taskResult = s.getTaskResult(jobId, taskname);
        if (taskResult == null) {
            TaskIdData taskIdData = new TaskIdData();
            taskIdData.setReadableName(taskname);
            TaskResultData taskResultData = new TaskResultData();
            taskResultData.setId(taskIdData);
            return taskResultData;
        }
        return buildTaskResultData(taskResult);
    } 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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 39 with PermissionRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method jobTask.

/**
 * Return the task state of the task <code>taskname</code> of the job
 * <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return the task state of the task <code>taskname</code> of the job
 *         <code>jobId</code>
 */
@Override
@GET
@Path("jobs/{jobid}/tasks/{taskname}")
@Produces("application/json")
public TaskStateData jobTask(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, UnknownTaskRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname);
        JobState jobState = s.getJobState(jobId);
        for (TaskState ts : jobState.getTasks()) {
            if (ts.getId().getReadableName().equals(taskname)) {
                return mapper.map(ts, TaskStateData.class);
            }
        }
        throw new UnknownTaskRestException("task " + taskname + "not found");
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) JobState(org.ow2.proactive.scheduler.common.job.JobState) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with PermissionRestException

use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException in project scheduling by ow2-proactive.

the class SchedulerStateRest method getJobTasksIdsByTag.

/**
 * Returns a list of the name of the tasks belonging to job and filtered by
 * a given tag. <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            jobid one wants to list the tasks' name
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the list of task ids with the total number of them
 */
@Override
@GET
@Path("jobs/{jobid}/tasks/tag/{tasktag}")
@Produces("application/json")
public RestPage<String> getJobTasksIdsByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTaskByTagPaginated(taskTag, 0, TASKS_PAGE_SIZE);
        List<TaskState> tasks = page.getTaskStates();
        List<String> tasksName = new ArrayList<>(tasks.size());
        for (TaskState ts : tasks) {
            tasksName.add(ts.getId().getReadableName());
        }
        return new RestPage<String>(tasksName, page.getSize());
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)39 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)39 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)39 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)39 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)37 Path (javax.ws.rs.Path)34 Produces (javax.ws.rs.Produces)32 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)27 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)27 GET (javax.ws.rs.GET)26 GZIP (org.jboss.resteasy.annotations.GZIP)17 ArrayList (java.util.ArrayList)13 JobState (org.ow2.proactive.scheduler.common.job.JobState)13 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)12 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)11 FileObject (org.apache.commons.vfs2.FileObject)9 Session (org.ow2.proactive_grid_cloud_portal.common.Session)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)7 IOException (java.io.IOException)6 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)6