Search in sources :

Example 1 with MyriadBadConfigurationException

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();
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) MyriadBadConfigurationException(org.apache.myriad.configuration.MyriadBadConfigurationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 2 with MyriadBadConfigurationException

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);
}
Also used : ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) MyriadBadConfigurationException(org.apache.myriad.configuration.MyriadBadConfigurationException) NodeTask(org.apache.myriad.state.NodeTask) LikeConstraint(org.apache.myriad.scheduler.constraints.LikeConstraint) Constraint(org.apache.myriad.scheduler.constraints.Constraint) HashSet(java.util.HashSet)

Aggregations

MyriadBadConfigurationException (org.apache.myriad.configuration.MyriadBadConfigurationException)2 Timed (com.codahale.metrics.annotation.Timed)1 HashSet (java.util.HashSet)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)1 Constraint (org.apache.myriad.scheduler.constraints.Constraint)1 LikeConstraint (org.apache.myriad.scheduler.constraints.LikeConstraint)1 NodeTask (org.apache.myriad.state.NodeTask)1