use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.
the class Items method getXml.
/**
* Gets the resource's properties (length, owner, permitions etc.)
*
* @return the resource's properties
* @throws Exception
*/
@Path("query/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<LogicalDataWrapped> getXml() throws Exception {
try (Connection cn = getCatalogue().getConnection()) {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
List<LogicalDataWrapped> res = queryLogicalData(mp, cn);
return res;
} catch (SQLException ex) {
Logger.getLogger(Items.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.
the class SDNService method setStats.
@Path("optimizeFlow")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void setStats(JAXBElement<Endpoints> jbEndpoints) throws IOException, InterruptedException {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.getRoles().contains("worker") || mp.isAdmin()) {
Endpoints endpoints = jbEndpoints.getValue();
if (sdnClient == null) {
String uri = PropertiesHelper.getSDNControllerURL();
sdnClient = new SDNControllerClient(uri);
}
Set<String> sources = new HashSet<>();
sources.add(endpoints.source);
List<DefaultWeightedEdge> shortestPath = sdnClient.getShortestPath(endpoints.destination, sources);
sdnClient.pushFlow(shortestPath);
}
}
use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.
the class SetBulkPermissionsResource method setPermissions.
// @PUT
// @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public void setPermissions(@QueryParam("path") String path, JAXBElement<Permissions> jbPermissions) throws UnsupportedEncodingException {
try (Connection connection = catalogue.getConnection()) {
try {
Permissions permissions = jbPermissions.getValue();
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
setPermissionsJava(path, permissions, mp, connection);
connection.commit();
} catch (SQLException ex) {
Logger.getLogger(SetBulkPermissionsResource.class.getName()).log(Level.SEVERE, null, ex);
connection.rollback();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (SQLException ex) {
Logger.getLogger(SetBulkPermissionsResource.class.getName()).log(Level.SEVERE, null, ex);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.
the class StatsService method setStats.
@Path("set")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void setStats(JAXBElement<Stats> jbStats) {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.getRoles().contains("worker") || mp.isAdmin()) {
try {
Stats stats = jbStats.getValue();
getCatalogue().setSpeed(stats);
} catch (SQLException ex) {
Logger.getLogger(StatsService.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
use of nl.uva.cs.lobcder.auth.MyPrincipal in project lobcder by skoulouzis.
the class StorageSitesService method updateLogicalDataAndPdri.
@PUT
@Path("update_pdri/{uid}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void updateLogicalDataAndPdri(PDRIDescrWrapperList pdris, @PathParam("uid") Long uid) throws SQLException, IOException {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.isAdmin()) {
try (Connection cn = getCatalogue().getConnection()) {
for (PDRIDescr pdriDescr : pdris.getPdris()) {
LogicalData logicalData = getCatalogue().getLogicalDataByUid(uid, cn);
PDRI pdri = PDRIFactory.getFactory().createInstance(pdriDescr, false);
logicalData.setLength(pdri.getLength());
getCatalogue().updatePdri(logicalData, pdri, cn);
}
cn.commit();
cn.close();
}
}
}
Aggregations