2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.common.scripts;
23 import org.apache.commons.lang3.*
25 import groovy.xml.XmlUtil
26 import org.onap.so.bpmn.core.UrnPropertiesReader
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
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
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
47 import org.onap.so.logger.MessageEnum
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
62 * This groovy class supports the any Network processes that need the methods defined here.
65 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NetworkUtils.class);
68 public MsoUtils utils = new MsoUtils()
69 private AbstractServiceTaskProcessor taskProcessor
71 public NetworkUtils(AbstractServiceTaskProcessor taskProcessor) {
72 this.taskProcessor = taskProcessor
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
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 = ""
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")
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") : ""
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)
112 String failIfExists = "false"
114 String cloudRegion = cloudRegionId
115 String tenantId = utils.getNodeText(requestInput, "tenant-id")
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")
124 networkType = utils.getNodeText(queryIdResponse, "network-type")
125 modelCustomizationUuid = utils.getNodeText(requestInput, "modelCustomizationId")
129 String networkName = utils.getNodeText(queryIdResponse, "network-name")
130 String networkId = utils.getNodeText(queryIdResponse, "network-id")
131 String networkTechnology = utils.getNodeText(queryIdResponse, "network-technology")
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>
142 </contrailNetwork>"""
143 networkTechnology = "CONTRAIL" // replace
148 if (utils.nodeExists(queryIdResponse, "subnets")) {
149 def subnetsGroup = utils.getNodeXml(queryIdResponse, "subnets", false)
150 subnets = buildSubnets(subnetsGroup)
153 String physicalNetworkName = ""
154 physicalNetworkName = utils.getNodeText(queryIdResponse, "physical-network-name")
156 String vlansCollection = buildVlans(queryIdResponse)
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?
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 >
173 </providerVlanNetwork>
176 <skipAAI>true</skipAAI>
177 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
178 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
181 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
182 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
184 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
185 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
186 </createNetworkRequest>
189 return createNetworkRequest
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
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 = ""
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")
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") : ""
223 String failIfExists = "false"
225 String cloudRegion = cloudRegionId
226 String tenantId = utils.getNodeText(requestInput, "tenant-id")
229 String networkName = utils.getNodeText(queryIdResponse, "network-name")
230 String networkId = utils.getNodeText(queryIdResponse, "network-id")
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")
239 networkType = utils.getNodeText(queryIdResponse, "network-type")
240 modelCustomizationUuid = utils.getNodeText(requestInput, "modelCustomizationId")
245 if (utils.nodeExists(queryIdResponse, "subnets")) {
246 def subnetsGroup = utils.getNodeXml(queryIdResponse, "subnets", false)
247 subnets = buildSubnets(subnetsGroup)
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)
256 String networkStackId = utils.getNodeText(queryIdResponse, "heat-stack-id")
257 if (networkStackId == 'null' || networkStackId == "" || networkStackId == null) {
258 networkStackId = "force_update"
261 String physicalNetworkName = utils.getNodeText(queryIdResponse, "physical-network-name")
262 String vlansCollection = buildVlans(queryIdResponse)
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>
278 </providerVlanNetwork>
280 <shared>${MsoUtils.xmlEscape(sharedValue)}</shared>
281 <external>${MsoUtils.xmlEscape(externalValue)}</external>
287 <skipAAI>true</skipAAI>
288 <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
289 <failIfExists>${MsoUtils.xmlEscape(failIfExists)}</failIfExists>
293 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
294 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
296 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
297 <notificationUrl></notificationUrl>
298 </updateNetworkRequest>""".trim()
301 return updateNetworkRequest
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
313 def String CreateNetworkVolumeRequest(groupId, volumeName, vnfType, tenantId) {
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>
324 <related-to>tenant</related-to>
326 <relationship-key>tenant.tenant-id</relationship-key>
327 <relationship-value>${MsoUtils.xmlEscape(tenantId)}</relationship-value>
333 return requestPayload
336 def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, tenantId, cloudRegion, namespace, modelCustomizationId) {
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>
348 <related-to>tenant</related-to>
350 <relationship-key>tenant.tenant-id</relationship-key>
351 <relationship-value>${MsoUtils.xmlEscape(tenantId)}</relationship-value>
354 <relationship-key>cloud-region.cloud-owner</relationship-key>
355 <relationship-value>att-aic</relationship-value>
358 <relationship-key>cloud-region.cloud-region-id</relationship-key>
359 <relationship-value>${MsoUtils.xmlEscape(cloudRegion)}</relationship-value>
365 return requestPayload
368 def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId) {
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>
380 <related-to>generic-vnf</related-to>
382 <relationship-key>generic-vnf.vnf-id</relationship-key>
383 <relationship-value>${MsoUtils.xmlEscape(vnfId)}</relationship-value>
387 <related-to>tenant</related-to>
389 <relationship-key>tenant.tenant-id</relationship-key>
390 <relationship-value>${MsoUtils.xmlEscape(tenantId)}</relationship-value>
393 <relationship-key>cloud-region.cloud-owner</relationship-key>
394 <relationship-value>att-aic</relationship-value>
397 <relationship-key>cloud-region.cloud-region-id</relationship-key>
398 <relationship-value>${MsoUtils.xmlEscape(cloudRegion)}</relationship-value>
404 return requestPayload
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
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)
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>
439 return requestPayload
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
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)
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>
473 return requestPayload
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
482 def ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion) {
484 String contrailNetworkCreatedUpdate = ""
485 if(requeryIdAAIResponse!=null && createNetworkResponse!=null) {
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","")
492 createNetworkContrailResponse = utils.getNodeXml(createNetworkResponse, "updateNetworkContrailResponse", false).replace("tag0:","").replace(":tag0","")
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)
501 def rebuildSubnetList = ""
502 if (utils.nodeExists(requeryIdAAIResponse, 'subnet')) {
503 rebuildSubnetList = buildSubnets(requeryIdAAIResponse, createNetworkResponse)
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)
513 rebuildSegmentationAssignments = buildXMLElements(requeryIdAAIResponse, "", "segmentation-assignments", elementList)
517 // rebuild 'ctag-assignments' / rebuildCtagAssignments
518 def rebuildCtagAssignmentsList = ""
519 if (utils.nodeExists(requeryIdAAIResponse, 'ctag-assignment')) {
520 rebuildCtagAssignmentsList = rebuildCtagAssignments(requeryIdAAIResponse)
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)
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)
539 contrailNetworkFQDN = ""
542 contrailNetworkCreatedUpdate =
543 """<l3-network xmlns="${schemaVersion}">
544 ${rebuildNetworkElements}
546 ${rebuildSegmentationAssignments}
547 ${rebuildCtagAssignmentsList}
549 ${contrailNetworkFQDN}
550 </l3-network>""".trim()
553 return contrailNetworkCreatedUpdate
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>
565 * @param xmlInput the XML document
566 * @param paramName the param name (ex: 'shared')
567 * @return a param value for 'shared' (ex: '1')
569 def getParameterValue(xmlInput, paramName) {
572 def xml= new XmlSlurper().parseText(xmlInput)
573 rtn= xml.'**'.find {param->param.'@name'.text() == paramName}
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>
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)
593 def getParameterName(xmlInput, paramName) {
596 def xml= new XmlSlurper().parseText(xmlInput)
598 rtn= xml.'**'.find {param->param.'@name' == paramName}.'@name'
599 } catch (Exception ex) {
603 if (rtn==null || rtn=="") {
611 * This method returns the networkParams xml string.
614 * <param name="shared">1</param>
615 * <param name="external">0</external>
621 * <external>0</external>
626 def buildParams(networkParams) {
628 def netParams = new XmlParser().parseText(networkParams)
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}>"
638 build += "</networkParams>"
641 } catch (Exception ex) {
642 println ' buildParams error - ' + ex.getMessage()
648 def getVlans(xmlInput) {
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>'
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.
668 * <relationship-list>
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>
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>
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/']
694 def getVnfBindingObject(xmlInput) {
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()))
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']
721 def getNetworkPolicyObject(xmlInput) {
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()))
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']
749 def getNetworkTableRefObject(xmlInput) {
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()))
771 * similar to network policymethod
772 * @param xmlInput the XML document
773 * @return a list of IDs for related VNF instances
776 def getRelatedVnfIdList(xmlInput) {
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))
791 rtn.add(relatedLink.substring(relatedLink.indexOf("/generic-vnf/")+13, relatedLink.length()))
802 * similar to network policymethod
803 * @param xmlInput the XML document
804 * @return a list of IDs for related Network instances
807 def getRelatedNetworkIdList(xmlInput) {
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))
822 rtn.add(relatedLink.substring(relatedLink.indexOf("/l3-network/")+12, relatedLink.length()))
832 def isVfRelationshipExist(xmlInput) {
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") {
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)
870 return lcpCloudRegion
873 def getTenantId(xmlInput) {
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)
896 def isInstanceValueMatch(linkResource, globalSubscriberId, serviceType) {
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) {
904 if (serviceTypeLink == serviceType) {
909 } catch (Exception ex) {
910 println 'Exception - ' + ex.getMessage()
916 def getListWithElements(xmlInput, groupName) {
918 if (xmlInput != null) {
919 def relationshipData = new XmlSlurper().parseText(xmlInput)
920 rtn = relationshipData.'**'.findAll {it.name() == groupName}
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')
935 if (utils.nodeExists(createNetworkContrailResponse, 'networkStackId')) {
936 replaceNetworkId = utils.getNodeText(createNetworkContrailResponse, 'networkStackId')
939 if (utils.nodeExists(l3Network, 'neutron-network-id')) {
940 replaceNeutronNetworkId = utils.getNodeText(l3Network, 'neutron-network-id')
942 if (utils.nodeExists(createNetworkContrailResponse, 'neutronNetworkId')) {
943 replaceNeutronNetworkId = utils.getNodeText(createNetworkContrailResponse, 'neutronNetworkId')
946 if (utils.nodeExists(l3Network, 'contrail-network-fqdn')) {
947 replaceContrailNetworkFqdn = utils.getNodeText(l3Network, 'contrail-network-fqdn')
949 if (utils.nodeExists(createNetworkContrailResponse, 'networkFqdn')) {
950 replaceContrailNetworkFqdn = utils.getNodeText(createNetworkContrailResponse, 'networkFqdn')
957 if (l3Network != null) {
958 for (element in networkList) {
959 def xml= new XmlSlurper().parseText(l3Network)
960 var = xml.'**'.find {it.name() == element}
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+">"
969 if (element=="heat-stack-id") {
970 if (replaceNetworkId != "") {
971 xmlNetwork += "<"+element+">"+replaceNetworkId+"</"+element+">"
974 if (element=="neutron-network-id") {
975 if (replaceNeutronNetworkId != "") {
976 xmlNetwork += "<"+element+">"+replaceNeutronNetworkId+"</"+element+">"
979 if (element=="contrail-network-fqdn") {
980 if (replaceContrailNetworkFqdn != "") {
981 xmlNetwork += "<"+element+">"+replaceContrailNetworkFqdn+"</"+element+">"
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+">"
995 xmlNetwork += "<"+element+">"+var.toString()+"</"+element+">"
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>"
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!!!
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")
1024 if (utils.nodeExists(subnetsData, 'relationship')) {
1025 rebuildingSubnets = rebuildRelationship(requeryIdAAIResponse)
1028 } catch (Exception ex) {
1031 rebuildingSubnets += "</subnets>"
1034 return rebuildingSubnets
1037 def buildSubnets(queryIdResponse) {
1038 def rebuildingSubnets = ""
1039 def subnetsData = new XmlSlurper().parseText(queryIdResponse)
1040 //rebuildingSubnets += "<subnets>"
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!!!
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, "")
1056 } catch (Exception ex) {
1059 //rebuildingSubnets += "</subnets>"
1061 return rebuildingSubnets
1065 // build subnet sub-network single elements
1066 def buildSubNetworkElements(subnetXml, createNetworkResponse, elementList, parentName) {
1069 if (parentName != "") {
1070 xmlBuild += "<"+parentName+">"
1072 if (subnetXml != null) {
1073 for (element in elementList) {
1074 def xml= new XmlSlurper().parseText(subnetXml)
1075 var = xml.'**'.find {it.name() == element}
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+">"
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>"
1091 if (element=="neutron-subnet-id") {
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)
1100 xmlBuild += "<"+element+">"+var.toString()+"</"+element+">"
1109 if (parentName != "") {
1110 xmlBuild += "</"+parentName+">"
1115 // build subnet sub-network single elements
1116 def buildSubNetworkElements(subnetXml, elementList, parentName) {
1119 if (parentName != "") {
1120 xmlBuild += "<"+parentName+">"
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>"
1132 xmlBuild += "<start>"+var.toString()+"</start>"
1135 if (element == "dhcp-end") {
1136 if (var.toString() == 'null') {
1137 xmlBuild += "<end>"+""+"</end>"
1139 xmlBuild += "<end>"+var.toString()+"</end>"
1141 xmlBuild += "</allocationPools>"
1143 if (element == "network-start-address" || element == "cidr-mask") {
1144 if (element == "network-start-address") {
1145 networkStartAddress = var.toString()
1147 if (element == "cidr-mask") {
1148 xmlBuild += "<cidr>"+networkStartAddress+"/"+var.toString()+"</cidr>"
1151 if (element == "dhcp-enabled") {
1152 xmlBuild += "<enableDHCP>"+var.toString()+"</enableDHCP>"
1154 if (element == "gateway-address") {
1155 xmlBuild += "<gatewayIp>"+var.toString()+"</gatewayIp>"
1157 if (element == "ip-version") {
1158 String ipVersion = getIpvVersion(var.toString())
1159 xmlBuild += "<ipVersion>"+ipVersion+"</ipVersion>"
1161 if (element == "subnet-id") {
1162 xmlBuild += "<subnetId>"+var.toString()+"</subnetId>"
1164 if ((element == "subnet-name") && (var != null)) {
1165 xmlBuild += "<subnetName>"+var.toString()+"</subnetName>"
1167 if ((element == "ip-assignment-direction") && (var != null)) {
1168 xmlBuild += "<addrFromStart>"+var.toString()+"</addrFromStart>"
1170 if (element == "host-routes") {
1172 if (subnetXml.contains("host-routes")) {
1173 routes = buildHostRoutes(subnetXml)
1180 if (parentName != "") {
1181 xmlBuild += "</"+parentName+">"
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 = ""
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>"
1207 if (element == "next-hop") {
1208 buildHostRoutes += "<nextHop>"+var.toString()+"</nextHop>"
1211 buildHostRoutes += "</hostRoutes>"
1214 return buildHostRoutes
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)
1235 rebuildingCtagAssignments += "</ctag-assignment>"
1237 rebuildingCtagAssignments += "</ctag-assignments>"
1239 return rebuildingCtagAssignments
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)
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)
1279 rebuildingSubnets += "</relationship>"
1281 rebuildingSubnets += "</relationship-list>"
1283 return rebuildingSubnets
1286 def buildVlans(queryIdResponse) {
1287 def rebuildingSubnets = "<vlans>"
1288 def subnetsData = new XmlSlurper().parseText(queryIdResponse)
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)
1297 String vlan = utils.getNodeText(subnetXml, "segmentation-id")
1299 rebuildingSubnets += ","
1301 rebuildingSubnets += vlan
1303 } catch (Exception ex) {
1306 //rebuildingSubnets += "</subnets>"
1307 rebuildingSubnets += "</vlans>"
1309 return rebuildingSubnets
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
1325 * <ws:key>name</ws:key>
1326 * <ws:value>Edward</ws:value>
1329 * <ws:key>age</ws:key>
1330 * <ws:value>30</ws:value>
1333 * <ws:key>age</ws:key>
1334 * <ws:value>30</ws:value>
1338 * List elementList = ["key", "value"]
1339 * String rebuild = buildXMLElements(xmlInput, "inputs", "entry", elementList)
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>
1348 * List elementList = ["svc-request-id", "svc-notification-url", "svc-action"]
1349 * String rebuild = buildXMLElements(xmlInput, "" , "sdnc-request-header", elementList) // no parent tag
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>
1355 * List elementList = ["test-id", "test-user"]
1356 * String rebuild = buildXMLElements(xmlInput, "" , "", elementList)
1359 def buildXMLElements(xmlInput, parentName, childrenName, elementList) {
1360 def varChildren = ""
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}
1373 xmlBuildUnbounded += "<"+element+">"+var.toString()+"</"+element+">" +'\n'
1376 xmlBuildUnbounded += "</"+childrenName+">" +'\n'
1379 for (element in elementList) {
1380 var = xml.'*'.find {it.name() == element}
1382 xmlBuildUnbounded += "<"+element+">"+var.toString()+"</"+element+">" +'\n'
1388 if (parentName!="") {xmlBuildUnbounded += "</"+parentName+">" +'\n'}
1389 return xmlBuildUnbounded
1392 def getFirstNodeXml(xmlInput, element){
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)
1406 nodeToSerialize = fxml.'*'.find {it.name() == element}
1407 if (nodeToSerialize!=null) {
1408 nodeAsText = XmlUtil.serialize(nodeToSerialize)
1419 //TODO: This method still needs to be tested before using.
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
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
1435 public String networkUpdateSubnetInfo(String subnetsXml, String networkResponseXml){
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)
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")){
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)
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>
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()
1484 subnets = sb.append(subnet)
1487 subnets = utils.removeXmlPreamble(subnets)
1489 String subnetsList =
1500 * This method extracts the "value" node text for the the given subnet Id.
1502 * @param String inputSource - xml that contains the subnet id key and value
1503 * @param String subnetId - for which you want the value of
1505 * @return String value - node text of node named value associated with the given subnet id
1507 public String extractNeutSubId(String inputSource, String subnetId){
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)
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()
1530 public boolean isRollbackEnabled (DelegateExecution execution, String payloadXml) {
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
1541 rollbackEnabled = true
1543 rollbackValueSet = true;
1547 if (!rollbackValueSet) {
1549 if (UrnPropertiesReader.getVariable("mso.rollback", execution) != null) {
1550 rollbackEnabled = UrnPropertiesReader.getVariable("mso.rollback", execution).toBoolean()
1553 return rollbackEnabled
1558 * This method extracts the version for the the given ip-version.
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)
1564 public String getIpvVersion (String ipvVersion) {
1568 if (ipvVersion.isNumber()) {
1569 version = ipvVersion
1571 version = ipvVersion.substring(ipvVersion.indexOf("ipv")+3)
1572 if (!version.isNumber()) {
1573 version = ipvVersion
1576 } catch (Exception ex) {
1577 version = ipvVersion