if (!serviceManagementMap.containsKey(serviceName)) {
responder.sendString(HttpResponseStatus.NOT_FOUND, "Invalid Service Name");
return;
}
MasterServiceManager serviceManager = serviceManagementMap.get(serviceName);
int instance = getInstances(request);
if (!serviceManager.isServiceEnabled()) {
responder.sendString(HttpResponseStatus.FORBIDDEN, String.format("Service %s is not enabled", serviceName));
return;
}
Integer currentInstance = getSystemServiceInstanceCount(serviceName);
if (instance < serviceManager.getMinInstances() || instance > serviceManager.getMaxInstances()) {
String response = String.format("Instance count should be between [%s,%s]", serviceManager.getMinInstances(),
serviceManager.getMaxInstances());
responder.sendString(HttpResponseStatus.BAD_REQUEST, response);
return;
} else if (instance == currentInstance) {
responder.sendStatus(HttpResponseStatus.OK);
return;
}
serviceStore.setServiceInstance(serviceName, instance);
if (serviceManager.setInstances(instance)) {
responder.sendStatus(HttpResponseStatus.OK);
} else {
responder.sendString(HttpResponseStatus.BAD_REQUEST, "Operation did not succeed");
}
} catch (Exception e) {