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);
}
};
}
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);
}
};
}
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);
});
}
};
}
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);
});
}
};
}
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);
});
}
};
}
Aggregations