@Test public void testSpotParameters() { EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation(); Environment environment = new Environment(); environment.setCreateFreeIpa(true); int spotPercentage = 100; Double spotMaxPrice = 0.9; environmentDto.getFreeIpaCreation().setAws(FreeIpaCreationAwsParametersDto.builder() .withSpot(FreeIpaCreationAwsSpotParametersDto.builder() .withMaxPrice(spotMaxPrice) .withPercentage(spotPercentage) .build()) .build()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment)); when(supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())).thenReturn(true); when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(Optional.empty()); when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class)); when(freeIpaPollingService.pollWithTimeout( any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt())) .thenReturn(Pair.of(PollingResult.SUCCESS, null)); victim.accept(new Event<>(environmentDto)); ArgumentCaptor<CreateFreeIpaRequest> freeIpaRequestCaptor = ArgumentCaptor.forClass(CreateFreeIpaRequest.class); verify(freeIpaService).create(freeIpaRequestCaptor.capture()); CreateFreeIpaRequest freeIpaRequest = freeIpaRequestCaptor.getValue(); freeIpaRequest.getInstanceGroups().stream() .map(InstanceGroupRequest::getInstanceTemplate) .map(InstanceTemplateRequest::getAws) .map(AwsInstanceTemplateParameters::getSpot) .forEach(spotParameters -> { assertEquals(spotMaxPrice, spotParameters.getMaxPrice()); assertEquals(spotPercentage, spotParameters.getPercentage()); }); }
@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();  }