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.openecomp.mso.bpmn.common.scripts;
23 import org.apache.commons.lang3.*
25 import groovy.xml.XmlUtil
27 import javax.xml.parsers.DocumentBuilder
28 import javax.xml.parsers.DocumentBuilderFactory
29 import javax.xml.transform.Transformer
30 import javax.xml.transform.TransformerFactory
31 import javax.xml.transform.TransformerException
32 import javax.xml.transform.dom.DOMSource
33 import javax.xml.transform.stream.StreamResult
35 import org.camunda.bpm.engine.delegate.BpmnError
36 import org.camunda.bpm.engine.runtime.Execution
37 import org.w3c.dom.Document
38 import org.w3c.dom.Element
40 import org.w3c.dom.NamedNodeMap
41 import org.w3c.dom.Node
42 import org.w3c.dom.NodeList;
43 import org.xml.sax.InputSource
45 import org.camunda.bpm.engine.delegate.BpmnError
46 import org.camunda.bpm.engine.runtime.Execution
47 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
48 import org.w3c.dom.Document
49 import org.w3c.dom.Element
50 import org.w3c.dom.NamedNodeMap
51 import org.w3c.dom.Node
52 import org.w3c.dom.NodeList;
53 import org.xml.sax.InputSource
57 * This groovy class supports the any Network processes that need the methods defined here.
61 public MsoUtils utils = new MsoUtils()
62 private AbstractServiceTaskProcessor taskProcessor
64 public NetworkUtils(AbstractServiceTaskProcessor taskProcessor) {
65 this.taskProcessor = taskProcessor
69 * This method returns the string for Network request
70 * V2 for Contrail 3.x will populate cloud-region data in same cloudSiteId filed
71 * Network adapter will handle it properly
72 * @param requestId either 'request-id' or 'openecomp-mso-request-id'
73 * @param requestInput the request in the process
74 * @param queryIdResponse the response of REST AAI query by Id
75 * @param routeCollection the collection
76 * @param policyFqdns the policy
77 * @param tableCollection the collection
78 * @param cloudRegionId the cloud-region-region
79 * @return String request
81 def CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyFqdns, tableCollection, cloudRegionId, backoutOnFailure, source) {
82 String createNetworkRequest = null
83 if(requestInput!=null && queryIdResponse!=null) {
84 String serviceInstanceId = ""
85 String sharedValue = ""
86 String externalValue = ""
88 if (source == "VID") {
89 sharedValue = utils.getNodeText1(queryIdResponse, "is-shared-network") != null ? utils.getNodeText1(queryIdResponse, "is-shared-network") : "false"
90 externalValue = utils.getNodeText1(queryIdResponse, "is-external-network") != null ? utils.getNodeText1(queryIdResponse, "is-external-network") : "false"
91 serviceInstanceId = utils.getNodeText1(requestInput, "service-instance-id")
93 } else { // source = 'PORTAL'
94 sharedValue = getParameterValue(requestInput, "shared")
95 externalValue = getParameterValue(requestInput, "external")
96 serviceInstanceId = utils.getNodeText1(requestInput, "service-instance-id") != null ? utils.getNodeText1(requestInput, "service-instance-id") : ""
99 String networkParams = ""
100 if (utils.nodeExists(requestInput, "network-params")) {
101 String netParams = utils.getNodeXml(requestInput, "network-params", false).replace("tag0:","").replace(":tag0","")
102 networkParams = buildParams(netParams)
105 String failIfExists = "false"
107 String cloudRegion = cloudRegionId
108 String tenantId = utils.getNodeText1(requestInput, "tenant-id")
109 String networkType = ""
110 if (utils.nodeExists(requestInput, "networkModelInfo")) {
111 String networkModelInfo = utils.getNodeXml(requestInput, "networkModelInfo", false).replace("tag0:","").replace(":tag0","")
112 networkType = utils.getNodeText1(networkModelInfo, "modelName")
114 networkType = utils.getNodeText1(queryIdResponse, "network-type")
118 String networkName = utils.getNodeText1(queryIdResponse, "network-name")
119 String networkId = utils.getNodeText1(queryIdResponse, "network-id")
120 String networkTechnology = utils.getNodeText1(queryIdResponse, "network-technology")
122 // contrailNetwork - networkTechnology = 'Contrail' vs. 'AIC_SR_IOV')
123 String contrailNetwork = ""
124 if (networkTechnology.contains('Contrail') || networkTechnology.contains('contrail') || networkTechnology.contains('CONTRAIL')) {
125 contrailNetwork = """<contrailNetwork>
126 <shared>${sharedValue}</shared>
127 <external>${externalValue}</external>
131 </contrailNetwork>"""
132 networkTechnology = "CONTRAIL" // replace
137 if (utils.nodeExists(queryIdResponse, "subnets")) {
138 def subnetsGroup = utils.getNodeXml(queryIdResponse, "subnets", false)
139 subnets = buildSubnets(subnetsGroup)
142 String physicalNetworkName = ""
143 physicalNetworkName = utils.getNodeText1(queryIdResponse, "physical-network-name")
145 String vlansCollection = buildVlans(queryIdResponse)
147 String notificationUrl = "" //TODO - is this coming from URN? What variable/value to use?
148 //String notificationUrl = execution.getVariable("URN_?????") //TODO - is this coming from URN? What variable/value to use?
150 createNetworkRequest = """
151 <createNetworkRequest>
152 <cloudSiteId>${cloudRegion}</cloudSiteId>
153 <tenantId>${tenantId}</tenantId>
154 <networkId>${networkId}</networkId>
155 <networkName>${networkName}</networkName>
156 <networkType>${networkType}</networkType>
157 <networkTechnology>${networkTechnology}</networkTechnology>
158 <providerVlanNetwork>
159 <physicalNetworkName>${physicalNetworkName}</physicalNetworkName >
161 </providerVlanNetwork>
164 <skipAAI>true</skipAAI>
165 <backout>${backoutOnFailure}</backout>
166 <failIfExists>${failIfExists}</failIfExists>
169 <requestId>${requestId}</requestId>
170 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
172 <messageId>${messageId}</messageId>
173 <notificationUrl>${notificationUrl}</notificationUrl>
174 </createNetworkRequest>
177 return createNetworkRequest
182 * This method returns the string for Network request
183 * V2 for Contrail 3.x will populate cloud-region data in same cloudSiteId filed
184 * Network adapter will handle it properly
185 * @param requestId either 'request-id' or 'openecomp-mso-request-id'
186 * @param requestInput the request in the process
187 * @param queryIdResponse the response of REST AAI query by Id
188 * @param routeCollection the collection
189 * @param policyFqdns the policy
190 * @param cloudRegionId the cloud-region-region
191 * @return String request
193 def UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyFqdns, tableCollection, cloudRegionId, backoutOnFailure, source) {
194 String updateNetworkRequest = null
195 if(requestInput!=null && queryIdResponse!=null) {
196 String serviceInstanceId = ""
197 String sharedValue = ""
198 String externalValue = ""
200 if (source == "VID") {
201 sharedValue = utils.getNodeText1(queryIdResponse, "is-shared-network") != null ? utils.getNodeText1(queryIdResponse, "is-shared-network") : "false"
202 externalValue = utils.getNodeText1(queryIdResponse, "is-external-network") != null ? utils.getNodeText1(queryIdResponse, "is-external-network") : "false"
203 serviceInstanceId = utils.getNodeText1(requestInput, "service-instance-id")
205 } else { // source = 'PORTAL'
206 sharedValue = getParameterValue(requestInput, "shared")
207 externalValue = getParameterValue(requestInput, "external")
208 serviceInstanceId = utils.getNodeText1(requestInput, "service-instance-id") != null ? utils.getNodeText1(requestInput, "service-instance-id") : ""
211 String failIfExists = "false"
213 String cloudRegion = cloudRegionId
214 String tenantId = utils.getNodeText1(requestInput, "tenant-id")
217 String networkName = utils.getNodeText1(queryIdResponse, "network-name")
218 String networkId = utils.getNodeText1(queryIdResponse, "network-id")
219 String networkType = utils.getNodeText1(queryIdResponse, "network-type")
223 if (utils.nodeExists(queryIdResponse, "subnets")) {
224 def subnetsGroup = utils.getNodeXml(queryIdResponse, "subnets", false)
225 subnets = buildSubnets(subnetsGroup)
228 String networkParams = ""
229 if (utils.nodeExists(requestInput, "network-params")) {
230 String netParams = utils.getNodeXml(requestInput, "network-params", false).replace("tag0:","").replace(":tag0","")
231 networkParams = buildParams(netParams)
234 String networkStackId = utils.getNodeText1(queryIdResponse, "heat-stack-id")
235 if (networkStackId == 'null' || networkStackId == "" || networkStackId == null) {
236 networkStackId = "force_update"
239 String physicalNetworkName = utils.getNodeText1(queryIdResponse, "physical-network-name")
240 String vlansCollection = buildVlans(queryIdResponse)
242 updateNetworkRequest =
243 """<updateNetworkRequest>
244 <cloudSiteId>${cloudRegion}</cloudSiteId>
245 <tenantId>${tenantId}</tenantId>
246 <networkId>${networkId}</networkId>
247 <networkStackId>${networkStackId}</networkStackId>
248 <networkName>${networkName}</networkName>
249 <networkType>${networkType}</networkType>
250 <networkTypeVersion/>
251 <networkTechnology>CONTRAIL</networkTechnology>
252 <providerVlanNetwork>
253 <physicalNetworkName>${physicalNetworkName}</physicalNetworkName>
255 </providerVlanNetwork>
257 <shared>${sharedValue}</shared>
258 <external>${externalValue}</external>
264 <skipAAI>true</skipAAI>
265 <backout>${backoutOnFailure}</backout>
266 <failIfExists>${failIfExists}</failIfExists>
270 <requestId>${requestId}</requestId>
271 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
273 <messageId>${messageId}</messageId>
274 <notificationUrl></notificationUrl>
275 </updateNetworkRequest>""".trim()
278 return updateNetworkRequest
283 * This method returns the string for Create Volume Request payload
284 * @param groupId the volume-group-id
285 * @param volumeName the volume-group-name
286 * @param vnfType the vnf-type
287 * @param tenantId the value of relationship-key 'tenant.tenant-id'
288 * @return String request payload
290 def String CreateNetworkVolumeRequest(groupId, volumeName, vnfType, tenantId) {
292 String requestPayload =
293 """<volume-group xmlns="http://org.openecomp.mso/v6">
294 <volume-group-id>${groupId}</volume-group-id>
295 <volume-group-name>${volumeName}</volume-group-name>
296 <heat-stack-id></heat-stack-id>
297 <vnf-type>${vnfType}</vnf-type>
298 <orchestration-status>Pending</orchestration-status>
301 <related-to>tenant</related-to>
303 <relationship-key>tenant.tenant-id</relationship-key>
304 <relationship-value>${tenantId}</relationship-value>
310 return requestPayload
313 def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, tenantId, cloudRegion, namespace, modelCustomizationId) {
315 String requestPayload =
316 """<volume-group xmlns="${namespace}">
317 <volume-group-id>${groupId}</volume-group-id>
318 <volume-group-name>${volumeName}</volume-group-name>
319 <heat-stack-id></heat-stack-id>
320 <vnf-type>${vnfType}</vnf-type>
321 <orchestration-status>Pending</orchestration-status>
322 <vf-module-persona-model-customization-id>${modelCustomizationId}</vf-module-persona-model-customization-id>
325 <related-to>tenant</related-to>
327 <relationship-key>tenant.tenant-id</relationship-key>
328 <relationship-value>${tenantId}</relationship-value>
331 <relationship-key>cloud-region.cloud-owner</relationship-key>
332 <relationship-value>openecomp-aic</relationship-value>
335 <relationship-key>cloud-region.cloud-region-id</relationship-key>
336 <relationship-value>${cloudRegion}</relationship-value>
342 return requestPayload
345 def String createCloudRegionVolumeRequest(groupId, volumeName, vnfType, vnfId, tenantId, cloudRegion, namespace, modelCustomizationId) {
347 String requestPayload =
348 """<volume-group xmlns="${namespace}">
349 <volume-group-id>${groupId}</volume-group-id>
350 <volume-group-name>${volumeName}</volume-group-name>
351 <heat-stack-id></heat-stack-id>
352 <vnf-type>${vnfType}</vnf-type>
353 <orchestration-status>Pending</orchestration-status>
354 <vf-module-persona-model-customization-id>${modelCustomizationId}</vf-module-persona-model-customization-id>
357 <related-to>generic-vnf</related-to>
359 <relationship-key>generic-vnf.vnf-id</relationship-key>
360 <relationship-value>${vnfId}</relationship-value>
364 <related-to>tenant</related-to>
366 <relationship-key>tenant.tenant-id</relationship-key>
367 <relationship-value>${tenantId}</relationship-value>
370 <relationship-key>cloud-region.cloud-owner</relationship-key>
371 <relationship-value>openecomp-aic</relationship-value>
374 <relationship-key>cloud-region.cloud-region-id</relationship-key>
375 <relationship-value>${cloudRegion}</relationship-value>
381 return requestPayload
386 * This method returns the string for Update Volume Request payload
387 * @param requeryAAIVolGrpNameResponse the response of query volume group name (in AAI)
388 * @param heatStackId the value of heat stack id
389 * @return String request payload
391 def String updateCloudRegionVolumeRequest(requeryAAIVolGrpNameResponse, heatStackId, namespace, modelCustomizationId) {
392 String requestPayload = ""
393 if (requeryAAIVolGrpNameResponse != null) {
394 def groupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
395 def volumeName = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-name")
396 def vnfType = utils.getNodeText(requeryAAIVolGrpNameResponse, "vnf-type")
397 def resourceVersion = utils.getNodeText(requeryAAIVolGrpNameResponse, "resource-version")
398 def relationshipList = ""
399 if (utils.nodeExists(requeryAAIVolGrpNameResponse, "relationship")) {
400 relationshipList = rebuildRelationship(requeryAAIVolGrpNameResponse)
404 """<volume-group xmlns="${namespace}">
405 <volume-group-id>${groupId}</volume-group-id>
406 <volume-group-name>${volumeName}</volume-group-name>
407 <heat-stack-id>${heatStackId}</heat-stack-id>
408 <vnf-type>${vnfType}</vnf-type>
409 <orchestration-status>Active</orchestration-status>
410 <resource-version>${resourceVersion}</resource-version>
411 <vf-module-persona-model-customization-id>${modelCustomizationId}</vf-module-persona-model-customization-id>
416 return requestPayload
421 * This method returns the string for Update Volume Request payload
422 * @param requeryAAIVolGrpNameResponse the response of query volume group name (in AAI)
423 * @param heatStackId the value of heat stack id
424 * @return String request payload
426 def String UpdateNetworkVolumeRequest(requeryAAIVolGrpNameResponse, heatStackId) {
427 String requestPayload = ""
428 if (requeryAAIVolGrpNameResponse != null) {
429 def groupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id")
430 def volumeName = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-name")
431 def vnfType = utils.getNodeText(requeryAAIVolGrpNameResponse, "vnf-type")
432 def resourceVersion = utils.getNodeText(requeryAAIVolGrpNameResponse, "resource-version")
433 def relationshipList = ""
434 if (utils.nodeExists(requeryAAIVolGrpNameResponse, "relationship")) {
435 relationshipList = rebuildRelationship(requeryAAIVolGrpNameResponse)
439 """<volume-group xmlns="http://org.openecomp.mso/v6">
440 <volume-group-id>${groupId}</volume-group-id>
441 <volume-group-name>${volumeName}</volume-group-name>
442 <heat-stack-id>${heatStackId}</heat-stack-id>
443 <vnf-type>${vnfType}</vnf-type>
444 <orchestration-status>Active</orchestration-status>
445 <resource-version>${resourceVersion}</resource-version>
450 return requestPayload
454 * This method returns the string for Create Contrail Network payload
455 * @param requeryIdAAIResponse the response from AAI query by id
456 * @param createNetworkResponse the response of create network
457 * @return String contrailNetworkCreatedUpdate
459 def ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion) {
461 String contrailNetworkCreatedUpdate = ""
462 if(requeryIdAAIResponse!=null && createNetworkResponse!=null) {
464 def l3Network = utils.getNodeXml(requeryIdAAIResponse, "l3-network", false).replace("tag0:","").replace(":tag0","")
465 def createNetworkContrailResponse = ""
466 if (utils.nodeExists(createNetworkResponse, 'createNetworkResponse')) {
467 createNetworkContrailResponse = utils.getNodeXml(createNetworkResponse, "createNetworkResponse", false).replace("tag0:","").replace(":tag0","")
469 createNetworkContrailResponse = utils.getNodeXml(createNetworkResponse, "updateNetworkContrailResponse", false).replace("tag0:","").replace(":tag0","")
473 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",
474 "physical-network-name", "is-provider-network", "is-shared-network", "is-external-network"]
475 String rebuildNetworkElements = buildNetworkElements(l3Network, createNetworkContrailResponse, networkList)
478 def rebuildSubnetList = ""
479 if (utils.nodeExists(requeryIdAAIResponse, 'subnet')) {
480 rebuildSubnetList = buildSubnets(requeryIdAAIResponse, createNetworkResponse)
483 // rebuild 'segmentation-assignments'
484 def rebuildSegmentationAssignments = ""
485 if (utils.nodeExists(requeryIdAAIResponse, 'segmentation-assignments')) {
486 List elementList = ["segmentation-id"]
487 rebuildSegmentationAssignments = buildXMLElements(requeryIdAAIResponse, "", "segmentation-assignments", elementList)
490 // rebuild 'ctag-assignments' / rebuildCtagAssignments
491 def rebuildCtagAssignmentsList = ""
492 if (utils.nodeExists(requeryIdAAIResponse, 'ctag-assignment')) {
493 rebuildCtagAssignmentsList = rebuildCtagAssignments(requeryIdAAIResponse)
496 // rebuild 'relationship'
497 def relationshipList = ""
498 if (utils.nodeExists(requeryIdAAIResponse, 'relationship-list')) {
499 String rootRelationshipData = getFirstNodeXml(requeryIdAAIResponse, "relationship-list").drop(38).trim().replace("tag0:","").replace(":tag0","")
500 if (utils.nodeExists(rootRelationshipData, 'relationship')) {
501 relationshipList = rebuildRelationship(rootRelationshipData)
505 //Check for optional contrail network fqdn within CreateNetworkResponse
506 String contrailNetworkFQDN
507 if(utils.nodeExists(createNetworkResponse, "contrail-network-fqdn")){
508 contrailNetworkFQDN = utils.getNodeXml(createNetworkResponse, "contrail-network-fqdn")
509 contrailNetworkFQDN = utils.removeXmlNamespaces(contrailNetworkFQDN)
510 contrailNetworkFQDN = utils.removeXmlPreamble(contrailNetworkFQDN)
512 contrailNetworkFQDN = ""
515 contrailNetworkCreatedUpdate =
516 """<l3-network xmlns="${schemaVersion}">
517 ${rebuildNetworkElements}
519 ${rebuildSegmentationAssignments}
520 ${rebuildCtagAssignmentsList}
522 ${contrailNetworkFQDN}
523 </l3-network>""".trim()
526 return contrailNetworkCreatedUpdate
532 * This method returns the value for the name paramName.
533 * Ex: <network-params>
534 * <param name="shared">1</param>
535 * <param name="external">0</external>
538 * @param xmlInput the XML document
539 * @param paramName the param name (ex: 'shared')
540 * @return a param value for 'shared' (ex: '1')
542 def getParameterValue(xmlInput, paramName) {
545 def xml= new XmlSlurper().parseText(xmlInput)
546 rtn= xml.'**'.find {param->param.'@name'.text() == paramName}
556 * This method returns the name of param if found/match with paramName.
557 * Ex: <network-params>
558 * <param name="shared">1</param>
559 * <param name="external">0</external>
562 * @param xmlInput the XML document
563 * @param paramName the param name (ex: 'shared', )
564 * @return a param name for 'shared' (ex: 'shared' if found)
566 def getParameterName(xmlInput, paramName) {
569 def xml= new XmlSlurper().parseText(xmlInput)
571 rtn= xml.'**'.find {param->param.'@name' == paramName}.'@name'
572 } catch (Exception ex) {
576 if (rtn==null || rtn=="") {
584 * This method returns the networkParams xml string.
587 * <param name="shared">1</param>
588 * <param name="external">0</external>
594 * <external>0</external>
599 def buildParams(networkParams) {
601 def netParams = new XmlParser().parseText(networkParams)
603 def paramsList = netParams.'**'.findAll {param->param.'@name'}.'@name'
604 if (paramsList.size() > 0) {
605 build += "<networkParams>"
606 for (i in 0..paramsList.size()-1) {
607 def name = netParams.'**'.find {param->param.'@name' == paramsList[i]}.'@name'
608 def value= netParams.'**'.find {param->param.'@name' == paramsList[i]}.text()
609 build += "<${name}>${value}</${name}>"
611 build += "</networkParams>"
614 } catch (Exception ex) {
615 println ' buildParams error - ' + ex.getMessage()
621 def getVlans(xmlInput) {
623 if (xmlInput!=null) {
624 def vlansList = getListWithElements(xmlInput, 'vlans')
625 def vlansListSize = vlansList.size()
626 if (vlansListSize > 0) {
627 for (i in 0..vlansListSize-1) {
628 rtn += '<vlans>'+vlansList[i]+'</vlans>'
638 * This method returns the uri value for the vpn bindings.
639 * Return the a list of value of vpn binding in the <related-link> string.
641 * <relationship-list>
643 * <related-to>vpn-binding</related-to>
644 * <related-link>https://aai-app-e2e.test.openecomp.com:8443/aai/v6/network/vpn-bindings/vpn-binding/85f015d0-2e32-4c30-96d2-87a1a27f8017/</related-link>
645 * <relationship-data>
646 * <relationship-key>vpn-binding.vpn-id</relationship-key>
647 * <relationship-value>85f015d0-2e32-4c30-96d2-87a1a27f8017</relationship-value>
648 * </relationship-data>
651 * <related-to>vpn-binding</related-to>
652 * <related-link>https://aai-ext1.test.openecomp.com:8443/aai/v6/network/vpn-bindings/vpn-binding/24a4b507-853a-4a38-99aa-05fcc54be24d/</related-link>
653 * <relationship-data>
654 * <relationship-key>vpn-binding.vpn-id</relationship-key>
655 * <relationship-value>24a4b507-853a-4a38-99aa-05fcc54be24d</relationship-value>
656 * </relationship-data>
657 * <related-to-property>
658 * <property-key>vpn-binding.vpn-name</property-key>
659 * <property-value>oam_protected_net_6_MTN5_msotest1</property-value>
660 * </related-to-property>
662 * @param xmlInput the XML document
663 * @return a list of vpn binding values
664 * 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/']
667 def getVnfBindingObject(xmlInput) {
670 if (xmlInput!=null) {
671 def relationshipList = getListWithElements(xmlInput, 'relationship')
672 def relationshipListSize = relationshipList.size()
673 if (relationshipListSize > 0) {
674 for (i in 0..relationshipListSize-1) {
675 def relationshipXml = XmlUtil.serialize(relationshipList[i])
676 if (utils.getNodeText(relationshipXml, 'related-to') == "vpn-binding") {
677 def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
678 if (relatedLink != null || relatedLink != "") {
679 rtn.add(relatedLink.substring(relatedLink.indexOf("/aai/"), relatedLink.length()))
688 * similar to VNF bindings method
689 * @param xmlInput the XML document
690 * @return a list of network policy values
691 * 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']
694 def getNetworkPolicyObject(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') == "network-policy") {
704 def relatedLink = utils.getNodeText(relationshipXml, 'related-link')
705 if (relatedLink != null || relatedLink != "") {
706 rtn.add(relatedLink.substring(relatedLink.indexOf("/aai/"), relatedLink.length()))
716 * similar to network policymethod
717 * @param xmlInput the XML document
718 * @return a list of network policy values
719 * ex: ['aai/v$/network/route-table-references/route-table-reference/refFQDN1', 'aai/v$/network/route-table-references/route-table-reference/refFQDN2']
722 def getNetworkTableRefObject(xmlInput) {
725 if (xmlInput!=null) {
726 def relationshipList = getListWithElements(xmlInput, 'relationship')
727 def relationshipListSize = relationshipList.size()
728 if (relationshipListSize > 0) {
729 for (i in 0..relationshipListSize-1) {
730 def relationshipXml = XmlUtil.serialize(relationshipList[i])
731 if (utils.getNodeText(relationshipXml, 'related-to') == "route-table-reference") {
732 def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
733 if (relatedLink != null || relatedLink != "") {
734 rtn.add(relatedLink.substring(relatedLink.indexOf("/aai/"), relatedLink.length()))
744 * similar to network policymethod
745 * @param xmlInput the XML document
746 * @return a list of IDs for related VNF instances
749 def getRelatedVnfIdList(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') == "generic-vnf") {
759 def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
760 if (relatedLink != null || relatedLink != "") {
761 rtn.add(relatedLink.substring(relatedLink.indexOf("/generic-vnf/")+13, relatedLink.length()))
771 * similar to network policymethod
772 * @param xmlInput the XML document
773 * @return a list of IDs for related Network instances
776 def getRelatedNetworkIdList(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') == "l3-network") {
786 def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
787 if (relatedLink != null || relatedLink != "") {
788 rtn.add(relatedLink.substring(relatedLink.indexOf("/l3-network/")+12, relatedLink.length()))
797 def isVfRelationshipExist(xmlInput) {
799 if (xmlInput!=null) {
800 def relationshipList = getListWithElements(xmlInput, 'relationship')
801 def relationshipListSize = relationshipList.size()
802 if (relationshipListSize > 0) {
803 for (i in 0..relationshipListSize-1) {
804 def relationshipXml = XmlUtil.serialize(relationshipList[i])
805 if (utils.getNodeText(relationshipXml, 'related-to') == "vf-module") {
815 def getCloudRegion(xmlInput) {
816 String lcpCloudRegion = ""
817 if (xmlInput!=null) {
818 def relationshipList = getListWithElements(xmlInput, 'relationship')
819 def relationshipListSize = relationshipList.size()
820 if (relationshipListSize > 0) {
821 for (i in 0..relationshipListSize-1) {
822 def relationshipXml = XmlUtil.serialize(relationshipList[i])
823 if (utils.getNodeText(relationshipXml, 'related-to') == "cloud-region") {
824 def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
825 if (relatedLink != null || relatedLink != "") {
826 lcpCloudRegion = relatedLink.substring(relatedLink.indexOf("/openecomp-aic/")+9, relatedLink.length())
827 if (lcpCloudRegion.contains('/')) {
828 lcpCloudRegion = relatedLink.substring(relatedLink.indexOf("/openecomp-aic/")+9, relatedLink.length()-1)
835 return lcpCloudRegion
838 def getTenantId(xmlInput) {
840 if (xmlInput!=null) {
841 def relationshipList = getListWithElements(xmlInput, 'relationship')
842 def relationshipListSize = relationshipList.size()
843 if (relationshipListSize > 0) {
844 for (i in 0..relationshipListSize-1) {
845 def relationshipXml = XmlUtil.serialize(relationshipList[i])
846 if (utils.getNodeText(relationshipXml, 'related-to') == "tenant") {
847 def relatedLink = utils.getNodeText1(relationshipXml, 'related-link')
848 if (relatedLink != null || relatedLink != "") {
849 tenantId = relatedLink.substring(relatedLink.indexOf("/tenant/")+8, relatedLink.length())
850 if (tenantId.contains('/')) {
851 tenantId = relatedLink.substring(relatedLink.indexOf("/tenant/")+8, relatedLink.length()-1)
861 def isInstanceValueMatch(linkResource, globalSubscriberId, serviceType) {
864 String globalSubscriberIdLink = linkResource.substring(linkResource.indexOf("/customer/")+10, linkResource.indexOf("/service-subscriptions"))
865 String serviceTypeLink = linkResource.substring(linkResource.indexOf("/service-subscription/")+22, linkResource.indexOf("/service-instances"))
866 if (globalSubscriberIdLink == globalSubscriberId) {
869 if (serviceTypeLink == serviceType) {
874 } catch (Exception ex) {
875 println 'Exception - ' + ex.getMessage()
881 def getListWithElements(xmlInput, groupName) {
883 if (xmlInput != null) {
884 def relationshipData = new XmlSlurper().parseText(xmlInput)
885 rtn = relationshipData.'**'.findAll {it.name() == groupName}
891 // build network single elements
892 def buildNetworkElements(l3Network, createNetworkContrailResponse, networkList) {
893 def replaceNetworkId = ""
894 def replaceNeutronNetworkId = ""
895 def replaceContrailNetworkFqdn = ""
896 if (l3Network != null && createNetworkContrailResponse != null) {
897 if (utils.nodeExists(l3Network, 'heat-stack-id')) {
898 replaceNetworkId = utils.getNodeText(l3Network, 'heat-stack-id')
900 if (utils.nodeExists(createNetworkContrailResponse, 'networkStackId')) {
901 replaceNetworkId = utils.getNodeText(createNetworkContrailResponse, 'networkStackId')
904 if (utils.nodeExists(l3Network, 'neutron-network-id')) {
905 replaceNeutronNetworkId = utils.getNodeText(l3Network, 'neutron-network-id')
907 if (utils.nodeExists(createNetworkContrailResponse, 'neutronNetworkId')) {
908 replaceNeutronNetworkId = utils.getNodeText(createNetworkContrailResponse, 'neutronNetworkId')
911 if (utils.nodeExists(l3Network, 'contrail-network-fqdn')) {
912 replaceContrailNetworkFqdn = utils.getNodeText(l3Network, 'contrail-network-fqdn')
914 if (utils.nodeExists(createNetworkContrailResponse, 'networkFqdn')) {
915 replaceContrailNetworkFqdn = utils.getNodeText(createNetworkContrailResponse, 'networkFqdn')
922 if (l3Network != null) {
923 for (element in networkList) {
924 def xml= new XmlSlurper().parseText(l3Network)
925 var = xml.'**'.find {it.name() == element}
927 if (element=="orchestration-status") {
928 xmlNetwork += "<"+element+">"+"active"+"</"+element+">"
930 if (element=="heat-stack-id") {
931 if (replaceNetworkId != "") {
932 xmlNetwork += "<"+element+">"+replaceNetworkId+"</"+element+">"
935 if (element=="neutron-network-id") {
936 if (replaceNeutronNetworkId != "") {
937 xmlNetwork += "<"+element+">"+replaceNeutronNetworkId+"</"+element+">"
940 if (element=="contrail-network-fqdn") {
941 if (replaceContrailNetworkFqdn != "") {
942 xmlNetwork += "<"+element+">"+replaceContrailNetworkFqdn+"</"+element+">"
947 if (element=="orchestration-status") {
948 xmlNetwork += "<"+element+">"+"active"+"</"+element+">"
950 xmlNetwork += "<"+element+">"+var.toString()+"</"+element+">"
959 def buildSubnets(requeryIdAAIResponse, createNetworkResponse) {
960 def rebuildingSubnets = ""
961 if (requeryIdAAIResponse != null && utils.nodeExists(requeryIdAAIResponse, 'subnets')) {
962 def subnetIdMapValue = ""
963 def subnetsGroup = utils.getNodeXml(requeryIdAAIResponse, "subnets", false)
964 def subnetsData = new XmlSlurper().parseText(subnetsGroup)
965 rebuildingSubnets += "<subnets>"
967 def subnets = subnetsData.'**'.findAll {it.name() == "subnet"}
968 def subnetsSize = subnets.size()
969 for (i in 0..subnetsSize-1) {
970 def subnet = subnets[i]
971 def subnetXml = XmlUtil.serialize(subnet)
972 def subnetList = ["subnet-id", "neutron-subnet-id", "gateway-address", "network-start-address", "cidr-mask", "ip-version", "orchestration-status", "dhcp-enabled", "dhcp-start", "dhcp-end", "resource-version", "subnet-name"]
973 rebuildingSubnets += buildSubNetworkElements(subnetXml, createNetworkResponse, subnetList, "subnet")
975 if (utils.nodeExists(subnetsData, 'relationship')) {
976 rebuildingSubnets = rebuildRelationship(requeryIdAAIResponse)
979 } catch (Exception ex) {
982 rebuildingSubnets += "</subnets>"
985 return rebuildingSubnets
988 def buildSubnets(queryIdResponse) {
989 def rebuildingSubnets = ""
990 def subnetsData = new XmlSlurper().parseText(queryIdResponse)
991 //rebuildingSubnets += "<subnets>"
993 def subnets = subnetsData.'**'.findAll {it.name() == "subnet"}
994 def subnetsSize = subnets.size()
995 for (i in 0..subnetsSize-1) {
996 def subnet = subnets[i]
997 def subnetXml = XmlUtil.serialize(subnet)
998 def subnetList = ["dhcp-start", "dhcp-end", "network-start-address", "cidr-mask", "dhcp-enabled", "gateway-address", "ip-version", "subnet-id", "subnet-name"]
999 rebuildingSubnets += buildSubNetworkElements(subnetXml, subnetList, "subnets")
1000 //rebuildingSubnets += buildSubNetworkElements(subnetXml, subnetList, "")
1002 } catch (Exception ex) {
1005 //rebuildingSubnets += "</subnets>"
1007 return rebuildingSubnets
1011 // build subnet sub-network single elements
1012 def buildSubNetworkElements(subnetXml, createNetworkResponse, elementList, parentName) {
1015 if (parentName != "") {
1016 xmlBuild += "<"+parentName+">"
1018 if (subnetXml != null) {
1019 for (element in elementList) {
1020 def xml= new XmlSlurper().parseText(subnetXml)
1021 var = xml.'**'.find {it.name() == element}
1023 if (element=="orchestration-status") {
1024 xmlBuild += "<"+element+">"+"active"+"</"+element+">"
1025 } else { // "subnet-id", "neutron-subnet-id"
1026 if (element=="subnet-id") {
1027 if (utils.nodeExists(createNetworkResponse, "subnetMap")) {
1028 xmlBuild += "<"+element+">"+var.toString()+"</"+element+">"
1029 String neutronSubnetId = extractNeutSubId(createNetworkResponse, var.toString())
1030 xmlBuild += "<neutron-subnet-id>"+neutronSubnetId+"</neutron-subnet-id>"
1033 if (element=="neutron-subnet-id") {
1036 xmlBuild += "<"+element+">"+var.toString()+"</"+element+">"
1044 if (parentName != "") {
1045 xmlBuild += "</"+parentName+">"
1050 // build subnet sub-network single elements
1051 def buildSubNetworkElements(subnetXml, elementList, parentName) {
1054 if (parentName != "") {
1055 xmlBuild += "<"+parentName+">"
1057 if (subnetXml != null) {
1058 def networkStartAddress = ""
1059 for (element in elementList) {
1060 def xml= new XmlSlurper().parseText(subnetXml)
1061 var = xml.'**'.find {it.name() == element}
1062 if (element == "dhcp-start") {
1063 xmlBuild += "<allocationPools>"
1064 if (var.toString() == 'null') {
1065 xmlBuild += "<start>"+""+"</start>"
1067 xmlBuild += "<start>"+var.toString()+"</start>"
1070 if (element == "dhcp-end") {
1071 if (var.toString() == 'null') {
1072 xmlBuild += "<end>"+""+"</end>"
1074 xmlBuild += "<end>"+var.toString()+"</end>"
1076 xmlBuild += "</allocationPools>"
1078 if (element == "network-start-address" || element == "cidr-mask") {
1079 if (element == "network-start-address") {
1080 networkStartAddress = var.toString()
1082 if (element == "cidr-mask") {
1083 xmlBuild += "<cidr>"+networkStartAddress+"/"+var.toString()+"</cidr>"
1086 if (element == "dhcp-enabled") {
1087 xmlBuild += "<enableDHCP>"+var.toString()+"</enableDHCP>"
1089 if (element == "gateway-address") {
1090 xmlBuild += "<gatewayIp>"+var.toString()+"</gatewayIp>"
1092 if (element == "ip-version") {
1093 xmlBuild += "<ipVersion>"+var.toString()+"</ipVersion>"
1095 if (element == "subnet-id") {
1096 xmlBuild += "<subnetId>"+var.toString()+"</subnetId>"
1098 if ((element == "subnet-name") && (var != null)) {
1099 xmlBuild += "<subnetName>"+var.toString()+"</subnetName>"
1103 if (parentName != "") {
1104 xmlBuild += "</"+parentName+">"
1109 // rebuild ctag-assignments
1110 def rebuildCtagAssignments(xmlInput) {
1111 def rebuildingCtagAssignments = ""
1112 if (xmlInput!=null) {
1113 def ctagAssignmentsData = new XmlSlurper().parseText(xmlInput)
1114 rebuildingCtagAssignments += "<ctag-assignments>"
1115 def ctagAssignments = ctagAssignmentsData.'**'.findAll {it.name() == "ctag-assignment"}
1116 def ctagAssignmentsSize = ctagAssignments.size()
1117 for (i in 0..ctagAssignmentsSize-1) {
1118 def ctagAssignment = ctagAssignments[i]
1119 def ctagAssignmentXml = XmlUtil.serialize(ctagAssignment)
1120 rebuildingCtagAssignments += "<ctag-assignment>"
1121 List elementList = ["vlan-id-inner", "resource-version"]
1122 rebuildingCtagAssignments += buildXMLElements(ctagAssignmentXml, "" , "", elementList)
1123 if (utils.nodeExists(ctagAssignmentXml, 'relationship')) {
1124 rebuildingCtagAssignments += rebuildRelationship(ctagAssignmentXml)
1126 rebuildingCtagAssignments += "</ctag-assignment>"
1128 rebuildingCtagAssignments += "</ctag-assignments>"
1130 return rebuildingCtagAssignments
1133 // rebuild 'relationship-list'
1134 def rebuildRelationship(xmlInput) {
1135 def rebuildingSubnets = ""
1136 if (xmlInput!=null) {
1137 def subnetsData = new XmlSlurper().parseText(xmlInput)
1138 rebuildingSubnets += "<relationship-list>"
1139 def relationships = subnetsData.'**'.findAll {it.name() == "relationship"}
1140 def relationshipsSize = relationships.size()
1141 for (i in 0..relationshipsSize-1) {
1142 def relationship = relationships[i]
1143 def relationshipXml = XmlUtil.serialize(relationship)
1144 rebuildingSubnets += "<relationship>"
1145 def relationshipList = ["related-to", "related-link"]
1146 rebuildingSubnets += buildSubNetworkElements(relationshipXml, "", relationshipList, "")
1147 if (utils.nodeExists(relationshipXml, 'relationship-data')) {
1148 def relationshipDataXmlData = new XmlSlurper().parseText(relationshipXml)
1149 def relationshipsData = relationshipDataXmlData.'**'.findAll {it.name() == "relationship-data"}
1150 def relationshipsDataSize = relationshipsData.size()
1151 for (j in 0..relationshipsDataSize-1) {
1152 def relationshipData = relationshipsData[j]
1153 def relationshipDataXml = XmlUtil.serialize(relationshipData)
1154 def relationshipDataList = ["relationship-key", "relationship-value"]
1155 rebuildingSubnets += buildXMLElements(relationshipDataXml, "", "relationship-data", relationshipDataList)
1158 if (utils.nodeExists(relationshipXml, 'related-to-property')) {
1159 def relationshipDataXmlData = new XmlSlurper().parseText(relationshipXml)
1160 def relationshipsData = relationshipDataXmlData.'**'.findAll {it.name() == "related-to-property"}
1161 def relationshipsDataSize = relationshipsData.size()
1162 for (j in 0..relationshipsDataSize-1) {
1163 def relationshipData = relationshipsData[j]
1164 def relationshipDataXml = XmlUtil.serialize(relationshipData)
1165 def relationshipDataList = ["property-key", "property-value"]
1166 rebuildingSubnets += buildXMLElements(relationshipDataXml, "", "related-to-property", relationshipDataList)
1170 rebuildingSubnets += "</relationship>"
1172 rebuildingSubnets += "</relationship-list>"
1174 return rebuildingSubnets
1177 def buildVlans(queryIdResponse) {
1178 def rebuildingSubnets = "<vlans>"
1179 def subnetsData = new XmlSlurper().parseText(queryIdResponse)
1182 def subnets = subnetsData.'**'.findAll {it.name() == "segmentation-assignments"}
1183 def subnetsSize = subnets.size()
1184 for (i in 0..subnetsSize-1) {
1185 def subnet = subnets[i]
1186 def subnetXml = XmlUtil.serialize(subnet)
1188 String vlan = utils.getNodeText1(subnetXml, "segmentation-id")
1190 rebuildingSubnets += ","
1192 rebuildingSubnets += vlan
1194 } catch (Exception ex) {
1197 //rebuildingSubnets += "</subnets>"
1198 rebuildingSubnets += "</vlans>"
1200 return rebuildingSubnets
1203 /* Utility code to rebuild xml/elements in a list:
1204 * rebuild xml with 1) unbounded groups of elements; or
1205 * 2) one group of elements; or
1206 * 3) just one or more elements (in a list as argument)
1207 * @param xmlInput the XML document
1208 * @param parentName the parent name (ex: 'inputs')
1209 * @param childrenName the chilrendName (ex: 'entry' as unbounded/occurs>1)
1210 * @param elementList the element list of children (ex: 'key', 'value')
1211 * @return a string of rebuild xml
1216 * <ws:key>name</ws:key>
1217 * <ws:value>Edward</ws:value>
1220 * <ws:key>age</ws:key>
1221 * <ws:value>30</ws:value>
1224 * <ws:key>age</ws:key>
1225 * <ws:value>30</ws:value>
1229 * List elementList = ["key", "value"]
1230 * String rebuild = buildXMLElements(xmlInput, "inputs", "entry", elementList)
1232 * Ex 2: xmlInput // no parent tag
1233 * <ws:sdnc-request-header>
1234 * <ws:svc-request-id>fec8ec88-151a-45c9-ad60-8233e0fc8ff2</ws:svc-request-id>
1235 * <ws:svc-notification-url>https://msojra.mtsnj.aic.cip.openecomp.com:8443/adapters/rest/SDNCNotify</ws:svc-notification-url>
1236 * <ws:svc-action>assign</ws:svc-action>
1237 * </ws:sdnc-request-header>
1239 * List elementList = ["svc-request-id", "svc-notification-url", "svc-action"]
1240 * String rebuild = buildXMLElements(xmlInput, "" , "sdnc-request-header", elementList) // no parent tag
1242 * Ex 3: xmlInput // elements one after another (with no parent & children tag)
1243 * <ws:test-id>myTestid</ws:test-id>
1244 * <ws:test-user>myUser</ws:test-user>
1246 * List elementList = ["test-id", "test-user"]
1247 * String rebuild = buildXMLElements(xmlInput, "" , "", elementList)
1250 def buildXMLElements(xmlInput, parentName, childrenName, elementList) {
1251 def varChildren = ""
1253 def xmlBuildUnbounded = ""
1254 if (parentName!="") {xmlBuildUnbounded += "<"+parentName+">" +'\n'}
1255 if (xmlInput != null) {
1256 def xml= new XmlSlurper().parseText(xmlInput)
1257 if (childrenName!="") {
1258 varChildren = xml.'**'.findAll {it.name() == childrenName}
1259 for (i in 0..varChildren.size()-1) {
1260 xmlBuildUnbounded += "<"+childrenName+">" +'\n'
1261 for (element in elementList) {
1262 var = varChildren[i].'*'.find {it.name() == element}
1264 xmlBuildUnbounded += "<"+element+">"+var.toString()+"</"+element+">" +'\n'
1267 xmlBuildUnbounded += "</"+childrenName+">" +'\n'
1270 for (element in elementList) {
1271 var = xml.'*'.find {it.name() == element}
1273 xmlBuildUnbounded += "<"+element+">"+var.toString()+"</"+element+">" +'\n'
1279 if (parentName!="") {xmlBuildUnbounded += "</"+parentName+">" +'\n'}
1280 return xmlBuildUnbounded
1283 def getFirstNodeXml(xmlInput, element){
1285 def nodeToSerialize = ""
1286 if (xmlInput != null) {
1287 def fxml= new XmlSlurper().parseText(xmlInput)
1288 if (utils.nodeExists(xmlInput, "payload")) {
1289 nodeToSerialize = fxml.'payload'.'l3-network'.'*'.find {it.name() == element}
1290 if (nodeToSerialize!=null) {
1291 nodeAsText = XmlUtil.serialize(nodeToSerialize)
1297 nodeToSerialize = fxml.'*'.find {it.name() == element}
1298 if (nodeToSerialize!=null) {
1299 nodeAsText = XmlUtil.serialize(nodeToSerialize)
1310 //TODO: This method still needs to be tested before using.
1313 * This method is similar to the gennetwork:ContrailNetworUpdateCompletedObject
1314 * BPEL method. It extracts all of the required subnet information
1315 * for each subnet listed with an orch status equal to the one provided
1316 * and puts the corresponding infomation with the appropriate node for
1317 * updating aai. The method sets the orch status for each subnet to active
1319 * @param subnetsXml the entire subnets xml
1320 * @param requestInput the request in the process
1321 * @param queryIdResponse the response of REST AAI query by Id
1322 * @param queryVpnBindingResponse the response of REST AAI query by vpn binding
1323 * @param routeCollection the collection of vpnBinding's 'global-route-target'
1324 * @return String request
1326 public String networkUpdateSubnetInfo(String subnetsXml, String networkResponseXml){
1329 StringBuilder sb = new StringBuilder()
1330 InputSource source = new InputSource(new StringReader(subnetsXml));
1331 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1332 docFactory.setNamespaceAware(true)
1333 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1334 Document xml = docBuilder.parse(source)
1335 NodeList nodeList = xml.getElementsByTagNameNS("*", "subnet")
1336 for (int x = 0; x < nodeList.getLength(); x++) {
1337 Node node = nodeList.item(x)
1339 if (node.getNodeType() == Node.ELEMENT_NODE) {
1340 Element eElement = (Element) node
1341 String subnetOrchStatus = eElement.getElementsByTagNameNS("*", "orchestration-status").item(0).getTextContent()
1342 if(subnetOrchStatus.equals("pending-create")){
1344 String subnetId = eElement.getElementsByTagNameNS("*", "subnet-id").item(0).getTextContent()
1345 def netAddress = eElement.getElementsByTagNameNS("*", "network-start-address").item(0).getTextContent()
1346 def mask = eElement.getElementsByTagNameNS("*", "cidr-mask").item(0).getTextContent()
1347 def dhcpEnabledSubnet = eElement.getElementsByTagNameNS("*", "dhcp-enabled").item(0).getTextContent()
1348 def gatewayAddress = eElement.getElementsByTagNameNS("*", "gateway-address").item(0).getTextContent()
1349 def ipVersion = eElement.getElementsByTagNameNS("*", "ip-version").item(0).getTextContent()
1350 def relationshipList = eElement.getElementsByTagNameNS("*", "relationship-list").item(0).getTextContent() //TODO: test this
1351 String neutronSubnetId = extractNeutSubId(networkResponseXml, subnetId)
1354 <subnetId>${subnetId}</subnetId>
1355 <neutron-subnet-id>${neutronSubnetId}</neutron-subnet-id>
1356 <gateway-address>${gatewayAddress}</gateway-address>
1357 <network-start-address>${netAddress}</network-start-address>
1358 <cidr-mask>${mask}</cidr-mask>
1359 <ip-Version>${ipVersion}</ip-Version>
1360 <orchestration-status>active</orchestration-status>
1361 <dhcp-enabled>${dhcpEnabledSubnet}</dhcp-enabled>
1362 <relationship-list>${relationshipList}</relationship-list>
1365 }else if(subnetOrchStatus.equals("pending-delete")){
1366 StringWriter writer = new StringWriter()
1367 Transformer transformer = TransformerFactory.newInstance().newTransformer()
1368 transformer.transform(new DOMSource(node), new StreamResult(writer))
1369 subnet = writer.toString()
1375 subnets = sb.append(subnet)
1378 subnets = utils.removeXmlPreamble(subnets)
1380 String subnetsList =
1391 * This method extracts the "value" node text for the the given subnet Id.
1393 * @param String inputSource - xml that contains the subnet id key and value
1394 * @param String subnetId - for which you want the value of
1396 * @return String value - node text of node named value associated with the given subnet id
1398 public String extractNeutSubId(String inputSource, String subnetId){
1401 InputSource source = new InputSource(new StringReader(inputSource));
1402 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1403 docFactory.setNamespaceAware(true)
1404 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1405 Document xml = docBuilder.parse(source)
1406 NodeList nodeList = xml.getElementsByTagNameNS("*", "entry")
1407 for (int x = 0; x < nodeList.getLength(); x++) {
1408 Node node = nodeList.item(x)
1410 if (node.getNodeType() == Node.ELEMENT_NODE) {
1411 Element eElement = (Element) node
1412 String key = eElement.getElementsByTagNameNS("*", "key").item(0).getTextContent()
1413 if(key.equals(subnetId)){
1414 value = eElement.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1421 public boolean isRollbackEnabled (Execution execution, String payloadXml) {
1423 def rollbackEnabled = false
1424 def rollbackValueSet = false
1425 if (utils.nodeExists(payloadXml, "backout-on-failure")) {
1426 String backoutValue = utils.getNodeText1(payloadXml, "backout-on-failure")
1427 if (backoutValue != null && !backoutValue.isEmpty()) {
1428 if (backoutValue.equalsIgnoreCase("false")) {
1429 rollbackEnabled = false
1432 rollbackEnabled = true
1434 rollbackValueSet = true;
1438 if (!rollbackValueSet) {
1439 if (execution.getVariable("URN_mso_rollback") != null) {
1440 rollbackEnabled = execution.getVariable("URN_mso_rollback").toBoolean()
1443 return rollbackEnabled