summaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-dependency-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-dependency-model/src')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java33
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java32
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java29
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java183
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java71
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java37
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java83
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java31
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java32
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java29
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java64
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java133
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java48
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java49
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java114
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java115
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java36
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java36
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java43
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java74
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java48
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java89
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java329
23 files changed, 1738 insertions, 0 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java
new file mode 100644
index 000000000..5b5b3451b
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager;
+
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.DependencyTypes;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+
+public interface DependencyManager {
+ VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier, DependencyTypes dependencyType) throws InvalidDependencyModel, DependencyModelNotFound;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java
new file mode 100644
index 000000000..06a29cd1d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager;
+
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+
+public interface DependencyType {
+ VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModel, DependencyModelNotFound;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java
new file mode 100644
index 000000000..521e0edb3
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager.exception;
+
+
+public class DependencyModelNotFound extends Exception {
+ public DependencyModelNotFound(String message){
+ super(message);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java
new file mode 100644
index 000000000..397042ecd
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java
@@ -0,0 +1,183 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager.helper;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.Node;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+import java.io.IOException;
+import java.util.*;
+
+
+public class DependencyModelParser {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyModelParser.class);
+ private static Map<String, String> dependencyMap;
+ 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 MANDATORY = "mandatory";
+ private static final String TOPOLOGY_TEMPLATE = "topology_template";
+
+ static {
+ Map<String, String> dependencyTypeMappingMap =new HashMap<>();
+ dependencyTypeMappingMap.put("geo-activeactive", ACTIVE_ACTIVE);
+ dependencyTypeMappingMap.put("geo-activestandby", ACTIVE_PASSIVE);
+ dependencyTypeMappingMap.put("local-activeactive", ACTIVE_ACTIVE);
+ dependencyTypeMappingMap.put("local-activestandby", ACTIVE_PASSIVE);
+ dependencyMap = Collections.unmodifiableMap(dependencyTypeMappingMap);
+ }
+
+ public VnfcDependencyModel generateDependencyModel(String vnfModel,String vnfType) {
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+ boolean mandatory;
+ String resilienceType;
+ String prefix = "org.openecomp.resource.vfc."+vnfType+".abstract.nodes.";
+ try {
+ ObjectNode root = (ObjectNode) mapper.readTree(vnfModel);
+ logger.debug("VNF Model after parsing: " + root);
+
+ if(root.get(TOPOLOGY_TEMPLATE) == null || root.get(TOPOLOGY_TEMPLATE).get("node_templates") == null) {
+ throw new InvalidDependencyModel("Dependency model is missing 'topology_template' or 'node_templates' elements");
+ }
+
+ JsonNode topologyTemplateNode = root.get(TOPOLOGY_TEMPLATE);
+ JsonNode nodeTemplateNode = topologyTemplateNode.get("node_templates");
+ Iterator<Map.Entry<String, JsonNode>> itretor = nodeTemplateNode.fields();
+ for (JsonNode yamlNode : nodeTemplateNode) {
+ logger.debug("Processing node: " + yamlNode);
+ String vnfcType = itretor.next().getKey();
+ String type = yamlNode.get("type").textValue();
+ type = type.substring(0,type.lastIndexOf(".")+1);
+ if(type.concat(vnfcType).toLowerCase().startsWith(prefix.concat(vnfcType).toLowerCase())) {
+
+ 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());
+ }
+
+ if(yamlNode.get(PROPERTIES).findValue(MANDATORY) == null || yamlNode.get(PROPERTIES).findValue(MANDATORY).asText().isEmpty()) {
+ mandatory = false;
+ }else {
+ mandatory = yamlNode.get(PROPERTIES).findValue(MANDATORY).booleanValue();
+ }
+ String[] parentList = getDependencyArray(yamlNode);
+ Node<Vnfc> vnfcNode = getNode(dependencies, vnfcType);
+ if (vnfcNode != null) {
+ 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);
+ vnfcNode.getChild().setResilienceType(resilienceType);
+ if (parentList != null && parentList.length > 0) {
+ addDependencies(dependencies, vnfcNode, parentList);
+ }
+ vnfcNode.getChild().setMandatory(mandatory);
+ }
+
+ } else {
+ logger.debug("Creating dependency node for : " + vnfcType);
+ vnfcNode = new Node<>(new Vnfc(vnfcType, resilienceType, null, mandatory));
+ if (parentList != null && parentList.length > 0)
+ addDependencies(dependencies, vnfcNode, parentList);
+ 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);
+ throw new InvalidDependencyModel("Error parsing dependency model. " + e.getMessage());
+ }
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private void addDependencies(Set<Node<Vnfc>> nodes, Node node, String[] parentList) {
+ for (String type : parentList) {
+ String parentType = getVnfcType(type);
+ Node<Vnfc> parentNode = getNode(nodes, parentType);
+ if (parentNode != null) {
+ 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 ");
+ parentNode = new Node<>(new Vnfc(parentType, null));
+ node.addParent(parentNode.getChild());
+ logger.debug("Adding VNFC to dependency model : " + parentNode);
+ nodes.add(parentNode);
+ }
+ }
+ }
+
+ private String[] getDependencyArray(JsonNode node) {
+ JsonNode requirementsNode = node.get("requirements");
+ List<String> dependencyList = new ArrayList();
+ if(requirementsNode!=null) {
+ for (JsonNode internalNode : requirementsNode) {
+ if (nodeNullCheck(internalNode) &&"tosca.capabilities.Node".equalsIgnoreCase(internalNode.get("capability").asText())
+ && "tosca.relationships.DependsOn".equalsIgnoreCase(internalNode.get("relationship").asText())) {
+ if(internalNode.get("node") != null) {
+ dependencyList.add(internalNode.get("node").asText());
+ }else{
+ throw new InvalidDependencyModel("Error parsing dependency model. " + "Dependent Node not found for "+ node.get("type"));
+ }
+ }
+ }
+ return dependencyList.toArray(new String[0]);
+ }else{
+ return new String[0];
+ }
+ }
+
+ private boolean nodeNullCheck(JsonNode internalNode) {
+ return internalNode.get("dependency") != null && internalNode.get("capability") != null && internalNode.get("relationship") != null;
+ }
+
+ private Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) {
+ Iterator itr = nodes.iterator();
+ Node<Vnfc> node;
+ while (itr.hasNext()) {
+ node = (Node<Vnfc>) itr.next();
+ if (node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)) {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ private String getVnfcType(String type) {
+ return type.substring(type.lastIndexOf('.') + 1, type.length());
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
new file mode 100644
index 000000000..758d5ee7e
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager.impl;
+
+import org.openecomp.appc.dg.dependencymanager.DependencyManager;
+import org.openecomp.appc.dg.dependencymanager.DependencyType;
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.DependencyTypes;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+
+import org.openecomp.appc.cache.MetadataCache;
+import org.openecomp.appc.cache.impl.MetadataCacheFactory;
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class DependencyManagerImpl implements DependencyManager {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyManagerImpl.class);
+
+ MetadataCache<DependencyModelIdentifier,VnfcDependencyModel> cache;
+
+ DependencyManagerImpl(){
+ cache = MetadataCacheFactory.getInstance().getMetadataCache();
+ }
+
+ public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier,DependencyTypes dependencyType) throws InvalidDependencyModel, DependencyModelNotFound {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier
+ + " , DependencyTypes = " + dependencyType);
+ }
+ VnfcDependencyModel dependencyModel = cache.getObject(modelIdentifier);
+ if(dependencyModel == null){
+ logger.debug("Dependency model not found in cache, creating strategy for reading it");
+ DependencyType strategy = getStrategy(dependencyType);
+ dependencyModel = strategy.getVnfcDependencyModel(modelIdentifier);
+ }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Returning getVnfcDependencyModel with dependency model = "+ dependencyModel);
+ }
+ return dependencyModel;
+ }
+
+ private DependencyType getStrategy(DependencyTypes dependencyType) {
+ switch (dependencyType){
+ case RESOURCE:
+ return new ResourceDependency();
+ }
+ return null;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java
new file mode 100644
index 000000000..87bdd32fa
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager.impl;
+
+import org.openecomp.appc.dg.dependencymanager.DependencyManager;
+
+
+public class DependencyModelFactory {
+
+ private static class ReferenceHolder{
+ private static final DependencyManagerImpl INSTANCE = new DependencyManagerImpl();
+ }
+
+ public static DependencyManager createDependencyManager(){
+ return ReferenceHolder.INSTANCE;
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java
new file mode 100644
index 000000000..0cb9eebb4
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.dependencymanager.impl;
+
+import org.openecomp.appc.metadata.MetadataService;
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import org.openecomp.appc.dg.dependencymanager.DependencyType;
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.dependencymanager.helper.DependencyModelParser;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+
+public class ResourceDependency implements DependencyType{
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDependency.class);
+
+
+ private MetadataService metadataService;
+
+ public ResourceDependency(){
+ getMetadataServiceRef();
+ }
+
+ private void getMetadataServiceRef() {
+ BundleContext bctx = FrameworkUtil.getBundle(MetadataService.class).getBundleContext();
+ // Get MetadataService reference
+ ServiceReference sref = bctx.getServiceReference(MetadataService.class.getName());
+ if (sref != null) {
+ logger.info("MetadataService from bundlecontext");
+ metadataService = (MetadataService) bctx.getService(sref);
+
+ } else {
+ logger.info("MetadataService error from bundlecontext");
+ logger.warn("Cannot find service reference for org.openecomp.appc.metadata.MetadataService");
+ }
+ }
+
+ public void setMetadataService(MetadataService metadataService) {
+ this.metadataService = metadataService;
+ }
+
+ public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModel, DependencyModelNotFound {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier);
+ }
+ String vnfModel = metadataService.getVnfModel(modelIdentifier);
+ if(vnfModel ==null){
+ logger.debug("Vnf model not found from metadata service");
+ throw new DependencyModelNotFound("Invalid or Empty VNF Model");
+ }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Building dependency model for Vnf Model : " + vnfModel);
+ }
+ DependencyModelParser modelParser = new DependencyModelParser();
+ return modelParser.generateDependencyModel(vnfModel,modelIdentifier.getVnfType());
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java
new file mode 100644
index 000000000..6b87e6621
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder;
+
+import org.openecomp.appc.dg.objects.InventoryModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcFlowModel;
+
+
+public interface FlowBuilder {
+ VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel,InventoryModel inventoryModel);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java
new file mode 100644
index 000000000..3c3488f70
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder;
+
+import org.openecomp.appc.dg.objects.InventoryModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcFlowModel;
+
+
+public interface FlowStrategy {
+
+ VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java
new file mode 100644
index 000000000..8bec80a47
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.exception;
+
+
+public class InvalidDependencyModel extends RuntimeException {
+ public InvalidDependencyModel(String message){
+ super(message);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java
new file mode 100644
index 000000000..b9115187c
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.helper;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+
+
+public class Graph<T> {
+ private int size;
+ private List<T> vertexList;
+
+ private int[][] dependencyMatrix;
+
+ public Graph(int size){
+ this.size =size;
+ vertexList = new ArrayList<>();
+ dependencyMatrix = new int[size][size];
+ }
+
+ public void addVertex(T vertex){
+ vertexList.add(vertex);
+ }
+
+ public int getIndex(T vertex){
+ return vertexList.indexOf(vertex);
+ }
+
+ public void addEdge(T vertex1,T vertex2){
+ dependencyMatrix[vertexList.indexOf(vertex1)][vertexList.indexOf(vertex2)] = 1;
+ }
+
+ public int[][] getDependencyMatrix() {
+ return dependencyMatrix;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public List<T> getVertexList() {
+ return vertexList;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java
new file mode 100644
index 000000000..15ff20083
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.openecomp.appc.dg.flowbuilder.FlowStrategy;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.flowbuilder.helper.Graph;
+import org.openecomp.appc.dg.objects.*;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public abstract class AbstractFlowStrategy implements FlowStrategy {
+
+ protected Graph<Vnfc> graph;
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractFlowStrategy.class);
+
+ public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) {
+ if(logger.isTraceEnabled()){
+ logger.trace("Entering into buildFlowModel with dependency model = " + dependencyModel
+ + "inventory model = " +inventoryModel);
+ }
+
+ if(dependencyModel == null
+ || dependencyModel.getDependencies() ==null
+ || dependencyModel.getDependencies().size() ==0){
+ logger.debug("Dependency model not available, building flow model with sequence");
+ throw new InvalidDependencyModel("Dependency model either null or does not contain any dependency");
+ }
+
+ VnfcFlowModel flowModel = buildFlowModel(dependencyModel);
+ if(logger.isDebugEnabled()){
+ logger.debug("Flow Model without instance data: \n" + flowModel);
+ }
+
+ logger.info("Populating flow model with A&AI data");
+ populateFlowModel(flowModel,inventoryModel);
+ if(logger.isDebugEnabled()){
+ logger.debug("Flow Model with instance data: \n" + flowModel);
+ }
+
+ return flowModel;
+ }
+
+ private void populateFlowModel(VnfcFlowModel flowModel, InventoryModel inventoryModel) {
+ Iterator<List<Vnfc>> flowIterator = null;
+
+ for(Vnfc vnfcFromInventory:inventoryModel.getVnf().getVnfcs()){
+ flowIterator = flowModel.getModelIterator();
+ String vnfcType = vnfcFromInventory.getVnfcType();
+ while (flowIterator.hasNext()){
+ for(Vnfc vnfcFromFlowModel:flowIterator.next() ){
+ if(vnfcType.equalsIgnoreCase(vnfcFromFlowModel.getVnfcType())){
+ vnfcFromFlowModel.setVnfcName(vnfcFromInventory.getVnfcName());
+ vnfcFromFlowModel.addVms(vnfcFromInventory.getVserverList());
+ }
+ }
+ }
+
+ }
+
+ }
+
+ private VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel) throws InvalidDependencyModel {
+ Set<Node<Vnfc>> dependencies = dependencyModel.getDependencies();
+ graph = new Graph(dependencies.size());
+
+ for(Node<Vnfc> node:dependencies){
+ graph.addVertex(node.getChild());
+ }
+
+ for(Node node:dependencies){
+ Vnfc child = (Vnfc)node.getChild();
+ List<Vnfc> parents = node.getParents();
+ for(Vnfc parent:parents){
+ graph.addEdge(child,parent);
+ }
+ }
+ List<List<Vnfc>> dependencyList = orderDependencies();
+
+ VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder();
+ int count=0;
+ int flowModelSize = 0;
+ for(List<Vnfc> vnfcList:dependencyList){
+ builder.addMetadata(count,vnfcList);
+ flowModelSize += vnfcList.size();
+ count++;
+ }
+ if(flowModelSize != dependencies.size()){
+ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies");
+ }
+
+ return builder.build();
+ }
+
+ protected abstract List<List<Vnfc>> orderDependencies();
+
+ /*private VnfcFlowModel buildFlowModelWithoutSequence(InventoryModel inventoryModel) {
+ VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder();
+
+ for(Vnfc vnfc:inventoryModel.getVnf().getVnfcs()){
+ builder = builder.addMetadata(0,vnfc);
+ }
+
+ return builder.build();
+ }*/
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java
new file mode 100644
index 000000000..7b9759852
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.impl;
+
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.objects.FlowStrategies;
+
+
+public class FlowBuilderFactory {
+ private static class ReferenceHolder{
+ private static final FlowBuilderFactory FACTORY = new FlowBuilderFactory();
+ }
+
+ public static FlowBuilderFactory getInstance(){
+ return ReferenceHolder.FACTORY;
+ }
+
+ public FlowBuilder getFlowBuilder(FlowStrategies flowStrategy){
+
+ switch (flowStrategy){
+ case FORWARD:
+ return new FlowBuilderImpl(new ForwardFlowStrategy());
+ case REVERSE:
+ return new FlowBuilderImpl(new ReverseFlowStrategy());
+ }
+ return null;
+
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java
new file mode 100644
index 000000000..80bd3eec2
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.impl;
+
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.flowbuilder.FlowStrategy;
+import org.openecomp.appc.dg.objects.InventoryModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcFlowModel;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+
+public class FlowBuilderImpl implements FlowBuilder {
+
+
+
+ private FlowStrategy strategy;
+
+ FlowBuilderImpl(FlowStrategy strategy){
+ this.strategy = strategy;
+ }
+
+ public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) {
+ return strategy.buildFlowModel(dependencyModel, inventoryModel);
+ }
+
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java
new file mode 100644
index 000000000..486e942a7
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.impl;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class ForwardFlowStrategy extends AbstractFlowStrategy {
+ @Override
+ protected List<List<Vnfc>> orderDependencies() {
+ ArrayList<List<Vnfc>> arrayList = new ArrayList<>();
+
+ Queue<Vnfc> queue1 = new LinkedList();
+ Set<Vnfc> queue2 = new LinkedHashSet<>();
+
+ Set<Vnfc> uniqueElementSet = new HashSet<>();
+ Set<Vnfc> duplicateElementSet = new HashSet<>();
+
+ // identifying independent nodes in queue1
+ for(int rowIndex=0;rowIndex<graph.getSize();rowIndex++){
+ Integer sum = 0;
+ for(int colIndex=0;colIndex<graph.getSize();colIndex++){
+ sum+= graph.getDependencyMatrix()[rowIndex][colIndex];
+ }
+ if(sum==0){
+ Vnfc vnfc = graph.getVertexList().get(rowIndex);
+ queue1.add(vnfc);
+ }
+ }
+ if(queue1.isEmpty()){
+ throw new InvalidDependencyModel("There seems to be no Root/Independent node for Vnfc dependencies");
+ }
+ arrayList.add((List<Vnfc>)queue1);
+ queue1 = new LinkedList<>(queue1);
+
+ boolean flag = true;
+
+ while(flag){
+ // iterating over queue1 and for each node in it finding all dependent nodes and putting them on queue2
+ while(!queue1.isEmpty()){
+ Vnfc listItem = queue1.remove();
+ Integer colIndex = graph.getIndex(listItem);
+ for(Integer index =0;index<graph.getSize();index++){
+ Integer value = graph.getDependencyMatrix()[index][colIndex];
+ if(value ==1){
+ Vnfc vnfc = graph.getVertexList().get(index);
+ queue2.add(vnfc);
+ }
+ }
+ }
+ for(Vnfc vnfc:queue2){
+ if(!uniqueElementSet.add(vnfc)){
+ duplicateElementSet.add(vnfc);
+ }
+ }
+ if(queue2.isEmpty()){
+ flag= false; // empty queue2 indicates that all leaf nodes have been identified, i.e. stop the iteration
+ }
+ else{
+ arrayList.add(new ArrayList<Vnfc>(queue2));
+ if(arrayList.size()>graph.getSize()){
+ // dependency list cannot be larger than total number of nodes
+ // if it happens indicates cycle in the dependency
+ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies");
+ }
+ queue1.addAll(queue2);
+ queue2 = new LinkedHashSet<>();
+ }
+ }
+ // If any node depends on multiple nodes present in different execution sequence,
+ // its execution should happen on the higher order, removing its presence on lower execution sequence
+ if(!duplicateElementSet.isEmpty()){
+ for(Vnfc vnfc:duplicateElementSet){
+ boolean firstOccurrence= true;
+ for(int i=arrayList.size()-1;i>=0;i--){
+ List<Vnfc> list = arrayList.get(i);
+ if(list.contains(vnfc)){
+ if(firstOccurrence){
+ firstOccurrence =false;
+ continue;
+ }
+ else{
+ list.remove(vnfc);
+ }
+ }
+
+ }
+ }
+ }
+ return arrayList;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java
new file mode 100644
index 000000000..2ef051da1
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder.impl;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class ReverseFlowStrategy extends AbstractFlowStrategy {
+
+ @Override
+ protected List<List<Vnfc>> orderDependencies() {
+ ArrayList<List<Vnfc>> arrayList = new ArrayList<>();
+
+ Queue<Vnfc> queue1 = new LinkedList();
+ Set<Vnfc> queue2 = new LinkedHashSet<>();
+
+ Set<Vnfc> uniqueElementSet = new HashSet<>();
+ Set<Vnfc> duplicateElementSet = new HashSet<>();
+
+ // identifying independent nodes in queue1
+ for(int colIndex=0;colIndex<graph.getSize();colIndex++){
+ Integer sum = 0;
+ for(int rowIndex=0;rowIndex<graph.getSize();rowIndex++){
+ sum+= graph.getDependencyMatrix()[rowIndex][colIndex];
+ }
+ if(sum==0){
+ Vnfc vnfc = graph.getVertexList().get(colIndex);
+ queue1.add(vnfc);
+ }
+ }
+ if(queue1.isEmpty()){
+ throw new InvalidDependencyModel("There seems to be no leaf node for Vnfc dependencies");
+ }
+ arrayList.add((List<Vnfc>)queue1);
+ queue1 = new LinkedList<>(queue1);
+
+ boolean flag = true;
+
+ while(flag){
+ // iterating over queue1 and for each node in it finding all dependent nodes and putting them on queue2
+ while(!queue1.isEmpty()){
+ Vnfc listItem = queue1.remove();
+ Integer rowIndex = graph.getIndex(listItem);
+ for(Integer index =0;index<graph.getSize();index++){
+ Integer value = graph.getDependencyMatrix()[rowIndex][index];
+ if(value ==1){
+ Vnfc vnfc = graph.getVertexList().get(index);
+ queue2.add(vnfc);
+ }
+ }
+ }
+ for(Vnfc vnfc:queue2){
+ if(!uniqueElementSet.add(vnfc)){
+ duplicateElementSet.add(vnfc);
+ }
+ }
+ if(queue2.isEmpty()){
+ flag= false; // empty queue2 indicates that all leaf nodes have been identified, i.e. stop the iteration
+ }
+ else{
+ arrayList.add(new ArrayList<Vnfc>(queue2));
+ if(arrayList.size()>graph.getSize()){
+ // dependency list cannot be larger than total number of nodes
+ // if it happens indicates cycle in the dependency
+ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies");
+ }
+ queue1.addAll(queue2);
+ queue2 = new LinkedHashSet<>();
+ }
+ }
+ // If any node depends on multiple nodes present in different execution sequence,
+ // its execution should happen on the higher order, removing its presence on lower execution sequence
+ if(!duplicateElementSet.isEmpty()){
+ for(Vnfc vnfc:duplicateElementSet){
+ boolean firstOccurrence= true;
+ for(int i=0;i<arrayList.size();i++){
+ List<Vnfc> list = arrayList.get(i);
+ if(list.contains(vnfc)){
+ if(firstOccurrence){
+ firstOccurrence =false;
+ list.remove(vnfc);
+ }
+ else{
+ continue;
+ }
+ }
+
+ }
+ }
+ }
+ return arrayList;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java
new file mode 100644
index 000000000..e8b8c2591
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.objects;
+
+
+public enum DependencyTypes {
+ RESOURCE;
+
+ public static DependencyTypes findByString(String dependencyTypeStr){
+ for(DependencyTypes dependencyType : DependencyTypes.values()){
+ if(dependencyType.name().equalsIgnoreCase(dependencyTypeStr)){
+ return dependencyType;
+ }
+ }
+ return null;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java
new file mode 100644
index 000000000..8c3126bb5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.objects;
+
+
+public enum FlowStrategies {
+ FORWARD,REVERSE;
+
+ public static FlowStrategies findByString(String flowStrategyStr){
+ for(FlowStrategies flowStrategy:FlowStrategies.values()){
+ if(flowStrategy.name().equalsIgnoreCase(flowStrategyStr)){
+ return flowStrategy;
+ }
+ }
+ return null;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java
new file mode 100644
index 000000000..ffd3a35ba
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.objects;
+
+import org.openecomp.appc.domainmodel.Vnf;
+
+
+public class InventoryModel {
+
+ private Vnf vnf;
+
+ public InventoryModel(Vnf vnf){
+ this.vnf= vnf;
+ }
+
+ public Vnf getVnf() {
+ return vnf;
+ }
+
+ @Override
+ public String toString() {
+ return "InventoryModel = " + vnf.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java
new file mode 100644
index 000000000..a751504b8
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+
+public class Node<T> {
+ T child;
+ List<T> parents;
+
+ @Override
+ public int hashCode(){
+ return child.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object){
+ if(object == null){
+ return false;
+ }
+ if(!(object instanceof Node)){
+ return false;
+ }
+ Node node = (Node)object;
+ return this.child.equals(node.getChild());
+ }
+
+ public Node(T child){
+ this.child = child;
+ this.parents = new LinkedList<>();
+ }
+
+ public T getChild() {
+ return child;
+ }
+
+ public List<T> getParents() {
+ return parents;
+ }
+
+ public void addParent(T parent){
+ this.parents.add(parent);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("Node : child = " + child + " , parents = ");
+ for(T parent:parents){
+ stringBuilder.append(parent).append(",");
+ }
+ return stringBuilder.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java
new file mode 100644
index 000000000..12b5c15a5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.objects;
+
+import java.util.Set;
+
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class VnfcDependencyModel {
+ private Set<Node<Vnfc>> dependencies;
+
+ public VnfcDependencyModel(Set<Node<Vnfc>> dependencies){
+ this.dependencies = dependencies;
+ }
+
+ public Set<Node<Vnfc>> getDependencies() {
+ return dependencies;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("dependencies = ");
+ for(Node node:dependencies){
+ stringBuilder.append(node.toString()).append(", ");
+ }
+ return super.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java
new file mode 100644
index 000000000..ef3934162
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.objects;
+
+import java.util.*;
+
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class VnfcFlowModel {
+ private Map<Integer,List<Vnfc>> flowModelMap;
+
+ private VnfcFlowModel(VnfcFlowModelBuilder builder){
+ this.flowModelMap = builder.map;
+
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("Flow Model : ");
+ Iterator<List<Vnfc>> iterator = getModelIterator();
+ while(iterator.hasNext()){
+ for(Vnfc vnfc:iterator.next()){
+ stringBuilder.append(vnfc.toString()).append(", \n");
+ }
+ }
+
+ return stringBuilder.toString();
+ }
+
+ public Iterator<List<Vnfc>> getModelIterator(){
+ return flowModelMap.values().iterator();
+ }
+
+ public static class VnfcFlowModelBuilder{
+
+ Map<Integer,List<Vnfc>> map;
+
+ public VnfcFlowModelBuilder(){
+ map = new HashMap<>();
+ }
+
+ public VnfcFlowModelBuilder addMetadata(Integer index,Vnfc vnfc){
+ List<Vnfc> vnfcList = this.map.get(index);
+ if(vnfcList == null){
+ vnfcList = new LinkedList<>();
+ map.put(index,vnfcList);
+ }
+ vnfcList.add(vnfc);
+ return this;
+ }
+
+ public VnfcFlowModelBuilder addMetadata(Integer index,List<Vnfc> vnfcs){
+ List<Vnfc> vnfcList = this.map.get(index);
+ if(vnfcList == null){
+ vnfcList = new LinkedList<>();
+ map.put(index,vnfcList);
+ }
+ vnfcList.addAll(vnfcs);
+ return this;
+ }
+
+ public VnfcFlowModel build(){
+ return new VnfcFlowModel(this);
+ }
+
+ }
+
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java
new file mode 100644
index 000000000..c6b36da86
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java
@@ -0,0 +1,329 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.openecomp.appc.dg.flowbuilder;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.flowbuilder.impl.FlowBuilderFactory;
+import org.openecomp.appc.dg.objects.*;
+import org.openecomp.appc.domainmodel.Vnf;
+import org.openecomp.appc.domainmodel.Vnfc;
+import org.openecomp.appc.domainmodel.Vserver;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+
+public class TestFlowBuilder {
+
+ @Test
+ public void testForwardFlowBuilder(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+ InventoryModel inventoryModel = readInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("SMP","Active-Passive","SMP_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("BE","Active-Active","BE_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("FE","Active-Active","FE_Name")));
+ }
+
+ @Test
+ public void testReverseFlowBuilder(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.REVERSE);
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+ InventoryModel inventoryModel = readInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("FE","Active-Active","FE_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("BE","Active-Active","BE_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("SMP","Active-Passive","SMP_Name")));
+ }
+
+ @Test
+ public void testComplexFlowBuilderForward(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readComplexDependencyModel();
+ InventoryModel inventoryModel = readComplexInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("A","Active-Active","A_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("E","Active-Active","E_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("B","Active-Active","B_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("C","Active-Active","C_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("D","Active-Active","D_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("F","Active-Active","F_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("G","Active-Active","G_Name")));
+
+ }
+
+ @Test
+ public void testComplexFlowBuilderReverse(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.REVERSE);
+ VnfcDependencyModel dependencyModel = readComplexDependencyModel();
+ InventoryModel inventoryModel = readComplexInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("D","Active-Active","D_Name")));
+
+ Assert.assertTrue(list.contains(new Vnfc("G","Active-Active","G_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("B","Active-Active","B_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("F","Active-Active","F_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("C","Active-Active","C_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("E","Active-Active","E_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("A","Active-Active","A_Name")));
+
+ }
+
+ @Test(expected = InvalidDependencyModel.class)
+ public void testCyclicBuilder(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
+ InventoryModel inventoryModel = readInventoryModel();
+ builder.buildFlowModel(dependencyModel,inventoryModel);
+ }
+
+ @Test(expected = InvalidDependencyModel.class)
+ public void testCyclicBuilderWithRootNode(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readCyclicDependencyModelWithRootNode();
+ InventoryModel inventoryModel = readInventoryModel();
+ builder.buildFlowModel(dependencyModel,inventoryModel);
+ }
+
+ private VnfcDependencyModel readCyclicDependencyModelWithRootNode() {
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+
+ bNode.addParent(c);
+ cNode.addParent(b);
+
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private InventoryModel readComplexInventoryModel() {
+ Vnf vnf = new Vnf("vnf_1","vABCD","1");
+
+ Vnfc vnfcA = new Vnfc("A","Active-Active","A_Name");
+ Vnfc vnfcB = new Vnfc("B","Active-Active","B_Name");
+ Vnfc vnfcC = new Vnfc("C","Active-Active","C_Name");
+ Vnfc vnfcD = new Vnfc("D","Active-Active","D_Name");
+ Vnfc vnfcE = new Vnfc("E","Active-Active","E_Name");
+ Vnfc vnfcF = new Vnfc("F","Active-Active","F_Name");
+ Vnfc vnfcG = new Vnfc("G","Active-Active","G_Name");
+
+ vnfcA.addVm(new Vserver("VM_URL_A1"));
+ vnfcB.addVm(new Vserver("VM_URL_B1"));
+ vnfcC.addVm(new Vserver("VM_URL_C1"));
+ vnfcD.addVm(new Vserver("VM_URL_D1"));
+ vnfcE.addVm(new Vserver("VM_URL_E1"));
+ vnfcF.addVm(new Vserver("VM_URL_F1"));
+ vnfcG.addVm(new Vserver("VM_URL_G1"));
+
+ vnf.addVnfc(vnfcA);
+ vnf.addVnfc(vnfcB);
+ vnf.addVnfc(vnfcC);
+ vnf.addVnfc(vnfcD);
+ vnf.addVnfc(vnfcE);
+ vnf.addVnfc(vnfcF);
+ vnf.addVnfc(vnfcG);
+
+ return new InventoryModel(vnf);
+ }
+
+ private VnfcDependencyModel readComplexDependencyModel() {
+ Vnfc a = new Vnfc("A","Active-Active",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+ Vnfc e = new Vnfc("E","Active-Active",null);
+ Vnfc f = new Vnfc("F","Active-Active",null);
+ Vnfc g = new Vnfc("G","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+ Node eNode = new Node(e);
+ Node fNode = new Node(f);
+ Node gNode = new Node(g);
+
+ bNode.addParent(a);
+ cNode.addParent(a);
+
+ bNode.addParent(e);
+ cNode.addParent(e);
+
+ dNode.addParent(b);
+ gNode.addParent(b);
+
+ fNode.addParent(c);
+
+ gNode.addParent(f);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+ dependencies.add(eNode);
+ dependencies.add(fNode);
+ dependencies.add(gNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private VnfcDependencyModel readCyclicDependencyModel() {
+
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+
+ bNode.addParent(a);
+
+ bNode.addParent(d);
+ dNode.addParent(c);
+ cNode.addParent(b);
+
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+
+ return new VnfcDependencyModel(dependencies);
+
+ }
+
+ private InventoryModel readInventoryModel() {
+ Vnf vnf = new Vnf("vnf_1","vSCP","1");
+
+ Vnfc smp = new Vnfc("SMP",null,"SMP_Name");
+ Vserver smpVm1 = new Vserver("SMP_URL1");
+ Vserver smpVm2 = new Vserver("SMP_URL2");
+
+ smp.addVm(smpVm1);
+ smp.addVm(smpVm2);
+
+ Vnfc be = new Vnfc("BE",null,"BE_Name");
+
+ Vserver beVm1 = new Vserver("BE_URL1");
+ Vserver beVm2 = new Vserver("BE_URL2");
+ Vserver beVm3 = new Vserver("BE_URL3");
+ Vserver beVm4 = new Vserver("BE_URL4");
+ Vserver beVm5 = new Vserver("BE_URL5");
+
+ be.addVm(beVm1);
+ be.addVm(beVm2);
+ be.addVm(beVm3);
+ be.addVm(beVm4);
+ be.addVm(beVm5);
+
+ Vnfc fe = new Vnfc("FE",null,"FE_Name");
+
+ Vserver feVm1 = new Vserver("FE_URL1");
+ Vserver feVm2 = new Vserver("FE_URL2");
+
+ fe.addVm(feVm1);
+ fe.addVm(feVm2);
+
+ vnf.addVnfc(smp);
+ vnf.addVnfc(be);
+ vnf.addVnfc(fe);
+
+ return new InventoryModel(vnf);
+ }
+
+ private VnfcDependencyModel readDependencyModel() {
+ Vnfc smp = new Vnfc("SMP","Active-Passive",null);
+ Vnfc be = new Vnfc("BE","Active-Active",null);
+ Vnfc fe = new Vnfc("FE","Active-Active",null);
+
+
+ Node smpNode = new Node(smp);
+ Node beNode = new Node(be);
+ Node feNode = new Node(fe);
+
+ beNode.addParent(smp);
+ feNode.addParent(be);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(smpNode);
+ dependencies.add(feNode);
+ dependencies.add(beNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+}