Search in sources :

Example 1 with ResourceCrnPayload

use of com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload in project cloudbreak by hortonworks.

the class EnvStopActions method finishedAction.

@Bean(name = "ENV_STOP_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvStopAction<>(ResourceCrnPayload.class) {

        @Override
        protected void doExecute(CommonContext context, ResourceCrnPayload payload, Map<Object, Object> variables) {
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.ENV_STOPPED, ResourceEvent.ENVIRONMENT_STOPPED, EnvStopState.ENV_STOP_FINISHED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_STOP_FINISHED, environmentDto);
            LOGGER.info("Flow entered into ENV_STOP_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_STOP_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceCrnPayload(com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with ResourceCrnPayload

use of com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload in project cloudbreak by hortonworks.

the class EnvStartActions method finishedAction.

@Bean(name = "ENV_START_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvStartAction<>(ResourceCrnPayload.class) {

        @Override
        protected void doExecute(CommonContext context, ResourceCrnPayload payload, Map<Object, Object> variables) {
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.AVAILABLE, ResourceEvent.ENVIRONMENT_STARTED, EnvStartState.ENV_START_FINISHED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_START_FINISHED, environmentDto);
            LOGGER.info("Flow entered into ENV_START_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_START_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceCrnPayload(com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with ResourceCrnPayload

use of com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload in project cloudbreak by hortonworks.

the class LoadBalancerUpdateActions method finishedAction.

@Bean(name = "LOAD_BALANCER_UPDATE_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractLoadBalancerUpdateAction<>(ResourceCrnPayload.class) {

        @Override
        protected void doExecute(CommonContext context, ResourceCrnPayload payload, Map<Object, Object> variables) {
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.AVAILABLE, ResourceEvent.ENVIRONMENT_LOAD_BALANCER_UPDATE_FINISHED, LoadBalancerUpdateState.LOAD_BALANCER_UPDATE_FINISHED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_LOAD_BALANCER_UPDATE_FINISHED, environmentDto);
            LOGGER.info("Flow entered into LOAD_BALANCER_UPDATE_FINISHED_STATE");
            sendEvent(context, FINALIZE_LOAD_BALANCER_UPDATE_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceCrnPayload(com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 4 with ResourceCrnPayload

use of com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload in project cloudbreak by hortonworks.

the class EnvDeleteActions method finishedAction.

@Bean(name = "ENV_DELETE_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvDeleteAction<>(ResourceCrnPayload.class) {

        @Override
        protected void doExecute(CommonContext context, ResourceCrnPayload payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(env -> {
                String originalName = env.getName();
                env.setName(generateArchiveName(env.getName()));
                env.setDeletionTimestamp(new Date().getTime());
                env.setStatus(EnvironmentStatus.ARCHIVED);
                env.setStatusReason(null);
                env.setArchived(true);
                env.setProxyConfig(null);
                Environment result = environmentService.save(env);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto, true, true);
                simpleResponse.setName(originalName);
                metricService.incrementMetricCounter(MetricType.ENV_DELETION_FINISHED, environmentDto);
                eventService.sendEventAndNotificationWithPayload(environmentDto, context.getFlowTriggerUserCrn(), ResourceEvent.ENVIRONMENT_DELETION_FINISHED, simpleResponse);
            }, () -> LOGGER.error("Cannot finish the delete flow because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", payload.getResourceId()));
            LOGGER.info("Flow entered into ENV_DELETE_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_DELETE_EVENT.event(), payload);
        }
    };
}
Also used : SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceCrnPayload(com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload) Environment(com.sequenceiq.environment.environment.domain.Environment) Map(java.util.Map) Date(java.util.Date) Bean(org.springframework.context.annotation.Bean)

Example 5 with ResourceCrnPayload

use of com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload in project cloudbreak by hortonworks.

the class EnvStackConfigUpdatesActions method finishedAction.

@Bean(name = "STACK_CONFIG_UPDATES_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvStackConfigUpdatesAction<>(ResourceCrnPayload.class) {

        @Override
        protected void doExecute(CommonContext context, ResourceCrnPayload payload, Map<Object, Object> variables) {
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, getCurrentStatus(payload.getResourceId()), ResourceEvent.ENVIRONMENT_STACK_CONFIGS_UPDATE_FINISHED, EnvStackConfigUpdatesState.STACK_CONFIG_UPDATES_FINISHED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_STACK_CONFIG_UPDATE_FINISHED, environmentDto);
            LOGGER.info("Flow entered into STACK_CONFIG_UPDATES_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_STACK_CONIFG_UPDATES_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceCrnPayload(com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

ResourceCrnPayload (com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)5 CommonContext (com.sequenceiq.flow.core.CommonContext)5 Map (java.util.Map)5 Bean (org.springframework.context.annotation.Bean)5 SimpleEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 Date (java.util.Date)1