Search in sources :

Example 26 with PermissionRestException

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

the class RestDataspaceImpl method retrieve.

/**
 * Retrieves single or multiple files from specified location of the server.
 * The format of the GET URI is:
 * <P>
 * {@code http://<rest-server-path>/data/<dataspace>/<path-name>}
 * <p>
 * Example:
 * <p>
 * {@code http://localhost:8080/rest/rest/data/user/my-files/my-text-file.txt}
 * <ul>
 * <li>dataspace: can have two possible values, 'user' or 'global',
 * depending on the target <i>DATASPACE</i></li>
 * <li>path-name: location from which the file will be retrieved.</li>
 * </ul>
 * <b>Notes:</b>
 * <ul>
 * <li>If 'list' is specified as the 'comp' query parameter, an
 * {@link ListFile} type object will be return in JSON format. It will contain a list of files and folder contained in the selected
 * path.
 * </li>
 * <li>If 'recursive' is specified as the 'comp' query parameter, an
 * {@link ListFile} type object will be return in JSON format. It will contain a list of files and folder contained in the selected
 * path and all subfolders.
 * </li>
 * <li>If the pathname represents a file its contents will be returned as:
 * <ul>
 * <li>an octet stream, if its a compressed file or the client doesn't
 * accept encoded content</li>
 * <li>a 'gzip' encoded stream, if the client accepts 'gzip' encoded content
 * </li>
 * <li>a 'zip' encoded stream, if the client accepts 'zip' encoded contents</li>
 * </ul>
 * </li>
 * <li>If the pathname represents a directory, its contents will be returned
 * as 'zip' encoded stream.</li>
 * <li>file names or regular expressions can be used as 'includes' and
 * 'excludes' query parameters, in order to select which files to be
 * returned can be used to select the files returned.</li>
 * </ul>
 */
