@Test void acceptTestEnvironmentAndIdbmmsAndSuccess() { when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(IdBrokerMappingSource.IDBMMS))); underTest.accept(environmentDtoEvent); verify(idbmmsClient).deleteMappings(INTERNAL_ACTOR_CRN, ENVIRONMENT_CRN, Optional.empty()); verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture()); verifyEnvDeleteEvent(); }
@Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentDto.getResourceCrn()) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(START_S3GUARD_TABLE_DELETE_EVENT.selector()) .build(); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { String environmentCrn = environment.getResourceCrn(); if (environment.getExperimentalFeaturesJson().getIdBrokerMappingSource() == IdBrokerMappingSource.IDBMMS) { LOGGER.info("Deleting IDBroker mappings in IDBMMS associated with environment {}.", environmentCrn); deleteIdBrokerMappings(environmentCrn); } else { LOGGER.info("IDBMMS usage is disabled for environment {}. No need to delete IDBroker mappings.", environmentCrn); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } }
IdBrokerMappingsDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentDto.getResourceCrn()) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(START_S3GUARD_TABLE_DELETE_EVENT.selector()) .build(); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { String environmentCrn = environment.getResourceCrn(); if (environment.getExperimentalFeaturesJson().getIdBrokerMappingSource() == IdBrokerMappingSource.IDBMMS) { LOGGER.info("Deleting IDBroker mappings in IDBMMS associated with environment {}.", environmentCrn); deleteIdBrokerMappings(environmentCrn); } else { LOGGER.info("IDBMMS usage is disabled for environment {}. No need to delete IDBroker mappings.", environmentCrn); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } }
IdBrokerMappingsDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentDto.getResourceCrn()) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(START_S3GUARD_TABLE_DELETE_EVENT.selector()) .build(); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { String environmentCrn = environment.getResourceCrn(); if (environment.getExperimentalFeaturesJson().getIdBrokerMappingSource() == IdBrokerMappingSource.IDBMMS) { LOGGER.info("Deleting IDBroker mappings in IDBMMS associated with environment {}.", environmentCrn); deleteIdBrokerMappings(environmentCrn); } else { LOGGER.info("IDBMMS usage is disabled for environment {}. No need to delete IDBroker mappings.", environmentCrn); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } protected  IdBrokerMappingsDeleteHandler(EventSender eventSender, EnvironmentService environmentService, GrpcIdbmmsClient idbmmsClient); }
IdBrokerMappingsDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentDto.getResourceCrn()) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(START_S3GUARD_TABLE_DELETE_EVENT.selector()) .build(); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { String environmentCrn = environment.getResourceCrn(); if (environment.getExperimentalFeaturesJson().getIdBrokerMappingSource() == IdBrokerMappingSource.IDBMMS) { LOGGER.info("Deleting IDBroker mappings in IDBMMS associated with environment {}.", environmentCrn); deleteIdBrokerMappings(environmentCrn); } else { LOGGER.info("IDBMMS usage is disabled for environment {}. No need to delete IDBroker mappings.", environmentCrn); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } protected  IdBrokerMappingsDeleteHandler(EventSender eventSender, EnvironmentService environmentService, GrpcIdbmmsClient idbmmsClient); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector(); }
IdBrokerMappingsDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentDto.getResourceCrn()) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(START_S3GUARD_TABLE_DELETE_EVENT.selector()) .build(); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { String environmentCrn = environment.getResourceCrn(); if (environment.getExperimentalFeaturesJson().getIdBrokerMappingSource() == IdBrokerMappingSource.IDBMMS) { LOGGER.info("Deleting IDBroker mappings in IDBMMS associated with environment {}.", environmentCrn); deleteIdBrokerMappings(environmentCrn); } else { LOGGER.info("IDBMMS usage is disabled for environment {}. No need to delete IDBroker mappings.", environmentCrn); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } protected  IdBrokerMappingsDeleteHandler(EventSender eventSender, EnvironmentService environmentService, GrpcIdbmmsClient idbmmsClient); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector();  }