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