Search in sources :

Example 6 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class EnvClustersDeleteActions method datahubClustersDeleteAction.

@Bean(name = "DATAHUB_CLUSTERS_DELETE_STARTED_STATE")
public Action<?, ?> datahubClustersDeleteAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.DATAHUB_CLUSTERS_DELETE_IN_PROGRESS;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_DATAHUB_CLUSTERS_DELETION_STARTED;
            EnvClustersDeleteState envClustersDeleteState = EnvClustersDeleteState.DATAHUB_CLUSTERS_DELETE_STARTED_STATE;
            String logDeleteState = "Data Hub clusters";
            EnvironmentDeletionDto envDto = commonUpdateEnvironmentAndNotify(context, payload, environmentStatus, resourceEvent, envClustersDeleteState, logDeleteState);
            sendEvent(context, DELETE_DATAHUB_CLUSTERS_EVENT.selector(), envDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Bean(org.springframework.context.annotation.Bean)

Example 7 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class ClusterUpgradeValidationActions method clusterUpgradeValidationFailed.

@Bean(name = "CLUSTER_UPGRADE_VALIDATION_FAILED_STATE")
public Action<?, ?> clusterUpgradeValidationFailed() {
    return new AbstractAction<ClusterUpgradeValidationState, ClusterUpgradeValidationStateSelectors, ClusterUpgradeContext, ClusterUpgradeValidationFailureEvent>(ClusterUpgradeValidationFailureEvent.class) {

        @Inject
        private CloudbreakMessagesService messagesService;

        @Inject
        private StackUpdater stackUpdater;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<ClusterUpgradeValidationState, ClusterUpgradeValidationStateSelectors> stateContext, ClusterUpgradeValidationFailureEvent payload) {
            StackView stackView = stackService.getViewByIdWithoutAuth(payload.getResourceId());
            MDCBuilder.buildMdcContext(stackView);
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeValidationFailureEvent payload, Map<Object, Object> variables) {
            String errorMessage = payload.getException().getMessage();
            Long resourceId = payload.getResourceId();
            LOGGER.debug("Cluster upgrade validation failed with validation error: {}", errorMessage);
            ResourceEvent validationFailedResourceEvent = ResourceEvent.CLUSTER_UPGRADE_VALIDATION_FAILED;
            cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_FAILED.name(), validationFailedResourceEvent, List.of(errorMessage));
            String reason = messagesService.getMessage(validationFailedResourceEvent.getMessage(), List.of(errorMessage));
            stackUpdater.updateStackStatus(resourceId, DetailedStackStatus.AVAILABLE, reason);
            sendEvent(context, HANDLED_FAILED_CLUSTER_UPGRADE_VALIDATION_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeValidationFailureEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            LOGGER.warn("No failure payload in case of CLUSTER_UPGRADE_VALIDATION_FAILED_STATE. This should not happen.", ex);
            return null;
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<ClusterUpgradeValidationFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent());
        }
    };
}
Also used : StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) ClusterUpgradeContext(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.ClusterUpgradeContext) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Flow(com.sequenceiq.flow.core.Flow) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) List(java.util.List) ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) AbstractAction(com.sequenceiq.flow.core.AbstractAction) Map(java.util.Map) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent) ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent) Bean(org.springframework.context.annotation.Bean)

Example 8 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class ClusterDownscaleService method clusterDownscaleStarted.

