From b5fe8a69e90b950c07dc11af481eab7e9bab52c6 Mon Sep 17 00:00:00 2001 From: "Dunietz, Irwin" Date: Thu, 16 Jan 2020 15:13:14 -0500 Subject: Change code in appc dispatcher for new LCMs in R6 Also introduce some minor improvements to robustness, efficiency, & formatting. Issue-ID: APPC-1789 Signed-off-by: Dunietz, Irwin Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50 --- .../helper/DependencyModelParser.java | 69 +++++---- .../impl/DependencyManagerImpl.java | 20 +-- .../dependencymanager/impl/ResourceDependency.java | 20 +-- .../helper/DependencyModelParserTest.java | 62 ++++---- .../onap/appc/dg/flowbuilder/TestFlowBuilder.java | 170 ++++++++++----------- 5 files changed, 175 insertions(+), 166 deletions(-) (limited to 'appc-dg/appc-dg-shared/appc-dg-dependency-model') 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 48d1a05b6..4b40ba27a 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * 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========================================================= */ @@ -51,7 +50,7 @@ public class DependencyModelParser { private static final String PROPERTIES = "properties"; 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_AVAILABLITY = "high_availablity"; // Deprecated original spelling private static final String HIGH_AVAILABILITY = "high_availability"; private static final String MANDATORY = "mandatory"; private static final String TOPOLOGY_TEMPLATE = "topology_template"; @@ -69,7 +68,7 @@ public class DependencyModelParser { } public VnfcDependencyModel generateDependencyModel(String vnfModel, String vnfType) - throws InvalidDependencyModelException { + throws InvalidDependencyModelException { Set> dependencies = new HashSet<>(); ObjectMapper mapper = getMapper(); boolean mandatory; @@ -78,13 +77,15 @@ public class DependencyModelParser { try { ObjectNode root = (ObjectNode) mapper.readTree(vnfModel); - if (root.get(TOPOLOGY_TEMPLATE) == null || root.get(TOPOLOGY_TEMPLATE).get("node_templates") == null) { + JsonNode topologyTemplateNode = root.get(TOPOLOGY_TEMPLATE); + JsonNode nodeTemplateNode; + + if (topologyTemplateNode == null + || (nodeTemplateNode = topologyTemplateNode.get("node_templates")) == null) { throw new InvalidDependencyModelException( - "Dependency model is missing 'topology_template' or 'node_templates' elements"); + "Dependency model is missing 'topology_template' or 'node_templates' elements"); } - JsonNode topologyTemplateNode = root.get(TOPOLOGY_TEMPLATE); - JsonNode nodeTemplateNode = topologyTemplateNode.get("node_templates"); Iterator> iterator = nodeTemplateNode.fields(); for (JsonNode yamlNode : nodeTemplateNode) { logger.debug("Processing node: " + yamlNode); @@ -92,7 +93,7 @@ public class DependencyModelParser { String vnfcType = getQualifiedVnfcType(fullvnfcType); String type = yamlNode.get("type").textValue(); type = type.substring(0, type.lastIndexOf('.') + 1); - if (type.concat(vnfcType).toLowerCase().startsWith(prefix.concat(vnfcType).toLowerCase())) { + if (type.toLowerCase().startsWith(prefix.toLowerCase())) { resilienceType = resolveResilienceType(yamlNode); mandatory = resolveMandatory(yamlNode); @@ -103,23 +104,23 @@ public class DependencyModelParser { logger.debug("Dependency node already exists for vnfc Type: " + vnfcType); if (StringUtils.isEmpty(vnfcNode.getChild().getResilienceType())) { logger.debug("Updating resilience type, " - + "dependencies and mandatory attribute for VNFC type: " + vnfcType); + + "dependencies and mandatory attribute for VNFC type: " + vnfcType); vnfcNode.getChild().setResilienceType(resilienceType); tryFillNode(dependencies, parentList, vnfcNode); vnfcNode.getChild().setMandatory(mandatory); } } else { - logger.debug("Creating dependency node for : " + vnfcType); + logger.debug("Creating dependency node for: " + vnfcType); vnfcNode = new Node<>(createVnfc(mandatory, resilienceType, vnfcType)); tryFillNode(dependencies, parentList, vnfcNode); - logger.debug("Adding VNFC to dependency model : " + vnfcNode); + logger.debug("Adding VNFC to dependency model: " + vnfcNode); dependencies.add(vnfcNode); } } } } catch (IOException e) { - logger.error("Error parsing dependency model : " + vnfModel); - logger.error("Error message : " + e); + logger.error("Error parsing dependency model: " + vnfModel); + logger.error("Error message: " + e); throw new InvalidDependencyModelException("Error parsing dependency model. " + e.getMessage()); } return new VnfcDependencyModel(dependencies); @@ -136,8 +137,8 @@ public class DependencyModelParser { } private boolean mandatoryDoesNotExist(JsonNode yamlNode) { - return yamlNode.get(PROPERTIES).findValue(MANDATORY) == null || - yamlNode.get(PROPERTIES).findValue(MANDATORY).asText().isEmpty(); + return yamlNode.get(PROPERTIES).findValue(MANDATORY) == null + || yamlNode.get(PROPERTIES).findValue(MANDATORY).asText().isEmpty(); } private String resolveResilienceType(JsonNode yamlNode) { @@ -148,10 +149,10 @@ public class DependencyModelParser { 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 + // 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()) { + else if (yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY) == null + || yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).asText().isEmpty()) { resilienceType = ACTIVE_ACTIVE; } else { resilienceType = dependencyMap @@ -177,25 +178,27 @@ public class DependencyModelParser { String parentType = getVnfcType(type); Node parentNode = getNode(nodes, parentType); if (parentNode != null) { - logger.debug("VNFC already exists for VNFC type: " + parentType + ". Adding it to parent list "); + logger.debug("VNFC already exists for VNFC type: " + parentType + ". Adding it to parent list"); node.addParent(parentNode.getChild()); } else { - logger.debug("VNFC does not exist for VNFC type: " + parentType + ". Creating new VNFC "); + logger.debug("VNFC does not exist for VNFC type: " + parentType + ". Creating new VNFC"); parentNode = new Node<>(createVnfc(false, null, parentType)); node.addParent(parentNode.getChild()); - logger.debug("Adding VNFC to dependency model : " + parentNode); + logger.debug("Adding VNFC to dependency model: " + parentNode); nodes.add(parentNode); } } } private String[] getDependencyArray(JsonNode node, JsonNode nodeTemplateNode) - throws InvalidDependencyModelException { + throws InvalidDependencyModelException { JsonNode requirementsNode = node.get("requirements"); Set dependencyList = new HashSet<>(); if (requirementsNode != null) { for (JsonNode internalNode : requirementsNode) { - //TODO : In this release we are supporting both relationship = tosca.capabilities.Node and relationship =tosca.relationships.DependsOn we need to remove one of them in next release post confirming with SDC team + /* TODO: In this release we are supporting both relationship = tosca.capabilities.Node + and relationship = tosca.relationships.DependsOn + we need to remove one of them in next release post confirming with SDC team */ if (verifyNode(internalNode)) { parseDependencyModel(node, nodeTemplateNode, dependencyList, internalNode); } @@ -207,7 +210,7 @@ public class DependencyModelParser { } private void parseDependencyModel(JsonNode node, JsonNode nodeTemplateNode, Set dependencyList, - JsonNode internalNode) throws InvalidDependencyModelException { + JsonNode internalNode) throws InvalidDependencyModelException { if (internalNode.findValue("node") != null) { String nodeName = internalNode.findValue("node").asText(); @@ -215,20 +218,20 @@ public class DependencyModelParser { dependencyList.add(getQualifiedVnfcType(fullVnfcName)); } else { throw new InvalidDependencyModelException( - "Error parsing dependency model. " + "Dependent Node not found for " + node.get("type")); + "Error parsing dependency model. Dependent Node not found for " + node.get("type")); } } private boolean verifyNode(JsonNode internalNode) { - return nodeNullCheck(internalNode) && - "tosca.capabilities.Node".equalsIgnoreCase(internalNode.findValue("capability").asText()) && - ("tosca.relationships.DependsOn".equalsIgnoreCase(internalNode.findValue(RELATIONSHIP).asText()) || - "tosca.capabilities.Node".equalsIgnoreCase(internalNode.findValue(RELATIONSHIP).asText())); + return nodeNullCheck(internalNode) + && "tosca.capabilities.Node".equalsIgnoreCase(internalNode.findValue("capability").asText()) + && ("tosca.relationships.DependsOn".equalsIgnoreCase(internalNode.findValue(RELATIONSHIP).asText()) + || "tosca.capabilities.Node".equalsIgnoreCase(internalNode.findValue(RELATIONSHIP).asText())); } private boolean nodeNullCheck(JsonNode internalNode) { return internalNode.get("dependency") != null && internalNode.findValue("capability") != null - && internalNode.findValue(RELATIONSHIP) != null; + && internalNode.findValue(RELATIONSHIP) != null; } protected Node getNode(Set> nodes, String vnfcType) { 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 e9404dd41..60f5f0e30 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * 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========================================================= */ @@ -44,17 +43,18 @@ public class DependencyManagerImpl implements DependencyManager { MetadataCache cache; - DependencyManagerImpl(){ + DependencyManagerImpl() { cache = MetadataCacheFactory.getInstance().getMetadataCache(); } - public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier,DependencyTypes dependencyType) throws InvalidDependencyModelException, DependencyModelNotFound { + public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier, + DependencyTypes dependencyType) throws InvalidDependencyModelException, DependencyModelNotFound { if (logger.isTraceEnabled()) { - logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier + logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = " + modelIdentifier + " , DependencyTypes = " + dependencyType); } VnfcDependencyModel dependencyModel = cache.getObject(modelIdentifier); - if(dependencyModel == null){ + if (dependencyModel == null) { logger.debug("Dependency model not found in cache, creating strategy for reading it"); DependencyType strategy = getStrategy(dependencyType); // Throw exception if strategy could not be created because it is required @@ -65,13 +65,13 @@ public class DependencyManagerImpl implements DependencyManager { dependencyModel = strategy.getVnfcDependencyModel(modelIdentifier); } if (logger.isTraceEnabled()) { - logger.trace("Returning getVnfcDependencyModel with dependency model = "+ dependencyModel); + logger.trace("Returning getVnfcDependencyModel with dependency model = " + dependencyModel); } return dependencyModel; } private DependencyType getStrategy(DependencyTypes dependencyType) { - switch (dependencyType){ + switch (dependencyType) { case RESOURCE: return new ResourceDependency(); } diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/ResourceDependency.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/ResourceDependency.java index 167d23909..603ba3707 100644 --- a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/ResourceDependency.java +++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/onap/appc/dg/dependencymanager/impl/ResourceDependency.java @@ -2,22 +2,21 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * 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========================================================= */ @@ -38,14 +37,14 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; -public class ResourceDependency implements DependencyType{ +public class ResourceDependency implements DependencyType { private static final EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDependency.class); private MetadataService metadataService; - public ResourceDependency(){ + public ResourceDependency() { getMetadataServiceRef(); } @@ -67,12 +66,13 @@ public class ResourceDependency implements DependencyType{ this.metadataService = metadataService; } - public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModelException, DependencyModelNotFound { + public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) + throws InvalidDependencyModelException, DependencyModelNotFound { if (logger.isTraceEnabled()) { - logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier); + logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = " + modelIdentifier); } String vnfModel = metadataService.getVnfModel(modelIdentifier); - if(vnfModel ==null){ + if (vnfModel == null) { logger.debug("Vnf model not found from metadata service"); throw new DependencyModelNotFound("Invalid or Empty VNF Model"); } @@ -80,6 +80,6 @@ public class ResourceDependency implements DependencyType{ logger.trace("Building dependency model for Vnf Model : " + vnfModel); } DependencyModelParser modelParser = new DependencyModelParser(); - return modelParser.generateDependencyModel(vnfModel,modelIdentifier.getVnfType()); + return modelParser.generateDependencyModel(vnfModel, modelIdentifier.getVnfType()); } } 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 index e7951c61d..36a7210ff 100644 --- 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 @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2019 Ericsson * ============================================================================= + * Modifications Copyright (C) 2019 AT&T Intellectual Property + * ============================================================================= * 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 @@ -27,7 +29,9 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException; import org.onap.appc.dg.objects.VnfcDependencyModel; import org.onap.appc.dg.objects.Node; @@ -37,6 +41,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; +@RunWith(MockitoJUnitRunner.class) public class DependencyModelParserTest { @Rule @@ -54,7 +59,8 @@ public class DependencyModelParserTest { } @Test - public void testGenerateDependencyModel() throws InvalidDependencyModelException, JsonProcessingException, IOException { + 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"); @@ -63,7 +69,8 @@ public class DependencyModelParserTest { } @Test - public void testGenerateDependencyModelWithNode() throws InvalidDependencyModelException, JsonProcessingException, IOException { + public void testGenerateDependencyModelWithNode() + throws InvalidDependencyModelException, JsonProcessingException, IOException { ObjectNode topologyTemplate = new ObjectNode(JsonNodeFactory.instance); topologyTemplate = (ObjectNode) new ObjectMapper().readTree(jsonString); Node vnfc = new Node(new Vnfc()); @@ -76,32 +83,33 @@ public class DependencyModelParserTest { @Test public void testGenerateDependencyModelExceptionFlow() throws InvalidDependencyModelException { expectedEx.expect(InvalidDependencyModelException.class); - expectedEx.expectMessage("Dependency model is missing 'topology_template' or 'node_templates' elements"); + 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\"}" + - " }" + - " }" + - "}"; + 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_availability\": \"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/flowbuilder/TestFlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java index ef3a1af7b..07ca83a10 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -13,15 +13,14 @@ * 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========================================================= */ @@ -50,20 +49,20 @@ public class TestFlowBuilder { FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD); VnfcDependencyModel dependencyModel = readDependencyModel(); InventoryModel inventoryModel = readInventoryModel(); - VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel); + VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel, inventoryModel); Iterator> itr = flowModel.getModelIterator(); List list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("SMP","Active-Passive","SMP_Name"))); + Assert.assertTrue(list.contains(createVnfc("SMP", "Active-Passive", "SMP_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("BE","Active-Active","BE_Name"))); + Assert.assertTrue(list.contains(createVnfc("BE", "Active-Active", "BE_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("FE","Active-Active","FE_Name"))); + Assert.assertTrue(list.contains(createVnfc("FE", "Active-Active", "FE_Name"))); } - private Vnfc createVnfc(String vnfcType,String resilienceType,String vnfcName) { + private Vnfc createVnfc(String vnfcType, String resilienceType, String vnfcName) { Vnfc vnfc = new Vnfc(); vnfc.setVnfcType(vnfcType); vnfc.setVnfcName(vnfcName); @@ -76,17 +75,17 @@ public class TestFlowBuilder { FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.REVERSE); VnfcDependencyModel dependencyModel = readDependencyModel(); InventoryModel inventoryModel = readInventoryModel(); - VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel); + VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel, inventoryModel); Iterator> itr = flowModel.getModelIterator(); List list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("FE","Active-Active","FE_Name"))); + Assert.assertTrue(list.contains(createVnfc("FE", "Active-Active", "FE_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("BE","Active-Active","BE_Name"))); + Assert.assertTrue(list.contains(createVnfc("BE", "Active-Active", "BE_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("SMP","Active-Passive","SMP_Name"))); + Assert.assertTrue(list.contains(createVnfc("SMP", "Active-Passive", "SMP_Name"))); Assert.assertThat(flowModel.toString(), CoreMatchers.containsString("Flow Model : Vnfc : vnfcType = FE")); } @@ -96,25 +95,24 @@ public class TestFlowBuilder { FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD); VnfcDependencyModel dependencyModel = readComplexDependencyModel(); InventoryModel inventoryModel = readComplexInventoryModel(); - VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel); + VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel, inventoryModel); Iterator> itr = flowModel.getModelIterator(); - try{ + try { List list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("A","Active-Active","A_Name"))); - Assert.assertTrue(list.contains(createVnfc("E","Active-Active","E_Name"))); + Assert.assertTrue(list.contains(createVnfc("A", "Active-Active", "A_Name"))); + Assert.assertTrue(list.contains(createVnfc("E", "Active-Active", "E_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("B","Active-Active","B_Name"))); - Assert.assertTrue(list.contains(createVnfc("C","Active-Active","C_Name"))); + Assert.assertTrue(list.contains(createVnfc("B", "Active-Active", "B_Name"))); + Assert.assertTrue(list.contains(createVnfc("C", "Active-Active", "C_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("D","Active-Active","D_Name"))); - Assert.assertTrue(list.contains(createVnfc("F","Active-Active","F_Name"))); + Assert.assertTrue(list.contains(createVnfc("D", "Active-Active", "D_Name"))); + Assert.assertTrue(list.contains(createVnfc("F", "Active-Active", "F_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("G","Active-Active","G_Name"))); - } - catch (Exception e){ + Assert.assertTrue(list.contains(createVnfc("G", "Active-Active", "G_Name"))); + } catch (Exception e) { e.printStackTrace(); } } @@ -124,24 +122,24 @@ public class TestFlowBuilder { FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.REVERSE); VnfcDependencyModel dependencyModel = readComplexDependencyModel(); InventoryModel inventoryModel = readComplexInventoryModel(); - VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel); + VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel, inventoryModel); Iterator> itr = flowModel.getModelIterator(); List list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("D","Active-Active","D_Name"))); + Assert.assertTrue(list.contains(createVnfc("D", "Active-Active", "D_Name"))); - Assert.assertTrue(list.contains(createVnfc("G","Active-Active","G_Name"))); + Assert.assertTrue(list.contains(createVnfc("G", "Active-Active", "G_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("B","Active-Active","B_Name"))); - Assert.assertTrue(list.contains(createVnfc("F","Active-Active","F_Name"))); + Assert.assertTrue(list.contains(createVnfc("B", "Active-Active", "B_Name"))); + Assert.assertTrue(list.contains(createVnfc("F", "Active-Active", "F_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("C","Active-Active","C_Name"))); + Assert.assertTrue(list.contains(createVnfc("C", "Active-Active", "C_Name"))); list = itr.next(); - Assert.assertTrue(list.contains(createVnfc("E","Active-Active","E_Name"))); - Assert.assertTrue(list.contains(createVnfc("A","Active-Active","A_Name"))); + Assert.assertTrue(list.contains(createVnfc("E", "Active-Active", "E_Name"))); + Assert.assertTrue(list.contains(createVnfc("A", "Active-Active", "A_Name"))); } @@ -150,7 +148,7 @@ public class TestFlowBuilder { FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.findByString("FORWARD")); VnfcDependencyModel dependencyModel = readCyclicDependencyModel(); InventoryModel inventoryModel = readInventoryModel(); - builder.buildFlowModel(dependencyModel,inventoryModel); + builder.buildFlowModel(dependencyModel, inventoryModel); } @Test(expected = InvalidDependencyModelException.class) @@ -158,20 +156,20 @@ public class TestFlowBuilder { FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD); VnfcDependencyModel dependencyModel = readCyclicDependencyModelWithRootNode(); InventoryModel inventoryModel = readInventoryModel(); - builder.buildFlowModel(dependencyModel,inventoryModel); + builder.buildFlowModel(dependencyModel, inventoryModel); } - + @Test - public void testInventoryModelToString(){ - Vnf vnf = createVnf("vnf_1","vABCD","1"); + public void testInventoryModelToString() { + Vnf vnf = createVnf("vnf_1", "vABCD", "1"); InventoryModel inventoryModel = new InventoryModel(vnf); Assert.assertEquals("InventoryModel = Vnf : vnfId = vnf_1 , vnfType = vABCD", inventoryModel.toString()); } private VnfcDependencyModel readCyclicDependencyModelWithRootNode() { - Vnfc a = createVnfc("A","Active-Passive",null); - Vnfc b = createVnfc("B","Active-Active",null); - Vnfc c = createVnfc("C","Active-Active",null); + Vnfc a = createVnfc("A", "Active-Passive", null); + Vnfc b = createVnfc("B", "Active-Active", null); + Vnfc c = createVnfc("C", "Active-Active", null); Node aNode = new Node(a); @@ -194,28 +192,28 @@ public class TestFlowBuilder { } private InventoryModel readComplexInventoryModel() { - Vnf vnf = createVnf("vnf_1","vABCD","1"); - - Vnfc vnfcA = createVnfc("A","Active-Active","A_Name"); - Vnfc vnfcB = createVnfc("B","Active-Active","B_Name"); - Vnfc vnfcC = createVnfc("C","Active-Active","C_Name"); - Vnfc vnfcD = createVnfc("D","Active-Active","D_Name"); - Vnfc vnfcE = createVnfc("E","Active-Active","E_Name"); - Vnfc vnfcF = createVnfc("F","Active-Active","F_Name"); - Vnfc vnfcG = createVnfc("G","Active-Active","G_Name"); - - vnf.addVserver(createVserver("VM_URL_A1",vnfcA)); - vnf.addVserver(createVserver("VM_URL_B1",vnfcB)); - vnf.addVserver(createVserver("VM_URL_C1",vnfcC)); - vnf.addVserver(createVserver("VM_URL_D1",vnfcD)); - vnf.addVserver(createVserver("VM_URL_E1",vnfcE)); - vnf.addVserver(createVserver("VM_URL_F1",vnfcF)); - vnf.addVserver(createVserver("VM_URL_G1",vnfcG)); + Vnf vnf = createVnf("vnf_1", "vABCD", "1"); + + Vnfc vnfcA = createVnfc("A", "Active-Active", "A_Name"); + Vnfc vnfcB = createVnfc("B", "Active-Active", "B_Name"); + Vnfc vnfcC = createVnfc("C", "Active-Active", "C_Name"); + Vnfc vnfcD = createVnfc("D", "Active-Active", "D_Name"); + Vnfc vnfcE = createVnfc("E", "Active-Active", "E_Name"); + Vnfc vnfcF = createVnfc("F", "Active-Active", "F_Name"); + Vnfc vnfcG = createVnfc("G", "Active-Active", "G_Name"); + + vnf.addVserver(createVserver("VM_URL_A1", vnfcA)); + vnf.addVserver(createVserver("VM_URL_B1", vnfcB)); + vnf.addVserver(createVserver("VM_URL_C1", vnfcC)); + vnf.addVserver(createVserver("VM_URL_D1", vnfcD)); + vnf.addVserver(createVserver("VM_URL_E1", vnfcE)); + vnf.addVserver(createVserver("VM_URL_F1", vnfcF)); + vnf.addVserver(createVserver("VM_URL_G1", vnfcG)); return new InventoryModel(vnf); } - private Vnf createVnf(String vnfId,String vnfType,String vnfVersion) { + private Vnf createVnf(String vnfId, String vnfType, String vnfVersion) { Vnf vnf = new Vnf(); vnf.setVnfId(vnfId); vnf.setVnfType(vnfType); @@ -224,13 +222,13 @@ public class TestFlowBuilder { } private VnfcDependencyModel readComplexDependencyModel() { - Vnfc a = createVnfc("A","Active-Active",null); - Vnfc b = createVnfc("B","Active-Active",null); - Vnfc c = createVnfc("C","Active-Active",null); - Vnfc d = createVnfc("D","Active-Active",null); - Vnfc e = createVnfc("E","Active-Active",null); - Vnfc f = createVnfc("F","Active-Active",null); - Vnfc g = createVnfc("G","Active-Active",null); + Vnfc a = createVnfc("A", "Active-Active", null); + Vnfc b = createVnfc("B", "Active-Active", null); + Vnfc c = createVnfc("C", "Active-Active", null); + Vnfc d = createVnfc("D", "Active-Active", null); + Vnfc e = createVnfc("E", "Active-Active", null); + Vnfc f = createVnfc("F", "Active-Active", null); + Vnfc g = createVnfc("G", "Active-Active", null); Node aNode = new Node(a); @@ -268,10 +266,10 @@ public class TestFlowBuilder { private VnfcDependencyModel readCyclicDependencyModel() { - Vnfc a = createVnfc("A","Active-Passive",null); - Vnfc b = createVnfc("B","Active-Active",null); - Vnfc c = createVnfc("C","Active-Active",null); - Vnfc d = createVnfc("D","Active-Active",null); + Vnfc a = createVnfc("A", "Active-Passive", null); + Vnfc b = createVnfc("B", "Active-Active", null); + Vnfc c = createVnfc("C", "Active-Active", null); + Vnfc d = createVnfc("D", "Active-Active", null); Node aNode = new Node(a); @@ -297,22 +295,22 @@ public class TestFlowBuilder { } private InventoryModel readInventoryModel() { - Vnf vnf = createVnf("vnf_1","vSCP","1"); + Vnf vnf = createVnf("vnf_1", "vSCP", "1"); - Vnfc smp = createVnfc("SMP",null,"SMP_Name"); - Vserver smpVm1 = createVserver("SMP_URL1",smp); - Vserver smpVm2 = createVserver("SMP_URL2",smp); + Vnfc smp = createVnfc("SMP", null, "SMP_Name"); + Vserver smpVm1 = createVserver("SMP_URL1", smp); + Vserver smpVm2 = createVserver("SMP_URL2", smp); vnf.addVserver(smpVm1); vnf.addVserver(smpVm2); - Vnfc be = createVnfc("BE",null,"BE_Name"); + Vnfc be = createVnfc("BE", null, "BE_Name"); - Vserver beVm1 = createVserver("BE_URL1",be); - Vserver beVm2 = createVserver("BE_URL2",be); - Vserver beVm3 = createVserver("BE_URL3",be); - Vserver beVm4 = createVserver("BE_URL4",be); - Vserver beVm5 = createVserver("BE_URL5",be); + Vserver beVm1 = createVserver("BE_URL1", be); + Vserver beVm2 = createVserver("BE_URL2", be); + Vserver beVm3 = createVserver("BE_URL3", be); + Vserver beVm4 = createVserver("BE_URL4", be); + Vserver beVm5 = createVserver("BE_URL5", be); vnf.addVserver(beVm1); vnf.addVserver(beVm2); @@ -320,10 +318,10 @@ public class TestFlowBuilder { vnf.addVserver(beVm4); vnf.addVserver(beVm5); - Vnfc fe = createVnfc("FE",null,"FE_Name"); + Vnfc fe = createVnfc("FE", null, "FE_Name"); - Vserver feVm1 = createVserver("FE_URL1",fe); - Vserver feVm2 = createVserver("FE_URL2",fe); + Vserver feVm1 = createVserver("FE_URL1", fe); + Vserver feVm2 = createVserver("FE_URL2", fe); vnf.addVserver(feVm1); vnf.addVserver(feVm2); @@ -331,7 +329,7 @@ public class TestFlowBuilder { return new InventoryModel(vnf); } - private Vserver createVserver(String url,Vnfc vnfc) { + private Vserver createVserver(String url, Vnfc vnfc) { Vserver vserver = new Vserver(); vserver.setUrl(url); vserver.setVnfc(vnfc); @@ -340,9 +338,9 @@ public class TestFlowBuilder { } private VnfcDependencyModel readDependencyModel() { - Vnfc smp = createVnfc("SMP","Active-Passive",null); - Vnfc be = createVnfc("BE","Active-Active",null); - Vnfc fe = createVnfc("FE","Active-Active",null); + Vnfc smp = createVnfc("SMP", "Active-Passive", null); + Vnfc be = createVnfc("BE", "Active-Active", null); + Vnfc fe = createVnfc("FE", "Active-Active", null); Node smpNode = new Node(smp); -- cgit 1.2.3-korg