use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException 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.scheduler.exception.NotConnectedRestException 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.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerRestClient method list.
public ListFile list(String sessionId, String dataspacePath, String pathname) throws Exception {
StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl.toString()).path(pathname).queryParam("comp", "list");
Response response = null;
try {
response = target.request().header("sessionid", sessionId).get();
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Cannot list the specified location: %s", pathname), response);
}
}
return response.readEntity(ListFile.class);
} finally {
if (response != null) {
response.close();
}
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerRestClient method download.
public boolean download(String sessionId, String dataspacePath, String path, List<String> includes, List<String> excludes, File outputFile) throws Exception {
StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl.toString()).path(path);
if (includes != null && !includes.isEmpty()) {
target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
}
if (excludes != null && !excludes.isEmpty()) {
target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
}
Response response = null;
try {
response = target.request().header("sessionid", sessionId).acceptEncoding("*", "gzip", "zip").get();
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Cannot retrieve the file. Status code: %d", response.getStatus()), response);
}
}
if (response.hasEntity()) {
InputStream is = response.readEntity(InputStream.class);
if (isGZipEncoded(response)) {
if (outputFile.exists() && outputFile.isDirectory()) {
outputFile = new File(outputFile, response.getHeaderString("x-pds-pathname"));
}
Zipper.GZIP.unzip(is, outputFile);
} else if (isZipEncoded(response)) {
Zipper.ZIP.unzip(is, outputFile);
} else {
File container = outputFile.getParentFile();
if (!container.exists()) {
container.mkdirs();
}
Files.asByteSink(outputFile).writeFrom(is);
}
} else {
outputFile.createNewFile();
}
} finally {
if (response != null) {
response.close();
}
}
return true;
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerRestClient method metadata.
public Map<String, Object> metadata(String sessionId, String dataspacePath, String pathname) throws Exception {
StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append(escapeUrlPathSegment(pathname));
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl.toString());
Response response = null;
try {
response = target.request().header("sessionid", sessionId).head();
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Cannot get metadata from %s in %s.", pathname, dataspacePath), response);
}
}
MultivaluedMap<String, Object> headers = response.getHeaders();
Map<String, Object> metaMap = Maps.newHashMap();
if (headers.containsKey(HttpHeaders.LAST_MODIFIED)) {
metaMap.put(HttpHeaders.LAST_MODIFIED, headers.getFirst(HttpHeaders.LAST_MODIFIED));
}
return metaMap;
} finally {
if (response != null) {
response.close();
}
}
}
Aggregations