public void clusterDownscaleStarted(long stackId, Map<String, Integer> hostGroupWithAdjustment, Map<String, Set<Long>> hostGroupWithPrivateIds, ClusterDownscaleDetails details) {
    Set<String> hostGroups = hostGroupWithAdjustment.size() > 0 ? hostGroupWithAdjustment.keySet() : hostGroupWithPrivateIds.keySet();
    flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_DOWN, String.join(", ", hostGroups));
    clusterService.updateClusterStatusByStackId(stackId, DetailedStackStatus.DOWNSCALE_IN_PROGRESS);
    if (hostGroupWithAdjustment.size() > 0) {
        LOGGER.info("Decommissioning hosts '{}'", hostGroupWithAdjustment);
        Integer nodeCount = hostGroupWithAdjustment.values().stream().reduce(0, Integer::sum);
        flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_REMOVING_NODES, String.valueOf(Math.abs(nodeCount)));
    } else {
        LOGGER.info("Decommissioning hosts '{}'", hostGroupWithPrivateIds);
        Stack stack = stackService.getByIdWithListsInTransaction(stackId);
        ResourceEvent resourceEvent = details.isForced() ? CLUSTER_FORCE_REMOVING_NODES : CLUSTER_REMOVING_NODES;
        List<Long> privateIds = hostGroupWithPrivateIds.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
        List<String> decommissionedHostNames = stackService.getHostNamesForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds);
        flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), resourceEvent, String.join(", ", decommissionedHostNames));
    }
}
Also used : ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 9 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class LoadBalancerUpdateActions method stackLoadBalancerUpdate.

@Bean(name = "STACK_UPDATE_STATE")
public Action<?, ?> stackLoadBalancerUpdate() {
    return new AbstractLoadBalancerUpdateAction<>(LoadBalancerUpdateEvent.class) {

        @Override
        protected void doExecute(CommonContext context, LoadBalancerUpdateEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.LOAD_BALANCER_STACK_UPDATE_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_LOAD_BALANCER_STACK_UPDATE_STARTED;
            LoadBalancerUpdateState loadBalancerUpdateState = LoadBalancerUpdateState.STACK_UPDATE_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, loadBalancerUpdateState);
            EnvironmentLoadBalancerDto environmentLoadBalancerDto = EnvironmentLoadBalancerDto.builder().withId(envDto.getId()).withEnvironmentDto(payload.getEnvironmentDto()).withEndpointAccessGateway(payload.getEndpointAccessGateway()).withEndpointGatewaySubnetIds(payload.getSubnetIds()).build();
            sendEvent(context, LoadBalancerUpdateHandlerSelectors.STACK_UPDATE_HANDLER_EVENT.selector(), environmentLoadBalancerDto);
        }
    };
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 10 with ResourceEvent

use of com.sequenceiq.cloudbreak.event.ResourceEvent in project cloudbreak by hortonworks.

the class LoadBalancerUpdateActions method environmentLoadBalancerUpdate.

@Bean(name = "ENVIRONMENT_UPDATE_STATE")
public Action<?, ?> environmentLoadBalancerUpdate() {
    return new AbstractLoadBalancerUpdateAction<>(LoadBalancerUpdateEvent.class) {

        @Override
        protected void doExecute(CommonContext context, LoadBalancerUpdateEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.LOAD_BALANCER_ENV_UPDATE_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_LOAD_BALANCER_ENV_UPDATE_STARTED;
            LoadBalancerUpdateState loadBalancerUpdateState = LoadBalancerUpdateState.ENVIRONMENT_UPDATE_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, loadBalancerUpdateState);
            EnvironmentLoadBalancerDto environmentLoadBalancerDto = EnvironmentLoadBalancerDto.builder().withId(envDto.getId()).withEnvironmentDto(payload.getEnvironmentDto()).withEndpointAccessGateway(payload.getEndpointAccessGateway()).withEndpointGatewaySubnetIds(payload.getSubnetIds()).build();
            sendEvent(context, LoadBalancerUpdateHandlerSelectors.ENVIRONMENT_UPDATE_HANDLER_EVENT.selector(), environmentLoadBalancerDto);
        }
    };
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)20 Map (java.util.Map)15 Bean (org.springframework.context.annotation.Bean)12 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)11 CommonContext (com.sequenceiq.flow.core.CommonContext)11 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)9 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)4 Sets (com.google.common.collect.Sets)3 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)3 AVAILABLE (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE)3 START_IN_PROGRESS (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS)3 STOPPED (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED)3 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)3 DECOMMISSION_FAILED (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED)3 FAILED (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED)3 SERVICES_HEALTHY (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY)3 SERVICES_RUNNING (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING)3 SERVICES_UNHEALTHY (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY)3 RecoveryMode (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode)3 StatusRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest)3