Search in sources :

Example 41 with PermissionRestException

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

the class SchedulerStateRest method pullFile.

/**
 * Either Pulls a file from the given DataSpace to the local file system or
 * list the content of a directory if the path refers to a directory In the
 * case the path to a file is given, the content of this file will be
 * returns as an input stream In the case the path to a directory is given,
 * the input stream returned will be a text stream containing at each line
 * the content of the directory
 *
 * @param sessionId
 *            a valid session id
 * @param spaceName
 *            the name of the data space involved (GLOBAL or USER)
 * @param filePath
 *            the path to the file or directory whose content must be
 *            received
 */
@Override
public InputStream pullFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath) throws IOException, NotConnectedRestException, PermissionRestException {
    checkAccess(sessionId, "pullFile");
    Session session = dataspaceRestApi.checkSessionValidity(sessionId);
    filePath = normalizeFilePath(filePath, null);
    FileObject sourcefo = dataspaceRestApi.resolveFile(session, spaceName, filePath);
    if (!sourcefo.exists() || !sourcefo.isReadable()) {
        RuntimeException ex = new IllegalArgumentException("File " + filePath + " does not exist or is not readable in space " + spaceName);
        logger.error(ex);
        throw ex;
    }
    if (sourcefo.getType().equals(FileType.FOLDER)) {
        logger.info("[pullFile] reading directory content from " + sourcefo.getURL());
        // if it's a folder we return an InputStream listing its content
        StringBuilder sb = new StringBuilder();
        String nl = System.lineSeparator();
        for (FileObject fo : sourcefo.getChildren()) {
            sb.append(fo.getName().getBaseName() + nl);
        }
        return IOUtils.toInputStream(sb.toString());
    } else if (sourcefo.getType().equals(FileType.FILE)) {
        logger.info("[pullFile] reading file content from " + sourcefo.getURL());
        return sourcefo.getContent().getInputStream();
    } else {
        RuntimeException ex = new IllegalArgumentException("File " + filePath + " has an unsupported type " + sourcefo.getType());
        logger.error(ex);
        throw ex;
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 42 with PermissionRestException

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

the class SchedulerStateRest method schedulerChangeJobPriorityByName.

/**
 * changes the priority of a job
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the job id
 * @param priorityName
 *            a string representing the name of the priority
 * @throws NotConnectedRestException
 * @throws UnknownJobRestException
 * @throws PermissionRestException
 * @throws JobAlreadyFinishedRestException
 */
@Override
@PUT
@Path("jobs/{jobid}/priority/byname/{name}")
public void schedulerChangeJobPriorityByName(@HeaderParam("sessionid") final String sessionId, @PathParam("jobid") final String jobId, @PathParam("name") String priorityName) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException, JobAlreadyFinishedRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/priority/byname/" + priorityName);
        s.changeJobPriority(jobId, JobPriority.findPriority(priorityName));
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (JobAlreadyFinishedException e) {
        throw new JobAlreadyFinishedRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) JobAlreadyFinishedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobAlreadyFinishedRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) 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) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 43 with PermissionRestException

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

the class SchedulerStateRest method jobs.

/**
 * Returns the ids of the current jobs under a list of string.
 *
 * @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
 * @return a list of jobs' ids under the form of a list of string
 */
@Override
@GET
@Path("jobs")
@Produces("application/json")
public RestPage<String> jobs(@HeaderParam("sessionid") String sessionId, @QueryParam("index") @DefaultValue("-1") int index, @QueryParam("limit") @DefaultValue("-1") int limit) throws NotConnectedRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "/scheduler/jobs");
        Page<JobInfo> page = s.getJobs(index, limit, new JobFilterCriteria(false, true, true, true), DEFAULT_JOB_SORT_PARAMS);
        List<String> ids = new ArrayList<String>(page.getList().size());
        for (JobInfo jobInfo : page.getList()) {
            ids.add(jobInfo.getJobId().value());
        }
        return new RestPage<String>(ids, page.getSize());
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : JobFilterCriteria(org.ow2.proactive.scheduler.common.JobFilterCriteria) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) 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)

Example 44 with PermissionRestException

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

the class SchedulerStateRest method getJobTaskStatesPaginated.

/**
 * Returns a list of taskState with pagination
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the job id
 * @param offset
 *            the index of the first TaskState to return
 * @param limit
 *            the index (non inclusive) of the last TaskState to return
 * @return a list of task' states of the job <code>jobId</code>
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/taskstates/paginated")
@Produces("application/json")
public RestPage<TaskStateData> getJobTaskStatesPaginated(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("-1") int limit) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    if (limit == -1)
        limit = TASKS_PAGE_SIZE;
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/taskstates/paginated");
        JobState jobState = s.getJobState(jobId);
        TaskStatesPage page = jobState.getTasksPaginated(offset, limit);
        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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) 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) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) JobState(org.ow2.proactive.scheduler.common.job.JobState) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 45 with PermissionRestException

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

the class SchedulerStateRest method jobResultValue.

/**
 * Returns all the task results of this job as a map whose the key is the
 * name of the task and its task result.<br>
 * If the result cannot be instantiated, the content is replaced by the
 * string 'Unknown value type'. To get the serialized form of a given
 * result, one has to call the following restful service
 * jobs/{jobid}/tasks/{taskname}/result/serializedvalue
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            a job id
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/value")
@Produces("application/json")
public Map<String, String> jobResultValue(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, PermissionRestException, UnknownJobRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/value");
        JobResult jobResult = PAFuture.getFutureValue(s.getJobResult(jobId));
        if (jobResult == null) {
            return null;
        }
        Map<String, TaskResult> allResults = jobResult.getAllResults();
        Map<String, String> res = new HashMap<>(allResults.size());
        for (final Entry<String, TaskResult> entry : allResults.entrySet()) {
            TaskResult taskResult = entry.getValue();
            String value = getTaskResultValueAsStringOrExceptionStackTrace(taskResult);
            res.put(entry.getKey(), value);
        }
        return res;
    } 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) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) HashMap(java.util.HashMap) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

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