summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2020-08-27 13:07:44 +0100
committerefiacor <fiachra.corcoran@est.tech>2020-08-28 10:40:51 +0100
commit237b2108d287e6dc08b8a5760febc368a54f70f1 (patch)
treec6a94bdbee1ab48d6bdc0ebe902824427f2fe229
parent926c05ce1a2f808295c9c0f2f6068feb85da2d46 (diff)
[aai-babel] Add support for sndc props parsing
Signed-off-by: efiacor <fiachra.corcoran@est.tech> Issue-ID: AAI-3121 Change-Id: I9ed925e7e95d73b30942df895d19fba0c36500f0
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java2
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java23
-rw-r--r--src/test/java/org/onap/aai/babel/testdata/CsarTest.java1
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java11
-rw-r--r--src/test/resources/compressedArtifacts/service-Testpnfsvc-csar.csarbin0 -> 89414 bytes
-rw-r--r--src/test/resources/tosca-mappings.json20
8 files changed, 82 insertions, 5 deletions
diff --git a/pom.xml b/pom.xml
index 8700c73..24ab5c6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,7 +79,7 @@
<javax.ws.rs.version>2.1</javax.ws.rs.version>
<mvn.jaxb2.version>0.13.2</mvn.jaxb2.version>
<aai-schema.group.id>org.onap.aai.schema-service</aai-schema.group.id>
- <aai-schema.version>1.7.3</aai-schema.version>
+ <aai-schema.version>1.7.6</aai-schema.version>
<aai.rest.client.version>1.2.1</aai.rest.client.version>
<sdc.distribution.client.version>1.3.0</sdc.distribution.client.version>
<xmlunit.version>1.6</xmlunit.version>
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
index 8da541f..c42518d 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
@@ -26,6 +26,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -51,17 +52,23 @@ import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.WidgetType;
import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
+import org.onap.sdc.tosca.parser.api.IEntityDetails;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
+import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Property;
import org.onap.sdc.toscaparser.api.elements.Metadata;
import org.slf4j.MDC;
public class AaiArtifactGenerator implements ArtifactGenerator {
+ private static final String SDNC_MODEL_VERSION = "sdnc_model_version";
+ private static final String SDNC_MODEL_NAME = "sdnc_model_name";
private static Logger log = LogHelper.INSTANCE;
private static final String MDC_PARAM_MODEL_INFO = "ARTIFACT_MODEL_INFO";
@@ -283,6 +290,12 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
Map<String, String> serviceMetadata = serviceVfNode.getMetaData().getAllProperties();
resourceModel.populateModelIdentificationInformation(serviceMetadata);
+ Map<String, String> pnfProps = getResourceProperties(csarHelper, SdcTypes.PNF);
+ resourceModel.populateModelIdentificationInformation(pnfProps);
+
+ Map<String, String> vfProps = getResourceProperties(csarHelper, SdcTypes.VF);
+ resourceModel.populateModelIdentificationInformation(vfProps);
+
parser.processResourceModels(resourceModel, getNonVnfChildren(serviceVfNode));
List<NodeTemplate> serviceVfList = ToscaParser.getServiceNodeTemplates(csarHelper)
@@ -300,6 +313,21 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
resources.add(resourceModel);
}
+ private Map<String, String> getResourceProperties(ISdcCsarHelper csarHelper, SdcTypes type) {
+ EntityQuery entityQuery = EntityQuery.newBuilder(type).build();
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
+ List<IEntityDetails> entityDetailsList = csarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
+ Map<String, String> props = new HashMap<>();
+ for (IEntityDetails entityDetails : entityDetailsList) {
+ Map<String, Property> properties = entityDetails.getProperties();
+ if (properties.get(SDNC_MODEL_VERSION) != null && properties.get(SDNC_MODEL_NAME) != null) {
+ props.put(SDNC_MODEL_VERSION, String.valueOf(properties.get(SDNC_MODEL_VERSION).getValue()));
+ props.put(SDNC_MODEL_NAME, String.valueOf(properties.get(SDNC_MODEL_NAME).getValue()));
+ }
+ }
+ return props;
+ }
+
/**
* Return all child Node Templates (via Substitution Mappings) that do not have a type ending VnfConfiguration.
*
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
index 5247959..50c5d5b 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
@@ -103,6 +103,8 @@ public class AaiModelGenerator {
modelVer.setModelName(model.getModelName());
modelVer.setModelVersion(model.getModelVersion());
modelVer.setModelVersionId(model.getModelNameVersionId());
+ modelVer.setSdncModelName(model.getSdncModelName());
+ modelVer.setSdncModelVersion(model.getSdncModelVersion());
modelVer.setModelElements(new ModelElements());
return modelVer;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
index 558b561..ad852af 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
@@ -85,6 +85,18 @@ public abstract class Model {
public void populate(Model model, String value) {
model.modelName = model.modelDescription = value;
}
+ },
+ SDNC_MODEL_NAME("sdnc_model_name") {
+ @Override
+ public void populate(Model model, String value) {
+ model.sdncModelName = value;
+ }
+ },
+ SDNC_MODEL_VERSION("sdnc_model_version") {
+ @Override
+ public void populate(Model model, String value) {
+ model.sdncModelVersion = value;
+ }
};
private static final Map<String, ModelIdentification> propertyToModelIdent;
@@ -118,6 +130,8 @@ public abstract class Model {
private String modelDescription;
private String instantiationType;
private String category;
+ private String sdncModelVersion;
+ private String sdncModelName;
protected Set<Resource> resources = new HashSet<>();
protected Set<Widget> widgets = new HashSet<>();
@@ -229,6 +243,15 @@ public abstract class Model {
public String getCategory() {
return category;
}
+
+ public String getSdncModelName() {
+ return sdncModelName;
+ }
+
+ public String getSdncModelVersion() {
+ return sdncModelVersion;
+ }
+
/**
* Gets widget version id.
*
diff --git a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
index 1885555..b8a86b4 100644
--- a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
+++ b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
@@ -37,6 +37,7 @@ import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
public enum CsarTest {
// @formatter:off
VNF_VENDOR_CSAR("catalog_csar.csar"),
+ PNF_VENDOR_CSAR("service-Testpnfsvc-csar.csar"),
NO_VNF_CONFIG_CSAR("noVnfConfiguration.csar"),
SD_WAN_CSAR_FILE("service-SdWanServiceTest-csar.csar"),
COS_AVPN_CSAR_FILE("service_CosAvpn_csar.csar"),
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java
index 404fb19..168f237 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java
@@ -21,10 +21,14 @@
package org.onap.aai.babel.xml.generator;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.util.Collections;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
+import org.onap.aai.babel.service.data.BabelArtifact;
import org.onap.aai.babel.testdata.CsarTest;
import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.data.Artifact;
@@ -51,5 +55,12 @@ public class TestModelGenerator {
Collections.singletonList(ymlFile));
}
+ @Test
+ public void testSdncPropsParsed() throws XmlArtifactGenerationException, IOException {
+ Artifact ymlFile = new Artifact(null, null, null, null);
+ List<BabelArtifact> babelArtifactList = new ModelGenerator().generateArtifacts(CsarTest.PNF_VENDOR_CSAR.getContent(),
+ Collections.singletonList(ymlFile));
+ assertTrue(babelArtifactList.get(1).getPayload().contains("sdnc-model-name"));
+ }
}
diff --git a/src/test/resources/compressedArtifacts/service-Testpnfsvc-csar.csar b/src/test/resources/compressedArtifacts/service-Testpnfsvc-csar.csar
new file mode 100644
index 0000000..9f563ff
--- /dev/null
+++ b/src/test/resources/compressedArtifacts/service-Testpnfsvc-csar.csar
Binary files differ
diff --git a/src/test/resources/tosca-mappings.json b/src/test/resources/tosca-mappings.json
index dfe666f..32491f6 100644
--- a/src/test/resources/tosca-mappings.json
+++ b/src/test/resources/tosca-mappings.json
@@ -121,15 +121,22 @@
"type": "CR",
"name": "cr",
"deleteFlag": true,
- "modelInvariantId": "collection-resource-invariant-id",
- "modelVersionId": "collection-resource-version-id"
+ "modelInvariantId": "collection-resource-invariant-id",
+ "modelVersionId": "collection-resource-version-id"
},
{
"type": "INSTANCE_GROUP",
"name": "instance-group",
"deleteFlag": true,
- "modelInvariantId": "instance-group-invariant-id",
- "modelVersionId": "instance-group-version-id"
+ "modelInvariantId": "instance-group-invariant-id",
+ "modelVersionId": "instance-group-version-id"
+ },
+ {
+ "type": "PNF",
+ "name": "pnf",
+ "deleteFlag": true,
+ "modelInvariantId": "pnf-instance-invariant-id",
+ "modelVersionId": "pnf-instance-version-id"
}
],
"widgetMappings": [
@@ -176,6 +183,11 @@
"type": "widget",
"widget": "VOLUME",
"deleteFlag": true
+ },
+ {
+ "prefix": "org.openecomp.resource.pnf",
+ "widget": "PNF",
+ "deleteFlag": true
}
]
}