Search in sources :

Example 1 with RemoveHostsSuccess

use of com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsSuccess in project cloudbreak by hortonworks.

the class RemoveHostsHandler method accept.

@Override
public void accept(Event<RemoveHostsRequest> removeHostsRequestEvent) {
    RemoveHostsRequest request = removeHostsRequestEvent.getData();
    Set<String> hostNames = request.getHostNames();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        if (stack.getPrimaryGatewayInstance() != null && stack.getPrimaryGatewayInstance().isReachable()) {
            List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
            PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames), hostOrchestrator, allGatewayConfigs);
            if (!orchestratorRemovalPollingResult.isSuccess()) {
                LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames);
            }
        } else {
            LOGGER.warn("Primary gateway is not reachable, can't remove hosts from orchestrator");
        }
        result = new RemoveHostsSuccess(request.getResourceId(), request.getHostGroupNames(), hostNames);
    } catch (Exception e) {
        result = new RemoveHostsFailed(removeHostsRequestEvent.getData().getResourceId(), e, request.getHostGroupNames(), hostNames);
    }
    eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result));
}
Also used : RemoveHostsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsSuccess) RemoveHostsFailed(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsFailed) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) RemoveHostsRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with RemoveHostsSuccess

use of com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsSuccess in project cloudbreak by hortonworks.

the class ClusterDownscaleActions method decommissionAction.

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

        @Override
        protected void doExecute(ClusterViewContext context, CollectDownscaleCandidatesResult payload, Map<Object, Object> variables) {
            variables.put(ContextKeys.PRIVATE_IDS, payload.getPrivateIds());
            Selectable event;
            if (isPayloadContainsAnyPrivateId(payload)) {
                Boolean repair = (Boolean) variables.get(REPAIR);
                Stack stack = stackService.getByIdWithListsInTransaction(context.getStackId());
                DecommissionRequest decommissionRequest = new DecommissionRequest(context.getStackId(), payload.getHostGroupNames(), payload.getPrivateIds(), payload.getRequest().getDetails());
                if (repair && stack.hasCustomHostname()) {
                    LOGGER.debug("Cluster decommission state identified that the current action is a repair, hence we're going that way from now.");
                    event = new DecommissionResult(decommissionRequest, getHostNamesForPrivateIds(payload.getPrivateIds(), stack));
                } else {
                    event = decommissionRequest;
                }
            } else {
                LOGGER.info("Handler wasn't able to collect any candidate [stackId:{}, host group name: {}] for downscaling, therefore we're handling " + "it as a success (since nothing to decommission)", context.getStackId(), payload.getHostGroupNames());
                event = new RemoveHostsSuccess(context.getStackId(), payload.getHostGroupNames(), emptySet());
            }
            sendEvent(context, event.selector(), event);
        }
    };
}
Also used : RemoveHostsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsSuccess) Selectable(com.sequenceiq.cloudbreak.common.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) DecommissionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult) ClusterViewContext(com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 RemoveHostsSuccess (com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsSuccess)2 AbstractClusterAction (com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction)1 ClusterViewContext (com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 PollingResult (com.sequenceiq.cloudbreak.polling.PollingResult)1 RemoveHostsFailed (com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsFailed)1 RemoveHostsRequest (com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsRequest)1 CollectDownscaleCandidatesResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult)1 DecommissionRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionRequest)1 DecommissionResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1