@Test public void shouldNotAttachInCaseOfMissingFreeIpa() throws Exception { EnvironmentDto environmentDto = aYarnEnvironmentDtoWithParentEnvironment(); Environment environment = anEnvironmentWithParent(); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment)); when(freeIpaService.describe(PARENT_ENVIRONMENT_CRN)).thenReturn(Optional.empty()); victim.accept(new Event<>(environmentDto)); verify(dnsV1Endpoint, never()).addDnsZoneForSubnets(any(AddDnsZoneForSubnetsRequest.class)); verify(freeIpaService, never()).attachChildEnvironment(any(AttachChildEnvironmentRequest.class)); verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Headers.class)); }
@Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); Optional<Environment> environmentOptional = environmentService.findEnvironmentById(environmentDto.getId()); try { if (environmentOptional.isPresent()) { Environment environment = environmentOptional.get(); if (Objects.nonNull(environment.getParentEnvironment())) { attachParentFreeIpa(environmentDto); } else if (environment.isCreateFreeIpa() && supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())) { createFreeIpa(environmentDtoEvent, environmentDto); } } eventSender().sendEvent(getNextStepObject(environmentDto), environmentDtoEvent.getHeaders()); } catch (Exception ex) { LOGGER.error(String.format("Error occurred during creating FreeIpa for environment %s.", environmentDto), ex); EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), ex, environmentDto.getResourceCrn()); eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent)); } }
FreeIpaCreationHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); Optional<Environment> environmentOptional = environmentService.findEnvironmentById(environmentDto.getId()); try { if (environmentOptional.isPresent()) { Environment environment = environmentOptional.get(); if (Objects.nonNull(environment.getParentEnvironment())) { attachParentFreeIpa(environmentDto); } else if (environment.isCreateFreeIpa() && supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())) { createFreeIpa(environmentDtoEvent, environmentDto); } } eventSender().sendEvent(getNextStepObject(environmentDto), environmentDtoEvent.getHeaders()); } catch (Exception ex) { LOGGER.error(String.format("Error occurred during creating FreeIpa for environment %s.", environmentDto), ex); EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), ex, environmentDto.getResourceCrn()); eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent)); } } }
FreeIpaCreationHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); Optional<Environment> environmentOptional = environmentService.findEnvironmentById(environmentDto.getId()); try { if (environmentOptional.isPresent()) { Environment environment = environmentOptional.get(); if (Objects.nonNull(environment.getParentEnvironment())) { attachParentFreeIpa(environmentDto); } else if (environment.isCreateFreeIpa() && supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())) { createFreeIpa(environmentDtoEvent, environmentDto); } } eventSender().sendEvent(getNextStepObject(environmentDto), environmentDtoEvent.getHeaders()); } catch (Exception ex) { LOGGER.error(String.format("Error occurred during creating FreeIpa for environment %s.", environmentDto), ex); EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), ex, environmentDto.getResourceCrn()); eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent)); } } FreeIpaCreationHandler(
            EventSender eventSender,
            EnvironmentService environmentService,
            FreeIpaService freeIpaService,
            DnsV1Endpoint dnsV1Endpoint,
            SupportedPlatforms supportedPlatforms,
            Map<CloudPlatform, FreeIpaNetworkProvider> freeIpaNetworkProviderMapByCloudPlatform,
            PollingService<FreeIpaPollerObject> freeIpaPollingService,
            FreeIpaServerRequestProvider freeIpaServerRequestProvider,
            TelemetryApiConverter telemetryApiConverter,
            CloudPlatformConnectors connectors,
            EventBus eventBus, @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); }
FreeIpaCreationHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); Optional<Environment> environmentOptional = environmentService.findEnvironmentById(environmentDto.getId()); try { if (environmentOptional.isPresent()) { Environment environment = environmentOptional.get(); if (Objects.nonNull(environment.getParentEnvironment())) { attachParentFreeIpa(environmentDto); } else if (environment.isCreateFreeIpa() && supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())) { createFreeIpa(environmentDtoEvent, environmentDto); } } eventSender().sendEvent(getNextStepObject(environmentDto), environmentDtoEvent.getHeaders()); } catch (Exception ex) { LOGGER.error(String.format("Error occurred during creating FreeIpa for environment %s.", environmentDto), ex); EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), ex, environmentDto.getResourceCrn()); eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent)); } } FreeIpaCreationHandler(
            EventSender eventSender,
            EnvironmentService environmentService,
            FreeIpaService freeIpaService,
            DnsV1Endpoint dnsV1Endpoint,
            SupportedPlatforms supportedPlatforms,
            Map<CloudPlatform, FreeIpaNetworkProvider> freeIpaNetworkProviderMapByCloudPlatform,
            PollingService<FreeIpaPollerObject> freeIpaPollingService,
            FreeIpaServerRequestProvider freeIpaServerRequestProvider,
            TelemetryApiConverter telemetryApiConverter,
            CloudPlatformConnectors connectors,
            EventBus eventBus, @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); @Override void accept(Event<EnvironmentDto> environmentDtoEvent); @Override String selector(); }
FreeIpaCreationHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); Optional<Environment> environmentOptional = environmentService.findEnvironmentById(environmentDto.getId()); try { if (environmentOptional.isPresent()) { Environment environment = environmentOptional.get(); if (Objects.nonNull(environment.getParentEnvironment())) { attachParentFreeIpa(environmentDto); } else if (environment.isCreateFreeIpa() && supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())) { createFreeIpa(environmentDtoEvent, environmentDto); } } eventSender().sendEvent(getNextStepObject(environmentDto), environmentDtoEvent.getHeaders()); } catch (Exception ex) { LOGGER.error(String.format("Error occurred during creating FreeIpa for environment %s.", environmentDto), ex); EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), ex, environmentDto.getResourceCrn()); eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent)); } } FreeIpaCreationHandler(
            EventSender eventSender,
            EnvironmentService environmentService,
            FreeIpaService freeIpaService,
            DnsV1Endpoint dnsV1Endpoint,
            SupportedPlatforms supportedPlatforms,
            Map<CloudPlatform, FreeIpaNetworkProvider> freeIpaNetworkProviderMapByCloudPlatform,
            PollingService<FreeIpaPollerObject> freeIpaPollingService,
            FreeIpaServerRequestProvider freeIpaServerRequestProvider,
            TelemetryApiConverter telemetryApiConverter,
            CloudPlatformConnectors connectors,
            EventBus eventBus, @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); @Override void accept(Event<EnvironmentDto> environmentDtoEvent); @Override String selector();  }