2e5499c1588dec084c2316d6b512a2882d213ab5
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / NetworkUtils.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.common.scripts;
22
23 import org.apache.commons.lang3.*
24
25 import groovy.xml.XmlUtil
26 import org.onap.so.bpmn.core.UrnPropertiesReader
27
28 import javax.xml.parsers.DocumentBuilder
29 import javax.xml.parsers.DocumentBuilderFactory
30 import javax.xml.transform.Transformer
31 import javax.xml.transform.TransformerFactory
32 import javax.xml.transform.TransformerException
33 import javax.xml.transform.dom.DOMSource
34 import javax.xml.transform.stream.StreamResult
35
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.delegate.DelegateExecution
38 import org.w3c.dom.Document
39 import org.w3c.dom.Element
40
41 import org.w3c.dom.NamedNodeMap
42 import org.w3c.dom.Node
43 import org.w3c.dom.NodeList;
44 import org.xml.sax.InputSource
45 import org.onap.so.logger.MsoLogger
46
47 import org.onap.so.logger.MessageEnum
48
49
50 import org.camunda.bpm.engine.delegate.BpmnError
51 import org.camunda.bpm.engine.delegate.DelegateExecution
52 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
53 import org.w3c.dom.Document
54 import org.w3c.dom.Element
55 import org.w3c.dom.NamedNodeMap
56 import org.w3c.dom.Node
57 import org.w3c.dom.NodeList;
58 import org.xml.sax.InputSource
59
60
61 /**
62  * This groovy class supports the any Network processes that need the methods defined here.
63  */
64 class NetworkUtils {
65         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NetworkUtils.class);
66
67
68         public MsoUtils utils = new MsoUtils()
69         private AbstractServiceTaskProcessor taskProcessor
70
71         public NetworkUtils(AbstractServiceTaskProcessor taskProcessor) {
72                 this.taskProcessor = taskProcessor
73         }
74
75         /**
76          * This method returns the string for Network request
77          * V2 for Contrail 3.x will populate cloud-region data in same cloudSiteId filed
78          * Network adapter will handle it properly
79          * @param requestId either 'request-id' or 'mso-request-id'
80          * @param requestInput the request in the process
81          * @param queryIdResponse the response of REST AAI query by Id
82          * @param routeCollection the collection
83          * @param policyFqdns the policy
84          * @param tableCollection the collection
85          * @param cloudRegionId the cloud-region-region
86          * @return String request
87          */
88         def CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyFqdns, tableCollection, cloudRegionId, backoutOnFailure, source) {
89                 String createNetworkRequest = null
90                 if(requestInput!=null && queryIdResponse!=null) {
91                                 String serviceInstanceId = ""
92                                 String sharedValue = ""
93                                 String externalValue = ""
94
95                                 if (source == "VID") {
96                                         sharedValue = utils.getNodeText(queryIdResponse, "is-shared-network") != null ? utils.getNodeText(queryIdResponse, "is-shared-network") : "false"
97                                         externalValue = utils.getNodeText(queryIdResponse, "is-external-network") != null ? utils.getNodeText(queryIdResponse, "is-external-network") : "false"
98                                         serviceInstanceId = utils.getNodeText(requestInput, "service-instance-id")
99
100                                 } else { // source = 'PORTAL'
101                                         sharedValue = getParameterValue(requestInput, "shared")
102                                         externalValue = getParameterValue(requestInput, "external")
103                                         serviceInstanceId = utils.getNodeText(requestInput, "service-instance-id") != null ? utils.getNodeText(requestInput, "service-instance-id") : ""
104                                 }
105
106                                 String networkParams = ""
107                                 if (utils.nodeExists(requestInput, "network-params")) {
108                                         String netParams = utils.getNodeXml(requestInput, "network-params", false).replace("tag0:","").replace(":tag0","")
109                                         networkParams = buildParams(netParams)
110                                 }
111
112                                 String failIfExists = "false"
113                                 // requestInput
114                                 String cloudRegion = cloudRegionId
115                                 String tenantId = utils.getNodeText(requestInput, "tenant-id")
116
117                                 String networkType = ""
118                                 String modelCustomizationUuid = ""
119                                 if (utils.nodeExists(requestInput, "networkModelInfo")) {
120                                         String networkModelInfo = utils.getNodeXml(requestInput, "networkModelInfo", false).replace("tag0:","").replace(":tag0","")
121                                         networkType = utils.getNodeText(networkModelInfo, "modelName")
122                                         modelCustomizationUuid = utils.getNodeText(networkModelInfo, "modelCustomizationUuid")
123                                 } else {
124                                         networkType = utils.getNodeText(queryIdResponse, "network-type")
125                                         modelCustomizationUuid = utils.getNodeText(requestInput, "modelCustomizationId")
126                                 }
127
128                                 // queryIdResponse
129                                 String networkName = utils.getNodeText(queryIdResponse, "network-name")
130                                 String networkId = utils.getNodeText(queryIdResponse, "network-id")
131                                 String networkTechnology = utils.getNodeText(queryIdResponse, "network-technology")
132
133                                 // contrailNetwork - networkTechnology = 'Contrail' vs. 'AIC_SR_IOV')
134                                 String contrailNetwork = ""
135                                 if (networkTechnology.contains('Contrail') || networkTechnology.contains('contrail') || networkTechnology.contains('CONTRAIL')) {
136                                         contrailNetwork = """<contrailNetwork>
137                                                                <shared>${MsoUtils.xmlEscape(sharedValue)}</shared>
138                                                                <external>${MsoUtils.xmlEscape(externalValue)}</external>
139                                                                ${routeCollection}
140                                                                ${policyFqdns}
141                                                                ${tableCollection}
142                                                          </contrailNetwork>"""
143                                         networkTechnology = "CONTRAIL"    // replace
144                             }
145
146                                 // rebuild subnets
147                                 String subnets = ""
148                                 if (utils.nodeExists(queryIdResponse, "subnets")) {
149                                         def subnetsGroup = utils.getNodeXml(queryIdResponse, "subnets", false)
150                                         subnets = buildSubnets(subnetsGroup)
151                                 }
152
153                                 String physicalNetworkName = ""
154                                 physicalNetworkName = utils.getNodeText(queryIdResponse, "physical-network-name")
155
156                                 String vlansCollection = buildVlans(queryIdResponse)
157
158                                 String notificationUrl = ""                                   //TODO - is this coming from URN? What variable/value to use?
159                                 //String notificationUrl = execution.getVariable("URN_?????") //TODO - is this coming from URN? What variable/value to use?
160
161                                 createNetworkRequest = """
162                                                                 <createNetworkRequest>
163                                                                         <cloudSiteId>${MsoUtils.xmlEscape(cloudRegion)}</cloudSiteId>
164                                                                         <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
165                                                                         <networkId>${MsoUtils.xmlEscape(networkId)}</networkId>
166                                                                         <networkName>${MsoUtils.xmlEscape(networkName)}</networkName>
167                                                                         <networkType>${MsoUtils.xmlEscape(networkType)}</networkType>
168                                                                         <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</modelCustomizationUuid>
169                                                                         <networkTechnology>${MsoUtils.xmlEscape(networkTechnology)}</networkTechnology>
170                                                                         <providerVlanNetwork>
171                                                                                 <physicalNetworkName>${MsoUtils.xmlEscape(physicalNetworkName)}</physicalNetworkName >
172                                                                                 ${vlansCollection}
173                                                                         </providerVlanNetwork>
174                                     ${contrailNetwork}
175                                                                         ${subnets}
176                                                                         <skipAAI>true</skipAAI>
177                                                                         <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
178                                                                         <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
179                                                                         ${networkParams}
180                                                                         <msoRequest>
181                                                                                 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
182                                                                                 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
183                                                                 </msoRequest>
184                                                                         <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
185                                                                         <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
186                                                                 </createNetworkRequest>
187                                                                 """.trim()
188                 }
189                 return createNetworkRequest
190
191         }
192
193         /**
194          * This method returns the string for Network request
195          * V2 for Contrail 3.x will populate cloud-region data in same cloudSiteId filed
196          * Network adapter will handle it properly
197          * @param requestId either 'request-id' or 'mso-request-id'
198          * @param requestInput the request in the process
199          * @param queryIdResponse the response of REST AAI query by Id
200          * @param routeCollection the collection
201          * @param policyFqdns the policy
202          * @param cloudRegionId the cloud-region-region
203          * @return String request
204          */
205         def UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyFqdns, tableCollection, cloudRegionId, backoutOnFailure, source) {
206                 String updateNetworkRequest = null
207                 if(requestInput!=null && queryIdResponse!=null) {
208                                 String serviceInstanceId = ""
209                                 String sharedValue = ""
210                                 String externalValue = ""
211
212                                 if (source == "VID") {
213                                         sharedValue = utils.getNodeText(queryIdResponse, "is-shared-network") != null ? utils.getNodeText(queryIdResponse, "is-shared-network") : "false"
214                                         externalValue = utils.getNodeText(queryIdResponse, "is-external-network") != null ? utils.getNodeText(queryIdResponse, "is-external-network") : "false"
215                                         serviceInstanceId = utils.getNodeText(requestInput, "service-instance-id")
216
217                                 } else { // source = 'PORTAL'
218                                         sharedValue = getParameterValue(requestInput, "shared")
219                                         externalValue = getParameterValue(requestInput, "external")
220                                         serviceInstanceId = utils.getNodeText(requestInput, "service-instance-id") != null ? utils.getNodeText(requestInput, "service-instance-id") : ""
221                                 }
222
223                                 String failIfExists = "false"
224                                 // requestInput
225                                 String cloudRegion = cloudRegionId
226                                 String tenantId = utils.getNodeText(requestInput, "tenant-id")
227
228                                 // queryIdResponse
229                                 String networkName = utils.getNodeText(queryIdResponse, "network-name")
230                                 String networkId = utils.getNodeText(queryIdResponse, "network-id")
231                                 
232                                 String networkType = ""
233                                 String modelCustomizationUuid = ""
234                                 if (utils.nodeExists(requestInput, "networkModelInfo")) {
235                                         String networkModelInfo = utils.getNodeXml(requestInput, "networkModelInfo", false).replace("tag0:","").replace(":tag0","")
236                                         networkType = utils.getNodeText(networkModelInfo, "modelName")
237                                         modelCustomizationUuid = utils.getNodeText(networkModelInfo, "modelCustomizationUuid")
238                                 } else {
239                                         networkType = utils.getNodeText(queryIdResponse, "network-type")
240                                         modelCustomizationUuid = utils.getNodeText(requestInput, "modelCustomizationId")
241                                 }
242
243                                 // rebuild subnets
244                                 String subnets = ""
245                                 if (utils.nodeExists(queryIdResponse, "subnets")) {
246                                         def subnetsGroup = utils.getNodeXml(queryIdResponse, "subnets", false)
247                                         subnets = buildSubnets(subnetsGroup)
248                                 }
249
250                                 String networkParams = ""
251                                 if (utils.nodeExists(requestInput, "network-params")) {
252                                         String netParams = utils.getNodeXml(requestInput, "network-params", false).replace("tag0:","").replace(":tag0","")
253                                         networkParams = buildParams(netParams)
254                                 }
255
256                                 String networkStackId = utils.getNodeText(queryIdResponse, "heat-stack-id")
257                                 if (networkStackId == 'null' || networkStackId == "" || networkStackId == null) {
258                                         networkStackId = "force_update"
259                                 }
260
261                                 String physicalNetworkName = utils.getNodeText(queryIdResponse, "physical-network-name")
262                                 String vlansCollection = buildVlans(queryIdResponse)
263
264                                 updateNetworkRequest =
265                          """<updateNetworkRequest>
266                                                                 <cloudSiteId>${MsoUtils.xmlEscape(cloudRegion)}</cloudSiteId>
267                                                                 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
268                                                                 <networkId>${MsoUtils.xmlEscape(networkId)}</networkId>
269                                                         <networkStackId>${MsoUtils.xmlEscape(networkStackId)}</networkStackId>
270                                                                 <networkName>${MsoUtils.xmlEscape(networkName)}</networkName>
271                                                                 <networkType>${MsoUtils.xmlEscape(networkType)}</networkType>
272                                                                 <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</modelCustomizationUuid>
273                                                                 <networkTypeVersion/>
274                                                                 <networkTechnology>CONTRAIL</networkTechnology>
275                                                                 <providerVlanNetwork>
276                                                                         <physicalNetworkName>${MsoUtils.xmlEscape(physicalNetworkName)}</physicalNetworkName>
277                                                                         ${vlansCollection}
278                                                                 </providerVlanNetwork>
279                                                                 <contrailNetwork>
280                                                                         <shared>${MsoUtils.xmlEscape(sharedValue)}</shared>
281                                                                         <external>${MsoUtils.xmlEscape(externalValue)}</external>
282                                                                         ${routeCollection}
283                                                                         ${policyFqdns}
284                                                                         ${tableCollection}
285                                                                 </contrailNetwork>
286                                                                 ${subnets}
287                                                                 <skipAAI>true</skipAAI>
288                                                                 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
289                                                                 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
290                                                                         ${networkParams}
291
292                                                                 <msoRequest>
293                                                                   <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
294                                                                   <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
295                                                                 </msoRequest>
296                                                                 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
297                                                                 <notificationUrl></notificationUrl>
298                                                         </updateNetworkRequest>""".trim()
299
300                 }
301                 return updateNetworkRequest
302
303         }
304
305         /**
306          * This method returns the string for Create Volume Request payload
307          * @param groupId the volume-group-id
308          * @param volumeName the volume-group-name
309          * @param vnfType the vnf-type
310          * @param tenantId the value of relationship-key 'tenant.tenant-id'
311          * @return String request payload
312          */
313         def String CreateNetworkVolumeRequest(groupId, volumeName, vnfType, tenantId) {
314
315                 String requestPayload =
316                 """<volume-group xmlns="http://org.onap.so/v6">
317                                 <volume-group-id>${MsoUtils.xmlEscape(groupId)}</volume-group-id>
318                                 <volume-group-name>${MsoUtils.xmlEscape(volumeName)}</volume-group-name>
319                                 <heat-stack-id></heat-stack-id>
320                                 <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
321                                 <orchestration-status>Pending</orchestration-status>
322                                 <relationship-list>
323                                    <relationship>
324                                            <related-to>tenant</related-to>
325                                            <relationship-data>
326                                                    <relationship-key>tenant.tenant-id</relationship-key>
327                                                    <relationship-value>${MsoUtils.xmlEscape(tenantId)}</relationship-value>
328                                            </relationship-data>
329                                    </relationship>
330                            </relationship-list>
331                    </volume-group>"""
332
333                 return requestPayload
334         }
335
336         def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, tenantId, cloudRegion, namespace, modelCustomizationId) {
337
338                                 String requestPayload =
339                                 """<volume-group xmlns="${namespace}">
340                                 <volume-group-id>${MsoUtils.xmlEscape(groupId)}</volume-group-id>
341                                 <volume-group-name>${MsoUtils.xmlEscape(volumeName)}</volume-group-name>
342                                 <heat-stack-id></heat-stack-id>
343                                 <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
344                                 <orchestration-status>Pending</orchestration-status>
345                                 <vf-module-model-customization-id>${MsoUtils.xmlEscape(modelCustomizationId)}</vf-module-model-customization-id>
346                                 <relationship-list>
347                                    <relationship>
348                                            <related-to>tenant</related-to>
349                                            <relationship-data>
350                                                    <relationship-key>tenant.tenant-id</relationship-key>
351                                                    <relationship-value>${MsoUtils.xmlEscape(tenantId)}</relationship-value>
352                                            </relationship-data>
353                                            <relationship-data>
354                                                    <relationship-key>cloud-region.cloud-owner</relationship-key>
355                                                    <relationship-value>att-aic</relationship-value>
356                                            </relationship-data>
357                                            <relationship-data>
358                                                    <relationship-key>cloud-region.cloud-region-id</relationship-key>
359                                                    <relationship-value>${MsoUtils.xmlEscape(cloudRegion)}</relationship-value>
360                                            </relationship-data>
361                                    </relationship>
362                            </relationship-list>
363                    </volume-group>"""
364
365                                 return requestPayload
366                         }
367
368         def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId) {
369
370                 String requestPayload =
371                 """<volume-group xmlns="${namespace}">
372                         <volume-group-id>${MsoUtils.xmlEscape(groupId)}</volume-group-id>
373                         <volume-group-name>${MsoUtils.xmlEscape(volumeName)}</volume-group-name>
374                         <heat-stack-id></heat-stack-id>
375                         <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
376                         <orchestration-status>Pending</orchestration-status>
377                         <vf-module-model-customization-id>${MsoUtils.xmlEscape(modelCustomizationId)}</vf-module-model-customization-id>
378                         <relationship-list>
379                                 <relationship>
380                                    <related-to>generic-vnf</related-to>
381                                    <relationship-data>
382                                            <relationship-key>generic-vnf.vnf-id</relationship-key>
383                                            <relationship-value>${MsoUtils.xmlEscape(vnfId)}</relationship-value>
384                                    </relationship-data>
385                            </relationship>
386                            <relationship>
387                                    <related-to>tenant</related-to>
388                                    <relationship-data>
389                                            <relationship-key>tenant.tenant-id</relationship-key>
390                                            <relationship-value>${MsoUtils.xmlEscape(tenantId)}</relationship-value>
391                                    </relationship-data>
392                                    <relationship-data>
393                                            <relationship-key>cloud-region.cloud-owner</relationship-key>
394                                            <relationship-value>att-aic</relationship-value>
395                                    </relationship-data>
396                                    <relationship-data>
397                                            <relationship-key>cloud-region.cloud-region-id</relationship-key>
398                                            <relationship-value>${MsoUtils.xmlEscape(cloudRegion)}</relationship-value>
399                                    </relationship-data>
400                            </relationship>
401                    </relationship-list>
402                 </volume-group>"""
403
404                 return requestPayload
405         }
406
407
408         /**
409          * This method returns the string for Update Volume Request payload
410          * @param requeryAAIVolGrpNameResponse the response of query volume group name (in AAI)
411           * @param heatStackId the value of heat stack id
412          * @return String request payload
413          */
414         def String updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackId, namespace, modelCustomizationId) {
415                 String requestPayload = ""
416                 if (requeryAAIVolGrpNameResponse != null) {
417                         def groupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
418                         def volumeName = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-name")
419                         def vnfType = utils.getNodeText(requeryAAIVolGrpNameResponse, "vnf-type")
420                         def resourceVersion = utils.getNodeText(requeryAAIVolGrpNameResponse, "resource-version")
421                         def relationshipList = ""
422                         if (utils.nodeExists(requeryAAIVolGrpNameResponse, "relationship")) {
423                                 relationshipList = rebuildRelationship(requeryAAIVolGrpNameResponse)
424                         }
425
426                         requestPayload =
427                                 """<volume-group xmlns="${namespace}">
428                                         <volume-group-id>${MsoUtils.xmlEscape(groupId)}</volume-group-id>
429                                         <volume-group-name>${MsoUtils.xmlEscape(volumeName)}</volume-group-name>
430                                         <heat-stack-id>${MsoUtils.xmlEscape(heatStackId)}</heat-stack-id>
431                                         <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
432                                         <orchestration-status>Active</orchestration-status>
433                                         <resource-version>${MsoUtils.xmlEscape(resourceVersion)}</resource-version>
434                                         <vf-module-model-customization-id>${MsoUtils.xmlEscape(modelCustomizationId)}</vf-module-model-customization-id>
435                                         ${relationshipList}
436                                  </volume-group>"""
437                 }
438
439                 return requestPayload
440         }
441
442
443         /**
444          * This method returns the string for Update Volume Request payload
445          * @param requeryAAIVolGrpNameResponse the response of query volume group name (in AAI)
446          * @param heatStackId the value of heat stack id
447          * @return String request payload
448          */
449         def String UpdateNetworkVolumeRequest(requeryAAIVolGrpNameResponse, heatStackId) {
450                 String requestPayload = ""
451                 if (requeryAAIVolGrpNameResponse != null) {
452                         def groupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
453                         def volumeName = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-name")
454                         def vnfType = utils.getNodeText(requeryAAIVolGrpNameResponse, "vnf-type")
455                         def resourceVersion = utils.getNodeText(requeryAAIVolGrpNameResponse, "resource-version")
456                         def relationshipList = ""
457                         if (utils.nodeExists(requeryAAIVolGrpNameResponse, "relationship")) {
458                                 relationshipList = rebuildRelationship(requeryAAIVolGrpNameResponse)
459                         }
460
461                         requestPayload =
462                                 """<volume-group xmlns="http://org.onap.so/v6">
463                                         <volume-group-id>${MsoUtils.xmlEscape(groupId)}</volume-group-id>
464                                         <volume-group-name>${MsoUtils.xmlEscape(volumeName)}</volume-group-name>
465                                         <heat-stack-id>${MsoUtils.xmlEscape(heatStackId)}</heat-stack-id>
466                                         <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
467                                         <orchestration-status>Active</orchestration-status>
468                                         <resource-version>${MsoUtils.xmlEscape(resourceVersion)}</resource-version>
469                                         ${relationshipList}
470                                  </volume-group>"""
471                 }
472
473                 return requestPayload
474         }
475
476         /**
477          * This method returns the string for Create Contrail Network payload
478          * @param requeryIdAAIResponse the response from AAI query by id
479          * @param createNetworkResponse the response of create network
480          * @return String contrailNetworkCreatedUpdate
481          */
482         def ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion) {
483
484                 String contrailNetworkCreatedUpdate = ""
485                 if(requeryIdAAIResponse!=null && createNetworkResponse!=null) {
486
487                         def l3Network = utils.getNodeXml(requeryIdAAIResponse, "l3-network", false).replace("tag0:","").replace(":tag0","")
488                         def createNetworkContrailResponse = ""
489                         if (utils.nodeExists(createNetworkResponse, 'createNetworkResponse')) {
490                            createNetworkContrailResponse = utils.getNodeXml(createNetworkResponse, "createNetworkResponse", false).replace("tag0:","").replace(":tag0","")
491                         } else {
492                            createNetworkContrailResponse = utils.getNodeXml(createNetworkResponse, "updateNetworkContrailResponse", false).replace("tag0:","").replace(":tag0","")
493                         }
494
495                         // rebuild network
496                         def networkList = ["network-id", "network-name", "network-type", "network-role", "network-technology", "neutron-network-id", "is-bound-to-vpn", "service-id", "network-role-instance", "resource-version", "resource-model-uuid", "orchestration-status", "heat-stack-id", "mso-catalog-key", "contrail-network-fqdn",
497                                                              "physical-network-name", "is-provider-network", "is-shared-network", "is-external-network"]
498                         String rebuildNetworkElements = buildNetworkElements(l3Network, createNetworkContrailResponse, networkList)
499
500                         // rebuild 'subnets'
501                         def rebuildSubnetList = ""
502                         if (utils.nodeExists(requeryIdAAIResponse, 'subnet')) {
503                              rebuildSubnetList = buildSubnets(requeryIdAAIResponse, createNetworkResponse)
504                         }
505
506                         // rebuild 'segmentation-assignments'
507                         def rebuildSegmentationAssignments = ""
508                         if (utils.nodeExists(requeryIdAAIResponse, 'segmentation-assignments')) {
509                                 List elementList = ["segmentation-id", "resource-version"]
510                                 if (utils.nodeExists(requeryIdAAIResponse, 'segmentation-assignment')) {  // new tag
511                                     rebuildSegmentationAssignments =  buildXMLElements(requeryIdAAIResponse, "segmentation-assignments", "segmentation-assignment", elementList)
512                                 } else {
513                                    rebuildSegmentationAssignments =  buildXMLElements(requeryIdAAIResponse, "", "segmentation-assignments", elementList)
514                                 }   
515                         }
516
517                         // rebuild 'ctag-assignments' / rebuildCtagAssignments
518                         def rebuildCtagAssignmentsList = ""
519                         if (utils.nodeExists(requeryIdAAIResponse, 'ctag-assignment')) {
520                                 rebuildCtagAssignmentsList = rebuildCtagAssignments(requeryIdAAIResponse)
521                         }
522
523                         // rebuild 'relationship'
524                         def relationshipList = ""
525                         if (utils.nodeExists(requeryIdAAIResponse, 'relationship-list')) {
526                                 String rootRelationshipData = getFirstNodeXml(requeryIdAAIResponse, "relationship-list").drop(38).trim().replace("tag0:","").replace(":tag0","")
527                                 if (utils.nodeExists(rootRelationshipData, 'relationship')) {
528                                         relationshipList = rebuildRelationship(rootRelationshipData)
529                                 }
530                         }
531
532                         //Check for optional contrail network fqdn within CreateNetworkResponse
533                         String contrailNetworkFQDN
534                         if(utils.nodeExists(createNetworkResponse, "contrail-network-fqdn")){
535                                 contrailNetworkFQDN = utils.getNodeXml(createNetworkResponse, "contrail-network-fqdn")
536                                 contrailNetworkFQDN = utils.removeXmlNamespaces(contrailNetworkFQDN)
537                                 contrailNetworkFQDN = utils.removeXmlPreamble(contrailNetworkFQDN)
538                         }else{
539                                 contrailNetworkFQDN = ""
540                         }
541
542                         contrailNetworkCreatedUpdate =
543                                  """<l3-network xmlns="${schemaVersion}">
544                                                 ${rebuildNetworkElements}
545                                                 ${rebuildSubnetList}
546                                                 ${rebuildSegmentationAssignments}
547                                                 ${rebuildCtagAssignmentsList}
548                                                 ${relationshipList}
549                                                 ${contrailNetworkFQDN}
550                                       </l3-network>""".trim()
551
552                 }
553                         return contrailNetworkCreatedUpdate
554         }
555
556
557
558         /**
559          * This method returns the value for the name paramName.
560          *   Ex:   <network-params>
561          *            <param name="shared">1</param>
562          *            <param name="external">0</external>
563          *         </network-params>
564          *
565          * @param xmlInput the XML document
566          * @param paramName the param name (ex: 'shared')
567          * @return a param value for 'shared' (ex: '1')
568          */
569         def getParameterValue(xmlInput, paramName) {
570                 def rtn=""
571                 if(xmlInput!=null){
572                         def xml= new XmlSlurper().parseText(xmlInput)
573                         rtn= xml.'**'.find {param->param.'@name'.text() == paramName}
574                 }
575                 if (rtn==null) {
576                         return ""
577                 } else {
578                    return rtn
579                 }
580         }
581
582         /**
583          * This method returns the name of param if found/match with paramName.
584          *   Ex:   <network-params>
585          *            <param name="shared">1</param>
586          *            <param name="external">0</external>
587          *         </network-params>
588          *
589          * @param xmlInput the XML document
590          * @param paramName the param name (ex: 'shared', )
591          * @return a param name for 'shared' (ex: 'shared' if found)
592          */
593         def getParameterName(xmlInput, paramName) {
594                 def rtn=""
595                 if(xmlInput!=null){
596                         def xml= new XmlSlurper().parseText(xmlInput)
597                         try {
598                                 rtn= xml.'**'.find {param->param.'@name' == paramName}.'@name'
599                         } catch (Exception ex) {
600                             rtn=""
601                         }
602                 }
603                 if (rtn==null || rtn=="") {
604                         return ""
605                 } else {
606                    return rtn
607                 }
608         }
609
610         /**
611          * This method returns the networkParams xml string.
612          *   Ex: input:
613          *         <network-params>
614          *            <param name="shared">1</param>
615          *            <param name="external">0</external>
616          *         </network-params>
617          *
618          *   Sample result:
619          *         <networkParams>
620      *            <shared>1</shared>
621      *            <external>0</external>
622      *         </networkParams>
623      *
624          */
625
626         def buildParams(networkParams) {
627                 def build = ""
628                         def netParams = new XmlParser().parseText(networkParams)
629                         try {
630                                 def paramsList = netParams.'**'.findAll {param->param.'@name'}.'@name'
631                                 if (paramsList.size() > 0) {
632                                         build += "<networkParams>"
633                                         for (i in 0..paramsList.size()-1) {
634                         def name = netParams.'**'.find {param->param.'@name' == paramsList[i]}.'@name'
635                                                 def value= netParams.'**'.find {param->param.'@name' == paramsList[i]}.text()
636                                                 build += "<${name}>${MsoUtils.xmlEscape(value)}</${name}>"
637                                         }
638                                         build += "</networkParams>"
639                                 }
640
641                         } catch (Exception ex) {
642                                 println ' buildParams error - ' + ex.getMessage()
643                                 build = ""
644                         }
645                 return build
646         }
647
648         def getVlans(xmlInput) {
649                 def rtn = ""
650                 if (xmlInput!=null) {
651                         def vlansList = getListWithElements(xmlInput, 'vlans')
652                         def vlansListSize = vlansList.size()
653                         if (vlansListSize > 0) {
654                                 for (i in 0..vlansListSize-1) {
655                                    rtn += '<vlans>'+vlansList[i]+'</vlans>'
656                                 }
657                         }
658                 }
659                 return rtn
660
661
662         }
663
664         /**
665          * This method returns the uri value for the vpn bindings.
666          * Return the a list of value of vpn binding in the <related-link> string.
667          * Ex.
668          *   <relationship-list>
669          *      <relationship>
670          *          <related-to>vpn-binding</related-to>
671          *          <related-link>https://aai-app-e2e.test.openecomp.com:8443/aai/v6/network/vpn-bindings/vpn-binding/85f015d0-2e32-4c30-96d2-87a1a27f8017/</related-link>
672          *          <relationship-data>
673          *             <relationship-key>vpn-binding.vpn-id</relationship-key>
674          *             <relationship-value>85f015d0-2e32-4c30-96d2-87a1a27f8017</relationship-value>
675          *          </relationship-data>
676          *       </relationship>
677          *              <relationship>
678          *              <related-to>vpn-binding</related-to>
679          *                      <related-link>https://aai-ext1.test.openecomp.com:8443/aai/v6/network/vpn-bindings/vpn-binding/24a4b507-853a-4a38-99aa-05fcc54be24d/</related-link>
680          *                      <relationship-data>
681          *                         <relationship-key>vpn-binding.vpn-id</relationship-key>
682          *                         <relationship-value>24a4b507-853a-4a38-99aa-05fcc54be24d</relationship-value>
683          *                  </relationship-data>
684          *                      <related-to-property>
685          *                        <property-key>vpn-binding.vpn-name</property-key>
686          *                        <property-value>oam_protected_net_6_MTN5_msotest1</property-value>
687          *                      </related-to-property>
688          *              </relationship>
689          * @param xmlInput the XML document
690          * @return a list of vpn binding values
691          *            ex: ['aai/v6/network/vpn-bindings/vpn-binding/85f015d0-2e32-4c30-96d2-87a1a27f8017/', 'aai/v6/network/vpn-bindings/vpn-binding/c980a6ef-3b88-49f0-9751-dbad8608d0a6/']
692          *
693          **/
694         def getVnfBindingObject(xmlInput) {
695                 //def rtn = null
696                 List rtn = []
697                 if (xmlInput!=null) {
698                         def relationshipList = getListWithElements(xmlInput, 'relationship')
699                         def relationshipListSize = relationshipList.size()
700                         if (relationshipListSize > 0) {
701                                 for (i in 0..relationshipListSize-1) {
702                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
703                                    if (utils.getNodeText(relationshipXml, 'related-to') == "vpn-binding") {
704                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
705                                           if (relatedLink != null || relatedLink != "") {
706                                                  rtn.add(relatedLink.substring(relatedLink.indexOf("/aai/"), relatedLink.length()))
707                                           }
708                                    }
709                                 }
710                         }
711                 }
712                 return rtn
713         }
714         /**
715          * similar to VNF bindings method
716         * @param xmlInput the XML document
717         * @return a list of network policy values
718         *            ex: ['aai/v$/network/network-policies/network-policy/cee6d136-e378-4678-a024-2cd15f0ee0cg', 'aai/v$/network/network-policies/network-policy/cee6d136-e378-4678-a024-2cd15f0ee0cg']
719         *
720         **/
721         def getNetworkPolicyObject(xmlInput) {
722                 //def rtn = null
723                 List rtn = []
724                 if (xmlInput!=null) {
725                         def relationshipList = getListWithElements(xmlInput, 'relationship')
726                         def relationshipListSize = relationshipList.size()
727                         if (relationshipListSize > 0) {
728                                 for (i in 0..relationshipListSize-1) {
729                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
730                                    if (utils.getNodeText(relationshipXml, 'related-to') == "network-policy") {
731                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
732                                           if (relatedLink != null || relatedLink != "") {
733                                                  rtn.add(relatedLink.substring(relatedLink.indexOf("/aai/"), relatedLink.length()))
734                                           }
735                                    }
736                                 }
737                         }
738                 }
739                 return rtn
740         }
741
742         /**
743          * similar to network policymethod
744         * @param xmlInput the XML document
745         * @return a list of network policy values
746         *            ex: ['aai/v$/network/route-table-references/route-table-reference/refFQDN1', 'aai/v$/network/route-table-references/route-table-reference/refFQDN2']
747         *
748         **/
749         def getNetworkTableRefObject(xmlInput) {
750                 //def rtn = null
751                 List rtn = []
752                 if (xmlInput!=null) {
753                         def relationshipList = getListWithElements(xmlInput, 'relationship')
754                         def relationshipListSize = relationshipList.size()
755                         if (relationshipListSize > 0) {
756                                 for (i in 0..relationshipListSize-1) {
757                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
758                                    if (utils.getNodeText(relationshipXml, 'related-to') == "route-table-reference") {
759                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
760                                           if (relatedLink != null || relatedLink != "") {
761                                                  rtn.add(relatedLink.substring(relatedLink.indexOf("/aai/"), relatedLink.length()))
762                                           }
763                                    }
764                                 }
765                         }
766                 }
767                 return rtn
768         }
769
770         /**
771          * similar to network policymethod
772         * @param xmlInput the XML document
773         * @return a list of IDs for related VNF instances
774         *
775         **/
776         def getRelatedVnfIdList(xmlInput) {
777                 //def rtn = null
778                 List rtn = []
779                 if (xmlInput!=null) {
780                         def relationshipList = getListWithElements(xmlInput, 'relationship')
781                         def relationshipListSize = relationshipList.size()
782                         if (relationshipListSize > 0) {
783                                 for (i in 0..relationshipListSize-1) {
784                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
785                                    if (utils.getNodeText(relationshipXml, 'related-to') == "generic-vnf") {
786                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
787                                           if (relatedLink != null || relatedLink != "") {
788                                                  if (relatedLink.substring(relatedLink.indexOf("/generic-vnf/")+13, relatedLink.length()).contains('/')) {
789                                                          rtn.add(relatedLink.substring(relatedLink.indexOf("/generic-vnf/")+13, relatedLink.length()-1))
790                                                  } else {
791                                                      rtn.add(relatedLink.substring(relatedLink.indexOf("/generic-vnf/")+13, relatedLink.length()))
792                                                  }
793                                           }
794                                    }
795                                 }
796                         }
797                 }
798                 return rtn
799         }
800
801         /**
802          * similar to network policymethod
803         * @param xmlInput the XML document
804         * @return a list of IDs for related Network instances
805         *
806         **/
807         def getRelatedNetworkIdList(xmlInput) {
808                 //def rtn = null
809                 List rtn = []
810                 if (xmlInput!=null) {
811                         def relationshipList = getListWithElements(xmlInput, 'relationship')
812                         def relationshipListSize = relationshipList.size()
813                         if (relationshipListSize > 0) {
814                                 for (i in 0..relationshipListSize-1) {
815                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
816                                    if (utils.getNodeText(relationshipXml, 'related-to') == "l3-network") {
817                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
818                                           if (relatedLink != null || relatedLink != "") {
819                                                  if (relatedLink.substring(relatedLink.indexOf("/l3-network/")+12, relatedLink.length()).contains('/')) {
820                                                          rtn.add(relatedLink.substring(relatedLink.indexOf("/l3-network/")+12, relatedLink.length()-1))
821                                                  } else {
822                                                      rtn.add(relatedLink.substring(relatedLink.indexOf("/l3-network/")+12, relatedLink.length()))
823                                                  }
824                                           }
825                                    }
826                                 }
827                         }
828                 }
829                 return rtn
830         }
831
832         def isVfRelationshipExist(xmlInput) {
833                 Boolean rtn = false
834                 if (xmlInput!=null) {
835                         def relationshipList = getListWithElements(xmlInput, 'relationship')
836                         def relationshipListSize = relationshipList.size()
837                         if (relationshipListSize > 0) {
838                                 for (i in 0..relationshipListSize-1) {
839                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
840                                    if (utils.getNodeText(relationshipXml, 'related-to') == "vf-module") {
841                                              rtn = true
842                                    }
843                                 }
844                         }
845                 }
846                 return rtn
847
848         }
849
850         def getCloudRegion(xmlInput) {
851                 String lcpCloudRegion = ""
852                 if (xmlInput!=null) {
853                         def relationshipList = getListWithElements(xmlInput, 'relationship')
854                         def relationshipListSize = relationshipList.size()
855                         if (relationshipListSize > 0) {
856                                 for (i in 0..relationshipListSize-1) {
857                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
858                                    if (utils.getNodeText(relationshipXml, 'related-to') == "cloud-region") {
859                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
860                                           if (relatedLink != null || relatedLink != "") {
861                                                  lcpCloudRegion = relatedLink.substring(relatedLink.indexOf("/att-aic/")+9, relatedLink.length())
862                                                  if (lcpCloudRegion.contains('/')) {
863                                                          lcpCloudRegion = relatedLink.substring(relatedLink.indexOf("/att-aic/")+9, relatedLink.length()-1)
864                                                  }
865                                           }
866                                    }
867                                 }
868                         }
869                 }
870                 return lcpCloudRegion
871         }
872
873         def getTenantId(xmlInput) {
874                 String tenantId = ""
875                 if (xmlInput!=null) {
876                         def relationshipList = getListWithElements(xmlInput, 'relationship')
877                         def relationshipListSize = relationshipList.size()
878                         if (relationshipListSize > 0) {
879                                 for (i in 0..relationshipListSize-1) {
880                                    def relationshipXml = XmlUtil.serialize(relationshipList[i])
881                                    if (utils.getNodeText(relationshipXml, 'related-to') == "tenant") {
882                                           def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
883                                           if (relatedLink != null || relatedLink != "") {
884                                                  tenantId = relatedLink.substring(relatedLink.indexOf("/tenant/")+8, relatedLink.length())
885                                                  if (tenantId.contains('/')) {
886                                                          tenantId = relatedLink.substring(relatedLink.indexOf("/tenant/")+8, relatedLink.length()-1)
887                                                  }
888                                           }
889                                    }
890                                 }
891                         }
892                 }
893                 return tenantId
894         }
895
896         def isInstanceValueMatch(linkResource, globalSubscriberId, serviceType) {
897                 Boolean rtn = false
898                 try {
899                         String globalSubscriberIdLink = linkResource.substring(linkResource.indexOf("/customer/")+10, linkResource.indexOf("/service-subscriptions"))
900                         String serviceTypeLink = linkResource.substring(linkResource.indexOf("/service-subscription/")+22, linkResource.indexOf("/service-instances"))
901                         if (globalSubscriberIdLink == globalSubscriberId) {
902                                         rtn = true
903                         } else {
904                                 if (serviceTypeLink == serviceType) {
905                                         rtn = true
906                                 }
907                         }
908
909                 } catch (Exception ex) {
910                     println 'Exception - ' + ex.getMessage()
911                         return false
912                 }
913         return rtn
914         }
915
916         def getListWithElements(xmlInput, groupName) {
917                 def rtn = ""
918                 if (xmlInput != null) {
919                         def relationshipData = new XmlSlurper().parseText(xmlInput)
920                         rtn = relationshipData.'**'.findAll {it.name() == groupName}
921                 }
922                 return rtn
923
924         }
925
926         // build network single elements
927         def buildNetworkElements(l3Network, createNetworkContrailResponse, networkList) {
928                 def replaceNetworkId = ""
929                 def replaceNeutronNetworkId = ""
930                 def replaceContrailNetworkFqdn = ""
931                 if (l3Network != null && createNetworkContrailResponse != null) {
932                         if (utils.nodeExists(l3Network, 'heat-stack-id')) {
933                                 replaceNetworkId = utils.getNodeText(l3Network, 'heat-stack-id')
934                         } else {
935                                 if (utils.nodeExists(createNetworkContrailResponse, 'networkStackId')) {
936                                         replaceNetworkId = utils.getNodeText(createNetworkContrailResponse, 'networkStackId')
937                                 }
938                         }
939                         if (utils.nodeExists(l3Network, 'neutron-network-id')) {
940                                 replaceNeutronNetworkId = utils.getNodeText(l3Network, 'neutron-network-id')
941                         } else {
942                                 if (utils.nodeExists(createNetworkContrailResponse, 'neutronNetworkId')) {
943                                         replaceNeutronNetworkId = utils.getNodeText(createNetworkContrailResponse, 'neutronNetworkId')
944                                 }
945                         }
946                         if (utils.nodeExists(l3Network, 'contrail-network-fqdn')) {
947                                 replaceContrailNetworkFqdn = utils.getNodeText(l3Network, 'contrail-network-fqdn')
948                         } else {
949                                 if (utils.nodeExists(createNetworkContrailResponse, 'networkFqdn')) {
950                                         replaceContrailNetworkFqdn = utils.getNodeText(createNetworkContrailResponse, 'networkFqdn')
951                                 }
952                         }
953                 }
954
955                 String var = ""
956                 def xmlNetwork = ""
957                 if (l3Network != null) {
958                         for (element in networkList) {
959                                 def xml= new XmlSlurper().parseText(l3Network)
960                                 var = xml.'**'.find {it.name() == element}
961                                 if (var == null) {
962                                         if (element=="orchestration-status") {
963                                                 if (var.toString() == 'pending-create' || var.toString() == 'PendingCreate') {
964                                                         xmlNetwork += "<"+element+">"+"Created"+"</"+element+">"
965                                             } else { //pending-update or PendingUpdate
966                                                         xmlNetwork += "<"+element+">"+"Active"+"</"+element+">"
967                                             }
968                                         }       
969                                         if (element=="heat-stack-id") {
970                                                 if (replaceNetworkId != "") {
971                                                         xmlNetwork += "<"+element+">"+replaceNetworkId+"</"+element+">"
972                                                 }
973                                         }
974                                         if (element=="neutron-network-id") {
975                                                 if (replaceNeutronNetworkId != "") {
976                                                         xmlNetwork += "<"+element+">"+replaceNeutronNetworkId+"</"+element+">"
977                                                 }
978                                         }
979                                         if (element=="contrail-network-fqdn") {
980                                                 if (replaceContrailNetworkFqdn != "") {
981                                                         xmlNetwork += "<"+element+">"+replaceContrailNetworkFqdn+"</"+element+">"
982                                                 }
983                                         }
984
985                                 } else {
986                                         if (element=="orchestration-status") {
987                                            if (element=="orchestration-status") {
988                                                   if (var.toString() == 'pending-create' || var.toString() == 'PendingCreate') {
989                                                       xmlNetwork += "<"+element+">"+"Created"+"</"+element+">"
990                                                   } else { //pending-update or PendingUpdate
991                                                           xmlNetwork += "<"+element+">"+"Active"+"</"+element+">"
992                                                   }
993                                            }   
994                                     } else {
995                                     xmlNetwork += "<"+element+">"+var.toString()+"</"+element+">"
996                                         }
997                                 }       
998                          }
999                 }
1000                 return xmlNetwork
1001         }
1002
1003         def buildSubnets(requeryIdAAIResponse, createNetworkResponse) {
1004                 def rebuildingSubnets = ""
1005                 if (requeryIdAAIResponse != null && utils.nodeExists(requeryIdAAIResponse, 'subnets')) {
1006                         def subnetIdMapValue = ""
1007                         def subnetsGroup = utils.getNodeXml(requeryIdAAIResponse, "subnets", false)
1008                         def subnetsData = new XmlSlurper().parseText(subnetsGroup)
1009                         rebuildingSubnets += "<subnets>"
1010                         try {
1011                                 def subnets = subnetsData.'**'.findAll {it.name() == "subnet"}
1012                                 def subnetsSize = subnets.size()
1013                                 for (i in 0..subnetsSize-1) {
1014                                    def subnet = subnets[i]
1015                                    def subnetXml = XmlUtil.serialize(subnet)
1016                                    def orchestrationStatus = utils.getNodeText(subnetXml, "orchestration-status")
1017                                    if (orchestrationStatus == "PendingDelete" || orchestrationStatus == "pending-delete") {
1018                                            // skip, do not include in processing, remove!!!
1019                                    } else {
1020                                       def subnetList = ["subnet-id", "neutron-subnet-id", "gateway-address", "network-start-address", "cidr-mask", "ip-version", "orchestration-status", "dhcp-enabled", "dhcp-start", "dhcp-end", "subnet-role", "resource-version", "subnet-name", "ip-assignment-direction", "host-routes"]
1021                                       rebuildingSubnets += buildSubNetworkElements(subnetXml, createNetworkResponse, subnetList, "subnet")
1022                                    }      
1023                                 }
1024                                 if (utils.nodeExists(subnetsData, 'relationship')) {
1025                                         rebuildingSubnets = rebuildRelationship(requeryIdAAIResponse)
1026                                 }
1027
1028                         } catch (Exception ex) {
1029                                 // error
1030                         } finally {
1031                                 rebuildingSubnets += "</subnets>"
1032                         }
1033                 }
1034                 return rebuildingSubnets
1035         }
1036
1037         def buildSubnets(queryIdResponse) {
1038                 def rebuildingSubnets = ""
1039                 def subnetsData = new XmlSlurper().parseText(queryIdResponse)
1040                 //rebuildingSubnets += "<subnets>"
1041                 try {
1042                         def subnets = subnetsData.'**'.findAll {it.name() == "subnet"}
1043                         def subnetsSize = subnets.size()
1044                         for (i in 0..subnetsSize-1) {
1045                            def subnet = subnets[i]
1046                            def subnetXml = XmlUtil.serialize(subnet)
1047                            def orchestrationStatus = utils.getNodeText(subnetXml, "orchestration-status")
1048                            if (orchestrationStatus == "pending-delete" || orchestrationStatus == "PendingDelete") {
1049                                    // skip, do not include in processing, remove!!!
1050                            } else {
1051                                         def subnetList = ["dhcp-start", "dhcp-end", "network-start-address", "cidr-mask", "dhcp-enabled", "gateway-address", "ip-version", "subnet-id", "subnet-name", "ip-assignment-direction", "host-routes"]
1052                                         rebuildingSubnets += buildSubNetworkElements(subnetXml, subnetList, "subnets")
1053                                         //rebuildingSubnets += buildSubNetworkElements(subnetXml, subnetList, "")
1054                            }    
1055                         }
1056                 } catch (Exception ex) {
1057                    //
1058                 } finally {
1059                   //rebuildingSubnets += "</subnets>"
1060                 }
1061                 return rebuildingSubnets
1062         }
1063
1064
1065         // build subnet sub-network single elements
1066         def buildSubNetworkElements(subnetXml, createNetworkResponse, elementList, parentName) {
1067                 String var = ""
1068                 def xmlBuild = ""
1069                 if (parentName != "") {
1070                    xmlBuild += "<"+parentName+">"
1071                 }
1072                 if (subnetXml != null) {
1073                         for (element in elementList) {
1074                           def xml= new XmlSlurper().parseText(subnetXml)
1075                           var = xml.'**'.find {it.name() == element}
1076                           if (var != null) {
1077                                  if (element=="orchestration-status") {
1078                                         if(var.toString() == 'pending-create' || var.toString() == 'PendingCreate') {   
1079                                                 xmlBuild += "<"+element+">"+"Created"+"</"+element+">"
1080                                         } else { // pending-update or PendingUpdate'
1081                                            xmlBuild += "<"+element+">"+"Active"+"</"+element+">"
1082                                         }
1083                                  } else { // "subnet-id", "neutron-subnet-id"
1084                                          if (element=="subnet-id") {
1085                                                  if (utils.nodeExists(createNetworkResponse, "subnetMap")) {
1086                                                          xmlBuild += "<"+element+">"+var.toString()+"</"+element+">"
1087                                                          String neutronSubnetId = extractNeutSubId(createNetworkResponse, var.toString())
1088                                                          xmlBuild += "<neutron-subnet-id>"+neutronSubnetId+"</neutron-subnet-id>"
1089                                                  }
1090                                          } else {
1091                                              if (element=="neutron-subnet-id") {
1092                                // skip
1093                                                  } else {
1094                                                          if (element=="host-routes") {
1095                                                                  if (subnetXml.contains("host-routes")) {
1096                                                                          List elementRoute = ["host-route-id", "route-prefix", "next-hop", "next-hop-type", "resource-version"]
1097                                                                          xmlBuild += buildXMLElements(subnetXml, "host-routes", "host-route", elementRoute)
1098                                                                  }
1099                                                          } else {         
1100                                                                 xmlBuild += "<"+element+">"+var.toString()+"</"+element+">"
1101                                                          }        
1102                                                  }
1103                                          }
1104                                  }
1105                           }
1106                         }
1107
1108                 }
1109                 if (parentName != "") {
1110                    xmlBuild += "</"+parentName+">"
1111                 }
1112                 return xmlBuild
1113         }
1114
1115         // build subnet sub-network single elements
1116         def buildSubNetworkElements(subnetXml, elementList, parentName) {
1117                 def var = ""
1118                 def xmlBuild = ""
1119                 if (parentName != "") {
1120                         xmlBuild += "<"+parentName+">"
1121                  }
1122                 if (subnetXml != null) {
1123                     def networkStartAddress = ""
1124                         for (element in elementList) {
1125                                 def xml= new XmlSlurper().parseText(subnetXml)
1126                                 var = xml.'**'.find {it.name() == element}
1127                                 if (element == "dhcp-start") {
1128                                         xmlBuild += "<allocationPools>"
1129                                         if (var.toString() == 'null') {
1130                                                 xmlBuild += "<start>"+""+"</start>"
1131                                         } else {
1132                                                 xmlBuild += "<start>"+var.toString()+"</start>"
1133                                         }
1134                                 }
1135                                 if (element == "dhcp-end") {
1136                                         if (var.toString() == 'null') {
1137                                                 xmlBuild += "<end>"+""+"</end>"
1138                                         } else {
1139                                                 xmlBuild += "<end>"+var.toString()+"</end>"
1140                                         }
1141                                         xmlBuild += "</allocationPools>"
1142                                 }
1143                                 if (element == "network-start-address" || element == "cidr-mask") {
1144                                         if (element == "network-start-address") {
1145                                                 networkStartAddress = var.toString()
1146                                         }
1147                                         if (element == "cidr-mask") {
1148                                                 xmlBuild += "<cidr>"+networkStartAddress+"/"+var.toString()+"</cidr>"
1149                                         }
1150                                 }
1151                                 if (element == "dhcp-enabled") {
1152                                         xmlBuild += "<enableDHCP>"+var.toString()+"</enableDHCP>"
1153                                 }
1154                                 if (element == "gateway-address") {
1155                                         xmlBuild += "<gatewayIp>"+var.toString()+"</gatewayIp>"
1156                                 }
1157                                 if (element == "ip-version") {
1158                                         String ipVersion = getIpvVersion(var.toString())
1159                                         xmlBuild += "<ipVersion>"+ipVersion+"</ipVersion>"
1160                                 }
1161                                 if (element == "subnet-id") {
1162                                         xmlBuild += "<subnetId>"+var.toString()+"</subnetId>"
1163                                 }
1164                                 if ((element == "subnet-name") && (var != null)) {
1165                                         xmlBuild += "<subnetName>"+var.toString()+"</subnetName>"
1166                                 }
1167                                 if ((element == "ip-assignment-direction") && (var != null)) {
1168                                         xmlBuild += "<addrFromStart>"+var.toString()+"</addrFromStart>"
1169                                 }
1170                                 if (element == "host-routes") {
1171                                         def routes = ""
1172                                         if (subnetXml.contains("host-routes")) {
1173                                                 routes = buildHostRoutes(subnetXml)
1174                                         }
1175                                         xmlBuild += routes 
1176                                 }       
1177                                 
1178                         }
1179                 }
1180                 if (parentName != "") {
1181                         xmlBuild += "</"+parentName+">"
1182                  }
1183                 return xmlBuild
1184         }
1185
1186         // rebuild host-routes
1187         def buildHostRoutes(subnetXml) {
1188                 List  routeElementList = ["host-route-id", "route-prefix", "next-hop", "next-hop-type", "resource-version"]
1189                 def hostRoutes = buildXMLElements(subnetXml, "host-routes", "host-route", routeElementList)
1190                 def buildHostRoutes = ""
1191                 def var = ""
1192                 if (hostRoutes!=null) {
1193                         def routesData = new XmlSlurper().parseText(hostRoutes)
1194                         def routes = routesData.'**'.findAll {it.name() == "host-route"}
1195                         def routesSize = routes.size()
1196                         for (i in 0..routesSize-1) {
1197                            buildHostRoutes += "<hostRoutes>"
1198                            def route = routes[i]
1199                            def routeXml = XmlUtil.serialize(route)
1200                            List  elementList = ["route-prefix", "next-hop"]
1201                            for (element in elementList) {
1202                                    def xml= new XmlSlurper().parseText(routeXml)
1203                                    var = xml.'**'.find {it.name() == element}
1204                                    if (element == "route-prefix") {
1205                                            buildHostRoutes += "<prefix>"+var.toString()+"</prefix>"
1206                                    }
1207                                    if (element == "next-hop") {
1208                                            buildHostRoutes += "<nextHop>"+var.toString()+"</nextHop>"
1209                                    }
1210                            }
1211                            buildHostRoutes += "</hostRoutes>"
1212                         }   
1213                 }               
1214                 return buildHostRoutes          
1215                 
1216         }
1217         
1218         // rebuild ctag-assignments
1219         def rebuildCtagAssignments(xmlInput) {
1220                 def rebuildingCtagAssignments = ""
1221                 if (xmlInput!=null) {
1222                         def ctagAssignmentsData = new XmlSlurper().parseText(xmlInput)
1223                         rebuildingCtagAssignments += "<ctag-assignments>"
1224                         def ctagAssignments = ctagAssignmentsData.'**'.findAll {it.name() == "ctag-assignment"}
1225                         def ctagAssignmentsSize = ctagAssignments.size()
1226                         for (i in 0..ctagAssignmentsSize-1) {
1227                                 def ctagAssignment = ctagAssignments[i]
1228                                 def ctagAssignmentXml = XmlUtil.serialize(ctagAssignment)
1229                                 rebuildingCtagAssignments += "<ctag-assignment>"
1230                                 List elementList = ["vlan-id-inner", "resource-version"]
1231                                 rebuildingCtagAssignments +=  buildXMLElements(ctagAssignmentXml, ""      , "", elementList)
1232                                 if (utils.nodeExists(ctagAssignmentXml, 'relationship')) {
1233                                         rebuildingCtagAssignments += rebuildRelationship(ctagAssignmentXml)
1234                                 }
1235                                 rebuildingCtagAssignments += "</ctag-assignment>"
1236                         }
1237                         rebuildingCtagAssignments += "</ctag-assignments>"
1238                 }
1239                 return rebuildingCtagAssignments
1240         }
1241
1242         // rebuild 'relationship-list'
1243         def rebuildRelationship(xmlInput) {
1244                 def rebuildingSubnets = ""
1245                 if (xmlInput!=null) {
1246                         def subnetsData = new XmlSlurper().parseText(xmlInput)
1247                         rebuildingSubnets += "<relationship-list>"
1248                         def relationships = subnetsData.'**'.findAll {it.name() == "relationship"}
1249                         def relationshipsSize = relationships.size()
1250                         for (i in 0..relationshipsSize-1) {
1251                                 def relationship = relationships[i]
1252                                 def relationshipXml = XmlUtil.serialize(relationship)
1253                                 rebuildingSubnets += "<relationship>"
1254                                 def relationshipList = ["related-to", "related-link"]
1255                                 rebuildingSubnets += buildSubNetworkElements(relationshipXml, "", relationshipList, "")
1256                                 if (utils.nodeExists(relationshipXml, 'relationship-data')) {
1257                                         def relationshipDataXmlData = new XmlSlurper().parseText(relationshipXml)
1258                                         def relationshipsData = relationshipDataXmlData.'**'.findAll {it.name() == "relationship-data"}
1259                                         def relationshipsDataSize = relationshipsData.size()
1260                                         for (j in 0..relationshipsDataSize-1) {
1261                                                 def relationshipData = relationshipsData[j]
1262                                                 def relationshipDataXml = XmlUtil.serialize(relationshipData)
1263                                                 def relationshipDataList =  ["relationship-key", "relationship-value"]
1264                                                 rebuildingSubnets += buildXMLElements(relationshipDataXml, "", "relationship-data", relationshipDataList)
1265                                         }
1266                                 }
1267                                 if (utils.nodeExists(relationshipXml, 'related-to-property')) {
1268                                         def relationshipDataXmlData = new XmlSlurper().parseText(relationshipXml)
1269                                         def relationshipsData = relationshipDataXmlData.'**'.findAll {it.name() == "related-to-property"}
1270                                         def relationshipsDataSize = relationshipsData.size()
1271                                         for (j in 0..relationshipsDataSize-1) {
1272                                                 def relationshipData = relationshipsData[j]
1273                                                 def relationshipDataXml = XmlUtil.serialize(relationshipData)
1274                                                 def relationshipDataList =  ["property-key", "property-value"]
1275                                                 rebuildingSubnets += buildXMLElements(relationshipDataXml, "", "related-to-property", relationshipDataList)
1276                                         }
1277                                 }
1278
1279                                 rebuildingSubnets += "</relationship>"
1280                         }
1281                         rebuildingSubnets += "</relationship-list>"
1282                 }
1283                 return rebuildingSubnets
1284         }
1285
1286         def buildVlans(queryIdResponse) {
1287                 def rebuildingSubnets = "<vlans>"
1288                 def subnetsData = new XmlSlurper().parseText(queryIdResponse)
1289
1290                 try {
1291                         def subnets = subnetsData.'**'.findAll {it.name() == "segmentation-assignments"}
1292                         def subnetsSize = subnets.size()
1293                         for (i in 0..subnetsSize-1) {
1294                            def subnet = subnets[i]
1295                            def subnetXml = XmlUtil.serialize(subnet)
1296
1297                            String vlan = utils.getNodeText(subnetXml, "segmentation-id")
1298                            if (i>0){
1299                                    rebuildingSubnets += ","
1300                            }
1301                            rebuildingSubnets += vlan
1302                         }
1303                 } catch (Exception ex) {
1304                    //
1305                 } finally {
1306                   //rebuildingSubnets += "</subnets>"
1307                 rebuildingSubnets += "</vlans>"
1308                 }
1309                 return rebuildingSubnets
1310         }
1311
1312         /* Utility code to rebuild xml/elements in a list:
1313          * rebuild xml with 1) unbounded groups of elements; or
1314          *                  2) one group of elements; or
1315          *                  3) just one or more elements (in a list as argument)
1316          * @param xmlInput the XML document
1317          * @param parentName the parent name  (ex: 'inputs')
1318          * @param childrenName the chilrendName (ex: 'entry' as unbounded/occurs>1)
1319          * @param elementList the element list of children (ex: 'key', 'value')
1320          * @return a string of rebuild xml
1321          *
1322          * Ex 1: xmlInput:
1323          *    <ws:inputs>
1324          *       <ws:entry>
1325          *          <ws:key>name</ws:key>
1326          *          <ws:value>Edward</ws:value>
1327          *       </ws:entry>
1328          *       <ws:entry>
1329          *          <ws:key>age</ws:key>
1330          *          <ws:value>30</ws:value>
1331          *       </ws:entry>
1332          *       <ws:entry>
1333          *          <ws:key>age</ws:key>
1334          *          <ws:value>30</ws:value>
1335          *       </ws:entry>
1336          *    <ws:/inputs>
1337          * Usage:
1338          * List elementList = ["key", "value"]
1339          * String rebuild =  buildXMLElements(xmlInput, "inputs", "entry", elementList)
1340          *
1341          * Ex 2: xmlInput // no parent tag
1342          *   <ws:sdnc-request-header>
1343          *    <ws:svc-request-id>fec8ec88-151a-45c9-ad60-8233e0fc8ff2</ws:svc-request-id>
1344          *    <ws:svc-notification-url>https://localhost:8443/adapters/rest/SDNCNotify</ws:svc-notification-url>
1345          *    <ws:svc-action>assign</ws:svc-action>
1346          *   </ws:sdnc-request-header>
1347          * Usage:
1348          * List elementList = ["svc-request-id", "svc-notification-url", "svc-action"]
1349          * String rebuild =  buildXMLElements(xmlInput, ""      , "sdnc-request-header", elementList)  // no parent tag
1350          *
1351          * Ex 3: xmlInput // elements one after another (with no parent & children tag)
1352          * <ws:test-id>myTestid</ws:test-id>
1353          * <ws:test-user>myUser</ws:test-user>
1354          * Usage:
1355          * List elementList = ["test-id", "test-user"]
1356          * String rebuild =  buildXMLElements(xmlInput, ""      , "", elementList)
1357          *
1358          */
1359         def buildXMLElements(xmlInput, parentName, childrenName, elementList) {
1360                 def varChildren = ""
1361                 def var = ""
1362                 def xmlBuildUnbounded = ""
1363                 if (parentName!="") {xmlBuildUnbounded += "<"+parentName+">" +'\n'}
1364                 if (xmlInput != null) {
1365                         def xml= new XmlSlurper().parseText(xmlInput)
1366                         if (childrenName!="") {
1367                                 varChildren = xml.'**'.findAll {it.name() == childrenName}
1368                                 for (i in 0..varChildren.size()-1) {
1369                                         xmlBuildUnbounded += "<"+childrenName+">" +'\n'
1370                                         for (element in elementList) {
1371                                                 var = varChildren[i].'*'.find {it.name() == element}
1372                                            if (var != null) {
1373                                                   xmlBuildUnbounded += "<"+element+">"+var.toString()+"</"+element+">" +'\n'
1374                                            }
1375                                         }
1376                                         xmlBuildUnbounded += "</"+childrenName+">" +'\n'
1377                                 }
1378                         } else {
1379                                 for (element in elementList) {
1380                                         var = xml.'*'.find {it.name() == element}
1381                                         if (var != null) {
1382                                                 xmlBuildUnbounded += "<"+element+">"+var.toString()+"</"+element+">" +'\n'
1383                                         }
1384                                 }
1385                         }
1386
1387                 }
1388                 if (parentName!="") {xmlBuildUnbounded += "</"+parentName+">" +'\n'}
1389                 return xmlBuildUnbounded
1390          }
1391
1392         def getFirstNodeXml(xmlInput, element){
1393                 def nodeAsText = ""
1394                 def nodeToSerialize =  ""
1395                 if (xmlInput != null) {
1396                         def fxml= new XmlSlurper().parseText(xmlInput)
1397                         if (utils.nodeExists(xmlInput, "payload")) {
1398                                 nodeToSerialize = fxml.'payload'.'l3-network'.'*'.find {it.name() == element}
1399                                 if (nodeToSerialize!=null) {
1400                                         nodeAsText = XmlUtil.serialize(nodeToSerialize)
1401                                 } else {
1402                                     nodeAsText = ""
1403                                 }
1404
1405                         } else {
1406                                 nodeToSerialize = fxml.'*'.find {it.name() == element}
1407                                 if (nodeToSerialize!=null) {
1408                                         nodeAsText = XmlUtil.serialize(nodeToSerialize)
1409                                 } else {
1410                                         nodeAsText = ""
1411                                 }
1412
1413                         }
1414                 }
1415                 return nodeAsText
1416
1417         }
1418
1419 //TODO: This method still needs to be tested before using.
1420         /**
1421          *
1422          * This method is similar to the gennetwork:ContrailNetworUpdateCompletedObject
1423          * BPEL method.  It extracts all of the required subnet information
1424          * for each subnet listed with an orch status equal to the one provided
1425          * and puts the corresponding infomation with the appropriate node for
1426          * updating aai. The method sets the orch status for each subnet to active
1427          *
1428          * @param subnetsXml the entire subnets xml
1429          * @param requestInput the request in the process
1430          * @param queryIdResponse the response of REST AAI query by Id
1431          * @param queryVpnBindingResponse the response of REST AAI query by vpn binding
1432          * @param routeCollection the collection of vpnBinding's 'global-route-target'
1433          * @return String request
1434          */
1435         public String networkUpdateSubnetInfo(String subnetsXml, String networkResponseXml){
1436
1437                         String subnets = ""
1438                         StringBuilder sb = new StringBuilder()
1439                         InputSource source = new InputSource(new StringReader(subnetsXml));
1440                         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1441                         docFactory.setNamespaceAware(true)
1442                         DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1443                         Document xml = docBuilder.parse(source)
1444                         NodeList nodeList = xml.getElementsByTagNameNS("*", "subnet")
1445                         for (int x = 0; x < nodeList.getLength(); x++) {
1446                                 Node node = nodeList.item(x)
1447                                 String subnet = ""
1448                                 if (node.getNodeType() == Node.ELEMENT_NODE) {
1449                                         Element eElement = (Element) node
1450                                         String subnetOrchStatus = eElement.getElementsByTagNameNS("*", "orchestration-status").item(0).getTextContent()
1451                                         if(subnetOrchStatus.equals("pending-create")){
1452
1453                                                 String subnetId = eElement.getElementsByTagNameNS("*", "subnet-id").item(0).getTextContent()
1454                                                 def netAddress = eElement.getElementsByTagNameNS("*", "network-start-address").item(0).getTextContent()
1455                                                 def mask = eElement.getElementsByTagNameNS("*", "cidr-mask").item(0).getTextContent()
1456                                                 def dhcpEnabledSubnet = eElement.getElementsByTagNameNS("*", "dhcp-enabled").item(0).getTextContent()
1457                                                 def gatewayAddress = eElement.getElementsByTagNameNS("*", "gateway-address").item(0).getTextContent()
1458                                                 def ipVersion = eElement.getElementsByTagNameNS("*", "ip-version").item(0).getTextContent()
1459                                                 def relationshipList =  eElement.getElementsByTagNameNS("*", "relationship-list").item(0).getTextContent() //TODO: test this
1460                                                 String neutronSubnetId = extractNeutSubId(networkResponseXml, subnetId)
1461                                                 subnet =
1462                                                 """<subnet>
1463                                         <subnetId>${MsoUtils.xmlEscape(subnetId)}</subnetId>
1464                                         <neutron-subnet-id>${MsoUtils.xmlEscape(neutronSubnetId)}</neutron-subnet-id>
1465                                         <gateway-address>${MsoUtils.xmlEscape(gatewayAddress)}</gateway-address>
1466                                         <network-start-address>${MsoUtils.xmlEscape(netAddress)}</network-start-address>
1467                                         <cidr-mask>${MsoUtils.xmlEscape(mask)}</cidr-mask>
1468                                         <ip-Version>${MsoUtils.xmlEscape(ipVersion)}</ip-Version>
1469                                         <orchestration-status>active</orchestration-status>
1470                                         <dhcp-enabled>${MsoUtils.xmlEscape(dhcpEnabledSubnet)}</dhcp-enabled>
1471                                         <relationship-list>${relationshipList}</relationship-list>
1472                                         </subnet>"""
1473
1474                                         }else if(subnetOrchStatus.equals("pending-delete")){
1475                                                 StringWriter writer = new StringWriter()
1476                                                 Transformer transformer = TransformerFactory.newInstance().newTransformer()
1477                                                 transformer.transform(new DOMSource(node), new StreamResult(writer))
1478                                                 subnet = writer.toString()
1479
1480                                         }else{
1481                                                 subnet = ""
1482                                         }
1483                                 }
1484                                 subnets = sb.append(subnet)
1485                         }
1486
1487                         subnets = utils.removeXmlPreamble(subnets)
1488
1489                         String subnetsList =
1490                         """<subnets>
1491                         ${subnets}
1492                         </subnets>"""
1493
1494                         return subnetsList
1495         }
1496
1497
1498         /**
1499          *
1500          * This method extracts the "value" node text for the the given subnet Id.
1501          *
1502          * @param String inputSource - xml that contains the subnet id key and value
1503          * @param String subnetId - for which you want the value of
1504
1505          * @return String value - node text of node named value associated with the given subnet id
1506          */
1507         public String extractNeutSubId(String inputSource, String subnetId){
1508
1509                                 String value = ""
1510                                 InputSource source = new InputSource(new StringReader(inputSource));
1511                                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1512                                 docFactory.setNamespaceAware(true)
1513                                 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1514                                 Document xml = docBuilder.parse(source)
1515                                 NodeList nodeList = xml.getElementsByTagNameNS("*", "entry")
1516                                 for (int x = 0; x < nodeList.getLength(); x++) {
1517                                         Node node = nodeList.item(x)
1518                                         String subnet = ""
1519                                         if (node.getNodeType() == Node.ELEMENT_NODE) {
1520                                                 Element eElement = (Element) node
1521                                                 String key = eElement.getElementsByTagNameNS("*", "key").item(0).getTextContent()
1522                                                 if(key.equals(subnetId)){
1523                                                         value = eElement.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1524                                                 }
1525                                         }
1526                                 }
1527                                 return value
1528                         }
1529
1530         public boolean isRollbackEnabled (DelegateExecution execution, String payloadXml) {
1531
1532                 def rollbackEnabled = false
1533                 def rollbackValueSet = false
1534                 if (utils.nodeExists(payloadXml, "backout-on-failure")) {
1535                         String backoutValue = utils.getNodeText(payloadXml, "backout-on-failure")
1536                         if (backoutValue != null && !backoutValue.isEmpty()) {
1537                                 if (backoutValue.equalsIgnoreCase("false")) {
1538                                         rollbackEnabled = false
1539                                 }
1540                                 else {
1541                                         rollbackEnabled = true
1542                                 }
1543                                 rollbackValueSet = true;
1544                         }
1545                 }
1546
1547                 if (!rollbackValueSet) {
1548
1549                         if (UrnPropertiesReader.getVariable("mso.rollback", execution) != null) {
1550                             rollbackEnabled = UrnPropertiesReader.getVariable("mso.rollback", execution).toBoolean()
1551                         }
1552                 }
1553                 return rollbackEnabled
1554         }
1555         
1556         
1557         /**
1558          * This method extracts the version for the the given ip-version.
1559          *
1560          * @param String ipvVersion - IP protocols version (ex: ipv4 or ipv6 or 4 or 6)
1561          * @return String version - digit version (ex: 4 or 6)
1562          */
1563         
1564         public String getIpvVersion (String ipvVersion) {
1565                 
1566                 String version = ""
1567                 try {
1568                         if (ipvVersion.isNumber()) {
1569                                 version = ipvVersion
1570                         } else {
1571                                 version = ipvVersion.substring(ipvVersion.indexOf("ipv")+3)
1572                                 if (!version.isNumber()) {
1573                                         version = ipvVersion
1574                                 }
1575                         }
1576                 } catch (Exception ex) {
1577                         version = ipvVersion  
1578                 }
1579                 return version
1580         }
1581 }