Search in sources :

Example 31 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session 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 32 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session 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 33 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method rmDisconnect.

/**
 * Disconnects from resource manager and releases all the nodes taken by
 * user for computations.
 *
 * @param sessionId
 *            a valid session id
 * @throws NotConnectedException
 */
@Override
@POST
@Path("disconnect")
@Produces("application/json")
public void rmDisconnect(@HeaderParam("sessionid") String sessionId) throws NotConnectedException {
    RMProxyUserInterface rm = checkAccess(sessionId);
    rm.disconnect();
    sessionStore.terminate(sessionId);
}
Also used : RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 34 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method rmConnect.

/**
 * Log into the resource manager using an form containing 2 fields
 * @return the sessionid of the user if succeed
 * @throws RMException
 * @throws LoginException
 * @throws KeyException
 * @throws NodeException
 * @throws ActiveObjectCreationException
 */
@Override
@POST
@Path("login")
@Produces("application/json")
public String rmConnect(@FormParam("username") String username, @FormParam("password") String password) throws KeyException, LoginException, RMException, ActiveObjectCreationException, NodeException {
    Session session = sessionStore.create(username);
    session.connectToRM(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password));
    return session.getSessionId();
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 35 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method loginWithCredential.

/*
     * (non-Javadoc)
     * 
     * @see org.ow2.proactive_grid_cloud_portal.SchedulerRestInterface#loginWithCredential(org.ow2.
     * proactive_grid_cloud_portal.LoginForm)
     */
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("login")
@Produces("application/json")
public String loginWithCredential(@MultipartForm LoginForm multipart) throws ActiveObjectCreationException, NodeException, KeyException, IOException, LoginException, RMException {
    Session session;
    if (multipart.getCredential() != null) {
        session = sessionStore.createUnnamedSession();
        Credentials credentials = Credentials.getCredentials(multipart.getCredential());
        session.connectToRM(credentials);
    } else {
        session = sessionStore.create(multipart.getUsername());
        CredData credData = new CredData(CredData.parseLogin(multipart.getUsername()), CredData.parseDomain(multipart.getUsername()), multipart.getPassword(), multipart.getSshKey());
        session.connectToRM(credData);
    }
    return session.getSessionId();
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Path (javax.ws.rs.Path)49 Produces (javax.ws.rs.Produces)47 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)39 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)36 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)34 GET (javax.ws.rs.GET)32 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)29 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)25 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)24 GZIP (org.jboss.resteasy.annotations.GZIP)23 Session (org.ow2.proactive_grid_cloud_portal.common.Session)18 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)17 ArrayList (java.util.ArrayList)16 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)15 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)15 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)15 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 IOException (java.io.IOException)11 POST (javax.ws.rs.POST)11