use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.
the class ExperienceDeletionHandlerTest method testAcceptWhenDeleteActionThrowsExceptionThenEventSenderShouldAcceptEnvDeleteFailedEvent.
@Test
void testAcceptWhenDeleteActionThrowsExceptionThenEventSenderShouldAcceptEnvDeleteFailedEvent() {
Environment env = new Environment();
when(mockEntitlementService.isExperienceDeletionEnabled(TEST_ACCOUNT_ID)).thenReturn(true);
when(mockEnvironmentService.findEnvironmentById(TEST_ENV_ID)).thenReturn(Optional.of(env));
doThrow(new RuntimeException()).when(mockEnvironmentExperienceDeletionAction).execute(any(Environment.class), anyBoolean());
underTest.accept(mockEnvironmentDeletionDtoEvent);
verify(mockEnvironmentExperienceDeletionAction, times(ONCE)).execute(any(), anyBoolean());
verify(mockEnvironmentExperienceDeletionAction, times(ONCE)).execute(env, true);
verify(mockEventSender, times(ONCE)).sendEvent(any(EnvClusterDeleteFailedEvent.class), eq(mockEventHeaders));
verify(mockEventSender, never()).sendEvent(any(EnvDeleteEvent.class), any());
EnvClusterDeleteFailedEvent capturedDeleteEvent = (EnvClusterDeleteFailedEvent) baseNamedFlowEvent.getValue();
assertThat(capturedDeleteEvent.getResourceName()).isEqualTo(TEST_ENV_NAME);
assertThat(capturedDeleteEvent.getResourceId()).isEqualTo(TEST_ENV_ID);
assertThat(capturedDeleteEvent.getResourceCrn()).isEqualTo(TEST_ENV_CRN);
assertThat(capturedDeleteEvent.selector()).isEqualTo("FAILED_ENV_CLUSTERS_DELETE_EVENT");
}
use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.
the class DataLakeClustersDeleteHandlerTest method acceptFail.
@Test
void acceptFail() {
IllegalStateException error = new IllegalStateException("error");
when(environmentViewService.getById(ENV_ID)).thenThrow(error);
underTest.accept(environmentDtoEvent);
verify(sdxDeleteService, never()).deleteSdxClustersForEnvironment(any(), any(), anyBoolean());
verify(eventSender).sendEvent(any(EnvClusterDeleteFailedEvent.class), eq(headers));
verify(eventSender, never()).sendEvent(any(EnvDeleteEvent.class), any());
EnvClusterDeleteFailedEvent capturedDeleteFailedEvent = (EnvClusterDeleteFailedEvent) baseNamedFlowEvent.getValue();
assertThat(capturedDeleteFailedEvent.getResourceName()).isEqualTo(ENV_NAME);
assertThat(capturedDeleteFailedEvent.getResourceId()).isEqualTo(ENV_ID);
assertThat(capturedDeleteFailedEvent.getResourceCrn()).isEqualTo(RESOURCE_CRN);
assertThat(capturedDeleteFailedEvent.selector()).isEqualTo("FAILED_ENV_CLUSTERS_DELETE_EVENT");
assertThat(capturedDeleteFailedEvent.getException()).isEqualTo(error);
}
use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.
the class DataHubClusterDeletionHandlerTest method acceptFail.
@Test
void acceptFail() {
IllegalStateException error = new IllegalStateException("error");
when(environmentService.findEnvironmentById(ENV_ID)).thenThrow(error);
underTest.accept(environmentDtoEvent);
verify(datahubDeletionService, never()).deleteDatahubClustersForEnvironment(any(), any(), anyBoolean());
verify(eventSender).sendEvent(any(EnvClusterDeleteFailedEvent.class), eq(headers));
verify(eventSender, never()).sendEvent(any(EnvDeleteEvent.class), any());
EnvClusterDeleteFailedEvent capturedDeleteFailedEvent = (EnvClusterDeleteFailedEvent) baseNamedFlowEvent.getValue();
assertThat(capturedDeleteFailedEvent.getResourceName()).isEqualTo(ENV_NAME);
assertThat(capturedDeleteFailedEvent.getResourceId()).isEqualTo(ENV_ID);
assertThat(capturedDeleteFailedEvent.getResourceCrn()).isEqualTo(RESOURCE_CRN);
assertThat(capturedDeleteFailedEvent.selector()).isEqualTo("FAILED_ENV_CLUSTERS_DELETE_EVENT");
assertThat(capturedDeleteFailedEvent.getException()).isEqualTo(error);
}
use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.
the class DataHubClusterDeletionHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
LOGGER.debug("Accepting DataHubClustersDelete event");
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
try {
PollingConfig pollingConfig = getPollingConfig();
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> datahubDeletionService.deleteDatahubClustersForEnvironment(pollingConfig, environment, environmentDeletionDto.isForceDelete()));
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
}
}
use of com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent in project cloudbreak by hortonworks.
the class ExperienceDeletionHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDeletionDtoEvent) {
LOGGER.debug("Accepting XP Delete event");
EnvironmentDeletionDto environmentDeletionDto = environmentDeletionDtoEvent.getData();
EnvironmentDto envDto = environmentDeletionDtoEvent.getData().getEnvironmentDto();
try {
if (experienceDeletionEnabled) {
if (entitlementService.isExperienceDeletionEnabled(envDto.getAccountId())) {
environmentService.findEnvironmentById(envDto.getId()).ifPresent(environment -> environmentExperienceDeletionAction.execute(environment, environmentDeletionDto.isForceDelete()));
} else {
LOGGER.debug("Experience deletion is disabled by entitlement.");
}
} else {
LOGGER.debug("Experience deletion is disabled by Spring config.");
}
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
eventSender().sendEvent(envDeleteEvent, environmentDeletionDtoEvent.getHeaders());
} catch (Exception e) {
LOGGER.debug("Experience deletion failed with exception", e);
EnvClusterDeleteFailedEvent failedEvent = EnvClusterDeleteFailedEvent.builder().withEnvironmentID(envDto.getId()).withException(e).withResourceCrn(envDto.getResourceCrn()).withResourceName(envDto.getName()).build();
eventSender().sendEvent(failedEvent, environmentDeletionDtoEvent.getHeaders());
}
}
Aggregations