aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-dependency-model
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-dependency-model')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParser.java32
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java2
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java107
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java63
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java10
5 files changed, 204 insertions, 10 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParser.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParser.java
index d8a62c42d..48d1a05b6 100644
--- a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParser.java
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParser.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,6 +52,7 @@ public class DependencyModelParser {
private static final String ACTIVE_ACTIVE = "Active-Active";
private static final String ACTIVE_PASSIVE = "Active-Passive";
private static final String HIGH_AVAILABLITY = "high_availablity";
+ private static final String HIGH_AVAILABILITY = "high_availability";
private static final String MANDATORY = "mandatory";
private static final String TOPOLOGY_TEMPLATE = "topology_template";
private static final String RELATIONSHIP = "relationship";
@@ -68,7 +71,7 @@ public class DependencyModelParser {
public VnfcDependencyModel generateDependencyModel(String vnfModel, String vnfType)
throws InvalidDependencyModelException {
Set<Node<Vnfc>> dependencies = new HashSet<>();
- ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+ ObjectMapper mapper = getMapper();
boolean mandatory;
String resilienceType;
String prefix = "org.onap.resource.vfc." + vnfType + ".abstract.nodes.";
@@ -82,10 +85,10 @@ public class DependencyModelParser {
JsonNode topologyTemplateNode = root.get(TOPOLOGY_TEMPLATE);
JsonNode nodeTemplateNode = topologyTemplateNode.get("node_templates");
- Iterator<Map.Entry<String, JsonNode>> itretor = nodeTemplateNode.fields();
+ Iterator<Map.Entry<String, JsonNode>> iterator = nodeTemplateNode.fields();
for (JsonNode yamlNode : nodeTemplateNode) {
logger.debug("Processing node: " + yamlNode);
- String fullvnfcType = itretor.next().getValue().get("type").textValue();
+ String fullvnfcType = iterator.next().getValue().get("type").textValue();
String vnfcType = getQualifiedVnfcType(fullvnfcType);
String type = yamlNode.get("type").textValue();
type = type.substring(0, type.lastIndexOf('.') + 1);
@@ -95,8 +98,8 @@ public class DependencyModelParser {
mandatory = resolveMandatory(yamlNode);
String[] parentList = getDependencyArray(yamlNode, nodeTemplateNode);
Node<Vnfc> vnfcNode = getNode(dependencies, vnfcType);
-
if (vnfcNode != null) {
+ //This code appears to be unreachable
logger.debug("Dependency node already exists for vnfc Type: " + vnfcType);
if (StringUtils.isEmpty(vnfcNode.getChild().getResilienceType())) {
logger.debug("Updating resilience type, "
@@ -139,13 +142,20 @@ public class DependencyModelParser {
private String resolveResilienceType(JsonNode yamlNode) {
String resilienceType;
- if (yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY) == null ||
- yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).asText().isEmpty()) {
-
+ // If "high_availability" is present then use the correctly spelled property name
+ if (yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABILITY) != null &&
+ !yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABILITY).asText().isEmpty()) {
+ resilienceType = dependencyMap
+ .get(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABILITY).textValue());
+ }
+ // The property name "high_availability" was misspelled in the code so leaving in the code to check for the
+ // incorrectly spelled version to avoid breaking existing configurations using the misspelled version
+ else if (yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY) == null ||
+ yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).asText().isEmpty()) {
resilienceType = ACTIVE_ACTIVE;
} else {
resilienceType = dependencyMap
- .get(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).textValue());
+ .get(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).textValue());
}
return resilienceType;
}
@@ -221,7 +231,7 @@ public class DependencyModelParser {
&& internalNode.findValue(RELATIONSHIP) != null;
}
- private Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) {
+ protected Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) {
Iterator<Node<Vnfc>> itr = nodes.iterator();
Node<Vnfc> node;
while (itr.hasNext()) {
@@ -235,4 +245,8 @@ public class DependencyModelParser {
private String getVnfcType(String type) {
return type.substring(type.lastIndexOf('.') + 1, type.length());
}
+
+ protected ObjectMapper getMapper() {
+ return new ObjectMapper(new YAMLFactory());
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
index ecd3c0305..e9404dd41 100644
--- a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java
new file mode 100644
index 000000000..e7951c61d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java
@@ -0,0 +1,107 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.dependencymanager.helper;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException;
+import org.onap.appc.dg.objects.VnfcDependencyModel;
+import org.onap.appc.dg.objects.Node;
+import org.onap.appc.domainmodel.Vnfc;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class DependencyModelParserTest {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ DependencyModelParser parser = Mockito.spy(new DependencyModelParser());
+ ObjectMapper mockMapper;
+
+ @Before
+ public void setup() throws JsonProcessingException, IOException {
+ mockMapper = Mockito.mock(ObjectMapper.class);
+ ObjectNode mockNode = Mockito.mock(ObjectNode.class);
+ Mockito.doReturn(mockMapper).when(parser).getMapper();
+ Mockito.doReturn(mockNode).when(mockMapper).readTree("VNF_MODEL");
+ }
+
+ @Test
+ public void testGenerateDependencyModel() throws InvalidDependencyModelException, JsonProcessingException, IOException {
+ ObjectNode topologyTemplate = new ObjectNode(JsonNodeFactory.instance);
+ topologyTemplate = (ObjectNode) new ObjectMapper().readTree(jsonString);
+ Mockito.doReturn(topologyTemplate).when(mockMapper).readTree("VNF_MODEL");
+ VnfcDependencyModel model = parser.generateDependencyModel("VNF_MODEL", "VNF_TYPE");
+ Assert.assertEquals(2, model.getDependencies().size());
+ }
+
+ @Test
+ public void testGenerateDependencyModelWithNode() throws InvalidDependencyModelException, JsonProcessingException, IOException {
+ ObjectNode topologyTemplate = new ObjectNode(JsonNodeFactory.instance);
+ topologyTemplate = (ObjectNode) new ObjectMapper().readTree(jsonString);
+ Node<Vnfc> vnfc = new Node(new Vnfc());
+ Mockito.doReturn(vnfc).when(parser).getNode(Mockito.anySet(), Mockito.anyString());
+ Mockito.doReturn(topologyTemplate).when(mockMapper).readTree("VNF_MODEL");
+ VnfcDependencyModel model = parser.generateDependencyModel("VNF_MODEL", "VNF_TYPE");
+ Assert.assertEquals(0, model.getDependencies().size());
+ }
+
+ @Test
+ public void testGenerateDependencyModelExceptionFlow() throws InvalidDependencyModelException {
+ expectedEx.expect(InvalidDependencyModelException.class);
+ expectedEx.expectMessage("Dependency model is missing 'topology_template' or 'node_templates' elements");
+ VnfcDependencyModel model = parser.generateDependencyModel("VNF_MODEL", "VNF_TYPE");
+ }
+
+ private String jsonString = "{\"topology_template\": {" +
+ " \"node_templates\": {" +
+ " \"Property Definition_Template\": {" +
+ " \"type\": \"org.onap.resource.vfc.vnf_type.abstract.nodes.property definition\"," +
+ " \"properties\": {" +
+ " \"mandatory\": \"true\"," +
+ " \"high_availablity\": \"Active-Passive\"" +
+ " },\"requirements\": [" +
+ " {" +
+ " \"dependency\": {" +
+ " \"capability\": \"tosca.capabilities.Node\"," +
+ " \"node\": \"tosca.nodes.Root\"," +
+ " \"relationship\": \"tosca.relationships.DependsOn\"," +
+ " \"occurrences\": [" +
+ " 0," +
+ " \"UNBOUNDED\"" +
+ " ]" +
+ " }" +
+ " }" +
+ " ]" +
+ " },\"tosca.nodes.Root\": {\"type\": \"VNFC_NAME\"}" +
+ " }" +
+ " }" +
+ "}";
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java
new file mode 100644
index 000000000..e0214b1d5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.dependencymanager.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.cache.MetadataCache;
+import org.onap.appc.cache.impl.MetadataCacheFactory;
+import org.onap.appc.cache.impl.MetadataCacheImpl;
+import org.onap.appc.dg.dependencymanager.DependencyManager;
+import org.onap.appc.dg.objects.DependencyTypes;
+import org.onap.appc.dg.objects.VnfcDependencyModel;
+import org.onap.appc.metadata.objects.DependencyModelIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(MetadataCacheFactory.class)
+public class DependencyManagerImplTest {
+
+ private MetadataCacheFactory metadataCacheFactory = Mockito.mock(MetadataCacheFactory.class);
+ private MetadataCache<DependencyModelIdentifier,VnfcDependencyModel> cache;
+
+ @Before
+ public void setup() {
+ PowerMockito.mockStatic(MetadataCacheFactory.class);
+ PowerMockito.when(MetadataCacheFactory.getInstance()).thenReturn(metadataCacheFactory);
+ cache = (MetadataCacheImpl<DependencyModelIdentifier,VnfcDependencyModel>) Mockito.mock(MetadataCacheImpl.class);
+ PowerMockito.when(metadataCacheFactory.getMetadataCache()).thenReturn(cache);
+ }
+
+ @Test
+ public void testDependencyManager() throws Exception {
+ DependencyManager dmImpl = DependencyModelFactory.createDependencyManager();
+ DependencyModelIdentifier modelIdentifier = new DependencyModelIdentifier("VNF_TYPE", "CATALOG_VERSION");
+ DependencyTypes dependencyType = DependencyTypes.findByString("resource");
+ Mockito.when(cache.getObject(Mockito.any(DependencyModelIdentifier.class))).thenReturn(new VnfcDependencyModel(null));
+ dmImpl.getVnfcDependencyModel(modelIdentifier, dependencyType);
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java
index 7b5800698..383417a1f 100644
--- a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +25,7 @@
package org.onap.appc.dg.flowbuilder;
+import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import org.onap.appc.dg.flowbuilder.FlowBuilder;
@@ -82,6 +85,8 @@ public class TestFlowBuilder {
list = itr.next();
Assert.assertTrue(list.contains(createVnfc("SMP","Active-Passive","SMP_Name")));
+
+ Assert.assertThat(flowModel.toString(), CoreMatchers.containsString("Flow Model : Vnfc : vnfcType = FE"));
}
@Test
@@ -140,7 +145,7 @@ public class TestFlowBuilder {
@Test(expected = InvalidDependencyModelException.class)
public void testCyclicBuilder() throws InvalidDependencyModelException {
- FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.findByString("FORWARD"));
VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
InventoryModel inventoryModel = readInventoryModel();
builder.buildFlowModel(dependencyModel,inventoryModel);
@@ -164,6 +169,9 @@ public class TestFlowBuilder {
Node bNode = new Node(b);
Node cNode = new Node(c);
+ Assert.assertTrue(aNode.equals(aNode));
+ Assert.assertFalse(aNode.equals(bNode));
+
bNode.addParent(c);
cNode.addParent(b);