@Test public void testBuildInstanceTemplateWithAttributes() throws Exception { Template template = new Template(); template.setVolumeTemplates(Sets.newHashSet()); template.setAttributes(new Json(Map.of("someAttr", "value"))); template.setSecretAttributes(new Json(Map.of("otherAttr", "value")).getValue()); InstanceTemplate instanceTemplate = underTest.buildInstanceTemplate( template, "name", 0L, InstanceStatus.CREATE_REQUESTED, "instanceImageId"); assertNotNull(instanceTemplate.getParameters()); assertEquals("value", instanceTemplate.getParameters().get("someAttr")); assertEquals("value", instanceTemplate.getParameters().get("otherAttr")); }
InstanceTemplate buildInstanceTemplate(Template template, String name, Long privateId, InstanceStatus status, String instanceImageId) { Json attributesJson = template.getAttributes(); Map<String, Object> attributes = Optional.ofNullable(attributesJson).map(Json::getMap).orElseGet(HashMap::new); Json fromVault = template.getSecretAttributes() == null ? null : new Json(template.getSecretAttributes()); Map<String, Object> secretAttributes = Optional.ofNullable(fromVault).map(Json::getMap).orElseGet(HashMap::new); Map<String, Object> fields = new HashMap<>(); fields.putAll(attributes); fields.putAll(secretAttributes); List<Volume> volumes = new ArrayList<>(); template.getVolumeTemplates().stream().forEach(volumeModel -> { for (int i = 0; i < volumeModel.getVolumeCount(); i++) { Volume volume = new Volume(VolumeUtils.VOLUME_PREFIX + (i + 1), volumeModel.getVolumeType(), volumeModel.getVolumeSize()); volumes.add(volume); } }); return new InstanceTemplate(template.getInstanceType(), name, privateId, volumes, status, fields, template.getId(), instanceImageId); }
StackToCloudStackConverter { InstanceTemplate buildInstanceTemplate(Template template, String name, Long privateId, InstanceStatus status, String instanceImageId) { Json attributesJson = template.getAttributes(); Map<String, Object> attributes = Optional.ofNullable(attributesJson).map(Json::getMap).orElseGet(HashMap::new); Json fromVault = template.getSecretAttributes() == null ? null : new Json(template.getSecretAttributes()); Map<String, Object> secretAttributes = Optional.ofNullable(fromVault).map(Json::getMap).orElseGet(HashMap::new); Map<String, Object> fields = new HashMap<>(); fields.putAll(attributes); fields.putAll(secretAttributes); List<Volume> volumes = new ArrayList<>(); template.getVolumeTemplates().stream().forEach(volumeModel -> { for (int i = 0; i < volumeModel.getVolumeCount(); i++) { Volume volume = new Volume(VolumeUtils.VOLUME_PREFIX + (i + 1), volumeModel.getVolumeType(), volumeModel.getVolumeSize()); volumes.add(volume); } }); return new InstanceTemplate(template.getInstanceType(), name, privateId, volumes, status, fields, template.getId(), instanceImageId); } }
StackToCloudStackConverter { InstanceTemplate buildInstanceTemplate(Template template, String name, Long privateId, InstanceStatus status, String instanceImageId) { Json attributesJson = template.getAttributes(); Map<String, Object> attributes = Optional.ofNullable(attributesJson).map(Json::getMap).orElseGet(HashMap::new); Json fromVault = template.getSecretAttributes() == null ? null : new Json(template.getSecretAttributes()); Map<String, Object> secretAttributes = Optional.ofNullable(fromVault).map(Json::getMap).orElseGet(HashMap::new); Map<String, Object> fields = new HashMap<>(); fields.putAll(attributes); fields.putAll(secretAttributes); List<Volume> volumes = new ArrayList<>(); template.getVolumeTemplates().stream().forEach(volumeModel -> { for (int i = 0; i < volumeModel.getVolumeCount(); i++) { Volume volume = new Volume(VolumeUtils.VOLUME_PREFIX + (i + 1), volumeModel.getVolumeType(), volumeModel.getVolumeSize()); volumes.add(volume); } }); return new InstanceTemplate(template.getInstanceType(), name, privateId, volumes, status, fields, template.getId(), instanceImageId); }  }
StackToCloudStackConverter { InstanceTemplate buildInstanceTemplate(Template template, String name, Long privateId, InstanceStatus status, String instanceImageId) { Json attributesJson = template.getAttributes(); Map<String, Object> attributes = Optional.ofNullable(attributesJson).map(Json::getMap).orElseGet(HashMap::new); Json fromVault = template.getSecretAttributes() == null ? null : new Json(template.getSecretAttributes()); Map<String, Object> secretAttributes = Optional.ofNullable(fromVault).map(Json::getMap).orElseGet(HashMap::new); Map<String, Object> fields = new HashMap<>(); fields.putAll(attributes); fields.putAll(secretAttributes); List<Volume> volumes = new ArrayList<>(); template.getVolumeTemplates().stream().forEach(volumeModel -> { for (int i = 0; i < volumeModel.getVolumeCount(); i++) { Volume volume = new Volume(VolumeUtils.VOLUME_PREFIX + (i + 1), volumeModel.getVolumeType(), volumeModel.getVolumeSize()); volumes.add(volume); } }); return new InstanceTemplate(template.getInstanceType(), name, privateId, volumes, status, fields, template.getId(), instanceImageId); }  CloudStack convert(Stack stack); CloudStack convertForDownscale(Stack stack, Set<String> deleteRequestedInstances); CloudStack convertForTermination(Stack stack, String instanceId); CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances); List<CloudInstance> buildInstances(Stack stack); CloudInstance buildInstance(InstanceMetaData instanceMetaData, InstanceGroup instanceGroup,
            StackAuthentication stackAuthentication, Long privateId, InstanceStatus status); Map<String, Object> buildCloudInstanceParameters(String environmentCrn, InstanceMetaData instanceMetaData, CloudPlatform platform); }
