@Test public void testConvert() { initMocks(); ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2"); StackV4Request request = getRequest("stack.json"); given(credentialClientService.getByCrn(anyString())).willReturn(credential); given(credentialClientService.getByName(anyString())).willReturn(credential); given(providerParameterCalculator.get(request)).willReturn(getMappable()); given(conversionService.convert(any(ClusterV4Request.class), eq(Cluster.class))).willReturn(new Cluster()); given(telemetryConverter.convert(null, StackType.WORKLOAD)).willReturn(new Telemetry()); Stack stack = underTest.convert(request); assertAllFieldsNotNull( stack, Arrays.asList("description", "cluster", "environmentCrn", "gatewayPort", "useCcm", "network", "securityConfig", "version", "created", "platformVariant", "cloudPlatform", "customHostname", "customDomain", "clusterNameAsSubdomain", "hostgroupNameAsHostname", "parameters", "creator", "environmentCrn", "terminated", "datalakeResourceId", "type", "inputs", "failurePolicy", "resourceCrn", "minaSshdServiceId", "externalDatabaseCreationType")); assertEquals("eu-west-1", stack.getRegion()); assertEquals("AWS", stack.getCloudPlatform()); assertEquals("mystack", stack.getName()); verify(telemetryConverter, times(1)).convert(null, StackType.WORKLOAD); verify(environmentClientService, times(1)).getByCrn(anyString()); verify(gatewaySecurityGroupDecorator, times(1)) .extendGatewaySecurityGroupWithDefaultGatewayCidrs(any(Stack.class), any(Tunnel.class)); }
@Override public Stack convert(StackV4Request source) { Workspace workspace = workspaceService.getForCurrentUser(); Stack stack = new Stack(); stack.setEnvironmentCrn(source.getEnvironmentCrn()); DetailedEnvironmentResponse environment = null; if (!Strings.isNullOrEmpty(source.getEnvironmentCrn())) { environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName()); } if (isTemplate(source)) { updateCustomDomainOrKerberos(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); convertAsStackTemplate(source, stack, environment); setNetworkAsTemplate(source, stack); } else { convertAsStack(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); setNetworkIfApplicable(source, stack, environment); stack.getComponents().add(getTelemetryComponent(stack, source)); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); stack.setParameters(parameter); } setTimeToLive(source, stack); stack.setWorkspace(workspace); stack.setDisplayName(source.getName()); stack.setDatalakeResourceId(getDatalakeResourceId(source, workspace)); stack.setStackAuthentication(getConversionService().convert(source.getAuthentication(), StackAuthentication.class)); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED)); stack.setCreated(clock.getCurrentTimeMillis()); stack.setInstanceGroups(convertInstanceGroups(source, stack)); measure(() -> updateCluster(source, stack, workspace), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName()); stack.setGatewayPort(source.getGatewayPort()); stack.setUuid(UUID.randomUUID().toString()); stack.setType(source.getType()); stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>()))); if (source.getImage() != null) { stack.getComponents().add(getImageComponent(source, stack)); } if (!isTemplate(source)) { gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel()); } stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType)); determineServiceTypeTag(stack, source.getTags()); determineServiceFeatureTag(stack, source.getTags()); return stack; }
StackV4RequestToStackConverter extends AbstractConversionServiceAwareConverter<StackV4Request, Stack> { @Override public Stack convert(StackV4Request source) { Workspace workspace = workspaceService.getForCurrentUser(); Stack stack = new Stack(); stack.setEnvironmentCrn(source.getEnvironmentCrn()); DetailedEnvironmentResponse environment = null; if (!Strings.isNullOrEmpty(source.getEnvironmentCrn())) { environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName()); } if (isTemplate(source)) { updateCustomDomainOrKerberos(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); convertAsStackTemplate(source, stack, environment); setNetworkAsTemplate(source, stack); } else { convertAsStack(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); setNetworkIfApplicable(source, stack, environment); stack.getComponents().add(getTelemetryComponent(stack, source)); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); stack.setParameters(parameter); } setTimeToLive(source, stack); stack.setWorkspace(workspace); stack.setDisplayName(source.getName()); stack.setDatalakeResourceId(getDatalakeResourceId(source, workspace)); stack.setStackAuthentication(getConversionService().convert(source.getAuthentication(), StackAuthentication.class)); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED)); stack.setCreated(clock.getCurrentTimeMillis()); stack.setInstanceGroups(convertInstanceGroups(source, stack)); measure(() -> updateCluster(source, stack, workspace), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName()); stack.setGatewayPort(source.getGatewayPort()); stack.setUuid(UUID.randomUUID().toString()); stack.setType(source.getType()); stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>()))); if (source.getImage() != null) { stack.getComponents().add(getImageComponent(source, stack)); } if (!isTemplate(source)) { gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel()); } stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType)); determineServiceTypeTag(stack, source.getTags()); determineServiceFeatureTag(stack, source.getTags()); return stack; } }
StackV4RequestToStackConverter extends AbstractConversionServiceAwareConverter<StackV4Request, Stack> { @Override public Stack convert(StackV4Request source) { Workspace workspace = workspaceService.getForCurrentUser(); Stack stack = new Stack(); stack.setEnvironmentCrn(source.getEnvironmentCrn()); DetailedEnvironmentResponse environment = null; if (!Strings.isNullOrEmpty(source.getEnvironmentCrn())) { environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName()); } if (isTemplate(source)) { updateCustomDomainOrKerberos(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); convertAsStackTemplate(source, stack, environment); setNetworkAsTemplate(source, stack); } else { convertAsStack(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); setNetworkIfApplicable(source, stack, environment); stack.getComponents().add(getTelemetryComponent(stack, source)); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); stack.setParameters(parameter); } setTimeToLive(source, stack); stack.setWorkspace(workspace); stack.setDisplayName(source.getName()); stack.setDatalakeResourceId(getDatalakeResourceId(source, workspace)); stack.setStackAuthentication(getConversionService().convert(source.getAuthentication(), StackAuthentication.class)); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED)); stack.setCreated(clock.getCurrentTimeMillis()); stack.setInstanceGroups(convertInstanceGroups(source, stack)); measure(() -> updateCluster(source, stack, workspace), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName()); stack.setGatewayPort(source.getGatewayPort()); stack.setUuid(UUID.randomUUID().toString()); stack.setType(source.getType()); stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>()))); if (source.getImage() != null) { stack.getComponents().add(getImageComponent(source, stack)); } if (!isTemplate(source)) { gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel()); } stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType)); determineServiceTypeTag(stack, source.getTags()); determineServiceFeatureTag(stack, source.getTags()); return stack; }  }
StackV4RequestToStackConverter extends AbstractConversionServiceAwareConverter<StackV4Request, Stack> { @Override public Stack convert(StackV4Request source) { Workspace workspace = workspaceService.getForCurrentUser(); Stack stack = new Stack(); stack.setEnvironmentCrn(source.getEnvironmentCrn()); DetailedEnvironmentResponse environment = null; if (!Strings.isNullOrEmpty(source.getEnvironmentCrn())) { environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName()); } if (isTemplate(source)) { updateCustomDomainOrKerberos(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); convertAsStackTemplate(source, stack, environment); setNetworkAsTemplate(source, stack); } else { convertAsStack(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); setNetworkIfApplicable(source, stack, environment); stack.getComponents().add(getTelemetryComponent(stack, source)); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); stack.setParameters(parameter); } setTimeToLive(source, stack); stack.setWorkspace(workspace); stack.setDisplayName(source.getName()); stack.setDatalakeResourceId(getDatalakeResourceId(source, workspace)); stack.setStackAuthentication(getConversionService().convert(source.getAuthentication(), StackAuthentication.class)); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED)); stack.setCreated(clock.getCurrentTimeMillis()); stack.setInstanceGroups(convertInstanceGroups(source, stack)); measure(() -> updateCluster(source, stack, workspace), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName()); stack.setGatewayPort(source.getGatewayPort()); stack.setUuid(UUID.randomUUID().toString()); stack.setType(source.getType()); stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>()))); if (source.getImage() != null) { stack.getComponents().add(getImageComponent(source, stack)); } if (!isTemplate(source)) { gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel()); } stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType)); determineServiceTypeTag(stack, source.getTags()); determineServiceFeatureTag(stack, source.getTags()); return stack; }  @Override Stack convert(StackV4Request source); }
StackV4RequestToStackConverter extends AbstractConversionServiceAwareConverter<StackV4Request, Stack> { @Override public Stack convert(StackV4Request source) { Workspace workspace = workspaceService.getForCurrentUser(); Stack stack = new Stack(); stack.setEnvironmentCrn(source.getEnvironmentCrn()); DetailedEnvironmentResponse environment = null; if (!Strings.isNullOrEmpty(source.getEnvironmentCrn())) { environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName()); } if (isTemplate(source)) { updateCustomDomainOrKerberos(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); convertAsStackTemplate(source, stack, environment); setNetworkAsTemplate(source, stack); } else { convertAsStack(source, stack); updateCloudPlatformAndRelatedFields(source, stack, environment); setNetworkIfApplicable(source, stack, environment); stack.getComponents().add(getTelemetryComponent(stack, source)); } Map<String, Object> asMap = providerParameterCalculator.get(source).asMap(); if (asMap != null) { Map<String, String> parameter = new HashMap<>(); asMap.forEach((key, value) -> parameter.put(key, value.toString())); stack.setParameters(parameter); } setTimeToLive(source, stack); stack.setWorkspace(workspace); stack.setDisplayName(source.getName()); stack.setDatalakeResourceId(getDatalakeResourceId(source, workspace)); stack.setStackAuthentication(getConversionService().convert(source.getAuthentication(), StackAuthentication.class)); stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED)); stack.setCreated(clock.getCurrentTimeMillis()); stack.setInstanceGroups(convertInstanceGroups(source, stack)); measure(() -> updateCluster(source, stack, workspace), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName()); stack.setGatewayPort(source.getGatewayPort()); stack.setUuid(UUID.randomUUID().toString()); stack.setType(source.getType()); stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>()))); if (source.getImage() != null) { stack.getComponents().add(getImageComponent(source, stack)); } if (!isTemplate(source)) { gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel()); } stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType)); determineServiceTypeTag(stack, source.getTags()); determineServiceFeatureTag(stack, source.getTags()); return stack; }  @Override Stack convert(StackV4Request source);  }