Search in sources :

Example 1 with WorkerStatus

use of nl.uva.cs.lobcder.rest.wrappers.WorkerStatus in project lobcder by skoulouzis.

the class PathReservationService method getXml.

@Path("get_workers/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<WorkerStatus> getXml() throws MalformedURLException {
    // rest/reservation/get_workers/?id=all
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    MultivaluedMap<String, String> queryParameters = info.getQueryParameters();
    if (mp.getRoles().contains("planner") || mp.isAdmin() && queryParameters != null && !queryParameters.isEmpty()) {
        String workerID = queryParameters.getFirst("id");
        ArrayList<WorkerStatus> workersStatus = new ArrayList<>();
        workers = PropertiesHelper.getWorkers();
        for (String s : workers) {
            WorkerStatus ws = new WorkerStatus();
            ws.setHostName(new URL(s).getHost());
            ws.setStatus("READY");
            workersStatus.add(ws);
        }
        return workersStatus;
    }
    return null;
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WorkerStatus(nl.uva.cs.lobcder.rest.wrappers.WorkerStatus) ArrayList(java.util.ArrayList) URL(java.net.URL) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with WorkerStatus

use of nl.uva.cs.lobcder.rest.wrappers.WorkerStatus in project lobcder by skoulouzis.

the class PathReservationService method getWorkersState.

@Path("workers/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<WorkerStatus> getWorkersState() {
    // rest/reservation/workers/?host=kscvdfv&host=sp2&host=192.168.1.1
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.getRoles().contains("planner") || mp.isAdmin()) {
        MultivaluedMap<String, String> queryParameters = info.getQueryParameters();
        List<String> queryWorkers = queryParameters.get("host");
        List<WorkerStatus> workersStatus = new ArrayList<>();
        workers = PropertiesHelper.getWorkers();
        for (String worker : queryWorkers) {
            WorkerStatus ws = new WorkerStatus();
            ws.setStatus("UNKNOWN");
            for (String w : workers) {
                if (w.contains(worker)) {
                    ws.setStatus("READY");
                    break;
                }
            }
            ws.setHostName(worker);
            workersStatus.add(ws);
        }
        return workersStatus;
    }
    return null;
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WorkerStatus(nl.uva.cs.lobcder.rest.wrappers.WorkerStatus) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)2 WorkerStatus (nl.uva.cs.lobcder.rest.wrappers.WorkerStatus)2 URL (java.net.URL)1