Search in sources :

Example 1 with EnvStopEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent in project cloudbreak by hortonworks.

the class EnvStopActions method stopDatalake.

@Bean(name = "STOP_DATALAKE_STATE")
public Action<?, ?> stopDatalake() {
    return new AbstractEnvStopAction<>(EnvStopEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStopEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.STOP_DATALAKE_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_STOP_DATALAKE_STARTED;
            EnvStopState envStopState = EnvStopState.STOP_DATALAKE_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStopState);
            sendEvent(context, EnvStopHandlerSelectors.STOP_DATALAKE_HANDLER_EVENT.selector(), envDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with EnvStopEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent in project cloudbreak by hortonworks.

the class StopDatahubHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        datahubPollerService.stopAttachedDatahubClusters(environmentDto.getId(), environmentDto.getResourceCrn());
        EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent().withSelector(EnvStopStateSelectors.ENV_STOP_DATALAKE_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_DATAHUB_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)

Example 3 with EnvStopEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent in project cloudbreak by hortonworks.

the class StopDatalakeHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        sdxPollerService.stopAttachedDatalakeClusters(environmentDto.getId(), environmentDto.getName());
        EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent().withSelector(EnvStopStateSelectors.ENV_STOP_FREEIPA_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_DATALAKE_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)

Example 4 with EnvStopEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent in project cloudbreak by hortonworks.

the class StopFreeIpaHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) {
            freeIpaService.describe(environmentDto.getResourceCrn()).ifPresentOrElse(freeIpa -> {
                if (freeIpa.getStatus() == null) {
                    throw new FreeIpaOperationFailedException("FreeIPA status is unpredictable, env stop will be interrupted.");
                } else if (freeIpa.getStatus().isStoppedPhase() || freeIpa.getStatus().isStopInProgressPhase()) {
                    LOGGER.info("Stop has already been triggered continuing without new stop trigger. FreeIPA status: {}", freeIpa.getStatus());
                } else if (!freeIpa.getStatus().isStoppable()) {
                    throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name());
                } else {
                    LOGGER.info("FreeIPA will be stopped.");
                    freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn());
                }
            }, () -> LOGGER.info("FreeIPA cannot be found by environment crn"));
        }
        EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent().withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.warn("Failed to stop Freeipa.", e);
        EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)

Example 5 with EnvStopEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent in project cloudbreak by hortonworks.

the class EnvStopActions method stopFreeipa.

@Bean(name = "STOP_FREEIPA_STATE")
public Action<?, ?> stopFreeipa() {
    return new AbstractEnvStopAction<>(EnvStopEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStopEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.STOP_FREEIPA_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_STOP_FREEIPA_STARTED;
            EnvStopState envStopState = EnvStopState.STOP_FREEIPA_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStopState);
            sendEvent(context, EnvStopHandlerSelectors.STOP_FREEIPA_HANDLER_EVENT.selector(), envDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)7 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)6 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)3 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)3 EnvStopFailedEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)3 CommonContext (com.sequenceiq.flow.core.CommonContext)3 Map (java.util.Map)3 Bean (org.springframework.context.annotation.Bean)3 EnvStackConfigUpdatesEvent (com.sequenceiq.environment.environment.flow.config.update.event.EnvStackConfigUpdatesEvent)1 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 LoadBalancerUpdateEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)1 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)1 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)1 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)1 Event (reactor.bus.Event)1