Search in sources :

Example 6 with ForbiddenException

use of co.cask.cdap.common.ForbiddenException in project cdap by caskdata.

the class MonitorHandler method monitor.

@Path("/system/services/{service-name}/status")
@GET
public void monitor(HttpRequest request, HttpResponder responder, @PathParam("service-name") String serviceName) throws Exception {
    if (!serviceManagementMap.containsKey(serviceName)) {
        throw new NotFoundException(String.format("Invalid service name %s", serviceName));
    }
    MasterServiceManager masterServiceManager = serviceManagementMap.get(serviceName);
    if (!masterServiceManager.isServiceEnabled()) {
        throw new ForbiddenException(String.format("Service %s is not enabled", serviceName));
    }
    if (masterServiceManager.canCheckStatus() && masterServiceManager.isServiceAvailable()) {
        JsonObject json = new JsonObject();
        json.addProperty("status", STATUSOK);
        responder.sendJson(HttpResponseStatus.OK, json);
    } else if (masterServiceManager.canCheckStatus()) {
        JsonObject json = new JsonObject();
        json.addProperty("status", STATUSNOTOK);
        responder.sendJson(HttpResponseStatus.OK, json);
    } else {
        throw new BadRequestException("Operation not valid for this service");
    }
}
Also used : ForbiddenException(co.cask.cdap.common.ForbiddenException) MasterServiceManager(co.cask.cdap.common.twill.MasterServiceManager) NotFoundException(co.cask.cdap.common.NotFoundException) JsonObject(com.google.gson.JsonObject) BadRequestException(co.cask.cdap.common.BadRequestException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ForbiddenException (co.cask.cdap.common.ForbiddenException)6 NotFoundException (co.cask.cdap.common.NotFoundException)6 MasterServiceManager (co.cask.cdap.common.twill.MasterServiceManager)6 BadRequestException (co.cask.cdap.common.BadRequestException)5 Path (javax.ws.rs.Path)5 ServiceUnavailableException (co.cask.cdap.common.ServiceUnavailableException)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 JsonObject (com.google.gson.JsonObject)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)1 POST (javax.ws.rs.POST)1