StackToCloudStackConverter { InstanceTemplate buildInstanceTemplate(Template template, String name, Long privateId, InstanceStatus status, String instanceImageId) { Json attributesJson = template.getAttributes(); Map<String, Object> attributes = Optional.ofNullable(attributesJson).map(Json::getMap).orElseGet(HashMap::new); Json fromVault = template.getSecretAttributes() == null ? null : new Json(template.getSecretAttributes()); Map<String, Object> secretAttributes = Optional.ofNullable(fromVault).map(Json::getMap).orElseGet(HashMap::new); Map<String, Object> fields = new HashMap<>(); fields.putAll(attributes); fields.putAll(secretAttributes); List<Volume> volumes = new ArrayList<>(); template.getVolumeTemplates().stream().forEach(volumeModel -> { for (int i = 0; i < volumeModel.getVolumeCount(); i++) { Volume volume = new Volume(VolumeUtils.VOLUME_PREFIX + (i + 1), volumeModel.getVolumeType(), volumeModel.getVolumeSize()); volumes.add(volume); } }); return new InstanceTemplate(template.getInstanceType(), name, privateId, volumes, status, fields, template.getId(), instanceImageId); }  CloudStack convert(Stack stack); CloudStack convertForDownscale(Stack stack, Set<String> deleteRequestedInstances); CloudStack convertForTermination(Stack stack, String instanceId); CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances); List<CloudInstance> buildInstances(Stack stack); CloudInstance buildInstance(InstanceMetaData instanceMetaData, InstanceGroup instanceGroup,
            StackAuthentication stackAuthentication, Long privateId, InstanceStatus status); Map<String, Object> buildCloudInstanceParameters(String environmentCrn, InstanceMetaData instanceMetaData, CloudPlatform platform);  }