@Path("/system/services/status") @GET public void getBootStatus(HttpRequest request, HttpResponder responder) { Map<String, String> result = new HashMap<>(); for (String service : serviceManagementMap.keySet()) { MasterServiceManager masterServiceManager = serviceManagementMap.get(service); if (masterServiceManager.isServiceEnabled() && masterServiceManager.canCheckStatus()) { String status = masterServiceManager.isServiceAvailable() ? STATUSOK : STATUSNOTOK; result.put(service, status); } } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result)); }
@Path("/system/services/status") @GET public void getBootStatus(HttpRequest request, HttpResponder responder) { Map<String, String> result = new HashMap<>(); for (String service : serviceManagementMap.keySet()) { MasterServiceManager masterServiceManager = serviceManagementMap.get(service); if (masterServiceManager.isServiceEnabled() && masterServiceManager.canCheckStatus()) { String status = masterServiceManager.isServiceAvailable() ? STATUSOK : STATUSNOTOK; result.put(service, status); } } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result)); }
/** * Returns the live info of CDAP Services */ @Path("/system/services/{service-name}/live-info") @GET public void getServiceLiveInfo(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 serviceManager = serviceManagementMap.get(serviceName); if (serviceManager.isServiceEnabled()) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(serviceManager.getLiveInfo())); } else { throw new ForbiddenException(String.format("Service %s is not enabled", serviceName)); } }
/** * Returns the live info of CDAP Services */ @Path("/system/services/{service-name}/live-info") @GET public void getServiceLiveInfo(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 serviceManager = serviceManagementMap.get(serviceName); if (serviceManager.isServiceEnabled()) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(serviceManager.getLiveInfo())); } else { throw new ForbiddenException(String.format("Service %s is not enabled", serviceName)); } }
/** * Returns the number of instances of CDAP Services */ @Path("/system/services/{service-name}/instances") @GET public void getServiceInstance(HttpRequest request, HttpResponder responder, @PathParam("service-name") String serviceName) throws Exception { JsonObject reply = new JsonObject(); if (!serviceManagementMap.containsKey(serviceName)) { throw new NotFoundException(String.format("Invalid service name %s", serviceName)); } MasterServiceManager serviceManager = serviceManagementMap.get(serviceName); if (serviceManager.isServiceEnabled()) { int actualInstance = serviceManagementMap.get(serviceName).getInstances(); reply.addProperty("provisioned", actualInstance); reply.addProperty("requested", getSystemServiceInstanceCount(serviceName)); responder.sendJson(HttpResponseStatus.OK, reply.toString()); } else { throw new ForbiddenException(String.format("Service %s is not enabled", serviceName)); } }
/** * Returns the number of instances of CDAP Services */ @Path("/system/services/{service-name}/instances") @GET public void getServiceInstance(HttpRequest request, HttpResponder responder, @PathParam("service-name") String serviceName) throws Exception { JsonObject reply = new JsonObject(); if (!serviceManagementMap.containsKey(serviceName)) { throw new NotFoundException(String.format("Invalid service name %s", serviceName)); } MasterServiceManager serviceManager = serviceManagementMap.get(serviceName); if (serviceManager.isServiceEnabled()) { int actualInstance = serviceManagementMap.get(serviceName).getInstances(); reply.addProperty("provisioned", actualInstance); reply.addProperty("requested", getSystemServiceInstanceCount(serviceName)); responder.sendJson(HttpResponseStatus.OK, reply.toString()); } else { throw new ForbiddenException(String.format("Service %s is not enabled", serviceName)); } }
/** * Reset the log levels of the service. * All loggers will be reset to the level when the service started. */ @Path("system/services/{service-name}/resetloglevels") @POST public void resetServiceLogLevels(FullHttpRequest 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("Failed to reset log levels for service %s " + "because the service is not enabled", serviceName)); } try { Set<String> loggerNames = parseBody(request, SET_STRING_TYPE); masterServiceManager.resetServiceLogLevels(loggerNames == null ? Collections.<String>emptySet() : loggerNames); responder.sendStatus(HttpResponseStatus.OK); } catch (IllegalStateException ise) { throw new ServiceUnavailableException(String.format("Failed to reset log levels for service %s " + "because the service may not be ready yet", serviceName)); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid Json in the body"); } }
/** * Reset the log levels of the service. * All loggers will be reset to the level when the service started. */ @Path("system/services/{service-name}/resetloglevels") @POST public void resetServiceLogLevels(FullHttpRequest 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("Failed to reset log levels for service %s " + "because the service is not enabled", serviceName)); } try { Set<String> loggerNames = parseBody(request, SET_STRING_TYPE); masterServiceManager.resetServiceLogLevels(loggerNames == null ? Collections.<String>emptySet() : loggerNames); responder.sendStatus(HttpResponseStatus.OK); } catch (IllegalStateException ise) { throw new ServiceUnavailableException(String.format("Failed to reset log levels for service %s " + "because the service may not be ready yet", serviceName)); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid Json in the body"); } }
@Path("/system/services") @GET public void getServiceSpec(HttpRequest request, HttpResponder responder) throws Exception { List<SystemServiceMeta> response = new ArrayList<>(); SortedSet<String> services = new TreeSet<>(serviceManagementMap.keySet()); List<String> serviceList = new ArrayList<>(services); for (String service : serviceList) { MasterServiceManager serviceManager = serviceManagementMap.get(service); if (serviceManager.isServiceEnabled()) { String logs = serviceManager.isLogAvailable() ? Constants.Monitor.STATUS_OK : Constants.Monitor.STATUS_NOTOK; String canCheck = serviceManager.canCheckStatus() ? ( serviceManager.isServiceAvailable() ? STATUSOK : STATUSNOTOK) : NOTAPPLICABLE; //TODO: Add metric name for Event Rate monitoring response.add(new SystemServiceMeta(service, serviceManager.getDescription(), canCheck, logs, serviceManager.getMinInstances(), serviceManager.getMaxInstances(), getSystemServiceInstanceCount(service), serviceManager.getInstances())); } } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response)); }
@Path("/system/services") @GET public void getServiceSpec(HttpRequest request, HttpResponder responder) throws Exception { List<SystemServiceMeta> response = new ArrayList<>(); SortedSet<String> services = new TreeSet<>(serviceManagementMap.keySet()); List<String> serviceList = new ArrayList<>(services); for (String service : serviceList) { MasterServiceManager serviceManager = serviceManagementMap.get(service); if (serviceManager.isServiceEnabled()) { String logs = serviceManager.isLogAvailable() ? Constants.Monitor.STATUS_OK : Constants.Monitor.STATUS_NOTOK; String canCheck = serviceManager.canCheckStatus() ? ( serviceManager.isServiceAvailable() ? STATUSOK : STATUSNOTOK) : NOTAPPLICABLE; //TODO: Add metric name for Event Rate monitoring response.add(new SystemServiceMeta(service, serviceManager.getDescription(), canCheck, logs, serviceManager.getMinInstances(), serviceManager.getMaxInstances(), getSystemServiceInstanceCount(service), serviceManager.getInstances())); } } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response)); }
/** * Update log levels for this service. */ @Path("system/services/{service-name}/loglevels") @PUT public void updateServiceLogLevels(FullHttpRequest 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("Failed to update log levels for service %s " + "because the service is not enabled", serviceName)); } try { // we are decoding the body to Map<String, String> instead of Map<String, LogEntry.Level> here since Gson will // serialize invalid enum values to null, which is allowed for log level, instead of throw an Exception. masterServiceManager.updateServiceLogLevels(transformLogLevelsMap(decodeArguments(request))); responder.sendStatus(HttpResponseStatus.OK); } catch (IllegalStateException ise) { throw new ServiceUnavailableException(String.format("Failed to update log levels for service %s " + "because the service may not be ready yet", serviceName)); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage()); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid Json in the body"); } }
/** * Update log levels for this service. */ @Path("system/services/{service-name}/loglevels") @PUT public void updateServiceLogLevels(FullHttpRequest 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("Failed to update log levels for service %s " + "because the service is not enabled", serviceName)); } try { // we are decoding the body to Map<String, String> instead of Map<String, LogEntry.Level> here since Gson will // serialize invalid enum values to null, which is allowed for log level, instead of throw an Exception. masterServiceManager.updateServiceLogLevels(transformLogLevelsMap(decodeArguments(request))); responder.sendStatus(HttpResponseStatus.OK); } catch (IllegalStateException ise) { throw new ServiceUnavailableException(String.format("Failed to update log levels for service %s " + "because the service may not be ready yet", serviceName)); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage()); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid Json in the body"); } }
if (!masterServiceManager.isServiceEnabled()) { String message = String.format("Failed to restart instance for %s because the service is not enabled.", serviceName);
if (!masterServiceManager.isServiceEnabled()) { String message = String.format("Failed to restart instance for %s because the service is not enabled.", serviceName);
if (!serviceManager.isServiceEnabled()) { throw new ForbiddenException(String.format("Service %s is not enabled", serviceName));
if (!serviceManager.isServiceEnabled()) { throw new ForbiddenException(String.format("Service %s is not enabled", serviceName));