diff options
author | KrupaNagabhushan <krupa.nagabhushan@est.tech> | 2021-10-15 14:52:43 +0100 |
---|---|---|
committer | Krupa Nagabhushan <krupa.nagabhushan@est.tech> | 2021-11-17 14:47:04 +0000 |
commit | 86671624c83f8d6af7523d1527858e9f93b35f11 (patch) | |
tree | 88dc11e51c1ec3acf0de8becf271207af66cd3cf /catalog-be | |
parent | ddd1badb175e660c8a52120443abd57a9a3a7aa6 (diff) |
Update service import to import self properties
Issue-ID: SDC-3764
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: I6d6c3a40484b0a5df2611c036740ad9965e6a73d
Diffstat (limited to 'catalog-be')
7 files changed, 80 insertions, 9 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java index a85b5542a0..1d37efef28 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java @@ -164,7 +164,23 @@ public class CsarBusinessLogic extends BaseBusinessLogic { CsarInfo csarInfo, String nodeName, Component component) { return yamlHandler .parseResourceInfoFromYAML(yamlName, topologyTemplateYaml, csarInfo.getCreatedNodesToscaResourceNames(), nodeTypesInfo, nodeName, - component); + component, getInterfaceTemplateYaml(csarInfo).orElse("")); + } + + private Optional<String> getInterfaceTemplateYaml(CsarInfo csarInfo) { + String[] yamlFile; + String interfaceTemplateYaml = ""; + if (csarInfo.getMainTemplateName().contains(".yml")) { + yamlFile = csarInfo.getMainTemplateName().split(".yml"); + interfaceTemplateYaml = yamlFile[0] + "-interface.yml"; + } else if (csarInfo.getMainTemplateName().contains(".yaml")) { + yamlFile = csarInfo.getMainTemplateName().split(".yaml"); + interfaceTemplateYaml = yamlFile[0] + "-interface.yaml"; + } + if (csarInfo.getCsar().containsKey(interfaceTemplateYaml)) { + return Optional.of(new String(csarInfo.getCsar().get(interfaceTemplateYaml))); + } + return Optional.empty(); } private String logAndThrowComponentException(ResponseFormat responseFormat, String logMessage, String... params) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 51794a3350..cb3057b49a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -62,10 +62,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -92,6 +92,7 @@ import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.UploadArtifactInfo; import org.openecomp.sdc.be.model.UploadCapInfo; @@ -130,7 +131,7 @@ public class YamlTemplateParsingHandler { public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames, Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName, - org.openecomp.sdc.be.model.Component component) { + org.openecomp.sdc.be.model.Component component, String interfaceTemplateYaml) { log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName); Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName); ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); @@ -142,6 +143,9 @@ public class YamlTemplateParsingHandler { parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate, component.getModel())); } if (getSubstitutionMappings(mappedToscaTemplate) != null) { + if (component.isService() && !interfaceTemplateYaml.isEmpty()) { + parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml))); + } parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) getSubstitutionMappings(mappedToscaTemplate).get(NODE_TYPE.getElementName())); } log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName); @@ -181,6 +185,10 @@ public class YamlTemplateParsingHandler { return inputs; } + private Map<String, PropertyDefinition> getProperties(Map<String, Object> toscaJson) { + return ImportUtils.getProperties(toscaJson).left().on(err -> new HashMap<>()); + } + private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson, String model) { Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES).left().on(err -> logPoliciesNotFound(fileName)); if (MapUtils.isNotEmpty(foundPolicies)) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index 8a855e0031..d3e7085e4f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -291,6 +291,16 @@ public class ServiceImportBusinessLogic { log.debug("name is locked {} status = {}", service.getSystemName(), lockResult); } try { + log.trace("************* Adding properties to service from interface yaml {}", yamlName); + Map<String, PropertyDefinition> properties = parsedToscaYamlInfo.getProperties(); + if (properties != null && !properties.isEmpty()) { + final List<PropertyDefinition> propertiesList = new ArrayList<>(); + properties.forEach((propertyName, propertyDefinition) -> { + propertyDefinition.setName(propertyName); + propertiesList.add(propertyDefinition); + }); + service.setProperties(propertiesList); + } log.trace("************* createResourceFromYaml before full create resource {}", yamlName); service = serviceImportParseLogic.createServiceTransaction(service, csarInfo.getModifier(), isNormative); log.trace("************* Going to add inputs from yaml {}", yamlName); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index 0453dc7fef..334bffd342 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -1475,7 +1475,7 @@ public class ResourceBusinessLogicTest { String resourceYml = new String(csar.get("Definitions/my_vnf.yaml")); YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null); - final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse); + final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse, ""); when(propertyOperation.getDataTypeByName("tosca.datatypes.testDataType.FromMainTemplate", "testModel")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); @@ -1510,7 +1510,7 @@ public class ResourceBusinessLogicTest { vduCp.getProperties().add(roleProp); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel("tosca.nodes.nfv.VduCp", "testModel_myVnf1.0")).thenReturn(Either.left(vduCp)); - when(yamlTemplateParsingHandler.parseResourceInfoFromYAML(any(), any(), any(), any(), any(), any())).thenReturn(parsedToscaYamlInfo); + when(yamlTemplateParsingHandler.parseResourceInfoFromYAML(any(), any(), any(), any(), any(), any(), any())).thenReturn(parsedToscaYamlInfo); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setType("myType"); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java index 6fcdd1373c..ee52431a4f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java @@ -208,7 +208,6 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Service oldService = createServiceObject(true); Resource resource = createOldResource(); String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml"); - ; String yamlName = "group.yml"; CsarInfo csarInfo = getCsarInfo(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java index 65ad5fc1a6..5f85b5134a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java @@ -47,6 +47,7 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.UploadArtifactInfo; import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; import org.openecomp.sdc.be.model.User; @@ -65,7 +66,9 @@ import java.util.stream.Collectors; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -149,18 +152,37 @@ public class YamlTemplateParsingHandlerTest { Resource resource = new Resource(); ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), - csarInfo.extractTypesInfo(), NODE_NAME, resource); + csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get()); validateParsedYaml(parsedYaml, NESTED_GROUP_NAME, Lists.newArrayList("heat_file", "description")); } @Test + public void parseServicePropertiesInfoFromYamlTest() { + String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME)); + CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME, + MAIN_TEMPLATE_NAME, main_template_content, true); + + Service service = new Service(); + ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), + csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get()); + + assertThat(parsedYaml.getProperties()).isNotNull(); + assertEquals(5, parsedYaml.getProperties().size()); + assertTrue(parsedYaml.getProperties().containsKey("skip_post_instantiation_configuration")); + assertTrue(parsedYaml.getProperties().containsKey("controller_actor")); + assertTrue(parsedYaml.getProperties().containsKey("cds_model_version")); + assertTrue(parsedYaml.getProperties().containsKey("cds_model_name")); + assertTrue(parsedYaml.getProperties().containsKey("default_software_version")); + } + + @Test public void parseResourceInfoFromYAMLTest() { Resource resource = new Resource(); ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), - new HashMap<>(), "", resource); + new HashMap<>(), "", resource, null); validateParsedYamlWithCapability(parsedYaml); } @@ -234,7 +256,7 @@ public class YamlTemplateParsingHandlerTest { public void parseResourceWithPoliciesDefined() { Resource resource = new Resource(); ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), - new HashMap<>(), "", resource); + new HashMap<>(), "", resource, ""); validateParsedYamlWithPolicies(parsedYaml); } @@ -393,4 +415,20 @@ public class YamlTemplateParsingHandlerTest { } return policyTypeDefinition; } + + private Optional<String> getInterfaceTemplateYaml(CsarInfo csarInfo) { + String[] yamlFile; + String interfaceTemplateYaml = ""; + if (csarInfo.getMainTemplateName().contains(".yml")) { + yamlFile = csarInfo.getMainTemplateName().split(".yml"); + interfaceTemplateYaml = yamlFile[0] + "-interface.yml"; + } else if (csarInfo.getMainTemplateName().contains(".yaml")) { + yamlFile = csarInfo.getMainTemplateName().split(".yaml"); + interfaceTemplateYaml = yamlFile[0] + "-interface.yaml"; + } + if (csarInfo.getCsar().containsKey(interfaceTemplateYaml)) { + return Optional.of(new String(csarInfo.getCsar().get(interfaceTemplateYaml))); + } + return Optional.empty(); + } } diff --git a/catalog-be/src/test/resources/csars/with_groups.csar b/catalog-be/src/test/resources/csars/with_groups.csar Binary files differindex 9259a81de0..49b5a440ea 100644 --- a/catalog-be/src/test/resources/csars/with_groups.csar +++ b/catalog-be/src/test/resources/csars/with_groups.csar |