Search in sources :

Example 1 with ReservationInfo

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;
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) ReservationInfo(nl.uva.cs.lobcder.rest.wrappers.ReservationInfo) Permissions(nl.uva.cs.lobcder.auth.Permissions) Connection(java.sql.Connection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)1 Permissions (nl.uva.cs.lobcder.auth.Permissions)1 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)1 ReservationInfo (nl.uva.cs.lobcder.rest.wrappers.ReservationInfo)1