Search in sources :

Example 1 with CollectDownscaleCandidatesRequest

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

the class ClusterDownscaleActions method collectCandidatesAction.

@Bean(name = "COLLECT_CANDIDATES_STATE")
public Action<?, ?> collectCandidatesAction() {
    return new AbstractClusterAction<ClusterDownscaleTriggerEvent>(ClusterDownscaleTriggerEvent.class) {

        @Override
        protected void doExecute(ClusterViewContext context, ClusterDownscaleTriggerEvent payload, Map<Object, Object> variables) {
            clusterDownscaleService.clusterDownscaleStarted(context.getStackId(), payload.getHostGroupName(), payload.getAdjustment(), payload.getHostNames());
            Selectable request = new CollectDownscaleCandidatesRequest(context.getStackId(), payload.getHostGroupName(), payload.getAdjustment(), payload.getHostNames());
            sendEvent(context.getFlowId(), request.selector(), request);
        }
    };
}
Also used : ClusterDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) CollectDownscaleCandidatesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest) 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 CollectDownscaleCandidatesRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest 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

CollectDownscaleCandidatesRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest)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 ClusterDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 CollectDownscaleCandidatesResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1