@GET
@Path("/{dataspace}/{path-name:.*}")
public Response retrieve(@HeaderParam("sessionid") String sessionId, @HeaderParam("Accept-Encoding") String encoding, @PathParam("dataspace") String dataspace, @PathParam("path-name") String pathname, @QueryParam("comp") String component, @QueryParam("includes") List<String> includes, @QueryParam("excludes") List<String> excludes) throws NotConnectedRestException, PermissionRestException {
    Session session = checkSessionValidity(sessionId);
    try {
        checkPathParams(dataspace, pathname);
        FileObject fo = resolveFile(session, dataspace, pathname);
        if (!fo.exists()) {
            return notFoundRes();
        }
        if (!Strings.isNullOrEmpty(component)) {
            return componentResponse(component, fo, includes, excludes);
        }
        if (fo.getType() == FileType.FILE) {
            if (VFSZipper.isZipFile(fo)) {
                logger.debug(String.format("Retrieving file %s in %s", pathname, dataspace));
                return fileComponentResponse(fo);
            } else if (Strings.isNullOrEmpty(encoding) || encoding.contains("*") || encoding.contains("gzip")) {
                logger.debug(String.format("Retrieving file %s as gzip in %s", pathname, dataspace));
                return gzipComponentResponse(pathname, fo);
            } else if (encoding.contains("zip")) {
                logger.debug(String.format("Retrieving file %s as zip in %s", pathname, dataspace));
                return zipComponentResponse(fo, null, null);
            } else {
                logger.debug(String.format("Retrieving file %s in %s", pathname, dataspace));
                return fileComponentResponse(fo);
            }
        } else {
            // folder
            if (Strings.isNullOrEmpty(encoding) || encoding.contains("*") || encoding.contains("zip")) {
                logger.debug(String.format("Retrieving folder %s as zip in %s", pathname, dataspace));
                return zipComponentResponse(fo, includes, excludes);
            } else {
                return badRequestRes("Folder retrieval only supported with zip encoding.");
            }
        }
    } catch (Throwable error) {
        logger.error(String.format("Cannot retrieve %s in %s.", pathname, dataspace), error);
        throw rethrow(error);
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 27 with PermissionRestException

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

the class SchedulerStateRest method taskResultByTag.

/**
 * Returns the task results of the set of task filtered by a given tag and
 * owned by the job <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the task results of the set of tasks filtered by the given tag.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result")
@Produces("application/json")
public List<TaskResultData> taskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskTag + "/result");
        List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
        ArrayList<TaskResultData> results = new ArrayList<TaskResultData>(taskResults.size());
        for (TaskResult current : taskResults) {
            TaskResultData r = buildTaskResultData(PAFuture.getFutureValue(current));
            results.add(r);
        }
        return results;
    } 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) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) 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 28 with PermissionRestException

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

the class SchedulerStateRest method taskFullLogs.

/**
 * Returns full logs generated by the task from user data spaces if task was
 * run using the precious logs option. Otherwise, logs are retrieved from
 * the database. In this last case they may be truncated.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return all the logs generated by the task (either stdout and stderr) or
 *         an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/log/full")
@Produces("application/json")
public InputStream taskFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
    try {
        if (sessionId == null) {
            sessionId = session;
        }
        Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/log/all");
        TaskResult taskResult = scheduler.getTaskResult(jobId, taskname);
        if (taskResult != null) {
            JobState jobState = scheduler.getJobState(taskResult.getTaskId().getJobId());
            boolean hasPreciousLogs = false;
            for (Task task : jobState.getTasks()) {
                if (task.getName().equals(taskname)) {
                    hasPreciousLogs = task.isPreciousLogs();
                    break;
                }
            }
            if (hasPreciousLogs) {
                return retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskResult.getTaskId());
            } else {
                logger.warn("Retrieving truncated logs for task '" + taskname + "'");
                return IOUtils.toInputStream(retrieveTaskLogsUsingDatabase(sessionId, jobId, taskname));
            }
        } else {
            return null;
        }
    } 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) Task(org.ow2.proactive.scheduler.common.task.Task) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) 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) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 29 with PermissionRestException

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

the class SchedulerStateRest method jobLogs.

/**
 * Returns all the logs generated by the job (either stdout and stderr)
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @return all the logs generated by the job (either stdout and stderr) or
 *         an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/log/all")
@Produces("application/json")
public String jobLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/log/all");
        JobResult jobResult = s.getJobResult(jobId);
        if (jobResult == null) {
            return "";
        }
        StringBuilder jobOutput = new StringBuilder();
        for (TaskResult tr : jobResult.getAllResults().values()) {
            if ((tr != null) && (tr.getOutput() != null)) {
                jobOutput.append(tr.getOutput().getAllLogs(true));
            }
        }
        return jobOutput.toString();
    } 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) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) 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) 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 30 with PermissionRestException

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

the class SchedulerStateRest method getSchedulerPropertiesFromSessionId.

@GET
@Override
@Path("properties")
@Produces("application/json")
public Map<String, Object> getSchedulerPropertiesFromSessionId(@HeaderParam("sessionid") final String sessionId) throws NotConnectedRestException, PermissionRestException {
    SchedulerProxyUserInterface scheduler = checkAccess(sessionId, "properties");
    Map<String, Object> schedulerProperties = new HashMap<String, Object>();
    try {
        schedulerProperties = scheduler.getSchedulerProperties();
    } catch (NotConnectedException e) {
        logger.warn("Attempt to retrieve scheduler properties but failed because connection exception", e);
        throw new PermissionRestException(e);
    } catch (PermissionException e) {
        logger.warn("Attempt to retrieve scheduler properties but failed because permission exception", e);
        throw new NotConnectedRestException(e);
    }
    return schedulerProperties;
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) HashMap(java.util.HashMap) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) SchedulerProxyUserInterface(org.ow2.proactive.scheduler.common.util.SchedulerProxyUserInterface) FileObject(org.apache.commons.vfs2.FileObject) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) 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)

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