@Test void accept() { Environment environment = new Environment(); when(environmentService.findEnvironmentById(ENV_ID)).thenReturn(Optional.of(environment)); underTest.accept(environmentDtoEvent); verify(sdxDeleteService).deleteSdxClustersForEnvironment(any(PollingConfig.class), eq(environment), eq(false)); verify(eventSender).sendEvent(any(EnvDeleteEvent.class), eq(headers)); verify(eventSender, never()).sendEvent(any(EnvClusterDeleteFailedEvent.class), any()); EnvDeleteEvent capturedDeleteEvent = (EnvDeleteEvent) baseNamedFlowEvent.getValue(); assertThat(capturedDeleteEvent.getResourceName()).isEqualTo(ENV_NAME); assertThat(capturedDeleteEvent.getResourceId()).isEqualTo(ENV_ID); assertThat(capturedDeleteEvent.getResourceCrn()).isEqualTo(RESOURCE_CRN); assertThat(capturedDeleteEvent.selector()).isEqualTo("FINISH_ENV_CLUSTERS_DELETE_EVENT"); }
@Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { LOGGER.debug("Accepting DataLakeClustersDelete event"); EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { PollingConfig pollingConfig = getPollingConfig(); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> sdxDeleteService.deleteSdxClustersForEnvironment( 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()); } }
DataLakeClustersDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { LOGGER.debug("Accepting DataLakeClustersDelete event"); EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { PollingConfig pollingConfig = getPollingConfig(); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> sdxDeleteService.deleteSdxClustersForEnvironment( 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()); } } }
DataLakeClustersDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { LOGGER.debug("Accepting DataLakeClustersDelete event"); EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { PollingConfig pollingConfig = getPollingConfig(); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> sdxDeleteService.deleteSdxClustersForEnvironment( 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()); } } protected  DataLakeClustersDeleteHandler(EventSender eventSender, EnvironmentService environmentService, SdxDeleteService sdxDeleteService); }
DataLakeClustersDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { LOGGER.debug("Accepting DataLakeClustersDelete event"); EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { PollingConfig pollingConfig = getPollingConfig(); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> sdxDeleteService.deleteSdxClustersForEnvironment( 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()); } } protected  DataLakeClustersDeleteHandler(EventSender eventSender, EnvironmentService environmentService, SdxDeleteService sdxDeleteService); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector(); }
DataLakeClustersDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { LOGGER.debug("Accepting DataLakeClustersDelete event"); EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { PollingConfig pollingConfig = getPollingConfig(); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> sdxDeleteService.deleteSdxClustersForEnvironment( 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()); } } protected  DataLakeClustersDeleteHandler(EventSender eventSender, EnvironmentService environmentService, SdxDeleteService sdxDeleteService); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector();  }