Search in sources :

Example 1 with EnvStartEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent in project cloudbreak by hortonworks.

the class StartFreeIpaHandlerTest method testWhenFreeIpaDescribeTellsFreeIpaIsStartableThenStartEventHappens.

@Test
void testWhenFreeIpaDescribeTellsFreeIpaIsStartableThenStartEventHappens() {
    when(mockFreeIpaService.describe(MOCK_ENV_CRN)).thenReturn(Optional.of(mockDescribeFreeIpaResponse));
    when(mockDescribeFreeIpaResponse.getAvailabilityStatus()).thenReturn(AvailabilityStatus.UNAVAILABLE);
    when(mockDescribeFreeIpaResponse.getStatus()).thenReturn(Status.STOPPED);
    underTest.accept(mockEnvironmentDtoEvent);
    verify(mockEventSender, never()).sendEvent(any(EnvStartFailedEvent.class), eq(mockEventHeaders));
    verify(mockFreeIpaPollerService, times(1)).startAttachedFreeipaInstances(ENV_ID, MOCK_ENV_CRN);
    ArgumentCaptor<EnvStartEvent> startEventCaptor = ArgumentCaptor.forClass(EnvStartEvent.class);
    verify(mockEventSender, times(1)).sendEvent(startEventCaptor.capture(), eq(mockEventHeaders));
    EnvStartEvent envStartEvent = startEventCaptor.getValue();
    assertThat(envStartEvent.selector()).isEqualTo(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector());
}
Also used : EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with EnvStartEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent in project cloudbreak by hortonworks.

the class SynchronizeUsersHandlerTest method testWhenFreeIpaIsAvailableAndEnabledThenSynchronize.

@Test
void testWhenFreeIpaIsAvailableAndEnabledThenSynchronize() {
    ReflectionTestUtils.setField(underTest, "synchronizeOnStartEnabled", true);
    when(freeIpaService.describe(ENV_CRN)).thenReturn(Optional.of(describeFreeIpaResponse));
    when(describeFreeIpaResponse.getAvailabilityStatus()).thenReturn(AvailabilityStatus.AVAILABLE);
    when(describeFreeIpaResponse.getStatus()).thenReturn(Status.AVAILABLE);
    underTest.accept(environmentDtoEvent);
    verify(eventSender, never()).sendEvent(any(EnvStartFailedEvent.class), eq(eventHeaders));
    verify(freeIpaPollerService, times(1)).waitForSynchronizeUsers(ENV_ID, ENV_CRN);
    ArgumentCaptor<EnvStartEvent> startEventCaptor = ArgumentCaptor.forClass(EnvStartEvent.class);
    verify(eventSender, times(1)).sendEvent(startEventCaptor.capture(), eq(eventHeaders));
    EnvStartEvent envStartEvent = startEventCaptor.getValue();
    assertThat(envStartEvent.selector()).isEqualTo(EnvStartStateSelectors.FINISH_ENV_START_EVENT.selector());
}
Also used : EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) Test(org.junit.jupiter.api.Test)

Example 3 with EnvStartEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent in project cloudbreak by hortonworks.

the class SynchronizeUsersHandlerTest method testWhenFreeIpaIsAvailableAndDisabledThenDontSynchronize.

@Test
void testWhenFreeIpaIsAvailableAndDisabledThenDontSynchronize() {
    ReflectionTestUtils.setField(underTest, "synchronizeOnStartEnabled", false);
    underTest.accept(environmentDtoEvent);
    verify(eventSender, never()).sendEvent(any(EnvStartFailedEvent.class), eq(eventHeaders));
    verify(freeIpaPollerService, never()).waitForSynchronizeUsers(any(), any());
    ArgumentCaptor<EnvStartEvent> startEventCaptor = ArgumentCaptor.forClass(EnvStartEvent.class);
    verify(eventSender, times(1)).sendEvent(startEventCaptor.capture(), eq(eventHeaders));
    EnvStartEvent envStartEvent = startEventCaptor.getValue();
    assertThat(envStartEvent.selector()).isEqualTo(EnvStartStateSelectors.FINISH_ENV_START_EVENT.selector());
}
Also used : EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) Test(org.junit.jupiter.api.Test)

Example 4 with EnvStartEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent in project cloudbreak by hortonworks.

the class StartDatalakeHandler method accept.

@Override
public void accept(Event<EnvironmentStartDto> environmentStartDtoEvent) {
    EnvironmentDto environmentDto = environmentStartDtoEvent.getData().getEnvironmentDto();
    try {
        sdxPollerService.startAttachedDatalake(environmentDto.getId(), environmentDto.getName());
        EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent().withSelector(EnvStartStateSelectors.ENV_START_DATAHUB_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).withDataHubStart(environmentStartDtoEvent.getData().getDataHubStart()).build();
        eventSender().sendEvent(envStartEvent, environmentStartDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_DATALAKE_FAILED);
        eventSender().sendEvent(failedEvent, environmentStartDtoEvent.getHeaders());
    }
}
Also used : EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto)

Example 5 with EnvStartEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent in project cloudbreak by hortonworks.

the class SynchronizeUsersHandler method accept.

@Override
public void accept(Event<EnvironmentStartDto> environmentStartDtoEvent) {
    LOGGER.debug("User synchronization is {}.", synchronizeOnStartEnabled ? "enabled" : "disabled");
    EnvironmentDto environmentDto = environmentStartDtoEvent.getData().getEnvironmentDto();
    try {
        if (synchronizeOnStartEnabled) {
            freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> {
                if (freeIpa.getStatus() != null && freeIpa.getAvailabilityStatus() != null && !freeIpa.getAvailabilityStatus().isAvailable()) {
                    throw new FreeIpaOperationFailedException("FreeIPA is not in AVAILABLE state to synchronize users! Current state is: " + freeIpa.getStatus().name());
                }
            });
            freeIpaPollerService.waitForSynchronizeUsers(environmentDto.getId(), environmentDto.getResourceCrn());
        }
        EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent().withSelector(EnvStartStateSelectors.FINISH_ENV_START_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).withDataHubStart(environmentStartDtoEvent.getData().getDataHubStart()).build();
        eventSender().sendEvent(envStartEvent, environmentStartDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_SYNCHRONIZE_USERS_FAILED);
        eventSender().sendEvent(failedEvent, environmentStartDtoEvent.getHeaders());
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Aggregations

EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)12 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)8 EnvStartFailedEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent)7 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)4 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)4 EnvironmentStartDto (com.sequenceiq.environment.environment.dto.EnvironmentStartDto)4 CommonContext (com.sequenceiq.flow.core.CommonContext)4 Map (java.util.Map)4 Bean (org.springframework.context.annotation.Bean)4 Test (org.junit.jupiter.api.Test)3 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)2 EnvStackConfigUpdatesEvent (com.sequenceiq.environment.environment.flow.config.update.event.EnvStackConfigUpdatesEvent)1 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 LoadBalancerUpdateEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)1 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)1 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Event (reactor.bus.Event)1 Promise (reactor.rx.Promise)1