Search in sources :

Example 1 with CollectDownscaleCandidatesResult

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult in project cloudbreak by hortonworks.

the class ClusterDownscaleActions method decommissionAction.

@Bean(name = "DECOMMISSION_STATE")
public Action<?, ?> decommissionAction() {
    return new AbstractClusterAction<CollectDownscaleCandidatesResult>(CollectDownscaleCandidatesResult.class) {

        @Override
        protected void doExecute(ClusterViewContext context, CollectDownscaleCandidatesResult payload, Map<Object, Object> variables) {
            Selectable request = new DecommissionRequest(context.getStackId(), payload.getHostGroupName(), payload.getHostNames());
            sendEvent(context.getFlowId(), request.selector(), request);
        }
    };
}
Also used : Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) DecommissionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionRequest) CollectDownscaleCandidatesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult) AbstractClusterAction(com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction) Map(java.util.Map) ClusterViewContext(com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with CollectDownscaleCandidatesResult

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult in project cloudbreak by hortonworks.

the class CollectDownscaleCandidatesHandler method accept.

@Override
public void accept(Event<CollectDownscaleCandidatesRequest> event) {
    CollectDownscaleCandidatesRequest request = event.getData();
    CollectDownscaleCandidatesResult result;
    try {
        Stack stack = stackService.getByIdWithLists(request.getStackId());
        Set<String> hostNames;
        if (request.getHostNames() == null || request.getHostNames().isEmpty()) {
            hostNames = ambariDecommissioner.collectDownscaleCandidates(stack, request.getHostGroupName(), request.getScalingAdjustment());
        } else {
            hostNames = request.getHostNames();
            String hostName = hostNames.stream().findFirst().orElseThrow(() -> new BadRequestException("Unable to find host name"));
            ambariDecommissioner.verifyNodeCount(stack, stack.getCluster(), hostName);
        }
        result = new CollectDownscaleCandidatesResult(request, hostNames);
    } catch (Exception e) {
        result = new CollectDownscaleCandidatesResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : CollectDownscaleCandidatesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest) CollectDownscaleCandidatesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

CollectDownscaleCandidatesResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult)2 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 AbstractClusterAction (com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction)1 ClusterViewContext (com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 CollectDownscaleCandidatesRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest)1 DecommissionRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionRequest)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1