Search in sources :

Example 1 with EnvStartFailedEvent

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

the class SynchronizeUsersHandlerTest method testWhenFreeIpaIsNotAvailableThenFail.

@Test
void testWhenFreeIpaIsNotAvailableThenFail() {
    ReflectionTestUtils.setField(underTest, "synchronizeOnStartEnabled", true);
    when(freeIpaService.describe(ENV_CRN)).thenReturn(Optional.of(describeFreeIpaResponse));
    when(describeFreeIpaResponse.getAvailabilityStatus()).thenReturn(AvailabilityStatus.UNAVAILABLE);
    when(describeFreeIpaResponse.getStatus()).thenReturn(Status.STOPPED);
    underTest.accept(environmentDtoEvent);
    verify(eventSender, never()).sendEvent(any(EnvStartEvent.class), eq(eventHeaders));
    verify(freeIpaPollerService, never()).waitForSynchronizeUsers(any(), any());
    ArgumentCaptor<EnvStartFailedEvent> failEventCaptor = ArgumentCaptor.forClass(EnvStartFailedEvent.class);
    verify(eventSender, times(1)).sendEvent(failEventCaptor.capture(), eq(eventHeaders));
    EnvStartFailedEvent failedEvent = failEventCaptor.getValue();
    assertThat(failedEvent.getEnvironmentStatus()).isEqualTo(EnvironmentStatus.START_SYNCHRONIZE_USERS_FAILED);
}
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 2 with EnvStartFailedEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent 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 3 with EnvStartFailedEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent 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)

Example 4 with EnvStartFailedEvent

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

the class StartDatahubHandler method accept.

@Override
public void accept(Event<EnvironmentStartDto> environmentStartDtoEvent) {
    EnvironmentDto environmentDto = environmentStartDtoEvent.getData().getEnvironmentDto();
    try {
        if (START_ALL == environmentStartDtoEvent.getData().getDataHubStart()) {
            datahubPollerService.startAttachedDatahubClusters(environmentDto.getId(), environmentDto.getResourceCrn());
        }
        EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent().withSelector(EnvStartStateSelectors.ENV_START_SYNCHRONIZE_USERS_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_DATAHUB_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 EnvStartFailedEvent

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

the class StartFreeIpaHandlerTest method testWhenFreeIpaDescribeTellsFreeIpaIsNotStartableThenExceptionComesAndNoStartEventHappens.

@Test
void testWhenFreeIpaDescribeTellsFreeIpaIsNotStartableThenExceptionComesAndNoStartEventHappens() {
    when(mockFreeIpaService.describe(MOCK_ENV_CRN)).thenReturn(Optional.of(mockDescribeFreeIpaResponse));
    when(mockDescribeFreeIpaResponse.getAvailabilityStatus()).thenReturn(AvailabilityStatus.UNAVAILABLE);
    when(mockDescribeFreeIpaResponse.getStatus()).thenReturn(Status.DELETED_ON_PROVIDER_SIDE);
    underTest.accept(mockEnvironmentDtoEvent);
    verify(mockEventSender, never()).sendEvent(any(EnvStartEvent.class), any());
    verify(mockFreeIpaPollerService, never()).startAttachedFreeipaInstances(any(), any());
    ArgumentCaptor<EnvStartFailedEvent> startFailedEventCaptor = ArgumentCaptor.forClass(EnvStartFailedEvent.class);
    verify(mockEventSender, times(1)).sendEvent(startFailedEventCaptor.capture(), eq(mockEventHeaders));
    EnvStartFailedEvent envStartFailedEvent = startFailedEventCaptor.getValue();
    assertThat(envStartFailedEvent.getEnvironmentDto()).isEqualTo(environmentDto);
    assertThat(envStartFailedEvent.getEnvironmentStatus()).isEqualTo(EnvironmentStatus.START_FREEIPA_FAILED);
}
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)

Aggregations

EnvStartFailedEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent)7 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)6 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)5 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)2 Test (org.junit.jupiter.api.Test)2 CommonContext (com.sequenceiq.flow.core.CommonContext)1 Map (java.util.Map)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Bean (org.springframework.context.annotation.Bean)1