use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent 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.environment.environment.flow.creation.event.EnvCreationEvent 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.environment.environment.flow.creation.event.EnvCreationEvent 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);
});
}
};
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.
the class ResourceEncryptionInitializationHandlerTest method verifyEnvCreationEvent.
private void verifyEnvCreationEvent() {
BaseNamedFlowEvent event = baseNamedFlowEventCaptor.getValue();
assertThat(event).isInstanceOf(EnvCreationEvent.class);
EnvCreationEvent envCreationEvent = (EnvCreationEvent) event;
assertThat(envCreationEvent.getResourceName()).isEqualTo(ENVIRONMENT_NAME);
assertThat(envCreationEvent.getResourceCrn()).isEqualTo(ENVIRONMENT_CRN);
assertThat(envCreationEvent.getResourceId()).isEqualTo(ENVIRONMENT_ID);
assertThat(envCreationEvent.selector()).isEqualTo(START_FREEIPA_CREATION_EVENT.selector());
assertThat(headersArgumentCaptor.getValue()).isSameAs(headers);
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.
the class EnvCreationActionsTest method setUp.
@BeforeEach
void setUp() {
FlowParameters flowParameters = new FlowParameters(FLOW_ID, FLOW_TRIGGER_USER_CRN, null);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name())).thenReturn(flowParameters);
actionPayload = new EnvCreationEvent(ACTION_PAYLOAD_SELECTOR, ENVIRONMENT_ID, ENVIRONMENT_NAME, ENVIRONMENT_CRN);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(actionPayload);
when(stateContext.getExtendedState()).thenReturn(extendedState);
when(extendedState.getVariables()).thenReturn(new HashMap<>());
when(stateContext.getStateMachine()).thenReturn(stateMachine);
when(stateMachine.getState()).thenReturn(state);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
when(spanBuilder.start()).thenReturn(span);
when(tracer.activateSpan(span)).thenReturn(scope);
when(span.context()).thenReturn(spanContext);
when(flowEvent.name()).thenReturn("eventName");
}
Aggregations