[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / NetworkUtils.groovy
  * ============LICENSE_END=========================================================
  */
 
-package com.att.bpm.scripts;
+package org.openecomp.mso.bpmn.common.scripts;
 
 import org.apache.commons.lang3.*
 
 import groovy.xml.XmlUtil
+
 import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory
 import javax.xml.transform.Transformer
@@ -40,12 +41,12 @@ import org.w3c.dom.NamedNodeMap
 import org.w3c.dom.Node
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource
-import org.apache.commons.lang3.*
+
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.runtime.Execution
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
 import org.w3c.dom.Document
 import org.w3c.dom.Element
-
 import org.w3c.dom.NamedNodeMap
 import org.w3c.dom.Node
 import org.w3c.dom.NodeList;
@@ -64,12 +65,11 @@ class NetworkUtils {
                this.taskProcessor = taskProcessor
        }
 
-
        /**
         * This method returns the string for Network request
         * V2 for Contrail 3.x will populate cloud-region data in same cloudSiteId filed
         * Network adapter will handle it properly
-        * @param requestId either 'request-id' or 'att-mso-request-id'
+        * @param requestId either 'request-id' or 'openecomp-mso-request-id'
         * @param requestInput the request in the process
         * @param queryIdResponse the response of REST AAI query by Id
         * @param routeCollection the collection
@@ -106,12 +106,32 @@ class NetworkUtils {
                                // requestInput
                                String cloudRegion = cloudRegionId
                                String tenantId = utils.getNodeText1(requestInput, "tenant-id")
-
+                               String networkType = ""
+                               if (utils.nodeExists(requestInput, "networkModelInfo")) {
+                                       String networkModelInfo = utils.getNodeXml(requestInput, "networkModelInfo", false).replace("tag0:","").replace(":tag0","")
+                                       networkType = utils.getNodeText1(networkModelInfo, "modelName")
+                               } else {
+                                   networkType = utils.getNodeText1(queryIdResponse, "network-type")
+                               }
+                               
                                // queryIdResponse
                                String networkName = utils.getNodeText1(queryIdResponse, "network-name")
                                String networkId = utils.getNodeText1(queryIdResponse, "network-id")
-                               String networkType = utils.getNodeText1(queryIdResponse, "network-type")
-
+                               String networkTechnology = utils.getNodeText1(queryIdResponse, "network-technology")
+                               
+                               // contrailNetwork - networkTechnology = 'Contrail' vs. 'AIC_SR_IOV')
+                               String contrailNetwork = ""
+                               if (networkTechnology.contains('Contrail') || networkTechnology.contains('contrail') || networkTechnology.contains('CONTRAIL')) {
+                                       contrailNetwork = """<contrailNetwork>
+                                                              <shared>${sharedValue}</shared>
+                                                              <external>${externalValue}</external>
+                                                              ${routeCollection}
+                                                              ${policyFqdns}
+                                                              ${tableCollection}
+                                                        </contrailNetwork>"""
+                                       networkTechnology = "CONTRAIL"    // replace
+                           }
+                                                               
                                // rebuild subnets
                                String subnets = ""
                                if (utils.nodeExists(queryIdResponse, "subnets")) {
@@ -134,18 +154,12 @@ class NetworkUtils {
                                                                        <networkId>${networkId}</networkId>
                                                                        <networkName>${networkName}</networkName>
                                                                        <networkType>${networkType}</networkType>
-                                                                       <networkTechnology>CONTRAIL</networkTechnology>
+                                                                       <networkTechnology>${networkTechnology}</networkTechnology>
                                                                        <providerVlanNetwork>
                                                                                <physicalNetworkName>${physicalNetworkName}</physicalNetworkName >
                                                                                ${vlansCollection}
                                                                        </providerVlanNetwork>
-                                                                       <contrailNetwork>
-                                                                               <shared>${sharedValue}</shared>
-                                                                               <external>${externalValue}</external>
-                                                                               ${routeCollection}
-                                                                               ${policyFqdns}
-                                                                               ${tableCollection}
-                                                                       </contrailNetwork>
+                                    ${contrailNetwork}
                                                                        ${subnets}
                                                                        <skipAAI>true</skipAAI>
                                                                        <backout>${backoutOnFailure}</backout>
@@ -168,7 +182,7 @@ class NetworkUtils {
         * This method returns the string for Network request
         * V2 for Contrail 3.x will populate cloud-region data in same cloudSiteId filed
         * Network adapter will handle it properly
-        * @param requestId either 'request-id' or 'att-mso-request-id'
+        * @param requestId either 'request-id' or 'openecomp-mso-request-id'
         * @param requestInput the request in the process
         * @param queryIdResponse the response of REST AAI query by Id
         * @param routeCollection the collection
@@ -276,7 +290,7 @@ class NetworkUtils {
        def String CreateNetworkVolumeRequest(groupId, volumeName, vnfType, tenantId) {
 
                String requestPayload =
-               """<volume-group xmlns="http://org.openecomp.aai.inventory/v6">
+               """<volume-group xmlns="http://org.openecomp.mso/v6">
                                <volume-group-id>${groupId}</volume-group-id>
                                <volume-group-name>${volumeName}</volume-group-name>
                                <heat-stack-id></heat-stack-id>
@@ -296,7 +310,7 @@ class NetworkUtils {
                return requestPayload
        }
 
-       def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, tenantId, cloudRegion, namespace) {
+       def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, tenantId, cloudRegion, namespace, modelCustomizationId) {
 
                                String requestPayload =
                                """<volume-group xmlns="${namespace}">
@@ -305,6 +319,7 @@ class NetworkUtils {
                                <heat-stack-id></heat-stack-id>
                                <vnf-type>${vnfType}</vnf-type>
                                <orchestration-status>Pending</orchestration-status>
+                               <vf-module-persona-model-customization-id>${modelCustomizationId}</vf-module-persona-model-customization-id>
                                <relationship-list>
                                   <relationship>
                                           <related-to>tenant</related-to>
@@ -314,7 +329,7 @@ class NetworkUtils {
                                           </relationship-data>
                                           <relationship-data>
                                                   <relationship-key>cloud-region.cloud-owner</relationship-key>
-                                                  <relationship-value>att-aic</relationship-value>
+                                                  <relationship-value>openecomp-aic</relationship-value>
                                           </relationship-data>
                                           <relationship-data>
                                                   <relationship-key>cloud-region.cloud-region-id</relationship-key>
@@ -327,7 +342,7 @@ class NetworkUtils {
                                return requestPayload
                        }
        
-       def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace) {
+       def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId) {
                
                String requestPayload =
                """<volume-group xmlns="${namespace}">
@@ -336,6 +351,7 @@ class NetworkUtils {
                        <heat-stack-id></heat-stack-id>
                        <vnf-type>${vnfType}</vnf-type>
                        <orchestration-status>Pending</orchestration-status>
+                       <vf-module-persona-model-customization-id>${modelCustomizationId}</vf-module-persona-model-customization-id>
                        <relationship-list>
                                <relationship>
                                   <related-to>generic-vnf</related-to>
@@ -352,7 +368,7 @@ class NetworkUtils {
                                   </relationship-data>
                                   <relationship-data>
                                           <relationship-key>cloud-region.cloud-owner</relationship-key>
-                                          <relationship-value>att-aic</relationship-value>
+                                          <relationship-value>openecomp-aic</relationship-value>
                                   </relationship-data>
                                   <relationship-data>
                                           <relationship-key>cloud-region.cloud-region-id</relationship-key>
@@ -372,7 +388,7 @@ class NetworkUtils {
          * @param heatStackId the value of heat stack id
         * @return String request payload
         */
-       def String updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackId, namespace) {
+       def String updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackId, namespace, modelCustomizationId) {
                String requestPayload = ""
                if (requeryAAIVolGrpNameResponse != null) {
                        def groupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
@@ -392,6 +408,7 @@ class NetworkUtils {
                                        <vnf-type>${vnfType}</vnf-type>
                                        <orchestration-status>Active</orchestration-status>
                                        <resource-version>${resourceVersion}</resource-version>
+                                       <vf-module-persona-model-customization-id>${modelCustomizationId}</vf-module-persona-model-customization-id>
                                        ${relationshipList}
                                 </volume-group>"""
                }
@@ -419,7 +436,7 @@ class NetworkUtils {
                        }
 
                        requestPayload =
-                               """<volume-group xmlns="http://org.openecomp.aai.inventory/v6">
+                               """<volume-group xmlns="http://org.openecomp.mso/v6">
                                        <volume-group-id>${groupId}</volume-group-id>
                                        <volume-group-name>${volumeName}</volume-group-name>
                                        <heat-stack-id>${heatStackId}</heat-stack-id>
@@ -624,7 +641,7 @@ class NetworkUtils {
         *   <relationship-list>
         *      <relationship>
         *          <related-to>vpn-binding</related-to>
-        *          <related-link>https://aai-app-e2e.test.att.com:8443/aai/v6/network/vpn-bindings/vpn-binding/85f015d0-2e32-4c30-96d2-87a1a27f8017/</related-link>
+        *          <related-link>https://aai-app-e2e.test.openecomp.com:8443/aai/v6/network/vpn-bindings/vpn-binding/85f015d0-2e32-4c30-96d2-87a1a27f8017/</related-link>
         *          <relationship-data>
         *             <relationship-key>vpn-binding.vpn-id</relationship-key>
         *             <relationship-value>85f015d0-2e32-4c30-96d2-87a1a27f8017</relationship-value>
@@ -632,7 +649,7 @@ class NetworkUtils {
         *       </relationship>
         *              <relationship>
         *              <related-to>vpn-binding</related-to>
-        *                      <related-link>https://aai-ext1.test.att.com:8443/aai/v6/network/vpn-bindings/vpn-binding/24a4b507-853a-4a38-99aa-05fcc54be24d/</related-link>
+        *                      <related-link>https://aai-ext1.test.openecomp.com:8443/aai/v6/network/vpn-bindings/vpn-binding/24a4b507-853a-4a38-99aa-05fcc54be24d/</related-link>
         *                      <relationship-data>
         *                         <relationship-key>vpn-binding.vpn-id</relationship-key>
         *                         <relationship-value>24a4b507-853a-4a38-99aa-05fcc54be24d</relationship-value>
@@ -723,6 +740,59 @@ class NetworkUtils {
                return rtn
        }
        
+       /**
+        * similar to network policymethod
+       * @param xmlInput the XML document
+       * @return a list of IDs for related VNF instances
+       *
+       **/
+       def getRelatedVnfIdList(xmlInput) {
+               //def rtn = null
+               List rtn = []
+               if (xmlInput!=null) {
+                       def relationshipList = getListWithElements(xmlInput, 'relationship')
+                       def relationshipListSize = relationshipList.size()
+                       if (relationshipListSize > 0) {
+                               for (i in 0..relationshipListSize-1) {
+                                  def relationshipXml = XmlUtil.serialize(relationshipList[i])
+                                  if (utils.getNodeText(relationshipXml, 'related-to') == "generic-vnf") {
+                                         def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
+                                         if (relatedLink != null || relatedLink != "") {
+                                                rtn.add(relatedLink.substring(relatedLink.indexOf("/generic-vnf/")+13, relatedLink.length()))
+                                         }
+                                  }
+                               }
+                       }
+               }
+               return rtn
+       }
+       
+       /**
+        * similar to network policymethod
+       * @param xmlInput the XML document
+       * @return a list of IDs for related Network instances
+       *
+       **/
+       def getRelatedNetworkIdList(xmlInput) {
+               //def rtn = null
+               List rtn = []
+               if (xmlInput!=null) {
+                       def relationshipList = getListWithElements(xmlInput, 'relationship')
+                       def relationshipListSize = relationshipList.size()
+                       if (relationshipListSize > 0) {
+                               for (i in 0..relationshipListSize-1) {
+                                  def relationshipXml = XmlUtil.serialize(relationshipList[i])
+                                  if (utils.getNodeText(relationshipXml, 'related-to') == "l3-network") {
+                                         def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
+                                         if (relatedLink != null || relatedLink != "") {
+                                                rtn.add(relatedLink.substring(relatedLink.indexOf("/l3-network/")+12, relatedLink.length()))
+                                         }
+                                  }
+                               }
+                       }
+               }
+               return rtn
+       }
        
        def isVfRelationshipExist(xmlInput) {
                Boolean rtn = false
@@ -742,6 +812,52 @@ class NetworkUtils {
 
        }
 
+       def getCloudRegion(xmlInput) {
+               String lcpCloudRegion = ""
+               if (xmlInput!=null) {
+                       def relationshipList = getListWithElements(xmlInput, 'relationship')
+                       def relationshipListSize = relationshipList.size()
+                       if (relationshipListSize > 0) {
+                               for (i in 0..relationshipListSize-1) {
+                                  def relationshipXml = XmlUtil.serialize(relationshipList[i])
+                                  if (utils.getNodeText(relationshipXml, 'related-to') == "cloud-region") {
+                                         def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
+                                         if (relatedLink != null || relatedLink != "") {
+                                                lcpCloudRegion = relatedLink.substring(relatedLink.indexOf("/openecomp-aic/")+9, relatedLink.length())
+                                                if (lcpCloudRegion.contains('/')) {
+                                                        lcpCloudRegion = relatedLink.substring(relatedLink.indexOf("/openecomp-aic/")+9, relatedLink.length()-1)
+                                                }
+                                         }
+                                  }
+                               }
+                       }
+               }
+               return lcpCloudRegion
+       }
+       
+       def getTenantId(xmlInput) {
+               String tenantId = ""
+               if (xmlInput!=null) {
+                       def relationshipList = getListWithElements(xmlInput, 'relationship')
+                       def relationshipListSize = relationshipList.size()
+                       if (relationshipListSize > 0) {
+                               for (i in 0..relationshipListSize-1) {
+                                  def relationshipXml = XmlUtil.serialize(relationshipList[i])
+                                  if (utils.getNodeText(relationshipXml, 'related-to') == "tenant") {
+                                         def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
+                                         if (relatedLink != null || relatedLink != "") {
+                                                tenantId = relatedLink.substring(relatedLink.indexOf("/tenant/")+8, relatedLink.length())
+                                                if (tenantId.contains('/')) {
+                                                        tenantId = relatedLink.substring(relatedLink.indexOf("/tenant/")+8, relatedLink.length()-1)
+                                                }
+                                         }
+                                  }
+                               }
+                       }
+               }
+               return tenantId
+       }
+       
        def isInstanceValueMatch(linkResource, globalSubscriberId, serviceType) {
                Boolean rtn = false
                try {
@@ -1116,7 +1232,7 @@ class NetworkUtils {
         * Ex 2: xmlInput // no parent tag
         *   <ws:sdnc-request-header>
         *    <ws:svc-request-id>fec8ec88-151a-45c9-ad60-8233e0fc8ff2</ws:svc-request-id>
-        *    <ws:svc-notification-url>https://msojra.mtsnj.aic.cip.att.com:8443/adapters/rest/SDNCNotify</ws:svc-notification-url>
+        *    <ws:svc-notification-url>https://msojra.mtsnj.aic.cip.openecomp.com:8443/adapters/rest/SDNCNotify</ws:svc-notification-url>
         *    <ws:svc-action>assign</ws:svc-action>
         *   </ws:sdnc-request-header>
         * Usage:
@@ -1193,6 +1309,7 @@ class NetworkUtils {
 
 //TODO: This method still needs to be tested before using.
        /**
+        *
         * This method is similar to the gennetwork:ContrailNetworUpdateCompletedObject
         * BPEL method.  It extracts all of the required subnet information
         * for each subnet listed with an orch status equal to the one provided
@@ -1270,6 +1387,7 @@ class NetworkUtils {
 
 
        /**
+        *
         * This method extracts the "value" node text for the the given subnet Id.
         *
         * @param String inputSource - xml that contains the subnet id key and value
@@ -1302,8 +1420,8 @@ class NetworkUtils {
 
        public boolean isRollbackEnabled (Execution execution, String payloadXml) {
                
-               boolean rollbackEnabled = false
-               boolean rollbackValueSet = false
+               def rollbackEnabled = false
+               def rollbackValueSet = false
                if (utils.nodeExists(payloadXml, "backout-on-failure")) {
                        String backoutValue = utils.getNodeText1(payloadXml, "backout-on-failure")
                        if (backoutValue != null && !backoutValue.isEmpty()) {
@@ -1318,7 +1436,9 @@ class NetworkUtils {
                }
                
                if (!rollbackValueSet) {
-                       rollbackEnabled = execution.getVariable("URN_mso_rollback")
+                       if (execution.getVariable("URN_mso_rollback") != null) {
+                           rollbackEnabled = execution.getVariable("URN_mso_rollback").toBoolean()
+                       }   
                }
                return rollbackEnabled
        }