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