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