use of nl.uva.cs.lobcder.rest.wrappers.ReservationInfo in project lobcder by skoulouzis.
the class PathReservationService method request.
@Path("{commID}/request/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ReservationInfo request(@PathParam("commID") String communicationID) throws MalformedURLException, IOException {
// rest/reservation/5455/request/?dataPath=/sbuiifv/dsudsuds&storageSiteHost=sps1&storageSiteHost=sps2&storageSiteHost=sps3
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
MultivaluedMap<String, String> queryParameters = info.getQueryParameters();
if (mp.getRoles().contains("planner") || mp.isAdmin() && queryParameters != null && !queryParameters.isEmpty()) {
String dataName = queryParameters.getFirst("dataName");
if (dataName != null && dataName.length() > 0) {
List<String> storageList = queryParameters.get("storageSiteHost");
String storageSiteHost = null;
int index = -1;
if (storageList != null && storageList.size() > 0) {
storageSiteHost = getStorageSiteHost(storageList);
index = storageList.indexOf(storageSiteHost);
} else {
}
LogicalData ld;
Permissions p = null;
try (Connection cn = getCatalogue().getConnection()) {
// -----------------THIS IS TEMPORARY IT'S ONLY FOR THE DEMO!!!!!!!!!!
String fileNameWithOutExt = FilenameUtils.removeExtension(dataName);
fileNameWithOutExt += ".webm";
List<LogicalData> ldList = getCatalogue().getLogicalDataByName(io.milton.common.Path.path(fileNameWithOutExt), cn);
if (ldList == null || ldList.isEmpty()) {
ldList = getCatalogue().getLogicalDataByName(io.milton.common.Path.path(dataName), cn);
}
// --------------------------------------------------------------
if (ldList == null || ldList.isEmpty()) {
Response.status(Response.Status.NOT_FOUND);
return null;
}
// Should be only one
ld = ldList.get(0);
if (ld != null) {
p = getCatalogue().getPermissions(ld.getUid(), ld.getOwner(), cn);
}
} catch (SQLException ex) {
log.log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
// Integer alocationStrategy = Integer.valueOf(queryParameters.getFirst("allocationStrategy"));
ReservationInfo info = new ReservationInfo();
if (p != null && mp.canRead(p)) {
info.setCommunicationID(communicationID);
String workerURL = scheduleWorker(storageSiteHost, ld);
info.setCommunicationID(communicationID);
storageSiteHost = Network.replaceIP(storageSiteHost);
info.setStorageHost(storageSiteHost);
info.setStorageHostIndex(index);
workerURL = Network.replaceIP(workerURL);
info.setWorkerDataAccessURL(workerURL);
}
return info;
}
}
return null;
}
Aggregations