Search in sources :

Example 61 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class EnvStartActions method startDatahub.

@Bean(name = "START_DATAHUB_STATE")
public Action<?, ?> startDatahub() {
    return new AbstractEnvStartAction<>(EnvStartEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStartEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.START_DATAHUB_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_START_DATAHUB_STARTED;
            EnvStartState envStartState = EnvStartState.START_DATAHUB_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStartState);
            EnvironmentStartDto environmentStartDto = EnvironmentStartDto.builder().withDataHubStart(payload.getDataHubStartAction()).withEnvironmentDto(envDto).withId(envDto.getId()).build();
            sendEvent(context, EnvStartHandlerSelectors.START_DATAHUB_HANDLER_EVENT.selector(), environmentStartDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentStartDto(com.sequenceiq.environment.environment.dto.EnvironmentStartDto) Bean(org.springframework.context.annotation.Bean)

Example 62 with CommonContext

use of com.sequenceiq.flow.core.CommonContext 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)

Example 63 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class EnvStopActions method failedAction.

@Bean(name = "ENV_STOP_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractEnvStopAction<>(EnvStopFailedEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStopFailedEvent payload, Map<Object, Object> variables) {
            LOGGER.warn(String.format("Failed to stop environment '%s'. Status: '%s'.", payload.getEnvironmentDto(), payload.getEnvironmentStatus()), payload.getException());
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateFailedEnvironmentStatusAndNotify(context, payload, payload.getEnvironmentStatus(), convertStatus(payload.getEnvironmentStatus()), EnvStopState.ENV_STOP_FAILED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_STOP_FAILED, environmentDto, payload.getException());
            sendEvent(context, HANDLED_FAILED_ENV_STOP_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Map(java.util.Map) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent) Bean(org.springframework.context.annotation.Bean)

Example 64 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class EnvStopActions method stopDatahub.

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

        @Override
        protected void doExecute(CommonContext context, EnvStopEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.STOP_DATAHUB_STARTED;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_STOP_DATAHUB_STARTED;
            EnvStopState envStopState = EnvStopState.STOP_DATAHUB_STATE;
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStopState);
            sendEvent(context, EnvStopHandlerSelectors.STOP_DATAHUB_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 65 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class EnvClustersDeleteActions method failedAction.

@Bean(name = "ENV_CLUSTERS_DELETE_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvClusterDeleteFailedEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvClusterDeleteFailedEvent payload, Map<Object, Object> variables) {
            LOGGER.warn("Failed to delete environment", payload.getException());
            Exception e = payload.getException();
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                environment.setStatusReason(payload.getMessage() == null ? e.getMessage() : payload.getMessage());
                environment.setStatus(EnvironmentStatus.DELETE_FAILED);
                Environment result = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
                metricService.incrementMetricCounter(MetricType.ENV_CLUSTERS_DELETION_FAILED, environmentDto, payload.getException());
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ResourceEvent.ENVIRONMENT_DELETION_FAILED);
            }, () -> LOGGER.error("Cannot set delete failed to env because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", payload.getResourceId()));
            LOGGER.info("Flow entered into ENV_CLUSTERS_DELETE_FAILED_STATE");
            sendEvent(context, HANDLED_FAILED_ENV_CLUSTERS_DELETE_EVENT.event(), payload);
        }

        @Override
        protected CommonContext createFlowContext(FlowParameters flowParameters, StateContext<EnvClustersDeleteState, EnvClustersDeleteStateSelectors> stateContext, EnvClusterDeleteFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return new CommonContext(flowParameters);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) StateContext(org.springframework.statemachine.StateContext) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvClusterDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Aggregations

CommonContext (com.sequenceiq.flow.core.CommonContext)84 Map (java.util.Map)83 Bean (org.springframework.context.annotation.Bean)83 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)46 DiagnosticsCollectionEvent (com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent)13 DiagnosticsCollectionEvent (com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent)13 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)12 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)12 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)12 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)11 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)7 EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)7 CmDiagnosticsCollectionEvent (com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent)6 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)6 ResourceCrnPayload (com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload)5 Environment (com.sequenceiq.environment.environment.domain.Environment)4 EnvironmentStartDto (com.sequenceiq.environment.environment.dto.EnvironmentStartDto)4 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)4 DiagnosticParameters (com.sequenceiq.common.model.diagnostics.DiagnosticParameters)3 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)3