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.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.runtime.Execution
26 import org.openecomp.mso.bpmn.core.WorkflowException
27 import org.springframework.web.util.UriUtils
34 class SDNCAdapterUtils {
36 ExceptionUtil exceptionUtil = new ExceptionUtil()
38 private AbstractServiceTaskProcessor taskProcessor
40 public SDNCAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
41 this.taskProcessor = taskProcessor
44 String SDNCAdapterFeatureRequest(Execution execution, String requestName, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {
45 def utils=new MsoUtils()
47 def prefix = execution.getVariable('prefix')
48 def request = taskProcessor.getVariable(execution, requestName)
49 def requestInformation = utils.getNodeXml(request, 'request-information', false)
50 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
51 def featureInformation = utils.getNodeXml(request, 'feature-information', false)
52 def featureParameters = utils.getNodeXml(request, 'feature-parameters', false)
54 def requestId = execution.getVariable('testReqId') // for junits
56 requestId = execution.getVariable("openecomp-mso-request-id") + "-" + System.currentTimeMillis()
59 def svcInstanceId = execution.getVariable("openecomp-mso-service-instance-id")
61 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
62 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
63 def nnsFeatureInformation = utils.removeXmlNamespaces(featureInformation)
64 def nnsFeatureParameters = utils.removeXmlNamespaces(featureParameters)
66 String sdncAdapterFeatureRequest = """
67 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
68 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
69 <sdncadapter:RequestHeader>
70 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
71 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
72 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
73 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
74 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
75 </sdncadapter:RequestHeader>
76 <sdncadapterworkflow:SDNCRequestData>
77 ${nnsRequestInformation}
78 ${nnsServiceInformation}
79 ${nnsFeatureInformation}
80 ${nnsFeatureParameters}
81 </sdncadapterworkflow:SDNCRequestData>
82 <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${timeoutValueInMinutes}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
83 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
85 sdncAdapterFeatureRequest = utils.removeXmlPreamble(utils.formatXML(sdncAdapterFeatureRequest))
86 return sdncAdapterFeatureRequest
89 String SDNCAdapterActivateVnfRequest(Execution execution, String action, String callbackURL, String serviceOperation, String msoAction, String timeoutValueInMinutes) {
90 def utils=new MsoUtils()
92 def prefix = execution.getVariable('prefix')
93 def request = taskProcessor.getVariable(execution, prefix+'Request')
94 def requestInformation = utils.getNodeXml(request, 'request-information', false)
95 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
96 def vnfInformationList = utils.getNodeXml(request, 'vnf-information-list', false)
98 def requestId = execution.getVariable('testReqId') // for junits
100 requestId = execution.getVariable("openecomp-mso-request-id") + "-" + System.currentTimeMillis()
103 def svcInstanceId = execution.getVariable("openecomp-mso-service-instance-id")
105 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
106 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
107 def nnsVnfInformationList = utils.removeXmlNamespaces(vnfInformationList)
109 String sdncAdapterActivateVnfRequest = """
110 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
111 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
112 <sdncadapter:RequestHeader>
113 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
114 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
115 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
116 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
117 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
118 <sdncadapter:MsoAction>${msoAction}</sdncadapter:MsoAction>
119 </sdncadapter:RequestHeader>
120 <sdncadapterworkflow:SDNCRequestData>
121 ${nnsRequestInformation}
122 ${nnsServiceInformation}
123 ${nnsVnfInformationList}
124 </sdncadapterworkflow:SDNCRequestData>
125 <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${timeoutValueInMinutes}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
126 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
128 sdncAdapterActivateVnfRequest = utils.removeXmlPreamble(utils.formatXML(sdncAdapterActivateVnfRequest))
129 return sdncAdapterActivateVnfRequest
132 String SDNCAdapterL3ToHigherLayerRequest(Execution execution, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {
133 def utils=new MsoUtils()
135 def prefix = execution.getVariable('prefix')
136 def request = taskProcessor.getVariable(execution, prefix+'Request')
138 def requestInformation = """<request-information>
139 <request-id>${execution.getVariable("openecomp-mso-request-id")}</request-id>
140 <request-action>torepl</request-action>
141 <source>${execution.getVariable(prefix+"source")}</source>
142 <notification-url>${execution.getVariable(prefix+"notificationUrl")}</notification-url>
143 </request-information>"""
145 // Change the value of the 'request-information'.'request-action' element
146 def xml = new XmlSlurper().parseText(requestInformation)
147 if("assign".equalsIgnoreCase(action)){
148 xml.'request-action'.replaceBody('createTrinityBonding')
149 }else if("activate".equalsIgnoreCase(action)){
150 xml.'request-action'.replaceBody('activateTrinityBonding')
151 }else if("delete".equalsIgnoreCase(action)){
152 xml.'request-action'.replaceBody('deleteTrinityBonding')
154 requestInformation = utils.removeXmlPreamble(groovy.xml.XmlUtil.serialize(xml))
155 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
157 def requestId = execution.getVariable('testReqId') // for junits
159 requestId = execution.getVariable("openecomp-mso-request-id") + "-" + System.currentTimeMillis()
162 def svcInstanceId = execution.getVariable("openecomp-mso-service-instance-id")
164 //Build Service Information
165 // Send serviceName from CANOPI to sdnc for service-type
166 def serviceInformation = """<service-information>
167 <service-type>${execution.getVariable(prefix+"serviceName")}</service-type>
168 <service-instance-id>${svcInstanceId}</service-instance-id>
169 <subscriber-name>${execution.getVariable(prefix+"subscriberName")}</subscriber-name>
170 <subscriber-global-id>${execution.getVariable(prefix+"subscriberGlobalId")}</subscriber-global-id>
171 </service-information>"""
173 //Build Additional Information - vpn or vni
174 // Send serviceType from CANOPI to SDNC for nbnc-request-information service-type
175 def service = execution.getVariable(prefix+"serviceType")
176 def customerId = execution.getVariable(prefix+"customerId")
177 def vpnId = execution.getVariable(prefix+"vpnId")
178 def vpnRt = execution.getVariable(prefix+"vpnRt")
179 def vpnService = execution.getVariable(prefix+"vpnService")
180 def vpnRegion = execution.getVariable(prefix+"vpnRegion")
181 def additionalInfo = ""
182 if("assign".equalsIgnoreCase(action)){
183 additionalInfo = """<vpn-data-list>
184 <vpn-id>${vpnId}</vpn-id>
185 <vpn-rt>${vpnRt}</vpn-rt>
186 <vpn-service>${vpnService}</vpn-service>
187 <vpn-region>${vpnRegion}</vpn-region>
189 }else if("activate".equalsIgnoreCase(action) || "delete".equalsIgnoreCase(action)){
190 def vniId = execution.getVariable(prefix+'vniId')
191 additionalInfo = "<vni-id>${vniId}</vni-id>"
194 //Set Interface Status
195 def interfaceStatus = "DISABLE"
196 if("activate".equalsIgnoreCase(action)){
197 interfaceStatus = "ENABLE"
200 //Build SDNC Adapter Request
201 String sdncAdapterL3ToHLRequest = """
202 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
203 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
204 <sdncadapter:RequestHeader>
205 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
206 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
207 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
208 <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
209 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
210 </sdncadapter:RequestHeader>
211 <sdncadapterworkflow:SDNCRequestData>
212 ${nnsRequestInformation}
213 ${serviceInformation}
214 <nbnc-request-information>
215 <service-type>${service}</service-type>
216 <customer-id>${customerId}</customer-id>
217 <interface-status>${interfaceStatus}</interface-status>
219 </nbnc-request-information>
220 </sdncadapterworkflow:SDNCRequestData>
221 <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${timeoutValueInMinutes}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
222 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
224 sdncAdapterL3ToHLRequest = utils.removeXmlPreamble(utils.formatXML(sdncAdapterL3ToHLRequest))
226 return sdncAdapterL3ToHLRequest
231 private void SDNCAdapterActivateRequest(Execution execution, String resultVar, String svcAction,
232 String svcOperation, String additionalData) {
233 def utils=new MsoUtils()
235 def prefix = execution.getVariable('prefix')
236 def request = taskProcessor.getVariable(execution, prefix+'Request')
237 def requestInformation = utils.getNodeXml(request, 'request-information', false)
238 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
239 def serviceParameters = utils.getNodeXml(request, 'service-parameters', false)
241 def requestId = execution.getVariable('testReqId') // for junits
243 requestId = execution.getVariable("openecomp-mso-request-id") + "-" + System.currentTimeMillis()
246 def svcInstanceId = execution.getVariable("openecomp-mso-service-instance-id")
247 def msoAction = 'gammainternet'
249 def timeoutInMinutes = execution.getVariable('URN_mso_sdnc_timeout_firewall_minutes')
251 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
252 if (callbackUrl == null || callbackUrl.trim() == "") {
253 logError('mso:workflow:sdncadapter:callback URN is not set')
254 workflowException(execution, 'Internal Error', 9999) // TODO: what message and error code?
257 def l2HomingInformation = utils.getNodeXml(serviceParameters, 'l2-homing-information', false)
258 def internetEvcAccessInformation = utils.getNodeXml(serviceParameters, 'internet-evc-access-information', false)
259 def vrLan = utils.getNodeXml(serviceParameters, 'vr-lan', false)
260 def upceVmsServiceInformation = utils.getNodeXml(serviceParameters, 'ucpe-vms-service-information', false)
263 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
264 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
265 def nnsl2HomingInformation = utils.removeXmlNamespaces(l2HomingInformation)
266 def nnsInternetEvcAccessInformation = utils.removeXmlNamespaces(internetEvcAccessInformation)
267 def nnsVrLan = utils.removeXmlNamespaces(vrLan)
268 def nnsUpceVmsServiceInformation = utils.removeXmlNamespaces(upceVmsServiceInformation)
270 if (additionalData == null) {
275 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
276 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
277 <sdncadapter:RequestHeader>
278 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
279 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
280 <sdncadapter:SvcAction>${svcAction}</sdncadapter:SvcAction>
281 <sdncadapter:SvcOperation>${svcOperation}</sdncadapter:SvcOperation>
282 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
283 <sdncadapter:MsoAction>${msoAction}</sdncadapter:MsoAction>
284 </sdncadapter:RequestHeader>
285 <sdncadapterworkflow:SDNCRequestData>
287 ${nnsRequestInformation}
288 ${nnsServiceInformation}
289 ${nnsl2HomingInformation}
290 ${nnsInternetEvcAccessInformation}
292 ${nnsUpceVmsServiceInformation}
293 </sdncadapterworkflow:SDNCRequestData>
294 <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${timeoutInMinutes}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
295 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
298 content = utils.removeXmlPreamble(utils.formatXML(content))
299 execution.setVariable(resultVar, content)
303 * Builds an SDNC "reserve" request and stores it in the specified execution
305 * @param execution the execution
306 * @param resultVar the execution variable in which the result will be stored
308 public void sdncReservePrep(Execution execution, String action, String resultVar) {
309 sdncPrep(execution, resultVar, action , 'service-configuration-operation', null, this.taskProcessor)
313 * Builds a basic SDNC request and stores it in the specified execution variable.
314 * @param execution the execution
315 * @param resultVar the execution variable in which the result will be stored
316 * @param svcAction the svcAction element value
317 * @param svcOperation the svcOperation element value
318 * @param additionalData additional XML content to be inserted into the
319 * RequestData element (may be null)
321 public void sdncPrep(Execution execution, String resultVar, String svcAction,
322 String svcOperation, String additionalData, AbstractServiceTaskProcessor taskProcessor) {
323 def method = getClass().getSimpleName() + '.sdncPrep(' +
324 'execution=' + execution.getId() +
325 ', resultVar=' + resultVar +
326 ', svcAction=' + svcAction +
327 ', svcOperation=' + svcOperation +
328 ', additionalData=' + (additionalData == null ? "no" : "yes") +
331 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
332 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
333 MsoUtils utils = taskProcessor.utils
335 def prefix = execution.getVariable('prefix')
336 def request = taskProcessor.getVariable(execution, prefix+'Request')
337 def requestInformation = utils.getNodeXml(request, 'request-information', false)
338 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
339 def serviceParameters = utils.getChildNodes(request, 'service-parameters')
340 def requestAction = utils.getNodeText1(request, 'request-action')
342 def timeoutInMinutes = execution.getVariable('URN_mso_sdnc_timeout_firewall_minutes')
344 def requestId = execution.getVariable('testReqId') // for junits
346 requestId = execution.getVariable("openecomp-mso-request-id") + "-" + System.currentTimeMillis()
349 def svcInstanceId = execution.getVariable("openecomp-mso-service-instance-id")
350 def msoAction = 'gammainternet'
352 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
353 if (callbackUrl == null || callbackUrl.trim() == "") {
354 taskProcessor.logError('mso:workflow:sdncadapter:callback URN is not set')
355 taskProcessor.workflowException(execution, 'Internal Error', 9999) // TODO: what message and error code?
358 def l2HomingInformation = utils.getNodeXml(request, 'l2-homing-information', false)
359 def internetEvcAccessInformation = utils.getNodeXml(request, 'internet-evc-access-information', false)
360 def vrLan = utils.getNodeXml(request, 'vr-lan', false)
361 def upceVmsServiceInfo = utils.getNodeXml(request, 'ucpe-vms-service-information', false)
362 def vnfInformationList = utils.getNodeXml(request, 'vnf-information-list', false)
364 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
365 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
366 def nnsl2HomingInformation = utils.removeXmlNamespaces(l2HomingInformation)
367 def nnsInternetEvcAccessInformation = utils.removeXmlNamespaces(internetEvcAccessInformation)
368 def nnsVrLan = utils.removeXmlNamespaces(vrLan)
369 def nnsUpceVmsServiceInfo = utils.removeXmlNamespaces(upceVmsServiceInfo)
370 def nnsVnfInformationList = utils.removeXmlNamespaces(vrLan)
371 def nnsinternetSvcChangeDetails = ""
373 if(requestAction!=null && requestAction.equals("ChangeLayer3ServiceProvRequest")){
374 def internetSvcChangeDetails = utils.removeXmlNamespaces(serviceParameters)
375 nnsinternetSvcChangeDetails = """<internet-service-change-details>
376 ${internetSvcChangeDetails}
377 </internet-service-change-details>"""
380 if (additionalData == null) {
385 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
386 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
387 <sdncadapter:RequestHeader>
388 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
389 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
390 <sdncadapter:SvcAction>${svcAction}</sdncadapter:SvcAction>
391 <sdncadapter:SvcOperation>${svcOperation}</sdncadapter:SvcOperation>
392 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
393 <sdncadapter:MsoAction>${msoAction}</sdncadapter:MsoAction>
394 </sdncadapter:RequestHeader>
395 <sdncadapterworkflow:SDNCRequestData>
397 ${nnsRequestInformation}
398 ${nnsServiceInformation}
399 ${nnsl2HomingInformation}
400 ${nnsInternetEvcAccessInformation}
402 ${nnsUpceVmsServiceInfo}
403 ${nnsVnfInformationList}
404 ${nnsinternetSvcChangeDetails}
405 </sdncadapterworkflow:SDNCRequestData>
406 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
409 content = utils.removeXmlPreamble(utils.formatXML(content))
410 execution.setVariable(resultVar, content)
411 taskProcessor.logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
413 taskProcessor.logDebug('Exited ' + method, isDebugLogEnabled)
414 } catch (BpmnError e) {
416 } catch (Exception e) {
417 taskProcessor.logError('Caught exception in ' + method, e)
418 taskProcessor.workflowException(execution, 'Internal Error', 9999) // TODO: what message and error code?
423 * Builds a topology SDNC request and return String request.
424 * As V2 will use 1607-style request, region instead of aic clli code
425 * @param execution, the execution
426 * @param requestXML, the incoming request for the flow
427 * @param serviceInstanceId, the serviceIntance (if available)
428 * @param callbackUrl, the call back url
429 * @param action, the action element value
430 * @param requestAction the svcOperation element value
431 * @param cloudRegionId the aai's cloud-region-id
432 * @param networkId the aai's network-id
433 * @param additionalData additional XML content to be inserted into the
434 * RequestData element (may be null)
436 public String sdncTopologyRequestV2 (Execution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String queryAAIResponse, String additionalData) {
437 def utils=new MsoUtils()
439 String requestId = ""
441 requestId = execution.getVariable("openecomp-mso-request-id")
442 } catch (Exception ex) {
443 requestId = utils.getNodeText1(requestXML, "request-id")
446 String aicCloudRegion = cloudRegionId
448 if (utils.nodeExists(requestXML, "tenant-id")) {
449 tenantId = utils.getNodeText1(requestXML, "tenant-id")
451 String networkType = ""
452 if (utils.nodeExists(requestXML, "network-type")) {
453 networkType = utils.getNodeText1(requestXML, "network-type")
456 // Replace/Use the value of network-type from aai query (vs input) during Delete Network flows.
457 if (queryAAIResponse != null) {
458 networkType = utils.getNodeText1(queryAAIResponse, "network-type")
461 String serviceId = ""
462 if (utils.nodeExists(requestXML, "service-id")) {
463 serviceId = utils.getNodeText1(requestXML, "service-id")
465 String networkName = ""
466 if (utils.nodeExists(requestXML, "network-name")) {
467 networkName = utils.getNodeText1(requestXML, "network-name")
470 if (utils.nodeExists(requestXML, "source")) {
471 source = utils.getNodeText1(requestXML, "source")
474 // get resourceLink from subflow execution variable
475 String serviceType = ""
476 String subscriberName = ""
477 String siRelatedLink = execution.getVariable("GENGSI_siResourceLink")
478 if (siRelatedLink != null) {
480 int serviceStart = siRelatedLink.indexOf("service-subscription/")
481 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
482 serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
483 serviceType = UriUtils.decode(serviceType,"UTF-8")
484 // get subscriber name
485 int subscriberNameStart = siRelatedLink.indexOf("customers/customer/")
486 int subscriberNameEnd = siRelatedLink.indexOf("/service-subscriptions/")
487 subscriberName = siRelatedLink.substring(subscriberNameStart + 19, subscriberNameEnd)
488 subscriberName = UriUtils.decode(subscriberName,"UTF-8")
492 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://openecomp.com/mso/workflow/schema/v1"
493 xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
494 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1"
495 xmlns:ns5="http://openecomp.com/mso/request/types/v1">
496 <sdncadapter:RequestHeader>
497 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
498 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
499 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
500 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
501 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
502 </sdncadapter:RequestHeader>
503 <sdncadapterworkflow:SDNCRequestData>
504 <request-information>
505 <request-id>${requestId}</request-id>
506 <request-action>${requestAction}</request-action>
507 <source>${source}</source>
508 <notification-url></notification-url>
509 <order-number></order-number>
510 <order-version></order-version>
511 </request-information>
512 <service-information>
513 <service-id>${serviceId}</service-id>
514 <service-type>${serviceType}</service-type>
515 <service-instance-id>${serviceInstanceId}</service-instance-id>
516 <subscriber-name>${subscriberName}</subscriber-name>
517 </service-information>
518 <network-request-information>
519 <network-id>${networkId}</network-id>
520 <network-type>${networkType}</network-type>
521 <network-name>${networkName}</network-name>
522 <tenant>${tenantId}</tenant>
523 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
524 </network-request-information>
525 </sdncadapterworkflow:SDNCRequestData>
526 </aetgt:SDNCAdapterWorkflowRequest>""".trim()
532 * Builds a topology SDNC request and return String request.
533 * As V2 will use 1607-style request, region instead of aic clli code
534 * @param execution, the execution
535 * @param requestXML, the incoming request for the flow
536 * @param serviceInstanceId, the serviceIntance (if available)
537 * @param callbackUrl, the call back url
538 * @param action, the action element value
539 * @param requestAction the svcOperation element value
540 * @param cloudRegionId the aai's cloud-region-id
541 * @param networkId the aai's network-id
542 * @param additionalData additional XML content to be inserted into the
543 * RequestData element (may be null)
545 public String sdncTopologyRequestRsrc (Execution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String additionalData) {
546 def utils=new MsoUtils()
548 // SNDC is expecting requestId as unique each call.
549 String requestId = ""
550 String testRequestId = execution.getVariable("testMessageId") // for test purposes.
551 if (testRequestId == null) {
552 requestId = UUID.randomUUID() // generate unique
554 requestId = testRequestId
557 String aicCloudRegion = cloudRegionId
559 if (utils.nodeExists(requestXML, "tenant-id")) {
560 tenantId = utils.getNodeText1(requestXML, "tenant-id")
562 String networkType = ""
563 if (utils.nodeExists(requestXML, "network-type")) {
564 networkType = utils.getNodeText1(requestXML, "network-type")
567 String subscriptionServiceType = ""
568 if (utils.nodeExists(requestXML, "subscription-service-type")) {
569 subscriptionServiceType = utils.getNodeText1(requestXML, "subscription-service-type")
572 String globalCustomerId = ""
573 if (utils.nodeExists(requestXML, "global-customer-id")) {
574 globalCustomerId = utils.getNodeText1(requestXML, "global-customer-id")
577 String serviceId = ""
578 if (utils.nodeExists(requestXML, "service-id")) {
579 serviceId = utils.getNodeText1(requestXML, "service-id")
581 String networkName = ""
582 if (utils.nodeExists(requestXML, "network-name")) {
583 networkName = utils.getNodeText1(requestXML, "network-name")
586 if (utils.nodeExists(requestXML, "source")) {
587 source = utils.getNodeText1(requestXML, "source")
590 // get resourceLink from subflow execution variable
591 String serviceType = ""
592 String subscriberName = ""
593 String siRelatedLink = execution.getVariable("GENGSI_siResourceLink")
594 if (siRelatedLink != null) {
596 int serviceStart = siRelatedLink.indexOf("service-subscription/")
597 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
598 serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
599 serviceType = UriUtils.decode(serviceType,"UTF-8")
600 // get subscriber name
601 int subscriberNameStart = siRelatedLink.indexOf("customers/customer/")
602 int subscriberNameEnd = siRelatedLink.indexOf("/service-subscriptions/")
603 subscriberName = siRelatedLink.substring(subscriberNameStart + 19, subscriberNameEnd)
604 subscriberName = UriUtils.decode(subscriberName,"UTF-8")
607 // network-information from 'networkModelInfo' // verify the DB Catalog response
608 String networkModelInfo = utils.getNodeXml(requestXML, "networkModelInfo", false).replace("tag0:","").replace(":tag0","")
609 String modelInvariantUuid = utils.getNodeText1(networkModelInfo, "modelInvariantUuid") !=null ?
610 utils.getNodeText1(networkModelInfo, "modelInvariantUuid") : ""
611 String modelCustomizationUuid = utils.getNodeText1(networkModelInfo, "modelCustomizationUuid") !=null ?
612 utils.getNodeText1(networkModelInfo, "modelCustomizationUuid") : ""
613 String modelUuid = utils.getNodeText1(networkModelInfo, "modelUuid") !=null ?
614 utils.getNodeText1(networkModelInfo, "modelUuid") : ""
615 String modelVersion = utils.getNodeText1(networkModelInfo, "modelVersion") !=null ?
616 utils.getNodeText1(networkModelInfo, "modelVersion") : ""
617 String modelName = utils.getNodeText1(networkModelInfo, "modelName") !=null ?
618 utils.getNodeText1(networkModelInfo, "modelName") : ""
620 // service-information from 'networkModelInfo' // verify the DB Catalog response
621 String serviceModelInfo = utils.getNodeXml(requestXML, "serviceModelInfo", false).replace("tag0:","").replace(":tag0","")
622 String serviceModelInvariantUuid = utils.getNodeText1(serviceModelInfo, "modelInvariantUuid") !=null ?
623 utils.getNodeText1(serviceModelInfo, "modelInvariantUuid") : ""
624 String serviceModelUuid = utils.getNodeText1(serviceModelInfo, "modelUuid") !=null ?
625 utils.getNodeText1(serviceModelInfo, "modelUuid") : ""
626 String serviceModelVersion = utils.getNodeText1(serviceModelInfo, "modelVersion") !=null ?
627 utils.getNodeText1(serviceModelInfo, "modelVersion") : ""
628 String serviceModelName = utils.getNodeText1(serviceModelInfo, "modelName") !=null ?
629 utils.getNodeText1(serviceModelInfo, "modelName") : ""
633 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://openecomp.com/mso/workflow/schema/v1"
634 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1"
635 xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1">
636 <sdncadapter:RequestHeader>
637 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
638 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
639 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
640 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
641 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
642 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
643 </sdncadapter:RequestHeader>
644 <sdncadapterworkflow:SDNCRequestData>
645 <request-information>
646 <request-id>${requestId}</request-id>
647 <request-action>${requestAction}</request-action>
648 <source>${source}</source>
649 <notification-url></notification-url>
650 <order-number></order-number>
651 <order-version></order-version>
652 </request-information>
653 <service-information>
654 <service-id>${serviceId}</service-id>
655 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
656 <ecomp-model-information>
657 <model-invariant-uuid>${serviceModelInvariantUuid}</model-invariant-uuid>
658 <model-uuid>${serviceModelUuid}</model-uuid>
659 <model-version>${serviceModelVersion}</model-version>
660 <model-name>${serviceModelName}</model-name>
661 </ecomp-model-information>
662 <service-instance-id>${serviceInstanceId}</service-instance-id>
663 <global-customer-id>${globalCustomerId}</global-customer-id>
664 <subscriber-name>${subscriberName}</subscriber-name>
665 </service-information>
666 <network-information>
667 <network-id>${networkId}</network-id>
668 <network-type>${networkType}</network-type>
669 <ecomp-model-information>
670 <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
671 <model-customization-uuid>${modelCustomizationUuid}</model-customization-uuid>
672 <model-uuid>${modelUuid}</model-uuid>
673 <model-version>${modelVersion}</model-version>
674 <model-name>${modelName}</model-name>
675 </ecomp-model-information>
676 </network-information>
677 <network-request-input>
678 <network-name>${networkName}</network-name>
679 <tenant>${tenantId}</tenant>
680 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
681 <aic-clli></aic-clli>
682 <network-input-parameters/>
683 </network-request-input>
684 </sdncadapterworkflow:SDNCRequestData>
685 </aetgt:SDNCAdapterWorkflowRequest>""".trim()
691 * Validates a workflow response.
692 * @param execution the execution
693 * @param responseVar the execution variable in which the response is stored
694 * @param workflowException the WorkflowException Object returned from sdnc call
696 public void validateSDNCResponse(Execution execution, String response, WorkflowException workflowException, boolean successIndicator){
697 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
698 taskProcessor.utils.log("DEBUG", "SDNC Response is: " + response, isDebugLogEnabled)
699 taskProcessor.utils.log("DEBUG", "SuccessIndicator is: " + successIndicator, isDebugLogEnabled)
702 def prefix = execution.getVariable('prefix')
703 execution.setVariable(prefix+'sdncResponseSuccess', false)
704 taskProcessor.utils.log("DEBUG", "Response" + ' = ' + (response == null ? "" : System.lineSeparator()) + response, isDebugLogEnabled)
706 if (successIndicator == true){
707 if (response == null || response.trim().equals("")) {
708 taskProcessor.utils.log("DEBUG", response + ' is empty');
709 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "SDNCAdapter Workflow Response is Empty")
712 // we need to peer into the request data for error
713 def String sdncAdapterWorkflowResponse = taskProcessor.utils.getNodeXml(response, 'response-data', false)
714 def String decodedXml = decodeXML(sdncAdapterWorkflowResponse).replace('<?xml version="1.0" encoding="UTF-8"?>', "")
716 // change '&' to "& (if present as data, ex: subscriber-name = 'FOUR SEASONS HEATING & COOLING_8310006378683'
717 decodedXml = decodedXml.replace("&", "&")
719 taskProcessor.utils.log("DEBUG","decodedXml:\n" + decodedXml, isDebugLogEnabled)
721 int requestDataResponseCode = 200
722 def String requestDataResponseMessage = ''
725 if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
726 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")
727 } else if (taskProcessor.utils.nodeExists(decodedXml, "ResponseMessage")) {
728 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "ResponseMessage")
731 taskProcessor.utils.log("DEBUG", 'Error caught while decoding resposne ' + e.getMessage(), isDebugLogEnabled)
734 if(taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
735 taskProcessor.utils.log("DEBUG","response-code node Exist ", isDebugLogEnabled)
736 String code = taskProcessor.utils.getNodeText1(decodedXml, "response-code")
737 if(code.isEmpty() || code.equals("")){
738 // if response-code is blank then Success
739 taskProcessor.utils.log("DEBUG","response-code node is empty", isDebugLogEnabled)
740 requestDataResponseCode = 0
742 requestDataResponseCode = code.toInteger()
743 taskProcessor.utils.log("DEBUG","response-code is: " + requestDataResponseCode, isDebugLogEnabled)
745 }else if(taskProcessor.utils.nodeExists(decodedXml, "ResponseCode")){
746 taskProcessor.utils.log("DEBUG","ResponseCode node Exist ", isDebugLogEnabled)
747 String code = taskProcessor.utils.getNodeText1(decodedXml, "ResponseCode")
748 if(code.isEmpty() || code.equals("")){
749 // if ResponseCode blank then Success
750 taskProcessor.utils.log("DEBUG","ResponseCode node is empty", isDebugLogEnabled)
751 requestDataResponseCode = 0
753 requestDataResponseCode = code.toInteger()
754 taskProcessor.utils.log("DEBUG","ResponseCode is: " + requestDataResponseCode, isDebugLogEnabled)
757 taskProcessor.utils.log("DEBUG","A Response Code DOES NOT Exist.", isDebugLogEnabled)
758 // if a response code does not exist then Success
759 requestDataResponseCode = 0
763 // if a response code is 0 or 200 then Success
764 if (requestDataResponseCode == 200 || requestDataResponseCode == 0) {
765 execution.setVariable(prefix+'sdncResponseSuccess', true)
766 taskProcessor.utils.log("DEBUG", "Setting sdncResponseSuccess to True ", isDebugLogEnabled)
767 taskProcessor.utils.log("DEBUG", "Exited ValidateSDNCResponse Method", isDebugLogEnabled)
769 ExceptionUtil exceptionUtil = new ExceptionUtil()
770 String convertedCode = exceptionUtil.MapSDNCResponseCodeToErrorCode(requestDataResponseCode.toString())
771 int convertedCodeInt = Integer.parseInt(convertedCode)
772 exceptionUtil.buildAndThrowWorkflowException(execution, convertedCodeInt, "Received error from SDN-C: " + requestDataResponseMessage)
776 //TODO proper handling of new, non numerical response codes in 1607 and new error handling for common API
777 requestDataResponseCode = 500
780 taskProcessor.utils.log("DEBUG", "SDNC callback response-code: " + requestDataResponseCode, isDebugLogEnabled)
781 taskProcessor.utils.log("DEBUG", "SDNC callback response-message: " + requestDataResponseMessage, isDebugLogEnabled)
785 taskProcessor.utils.log("DEBUG", 'SDNCAdapter Subflow did NOT complete Successfully. SuccessIndicator is False. ')
786 if(workflowException != null){
787 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
789 //TODO : what error code and error message use here
790 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - SDNCAdapter Subflow did NOT complete successfully.")
794 } catch (BpmnError e) {
796 } catch (Exception e) {
797 taskProcessor.utils.log("DEBUG", 'END of Validate SDNC Response', isDebugLogEnabled)
798 exceptionUtil.buildAndThrowWorkflowException(execution, 500, 'Internal Error- Unable to validate SDNC Response ');
803 * Validates a workflow response.
804 * @param execution the execution
805 * @param responseVar the execution variable in which the response is stored
806 * @param responseCodeVar the execution variable in which the response code is stored
807 * @param errorResponseVar the execution variable in which the error response is stored
809 public void validateL3BondingSDNCResp(Execution execution, String response, WorkflowException workflowException, boolean success) {
810 def method = getClass().getSimpleName() + '.validateL3BondingSDNCResp(' +
811 'execution=' + execution.getId() +
812 ', response=' + response +
814 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
815 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
816 def prefix = execution.getVariable('prefix')
817 CommonExceptionUtil commonExceptionUtil = new CommonExceptionUtil()
820 execution.setVariable(prefix+'sdncResponseSuccess', false)
822 taskProcessor.utils.log("sdncAdapter Success Indicator is: " + success, isDebugLogEnabled)
823 if (success == true) {
825 // we need to look inside the request data for error
826 def String callbackRequestData = taskProcessor.utils.getNodeXml(response, 'RequestData', false)
827 def String decodedXml = decodeXML(callbackRequestData)
828 taskProcessor.utils.log("DEBUG","decodedXml:\n" + decodedXml, isDebugLogEnabled)
830 def requestDataResponseCode = '200'
831 def requestDataResponseMessage = ''
832 int intDataResponseCode = 200
834 if (taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
836 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText(decodedXml, "response-code"))
837 if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
838 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")
840 }else if(taskProcessor.utils.nodeExists(decodedXml, "ResponseCode")){
841 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText1(decodedXml, "ResponseCode")).toInteger()
842 }else if(taskProcessor.utils.nodeExists(response, "ResponseCode")){
843 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText1(response, "ResponseCode")).toInteger()
844 requestDataResponseMessage = taskProcessor.utils.getNodeText(response, "ResponseMessage")
847 taskProcessor.utils.log("DEBUG", "SDNC callback response-code: " + requestDataResponseCode, isDebugLogEnabled)
848 taskProcessor.utils.log("DEBUG", "SDNC callback response-message: " + requestDataResponseMessage, isDebugLogEnabled)
850 // Get the AAI Status to determine if rollback is needed on ASSIGN
852 if (taskProcessor.utils.nodeExists(decodedXml, "aai-status")) {
853 aai_status = ((String) taskProcessor.utils.getNodeText(decodedXml, "aai-status"))
854 taskProcessor.utils.log("DEBUG", "SDNC sent AAI STATUS code: " + aai_status, isDebugLogEnabled)
856 if (aai_status != null && !aai_status.equals("")) {
857 execution.setVariable(prefix+"AaiStatus",aai_status)
858 taskProcessor.utils.log("DEBUG", "Set variable " + prefix + "AaiStatus: " + execution.getVariable(prefix+"AaiStatus"), isDebugLogEnabled)
861 // Get the result string to determine if rollback is needed on ASSIGN in Add Bonding flow only
863 if (taskProcessor.utils.nodeExists(decodedXml, "result")) {
864 sdncResult = ((String) taskProcessor.utils.getNodeText(decodedXml, "result"))
865 taskProcessor.utils.log("DEBUG", "SDNC sent result: " + sdncResult, isDebugLogEnabled)
867 if (sdncResult != null && !sdncResult.equals("")) {
868 execution.setVariable(prefix+"SdncResult",sdncResult)
869 taskProcessor.utils.log("DEBUG", "Set variable " + prefix + "SdncResult: " + execution.getVariable(prefix+"SdncResult"), isDebugLogEnabled)
873 intDataResponseCode = Integer.parseInt(String.valueOf(requestDataResponseCode))
875 intDataResponseCode = 400
878 taskProcessor.utils.log("DEBUG", "intDataResponseCode " + intDataResponseCode , isDebugLogEnabled)
880 // if response-code is not Success (200, 201, etc) we need to throw an exception
881 if (intDataResponseCode != 200 && intDataResponseCode != 0) {
882 execution.setVariable(prefix+'ResponseCode', intDataResponseCode)
883 execution.setVariable("L3HLAB_rollback", true)
884 def msg = commonExceptionUtil.mapSDNCAdapterExceptionToErrorResponse(response, execution)
885 taskProcessor.commonWorkflowException(execution, intDataResponseCode, "Received error from SDN-C: " + msg)
889 taskProcessor.logWarn('sdncAdapter did not complete successfully, sdncAdapter Success Indicator was false ')
890 execution.setVariable("L3HLAB_rollback", true)
891 def msg = commonExceptionUtil.mapSDNCAdapterExceptionToErrorResponse(response, execution)
892 taskProcessor.commonWorkflowException(execution, responseCode, msg)
895 if (response == null || response.trim().equals("")) {
896 taskProcessor.logWarn('sdncAdapter workflow response is empty');
897 execution.setVariable("L3HLAB_rollback", true)
898 def msg = commonExceptionUtil.buildException("Exception occurred while validating SDNC response " , execution)
899 taskProcessor.commonWorkflowException(execution, intResponseCode, msg)
902 execution.setVariable(prefix+'sdncResponseSuccess', true)
903 taskProcessor.logDebug('Exited ' + method, isDebugLogEnabled)
904 } catch (BpmnError e) {
906 } catch (Exception e) {
907 taskProcessor.logError('Caught exception in ' + method, e)
908 execution.setVariable(prefix+"ResponseCode",400)
909 execution.setVariable("L3HLAB_rollback", true)
910 def msg = commonExceptionUtil.buildException("Exception occurred while validating SDNC response: " + e.getMessage(), execution)
911 taskProcessor.commonWorkflowException(execution, 400, msg)
916 * Decode XML - replace & < and > with '&', '<' and '>'
917 * @param xml - the xml to be decoded
919 private String decodeXML(String xml) {
920 def String decodedXml = xml.replaceAll("&", "&")
921 decodedXml = decodedXml.replaceAll("<", "<")
922 decodedXml = decodedXml.replaceAll(">", ">")