Merging in bug fixes
[appc.git] / appc-dg / appc-dg-shared / appc-dg-dependency-model / src / main / java / org / openecomp / appc / dg / dependencymanager / helper / DependencyModelParser.java
index 397042e..c068412 100644 (file)
@@ -1,10 +1,11 @@
 /*-
  * ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- *                                             reserved.
+ * Copyright (C) 2017 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
@@ -16,6 +17,8 @@
  * 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.
+ * 
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * ============LICENSE_END=========================================================
  */
 
@@ -65,7 +68,6 @@ public class DependencyModelParser {
         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");
@@ -76,7 +78,8 @@ public class DependencyModelParser {
             Iterator<Map.Entry<String, JsonNode>> itretor  = nodeTemplateNode.fields();
             for (JsonNode yamlNode : nodeTemplateNode) {
                 logger.debug("Processing node: " + yamlNode);
-                String vnfcType = itretor.next().getKey();
+                String fullvnfcType = itretor.next().getValue().get("type").textValue();
+                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())) {
@@ -92,7 +95,7 @@ public class DependencyModelParser {
                     }else {
                         mandatory = yamlNode.get(PROPERTIES).findValue(MANDATORY).booleanValue();
                     }
-                    String[] parentList = getDependencyArray(yamlNode);
+                    String[] parentList = getDependencyArray(yamlNode,nodeTemplateNode);
                     Node<Vnfc> vnfcNode = getNode(dependencies, vnfcType);
                     if (vnfcNode != null) {
                         logger.debug("Dependency node already exists for vnfc Type: " + vnfcType);
@@ -123,6 +126,10 @@ public class DependencyModelParser {
         return new VnfcDependencyModel(dependencies);
     }
 
+    private String getQualifiedVnfcType(String fullvnfcType) {
+        return fullvnfcType.substring(fullvnfcType.lastIndexOf(".")+1,fullvnfcType.length());
+    }
+
     private void addDependencies(Set<Node<Vnfc>> nodes, Node node, String[] parentList) {
         for (String type : parentList) {
             String parentType = getVnfcType(type);
@@ -140,15 +147,18 @@ public class DependencyModelParser {
         }
     }
 
-    private String[] getDependencyArray(JsonNode node) {
+    private String[] getDependencyArray(JsonNode node, JsonNode nodeTemplateNode) {
         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());
+                //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 (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()))) {
+                    if(internalNode.findValue("node") != null) {
+                        String nodeName = internalNode.findValue("node").asText();
+                        String fullVnfcName = nodeTemplateNode.get(nodeName).get("type").asText();
+                        dependencyList.add(getQualifiedVnfcType(fullVnfcName));
                     }else{
                         throw new InvalidDependencyModel("Error parsing dependency model. " + "Dependent Node not found for "+ node.get("type"));
                     }
@@ -161,7 +171,7 @@ public class DependencyModelParser {
     }
 
     private boolean nodeNullCheck(JsonNode internalNode) {
-        return internalNode.get("dependency") != null && internalNode.get("capability") != null && internalNode.get("relationship") != null;
+        return internalNode.get("dependency") != null && internalNode.findValue("capability") != null && internalNode.findValue("relationship") != null;
     }
 
     private Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) {