use of co.cask.cdap.common.twill.MasterServiceManager in project cdap by caskdata.
the class MonitorHandler method resetServiceLogLevels.
/**
* 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(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("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");
}
}
use of co.cask.cdap.common.twill.MasterServiceManager 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");
}
}
use of co.cask.cdap.common.twill.MasterServiceManager in project cdap by caskdata.
the class MonitorHandler method setServiceInstance.
/**
* Sets the number of instances of CDAP Services
*/
@Path("/system/services/{service-name}/instances")
@PUT
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void setServiceInstance(HttpRequest request, HttpResponder responder, @PathParam("service-name") final String serviceName) throws Exception {
if (!serviceManagementMap.containsKey(serviceName)) {
throw new NotFoundException(String.format("Invalid service name %s", serviceName));
}
MasterServiceManager serviceManager = serviceManagementMap.get(serviceName);
int instances = getInstances(request);
if (!serviceManager.isServiceEnabled()) {
throw new ForbiddenException(String.format("Service %s is not enabled", serviceName));
}
int currentInstances = getSystemServiceInstanceCount(serviceName);
if (instances < serviceManager.getMinInstances() || instances > serviceManager.getMaxInstances()) {
String response = String.format("Instance count should be between [%s,%s]", serviceManager.getMinInstances(), serviceManager.getMaxInstances());
throw new BadRequestException(response);
} else if (instances == currentInstances) {
responder.sendStatus(HttpResponseStatus.OK);
return;
}
serviceStore.setServiceInstance(serviceName, instances);
if (serviceManager.setInstances(instances)) {
responder.sendStatus(HttpResponseStatus.OK);
} else {
throw new BadRequestException("Operation did not succeed");
}
}
Aggregations