Search in sources :

Example 26 with CommonContext

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

the class EnvStackConfigUpdatesActions method collectClusterInfo.

@Bean(name = "STACK_CONFIG_UPDATES_START_STATE")
public Action<?, ?> collectClusterInfo() {
    return new AbstractEnvStackConfigUpdatesAction<>(EnvStackConfigUpdatesEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStackConfigUpdatesEvent payload, Map<Object, Object> variables) {
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, getCurrentStatus(payload.getResourceId()), ResourceEvent.ENVIRONMENT_STACK_CONFIGS_UPDATE_STARTED, EnvStackConfigUpdatesState.STACK_CONFIG_UPDATES_START_STATE);
            sendEvent(context, EnvStackConfigUpdatesHandlerSelectors.STACK_CONFIG_UPDATES_HANDLER_EVENT.selector(), environmentDto);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) EnvStackConfigUpdatesEvent(com.sequenceiq.environment.environment.flow.config.update.event.EnvStackConfigUpdatesEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 27 with CommonContext

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

the class EnvCreationActions method finishedAction.

@Bean(name = "ENV_CREATION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            LOGGER.debug("Finished to create environment with payload {}", payload);
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                environment.setStatus(EnvironmentStatus.AVAILABLE);
                environment.setStatusReason(null);
                Environment result = environmentService.save(environment);
                environmentJobService.schedule(result.getId());
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
                metricService.incrementMetricCounter(MetricType.ENV_CREATION_FINISHED, environmentDto);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_CREATION_FINISHED);
            }, () -> LOGGER.error("Cannot finish the creation of env, because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", payload.getResourceId()));
            LOGGER.info("Flow entered into ENV_CREATION_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_CREATION_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 28 with CommonContext

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

the class EnvCreationActions method environmentValidationAction.

@Bean(name = "ENVIRONMENT_CREATION_VALIDATION_STATE")
public Action<?, ?> environmentValidationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("Validation of Environment has started. Current state is - ENVIRONMENT_CREATION_VALIDATION_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_VALIDATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_VALIDATION_STARTED);
                EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).withValidationType(ValidationType.ENVIRONMENT_CREATION).build();
                sendEvent(context, VALIDATE_ENVIRONMENT_EVENT.selector(), environmentValidationDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment validation action went failed with EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_VALIDATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to validate environment creation request! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 29 with CommonContext

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

the class EnvCreationActions method resourceEncryptionInitializationAction.

@Bean(name = "ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED_STATE")
public Action<?, ?> resourceEncryptionInitializationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("Initialization of resource encryption has started." + " Current state is - ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED);
                sendEvent(context, INITIALIZE_ENVIRONMENT_RESOURCE_ENCRYPTION_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment encryption init action went failed with  EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create encryption resources for environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 30 with CommonContext

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

the class EnvCreationActions method publickeyCreationAction.

@Bean(name = "PUBLICKEY_CREATION_STARTED_STATE")
public Action<?, ?> publickeyCreationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("Creation of PublicKey has started. Current state is - PUBLICKEY_CREATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.PUBLICKEY_CREATE_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_PUBLICKEY_CREATION_STARTED);
                sendEvent(context, CREATE_PUBLICKEY_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment public key creation action went failed with EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_PUBLICKEY_CREATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create public key for environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) Map(java.util.Map) 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