Search in sources :

Example 81 with Session

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

the class RestDataspaceImpl method create.

@POST
@Path("/{dataspace}/{path-name:.*}")
public Response create(@HeaderParam("sessionid") String sessionId, @PathParam("dataspace") String dataspacePath, @PathParam("path-name") String pathname, @FormParam("mimetype") String mimeType) throws NotConnectedRestException, PermissionRestException {
    Session session = checkSessionValidity(sessionId);
    try {
        checkPathParams(dataspacePath, pathname);
        FileObject fileObject = resolveFile(session, dataspacePath, pathname);
        if (mimeType.equals(org.ow2.proactive_grid_cloud_portal.common.FileType.FOLDER.getMimeType())) {
            logger.debug(String.format("Creating folder %s in %s", pathname, dataspacePath));
            fileObject.createFolder();
        } else if (mimeType.equals(org.ow2.proactive_grid_cloud_portal.common.FileType.FILE.getMimeType())) {
            logger.debug(String.format("Creating file %s in %s", pathname, dataspacePath));
            fileObject.createFile();
        } else {
            return serverErrorRes("Cannot create specified file since mimetype is not specified");
        }
        return Response.ok().build();
    } catch (FileSystemException e) {
        logger.error(String.format("Cannot create %s in %s", pathname, dataspacePath), e);
        throw rethrow(e);
    } catch (Throwable e) {
        logger.error(String.format("Cannot create %s in %s", pathname, dataspacePath), e);
        throw rethrow(e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 82 with Session

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

the class RestDataspaceImpl method store.

/**
 * Upload a file to the specified location in the <i>dataspace</i>. The
 * format of the PUT 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><b>dataspace:</b> Can have two possible values, 'user' or 'global',
 * depending on target <i>DATASPACE</i>.</li>
 * <li><b>path-name:</b> Location in which the file is stored.</li>
 * </ul>
 * <b>Notes:</b>
 * <ul>
 * <li>If 'gzip' or 'zip' is specified in the 'Content-Encoding' header, the
 * contents of the request body will be decoded before being stored.</li>
 * <li>Any file that already exists in the specified location, it will be
 * replaced.</li>
 * </ul>
 */
@PUT
@Path("/{dataspace}/{path-name:.*}")
public Response store(@HeaderParam("sessionid") String sessionId, @HeaderParam("Content-Encoding") String encoding, @PathParam("dataspace") String dataspace, @PathParam("path-name") String pathname, InputStream is) throws NotConnectedRestException, PermissionRestException {
    Session session = checkSessionValidity(sessionId);
    try {
        checkPathParams(dataspace, pathname);
        logger.debug(String.format("Storing %s in %s", pathname, dataspace));
        writeFile(is, resolveFile(session, dataspace, pathname), encoding);
    } catch (Throwable error) {
        logger.error(String.format("Cannot save the requested file to %s in %s.", pathname, dataspace), error);
        rethrow(error);
    }
    return Response.status(Response.Status.CREATED).build();
}
Also used : Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 83 with Session

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

the class RestDataspaceImpl method metadata.

/**
 * Retrieve metadata of file in the location specified in <i>dataspace</i>.
 * The format of the HEAD 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}
 */
@HEAD
@Path("/{dataspace}/{path-name:.*}")
public Response metadata(@HeaderParam("sessionid") String sessionId, @PathParam("dataspace") String dataspacePath, @PathParam("path-name") String pathname) throws NotConnectedRestException, PermissionRestException {
    Session session = checkSessionValidity(sessionId);
    try {
        checkPathParams(dataspacePath, pathname);
        FileObject fo = resolveFile(session, dataspacePath, pathname);
        if (!fo.exists()) {
            return notFoundRes();
        }
        logger.debug(String.format("Retrieving metadata for %s in %s", pathname, dataspacePath));
        MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(FileSystem.metadata(fo));
        return Response.ok().replaceAll(headers).build();
    } catch (Throwable error) {
        logger.error(String.format("Cannot retrieve metadata for %s in %s.", pathname, dataspacePath), error);
        throw rethrow(error);
    }
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 84 with Session

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

the class RMRest method deployNodeSource.

/**
 * Start the nodes acquisition of the node source
 *
 * @param sessionId a valid session id
 * @param nodeSourceName the name of the node source to start
 * @return the result of the action, possibly containing the error message
 * @throws NotConnectedException
 */
@Override
@PUT
@Path("nodesource/deploy")
@Produces("application/json")
public NSState deployNodeSource(@HeaderParam("sessionid") String sessionId, @FormParam("nodeSourceName") String nodeSourceName) throws NotConnectedException {
    ResourceManager rm = checkAccess(sessionId);
    NSState nsState = new NSState();
    try {
        nsState.setResult(rm.deployNodeSource(nodeSourceName).getBooleanValue());
    } catch (RuntimeException ex) {
        nsState.setResult(false);
        nsState.setErrorMessage(cleanDisplayedErrorMessage(ex.getMessage()));
        nsState.setStackTrace(StringEscapeUtils.escapeJson(getStackTrace(ex)));
    }
    return nsState;
}
Also used : ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) NSState(org.ow2.proactive.resourcemanager.common.NSState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 85 with Session

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

the class RMRest method releaseNode.

/**
 * Release a node
 *
 * @param sessionId a valid session id
 * @param url node's URL
 * @return true of the node has been released
 * @throws NodeException
 * @throws NotConnectedException
 */
@Override
@POST
@Path("node/release")
@Produces("application/json")
public boolean releaseNode(@HeaderParam("sessionid") String sessionId, @FormParam("url") String url) throws NodeException, NotConnectedException {
    ResourceManager rm = checkAccess(sessionId);
    Node n;
    n = NodeFactory.getNode(url);
    return rm.releaseNode(n).getBooleanValue();
}
Also used : Node(org.objectweb.proactive.core.node.Node) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) 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