use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.
the class PublicKeyCreationHandlerTest method verifyEnvCreationEvent.
private void verifyEnvCreationEvent() {
BaseNamedFlowEvent event = baseNamedFlowEvent.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_ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_EVENT.selector());
assertThat(headersArgumentCaptor.getValue()).isSameAs(headers);
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.
the class EnvironmentValidationHandler method goToNetworkCreationState.
private void goToNetworkCreationState(Event<EnvironmentValidationDto> environmentDtoEvent, EnvironmentDto environmentDto) {
EnvCreationEvent envCreationEvent = EnvCreationEvent.builder().withResourceId(environmentDto.getResourceId()).withSelector(START_NETWORK_CREATION_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.
the class PublicKeyCreationHandler method accept.
@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
LOGGER.debug("Accepting PublicKeyCreation event");
EnvironmentDto environmentDto = environmentDtoEvent.getData();
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
if (environment.getAuthentication().isManagedKey()) {
boolean created = environmentResourceService.createAndUpdateSshKey(environment);
if (created) {
String publicKeyId = environment.getAuthentication().getPublicKeyId();
LOGGER.info("Update the environment and it's authentication with the created public SSH key id: '{}'", publicKeyId);
environmentService.save(environment);
} else {
LOGGER.info("The public key id could not be created for {}", environmentDto.getName());
}
} else {
LOGGER.debug("Environment {} requested no managed public key", environment.getName());
}
});
EnvCreationEvent envCreationEvent = getEnvCreateEvent(environmentDto);
eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
EnvCreationFailureEvent failedEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
Event<EnvCreationFailureEvent> ev = new Event<>(environmentDtoEvent.getHeaders(), failedEvent);
eventBus.notify(failedEvent.selector(), ev);
}
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.
the class EnvironmentReactorFlowManager method triggerCreationFlow.
public FlowIdentifier triggerCreationFlow(long envId, String envName, String userCrn, String envCrn) {
LOGGER.info("Environment creation flow triggered.");
EnvCreationEvent envCreationEvent = EnvCreationEvent.builder().withAccepted(new Promise<>()).withSelector(START_ENVIRONMENT_INITIALIZATION_EVENT.selector()).withResourceId(envId).withResourceName(envName).withResourceCrn(envCrn).build();
return eventSender.sendEvent(envCreationEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent 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);
}
};
}
Aggregations