Search in sources :

Example 1 with EnvCreationEvent

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);
}
Also used : BaseNamedFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)

Example 2 with EnvCreationEvent

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());
}
Also used : EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)

Example 3 with EnvCreationEvent

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);
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)

Example 4 with EnvCreationEvent

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)));
}
Also used : Promise(reactor.rx.Promise) EnvStackConfigUpdatesEvent(com.sequenceiq.environment.environment.flow.config.update.event.EnvStackConfigUpdatesEvent) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Event(reactor.bus.Event) EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) UpgradeCcmEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)

Example 5 with EnvCreationEvent

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

Aggregations

EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)16 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)9 EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)8 CommonContext (com.sequenceiq.flow.core.CommonContext)7 Map (java.util.Map)7 Bean (org.springframework.context.annotation.Bean)7 Event (reactor.bus.Event)3 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)1 EnvStackConfigUpdatesEvent (com.sequenceiq.environment.environment.flow.config.update.event.EnvStackConfigUpdatesEvent)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 LoadBalancerUpdateEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)1 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)1 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)1 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)1 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1