Search in sources :

Example 26 with NotConnectedRestException

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

the class SchedulerClient method getTaskIds.

@Override
public Page<TaskId> getTaskIds(String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit) throws NotConnectedException, PermissionException {
    RestPage<TaskStateData> page = null;
    try {
        page = restApi().getTaskStates(sid, from, to, mytasks, running, pending, finished, offset, limit, null);
    } catch (NotConnectedRestException e) {
        throw new NotConnectedException(e);
    } catch (PermissionRestException e) {
        throw new PermissionException(e);
    }
    List<TaskId> lTaskIds = new ArrayList<TaskId>(page.getList().size());
    for (TaskStateData taskStateData : page.getList()) {
        TaskInfoData taskInfo = taskStateData.getTaskInfo();
        TaskIdData taskIdData = taskInfo.getTaskId();
        JobId jobId = new JobIdImpl(taskInfo.getJobId().getId(), taskInfo.getJobId().getReadableName());
        TaskId taskId = TaskIdImpl.createTaskId(jobId, taskIdData.getReadableName(), taskIdData.getId());
        lTaskIds.add(taskId);
    }
    return new Page<TaskId>(lTaskIds, page.getSize());
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) TaskInfoData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskInfoData) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Page(org.ow2.proactive.scheduler.common.Page) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 27 with NotConnectedRestException

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

the class SchedulerClient method getJobInfo.

@Override
public JobInfo getJobInfo(String jobId) throws UnknownJobException, NotConnectedException, PermissionException {
    JobInfoData jobInfoData = null;
    try {
        jobInfoData = restApi().jobInfo(sid, jobId);
    } catch (NotConnectedRestException e) {
        throw new NotConnectedException(e);
    } catch (PermissionRestException e) {
        throw new PermissionException(e);
    } catch (UnknownJobRestException e) {
        throw new UnknownJobException(e);
    }
    JobInfoImpl jobInfoImpl = new JobInfoImpl();
    JobId newJobId = JobIdImpl.makeJobId(jobId);
    jobInfoImpl.setJobId(newJobId);
    jobInfoImpl.setJobOwner(jobInfoData.getJobOwner());
    jobInfoImpl.setFinishedTime(jobInfoData.getFinishedTime());
    jobInfoImpl.setRemovedTime(jobInfoData.getRemovedTime());
    jobInfoImpl.setStartTime(jobInfoData.getStartTime());
    jobInfoImpl.setInErrorTime(jobInfoData.getInErrorTime());
    jobInfoImpl.setSubmittedTime(jobInfoData.getSubmittedTime());
    jobInfoImpl.setNumberOfFinishedTasks(jobInfoData.getNumberOfFinishedTasks());
    jobInfoImpl.setNumberOfPendingTasks(jobInfoData.getNumberOfPendingTasks());
    jobInfoImpl.setNumberOfRunningTasks(jobInfoData.getNumberOfRunningTasks());
    jobInfoImpl.setNumberOfInErrorTasks(jobInfoData.getNumberOfInErrorTasks());
    jobInfoImpl.setNumberOfFaultyTasks(jobInfoData.getNumberOfFaultyTasks());
    jobInfoImpl.setTotalNumberOfTasks(jobInfoData.getTotalNumberOfTasks());
    jobInfoImpl.setJobPriority(JobPriority.findPriority(jobInfoData.getPriority().toString()));
    jobInfoImpl.setJobStatus(JobStatus.findPriority(jobInfoData.getStatus().toString()));
    if (jobInfoData.isToBeRemoved())
        jobInfoImpl.setToBeRemoved();
    jobInfoImpl.setGenericInformation(jobInfoData.getGenericInformation());
    jobInfoImpl.setVariables(jobInfoData.getVariables());
    return jobInfoImpl;
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) JobInfoData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobInfoData) 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) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) JobInfoImpl(org.ow2.proactive.scheduler.rest.data.JobInfoImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 28 with NotConnectedRestException

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

the class SchedulerClient method getTaskStates.

@Override
public Page<TaskState> getTaskStates(String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit, SortSpecifierContainer sortParams) throws NotConnectedException, PermissionException {
    RestPage<TaskStateData> page = null;
    SortSpecifierContainer sortContainer = new SortSpecifierContainer(sortParams.toString());
    try {
        page = restApi().getTaskStates(sid, from, to, mytasks, running, pending, finished, offset, limit, sortContainer);
    } catch (NotConnectedRestException e) {
        throw new NotConnectedException(e);
    } catch (PermissionRestException e) {
        throw new PermissionException(e);
    }
    List<TaskState> lTaskStates = new ArrayList<TaskState>(page.getList().size());
    for (TaskStateData taskStateData : page.getList()) {
        lTaskStates.add(new TaskStateImpl(taskStateData));
    }
    return new Page<TaskState>(lTaskStates, page.getSize());
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) SortSpecifierContainer(org.ow2.proactive.scheduler.common.SortSpecifierContainer) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) ArrayList(java.util.ArrayList) TaskStateImpl(org.ow2.proactive.scheduler.rest.data.TaskStateImpl) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Page(org.ow2.proactive.scheduler.common.Page) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 29 with NotConnectedRestException

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

the class RestDataspaceImpl method delete.

/**
 * Delete file(s) from the specified location in the <i>dataspace</i>. The
 * format of the DELETE URI is:
 * <p>
 * {@code http://<rest-server-path>/data/<dataspace>/<path-name>}
 * <p>
 * Example:
 * {@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 of the file(s) to be deleted.</li>
 * </ul>
 * <b>Notes:</b>
 * <ul>
 * <li>Only empty directories can be deleted.</li>
 * <li>File names or regular expressions can be used as 'includes' and
 * 'excludes' query parameters, in order to select which files to be deleted
 * inside the specified directory (path-name).</li>
 * </ul>
 */
@DELETE
@Path("/{dataspace}/{path-name:.*}")
public Response delete(@HeaderParam("sessionid") String sessionId, @PathParam("dataspace") String dataspace, @PathParam("path-name") String pathname, @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 Response.status(Response.Status.NO_CONTENT).build();
        }
        if (fo.getType() == FileType.FOLDER) {
            logger.debug(String.format("Deleting directory %s in %s", pathname, dataspace));
            return deleteDir(fo, includes, excludes);
        } else {
            logger.debug(String.format("Deleting file %s in %s", pathname, dataspace));
            fo.close();
            return fo.delete() ? noContentRes() : serverErrorRes("Cannot delete the file: %s", pathname);
        }
    } catch (Throwable error) {
        logger.error(String.format("Cannot delete %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 30 with NotConnectedRestException

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

Aggregations

NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)53 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)42 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)40 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)40 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)38 Path (javax.ws.rs.Path)37 Produces (javax.ws.rs.Produces)35 GET (javax.ws.rs.GET)28 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)28 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)28 GZIP (org.jboss.resteasy.annotations.GZIP)17 ArrayList (java.util.ArrayList)13 JobState (org.ow2.proactive.scheduler.common.job.JobState)13 Session (org.ow2.proactive_grid_cloud_portal.common.Session)12 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)12 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)11 Response (javax.ws.rs.core.Response)10 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)10 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)10 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)10