use of org.opencastproject.serviceregistry.api.JaxbServiceHealth in project opencast by opencast.
the class ServiceRegistryEndpoint method getHealthStatus.
@GET
@Path("health.xml")
@Produces(MediaType.APPLICATION_XML)
@RestQuery(name = "health", description = "Checks the status of the registered services", returnDescription = "Returns NO_CONTENT if services are in a proper state", restParameters = { @RestParameter(name = "serviceType", isRequired = false, type = Type.STRING, description = "The service type identifier"), @RestParameter(name = "host", isRequired = false, type = Type.STRING, description = "The host, including the http(s) protocol") }, reponses = { @RestResponse(responseCode = SC_OK, description = "Service states returned"), @RestResponse(responseCode = SC_NOT_FOUND, description = "No service of that type on that host is registered."), @RestResponse(responseCode = SC_SERVICE_UNAVAILABLE, description = "An error has occurred during stats processing") })
public Response getHealthStatus(@QueryParam("serviceType") String serviceType, @QueryParam("host") String host) throws NotFoundException {
try {
List<ServiceRegistration> services = null;
if (isNotBlank(serviceType) && isNotBlank(host)) {
// This is a request for one specific service. Return it, or SC_NOT_FOUND if not found
ServiceRegistration reg = serviceRegistry.getServiceRegistration(serviceType, host);
if (reg == null)
throw new NotFoundException();
services = new LinkedList<ServiceRegistration>();
services.add(reg);
} else if (isBlank(serviceType) && isBlank(host)) {
// This is a request for all service registrations
services = serviceRegistry.getServiceRegistrations();
} else if (isNotBlank(serviceType)) {
// This is a request for all service registrations of a particular type
services = serviceRegistry.getServiceRegistrationsByType(serviceType);
} else if (isNotBlank(host)) {
// This is a request for all service registrations of a particular host
services = serviceRegistry.getServiceRegistrationsByHost(host);
}
int healthy = 0;
int warning = 0;
int error = 0;
for (ServiceRegistration reg : services) {
if (ServiceState.NORMAL == reg.getServiceState()) {
healthy++;
} else if (ServiceState.WARNING == reg.getServiceState()) {
warning++;
} else if (ServiceState.ERROR == reg.getServiceState()) {
error++;
} else {
error++;
}
}
JaxbServiceHealth stats = new JaxbServiceHealth(healthy, warning, error);
return Response.ok(stats).build();
} catch (ServiceRegistryException e) {
throw new WebApplicationException(e);
}
}
Aggregations