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);
}
}
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();
}
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);
}
}
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;
}
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();
}
Aggregations