use of org.apache.myriad.configuration.MyriadBadConfigurationException in project incubator-myriad by apache.
the class ClustersResource method flexUpservice.
@Timed
@PUT
@Path("/flexupservice")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public Response flexUpservice(FlexUpServiceRequest request) {
Preconditions.checkNotNull(request, "request object cannot be null or empty");
LOGGER.info("Received Flexup a Service Request");
Integer instances = request.getInstances();
String serviceName = request.getServiceName();
LOGGER.info("Instances: {}", instances);
LOGGER.info("Service: {}", serviceName);
// Validate profile request
Response.ResponseBuilder response = Response.status(Response.Status.ACCEPTED);
if (cfg.getServiceConfiguration(serviceName) == null) {
response.status(Response.Status.BAD_REQUEST).entity("Service does not exist: " + serviceName);
LOGGER.error("Provided service does not exist " + serviceName);
return response.build();
}
if (!validateInstances(instances, response)) {
return response.build();
}
try {
this.myriadOperations.flexUpAService(instances, serviceName);
} catch (MyriadBadConfigurationException e) {
return response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
return response.build();
}
use of org.apache.myriad.configuration.MyriadBadConfigurationException in project incubator-myriad by apache.
the class MyriadOperations method flexUpAService.
/**
* Flexup a service
*
* @param instances
* @param serviceName
*
* @throws MyriadBadConfigurationException if total number of instances in active, staging, and pending
* states exceeds the ServiceConfiguration.maxInstances
*/
public void flexUpAService(int instances, String serviceName) throws MyriadBadConfigurationException {
final ServiceConfiguration auxTaskConf = cfg.getServiceConfiguration(serviceName).get();
if (auxTaskConf.getMaxInstances().isPresent()) {
// If total number of current and flex instances exceed maxInstances, throw an exception
int totalflexInstances = instances + getFlexibleInstances(serviceName);
Integer maxInstances = auxTaskConf.getMaxInstances().get();
if (maxInstances > 0) {
if (totalflexInstances > maxInstances) {
LOGGER.error("Current number of active, staging, pending and requested instances: {}" + ", while it is greater then max instances allowed: {}", totalflexInstances, maxInstances);
throw new MyriadBadConfigurationException("Current number of active, staging, pending instances and requested: " + totalflexInstances + ", while it is greater then max instances allowed: " + maxInstances);
}
}
}
final Double cpu = auxTaskConf.getCpus();
final Double mem = auxTaskConf.getJvmMaxMemoryMB();
Collection<NodeTask> nodes = new HashSet<>();
for (int i = 0; i < instances; i++) {
NodeTask nodeTask = new NodeTask(new ServiceResourceProfile(serviceName, cpu, mem, auxTaskConf.getPorts()), null);
nodeTask.setTaskPrefix(serviceName);
nodes.add(nodeTask);
}
LOGGER.info("Adding {} {} instances to cluster", nodes.size(), serviceName);
this.schedulerState.addNodes(nodes);
}
Aggregations