@Test public void shouldNotStopFreeipaGivenEnvironmentWithParent() { EnvironmentDto environmentDto = createEnvironmentDto(); environmentDto.setParentEnvironmentCrn("crn:parent"); Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto); underTest.accept(environmentDtoEvent); verify(freeIpaPollerService, times(0)).stopAttachedFreeipaInstances(any(), any()); verifyEnvStopEvent(environmentDtoEvent); }
@Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStoppable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); } EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent() .withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } }
StopFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStoppable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); } EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent() .withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } }
StopFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStoppable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); } EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent() .withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  StopFreeIpaHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); }
StopFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStoppable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); } EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent() .withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  StopFreeIpaHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); @Override String selector(); @Override void accept(Event<EnvironmentDto> environmentDtoEvent); }
StopFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStoppable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); } EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent() .withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  StopFreeIpaHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); @Override String selector(); @Override void accept(Event<EnvironmentDto> environmentDtoEvent);  }