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 com.att.bpm.scripts;
23 import org.openecomp.mso.bpmn.core.WorkflowException
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.runtime.Execution
27 import org.apache.commons.lang3.*
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("att-mso-request-id") + "-" + System.currentTimeMillis()
59 def svcInstanceId = execution.getVariable("att-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://ecomp.att.com/mso/workflow/schema/v1"
68 xmlns:sdncadapter="http://domain2.att.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("att-mso-request-id") + "-" + System.currentTimeMillis()
103 def svcInstanceId = execution.getVariable("att-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://ecomp.att.com/mso/workflow/schema/v1"
111 xmlns:sdncadapter="http://domain2.att.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("att-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("att-mso-request-id") + "-" + System.currentTimeMillis()
162 def svcInstanceId = execution.getVariable("att-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://ecomp.att.com/mso/workflow/schema/v1"
203 xmlns:sdncadapter="http://domain2.att.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("att-mso-request-id") + "-" + System.currentTimeMillis()
246 def svcInstanceId = execution.getVariable("att-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 internetEvcAccessInformation = utils.getNodeXml(serviceParameters, 'internet-evc-access-information', false)
258 def vrLan = utils.getNodeXml(serviceParameters, 'vr-lan', false)
260 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
261 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
262 def nnsInternetEvcAccessInformation = utils.removeXmlNamespaces(internetEvcAccessInformation)
263 def nnsVrLan = utils.removeXmlNamespaces(vrLan)
265 if (additionalData == null) {
270 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
271 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
272 <sdncadapter:RequestHeader>
273 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
274 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
275 <sdncadapter:SvcAction>${svcAction}</sdncadapter:SvcAction>
276 <sdncadapter:SvcOperation>${svcOperation}</sdncadapter:SvcOperation>
277 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
278 <sdncadapter:MsoAction>${msoAction}</sdncadapter:MsoAction>
279 </sdncadapter:RequestHeader>
280 <sdncadapterworkflow:SDNCRequestData>
282 ${nnsRequestInformation}
283 ${nnsServiceInformation}
284 ${nnsInternetEvcAccessInformation}
286 </sdncadapterworkflow:SDNCRequestData>
287 <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${timeoutInMinutes}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
288 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
291 content = utils.removeXmlPreamble(utils.formatXML(content))
292 execution.setVariable(resultVar, content)
296 * Builds an SDNC "reserve" request and stores it in the specified execution
298 * @param execution the execution
299 * @param resultVar the execution variable in which the result will be stored
301 public void sdncReservePrep(Execution execution, String action, String resultVar) {
302 sdncPrep(execution, resultVar, action , 'service-configuration-operation', null, this.taskProcessor)
306 * Builds a basic SDNC request and stores it in the specified execution variable.
307 * @param execution the execution
308 * @param resultVar the execution variable in which the result will be stored
309 * @param svcAction the svcAction element value
310 * @param svcOperation the svcOperation element value
311 * @param additionalData additional XML content to be inserted into the
312 * RequestData element (may be null)
314 public void sdncPrep(Execution execution, String resultVar, String svcAction,
315 String svcOperation, String additionalData, AbstractServiceTaskProcessor taskProcessor) {
316 def method = getClass().getSimpleName() + '.sdncPrep(' +
317 'execution=' + execution.getId() +
318 ', resultVar=' + resultVar +
319 ', svcAction=' + svcAction +
320 ', svcOperation=' + svcOperation +
321 ', additionalData=' + (additionalData == null ? "no" : "yes") +
324 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
325 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
326 MsoUtils utils = taskProcessor.utils
328 def prefix = execution.getVariable('prefix')
329 def request = taskProcessor.getVariable(execution, prefix+'Request')
330 def requestInformation = utils.getNodeXml(request, 'request-information', false)
331 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
332 def serviceParameters = utils.getChildNodes(request, 'service-parameters')
333 def requestAction = utils.getNodeText1(request, 'request-action')
335 def timeoutInMinutes = execution.getVariable('URN_mso_sdnc_timeout_firewall_minutes')
337 def requestId = execution.getVariable('testReqId') // for junits
339 requestId = execution.getVariable("att-mso-request-id") + "-" + System.currentTimeMillis()
342 def svcInstanceId = execution.getVariable("att-mso-service-instance-id")
343 def msoAction = 'gammainternet'
345 def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
346 if (callbackUrl == null || callbackUrl.trim() == "") {
347 taskProcessor.logError('mso:workflow:sdncadapter:callback URN is not set')
348 taskProcessor.workflowException(execution, 'Internal Error', 9999) // TODO: what message and error code?
351 def internetEvcAccessInformation = utils.getNodeXml(request, 'internet-evc-access-information', false)
352 def vrLan = utils.getNodeXml(request, 'vr-lan', false)
353 def vnfInformationList = utils.getNodeXml(request, 'vnf-information-list', false)
355 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
356 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
357 def nnsInternetEvcAccessInformation = utils.removeXmlNamespaces(internetEvcAccessInformation)
358 def nnsVrLan = utils.removeXmlNamespaces(vrLan)
359 def nnsVnfInformationList = utils.removeXmlNamespaces(vrLan)
360 def nnsinternetSvcChangeDetails = ""
362 if(requestAction!=null && requestAction.equals("ChangeLayer3ServiceProvRequest")){
363 def internetSvcChangeDetails = utils.removeXmlNamespaces(serviceParameters)
364 nnsinternetSvcChangeDetails = """<internet-service-change-details>
365 ${internetSvcChangeDetails}
366 </internet-service-change-details>"""
369 if (additionalData == null) {
374 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
375 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
376 <sdncadapter:RequestHeader>
377 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
378 <sdncadapter:SvcInstanceId>${svcInstanceId}</sdncadapter:SvcInstanceId>
379 <sdncadapter:SvcAction>${svcAction}</sdncadapter:SvcAction>
380 <sdncadapter:SvcOperation>${svcOperation}</sdncadapter:SvcOperation>
381 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
382 <sdncadapter:MsoAction>${msoAction}</sdncadapter:MsoAction>
383 </sdncadapter:RequestHeader>
384 <sdncadapterworkflow:SDNCRequestData>
386 ${nnsRequestInformation}
387 ${nnsServiceInformation}
388 ${nnsInternetEvcAccessInformation}
390 ${nnsVnfInformationList}
391 ${nnsinternetSvcChangeDetails}
392 </sdncadapterworkflow:SDNCRequestData>
393 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
396 content = utils.removeXmlPreamble(utils.formatXML(content))
397 execution.setVariable(resultVar, content)
398 taskProcessor.logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
400 taskProcessor.logDebug('Exited ' + method, isDebugLogEnabled)
401 } catch (BpmnError e) {
403 } catch (Exception e) {
404 taskProcessor.logError('Caught exception in ' + method, e)
405 taskProcessor.workflowException(execution, 'Internal Error', 9999) // TODO: what message and error code?
412 * Builds a topology SDNC request and return String request.
413 * As V2 will use 1607-style request, region instead of aic clli code
414 * @param execution, the execution
415 * @param requestXML, the incoming request for the flow
416 * @param serviceInstanceId, the serviceIntance (if available)
417 * @param callbackUrl, the call back url
418 * @param action, the action element value
419 * @param requestAction the svcOperation element value
420 * @param cloudRegionId the aai's cloud-region-id
421 * @param additionalData additional XML content to be inserted into the
422 * RequestData element (may be null)
424 public String sdncTopologyRequestV2 (Execution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String additionalData) {
425 def utils=new MsoUtils()
427 String requestId = ""
429 requestId = execution.getVariable("att-mso-request-id")
430 } catch (Exception ex) {
431 requestId = utils.getNodeText1(requestXML, "request-id")
434 String aicCloudRegion = cloudRegionId
436 if (utils.nodeExists(requestXML, "tenant-id")) {
437 tenantId = utils.getNodeText1(requestXML, "tenant-id")
439 String networkType = ""
440 if (utils.nodeExists(requestXML, "network-type")) {
441 networkType = utils.getNodeText1(requestXML, "network-type")
443 String serviceId = ""
444 if (utils.nodeExists(requestXML, "service-id")) {
445 serviceId = utils.getNodeText1(requestXML, "service-id")
447 String networkName = ""
448 if (utils.nodeExists(requestXML, "network-name")) {
449 networkName = utils.getNodeText1(requestXML, "network-name")
452 if (utils.nodeExists(requestXML, "source")) {
453 source = utils.getNodeText1(requestXML, "source")
456 // get resourceLink from subflow execution variable
457 String serviceType = ""
458 String subscriberName = ""
459 String siRelatedLink = execution.getVariable("GENGSI_siResourceLink")
460 if (siRelatedLink != null) {
462 int serviceStart = siRelatedLink.indexOf("service-subscription/")
463 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
464 serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
465 // get subscriber name
466 int subscriberNameStart = siRelatedLink.indexOf("customers/customer/")
467 int subscriberNameEnd = siRelatedLink.indexOf("/service-subscriptions/")
468 subscriberName = siRelatedLink.substring(subscriberNameStart + 19, subscriberNameEnd)
472 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
473 xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
474 xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1"
475 xmlns:ns5="http://ecomp.att.com/mso/request/types/v1">
476 <sdncadapter:RequestHeader>
477 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
478 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
479 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
480 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
481 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
482 </sdncadapter:RequestHeader>
483 <sdncadapterworkflow:SDNCRequestData>
484 <request-information>
485 <request-id>${requestId}</request-id>
486 <request-action>${requestAction}</request-action>
487 <source>${source}</source>
488 <notification-url></notification-url>
489 <order-number></order-number>
490 <order-version></order-version>
491 </request-information>
492 <service-information>
493 <service-id>${serviceId}</service-id>
494 <service-type>${serviceType}</service-type>
495 <service-instance-id>${serviceInstanceId}</service-instance-id>
496 <subscriber-name>${subscriberName}</subscriber-name>
497 </service-information>
498 <network-request-information>
499 <network-id>${networkId}</network-id>
500 <network-type>${networkType}</network-type>
501 <network-name>${networkName}</network-name>
502 <tenant>${tenantId}</tenant>
503 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
504 </network-request-information>
505 </sdncadapterworkflow:SDNCRequestData>
506 </aetgt:SDNCAdapterWorkflowRequest>""".trim()
512 * Validates a workflow response.
513 * @param execution the execution
514 * @param responseVar the execution variable in which the response is stored
515 * @param responseCodeVar the execution variable in which the response code is stored
516 * @param errorResponseVar the execution variable in which the error response is stored
519 public void validateSDNCResponseOld(Execution execution, String responseVar,
520 String responseCodeVar, String errorResponseVar) {
521 def method = getClass().getSimpleName() + '.validateWorkflowResponse(' +
522 'execution=' + execution.getId() +
523 ', responseVar=' + responseVar +
524 ', responseCodeVar=' + responseCodeVar +
525 ', errorResponseVar=' + errorResponseVar +
527 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
528 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
531 def prefix = execution.getVariable('prefix')
532 execution.setVariable(prefix+'sdncResponseSuccess', false)
533 def response = execution.getVariable(responseVar)
534 taskProcessor.logDebug(responseVar + ' = ' +
535 (response == null ? "" : System.lineSeparator()) +
536 response, isDebugLogEnabled)
538 def responseCode = execution.getVariable(responseCodeVar)
539 taskProcessor.logDebug(responseCodeVar + ' = ' + responseCode, isDebugLogEnabled)
541 def errorResponse = execution.getVariable(errorResponseVar)
543 errorResponse = taskProcessor.utils.getNodeText1(errorResponse,"ErrorMessage")
544 if (errorResponse == null) errorResponse = errorResponse
546 taskProcessor.logDebug(errorResponseVar + ' = ' +
547 (errorResponse == null ? "" : System.lineSeparator()) +
548 errorResponse, isDebugLogEnabled)
550 if ("200".equals(String.valueOf(responseCode)) || "201".equals(String.valueOf(responseCode))) {
552 // we need to peer into the request data for error
553 def String callbackRequestData = taskProcessor.utils.getNodeXml(response, 'RequestData', false)
554 def String decodedXml = decodeXML(callbackRequestData)
555 taskProcessor.utils.log("DEBUG","decodedXml:\n" + decodedXml, isDebugLogEnabled)
557 def int requestDataResponseCode = 200
558 def String requestDataResponseMessage = ''
560 if (taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
562 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText(decodedXml, "response-code")).toInteger()
564 //TODO proper handling of new, non numerical response codes in 1607 and new error handling for common API
565 requestDataResponseCode = 500
567 if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
568 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")
572 taskProcessor.utils.log("DEBUG", "SDNC callback response-code: " + requestDataResponseCode, isDebugLogEnabled)
573 taskProcessor.utils.log("DEBUG", "SDNC callback response-message: " + requestDataResponseMessage, isDebugLogEnabled)
575 // if response-code is not Success (200, 201, etc) we need to throw an exception
576 if (requestDataResponseCode < 200 || requestDataResponseCode > 299) {
577 ExceptionUtil exceptionUtil = new ExceptionUtil()
578 def convertedCode = exceptionUtil.MapSDNCResponseCodeToErrorCode(requestDataResponseCode.toString())
579 taskProcessor.workflowException(execution, "Received error from SDN-C: " + requestDataResponseMessage, convertedCode)
584 taskProcessor.logWarn('Expected response code 200 or 201 in ' + responseCodeVar + ', got \'' + responseCode + '\'')
585 taskProcessor.workflowException(execution, errorResponse, responseCode)
588 if (response == null || response.trim().equals("")) {
589 taskProcessor.logWarn(responseVar + ' is empty');
590 taskProcessor.workflowException(execution, errorResponse, responseCode)
593 execution.setVariable(prefix+'sdncResponseSuccess', true)
594 taskProcessor.logDebug('Exited ' + method, isDebugLogEnabled)
595 } catch (BpmnError e) {
597 } catch (Exception e) {
598 taskProcessor.logError('Caught exception in ' + method, e)
599 taskProcessor.workflowException(execution, 'Internal Error- Unable to validate SDNC Response ' + e.getMessage(), 500)
603 * Validates a workflow response.
604 * @param execution the execution
605 * @param responseVar the execution variable in which the response is stored
606 * @param workflowException the WorkflowException Object returned from sdnc call
608 public void validateSDNCResponse(Execution execution, String response, WorkflowException workflowException, boolean successIndicator){
609 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
610 taskProcessor.utils.log("DEBUG", "SDNC Response is: " + response, isDebugLogEnabled)
611 taskProcessor.utils.log("DEBUG", "SuccessIndicator is: " + successIndicator, isDebugLogEnabled)
614 def prefix = execution.getVariable('prefix')
615 execution.setVariable(prefix+'sdncResponseSuccess', false)
616 taskProcessor.utils.log("DEBUG", "Response" + ' = ' + (response == null ? "" : System.lineSeparator()) + response, isDebugLogEnabled)
618 if (successIndicator == true){
619 if (response == null || response.trim().equals("")) {
620 taskProcessor.utils.log("DEBUG", response + ' is empty');
621 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "SDNCAdapter Workflow Response is Empty")
624 // we need to peer into the request data for error
625 def String sdncAdapterWorkflowResponse = taskProcessor.utils.getNodeXml(response, 'response-data', false)
626 def String decodedXml = decodeXML(sdncAdapterWorkflowResponse).replace('<?xml version="1.0" encoding="UTF-8"?>', "")
628 // change '&' to "& (if present as data, ex: subscriber-name = 'FOUR SEASONS HEATING & COOLING_8310006378683'
629 decodedXml = decodedXml.replace("&", "&")
631 taskProcessor.utils.log("DEBUG","decodedXml:\n" + decodedXml, isDebugLogEnabled)
633 int requestDataResponseCode = 200
634 def String requestDataResponseMessage = ''
637 if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
638 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")
639 } else if (taskProcessor.utils.nodeExists(decodedXml, "ResponseMessage")) {
640 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "ResponseMessage")
643 taskProcessor.utils.log("DEBUG", 'Error caught while decoding resposne ' + e.getMessage(), isDebugLogEnabled)
646 if(taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
647 taskProcessor.utils.log("DEBUG","response-code node Exist ", isDebugLogEnabled)
648 String code = taskProcessor.utils.getNodeText1(decodedXml, "response-code")
649 if(code.isEmpty() || code.equals("")){
650 // if response-code is blank then Success
651 taskProcessor.utils.log("DEBUG","response-code node is empty", isDebugLogEnabled)
652 requestDataResponseCode = 0
654 requestDataResponseCode = code.toInteger()
655 taskProcessor.utils.log("DEBUG","response-code is: " + requestDataResponseCode, isDebugLogEnabled)
657 }else if(taskProcessor.utils.nodeExists(decodedXml, "ResponseCode")){
658 taskProcessor.utils.log("DEBUG","ResponseCode node Exist ", isDebugLogEnabled)
659 String code = taskProcessor.utils.getNodeText1(decodedXml, "ResponseCode")
660 if(code.isEmpty() || code.equals("")){
661 // if ResponseCode blank then Success
662 taskProcessor.utils.log("DEBUG","ResponseCode node is empty", isDebugLogEnabled)
663 requestDataResponseCode = 0
665 requestDataResponseCode = code.toInteger()
666 taskProcessor.utils.log("DEBUG","ResponseCode is: " + requestDataResponseCode, isDebugLogEnabled)
669 taskProcessor.utils.log("DEBUG","A Response Code DOES NOT Exist.", isDebugLogEnabled)
670 // if a response code does not exist then Success
671 requestDataResponseCode = 0
675 // if a response code is 0 or 200 then Success
676 if (requestDataResponseCode == 200 || requestDataResponseCode == 0) {
677 execution.setVariable(prefix+'sdncResponseSuccess', true)
678 taskProcessor.utils.log("DEBUG", "Setting sdncResponseSuccess to True ", isDebugLogEnabled)
679 taskProcessor.utils.log("DEBUG", "Exited ValidateSDNCResponse Method", isDebugLogEnabled)
681 ExceptionUtil exceptionUtil = new ExceptionUtil()
682 String convertedCode = exceptionUtil.MapSDNCResponseCodeToErrorCode(requestDataResponseCode.toString())
683 int convertedCodeInt = Integer.parseInt(convertedCode)
684 exceptionUtil.buildAndThrowWorkflowException(execution, convertedCodeInt, "Received error from SDN-C: " + requestDataResponseMessage)
688 //TODO proper handling of new, non numerical response codes in 1607 and new error handling for common API
689 requestDataResponseCode = 500
692 taskProcessor.utils.log("DEBUG", "SDNC callback response-code: " + requestDataResponseCode, isDebugLogEnabled)
693 taskProcessor.utils.log("DEBUG", "SDNC callback response-message: " + requestDataResponseMessage, isDebugLogEnabled)
697 taskProcessor.utils.log("DEBUG", 'SDNCAdapter Subflow did NOT complete Successfully. SuccessIndicator is False. ')
698 if(workflowException != null){
699 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
701 //TODO : what error code and error message use here
702 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - SDNCAdapter Subflow did NOT complete successfully.")
706 } catch (BpmnError e) {
708 } catch (Exception e) {
709 taskProcessor.utils.log("DEBUG", 'END of Validate SDNC Response', isDebugLogEnabled)
710 exceptionUtil.buildAndThrowWorkflowException(execution, 500, 'Internal Error- Unable to validate SDNC Response ');
715 * Validates a workflow response.
716 * @param execution the execution
717 * @param responseVar the execution variable in which the response is stored
718 * @param responseCodeVar the execution variable in which the response code is stored
719 * @param errorResponseVar the execution variable in which the error response is stored
721 public void validateL3BondingSDNCResp(Execution execution, String response, WorkflowException workflowException, boolean success) {
722 def method = getClass().getSimpleName() + '.validateL3BondingSDNCResp(' +
723 'execution=' + execution.getId() +
724 ', response=' + response +
726 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
727 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
728 def prefix = execution.getVariable('prefix')
729 CommonExceptionUtil commonExceptionUtil = new CommonExceptionUtil()
732 execution.setVariable(prefix+'sdncResponseSuccess', false)
734 taskProcessor.utils.log("sdncAdapter Success Indicator is: " + success, isDebugLogEnabled)
735 if (success == true) {
737 // we need to look inside the request data for error
738 def String callbackRequestData = taskProcessor.utils.getNodeXml(response, 'RequestData', false)
739 def String decodedXml = decodeXML(callbackRequestData)
740 taskProcessor.utils.log("DEBUG","decodedXml:\n" + decodedXml, isDebugLogEnabled)
742 def requestDataResponseCode = '200'
743 def requestDataResponseMessage = ''
744 int intDataResponseCode = 200
746 if (taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
748 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText(decodedXml, "response-code"))
749 if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
750 requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")
752 }else if(taskProcessor.utils.nodeExists(decodedXml, "ResponseCode")){
753 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText1(decodedXml, "ResponseCode")).toInteger()
754 }else if(taskProcessor.utils.nodeExists(response, "ResponseCode")){
755 requestDataResponseCode = ((String) taskProcessor.utils.getNodeText1(response, "ResponseCode")).toInteger()
756 requestDataResponseMessage = taskProcessor.utils.getNodeText(response, "ResponseMessage")
759 taskProcessor.utils.log("DEBUG", "SDNC callback response-code: " + requestDataResponseCode, isDebugLogEnabled)
760 taskProcessor.utils.log("DEBUG", "SDNC callback response-message: " + requestDataResponseMessage, isDebugLogEnabled)
762 // Get the AAI Status to determine if rollback is needed on ASSIGN
764 if (taskProcessor.utils.nodeExists(decodedXml, "aai-status")) {
765 aai_status = ((String) taskProcessor.utils.getNodeText(decodedXml, "aai-status"))
766 taskProcessor.utils.log("DEBUG", "SDNC sent AAI STATUS code: " + aai_status, isDebugLogEnabled)
768 if (aai_status != null && !aai_status.equals("")) {
769 execution.setVariable(prefix+"AaiStatus",aai_status)
770 taskProcessor.utils.log("DEBUG", "Set variable " + prefix + "AaiStatus: " + execution.getVariable(prefix+"AaiStatus"), isDebugLogEnabled)
773 // Get the result string to determine if rollback is needed on ASSIGN in Add Bonding flow only
775 if (taskProcessor.utils.nodeExists(decodedXml, "result")) {
776 sdncResult = ((String) taskProcessor.utils.getNodeText(decodedXml, "result"))
777 taskProcessor.utils.log("DEBUG", "SDNC sent result: " + sdncResult, isDebugLogEnabled)
779 if (sdncResult != null && !sdncResult.equals("")) {
780 execution.setVariable(prefix+"SdncResult",sdncResult)
781 taskProcessor.utils.log("DEBUG", "Set variable " + prefix + "SdncResult: " + execution.getVariable(prefix+"SdncResult"), isDebugLogEnabled)
785 intDataResponseCode = Integer.parseInt(String.valueOf(requestDataResponseCode))
787 intDataResponseCode = 400
790 taskProcessor.utils.log("DEBUG", "intDataResponseCode " + intDataResponseCode , isDebugLogEnabled)
792 // if response-code is not Success (200, 201, etc) we need to throw an exception
793 if (intDataResponseCode != 200 && intDataResponseCode != 0) {
794 execution.setVariable(prefix+'ResponseCode', intDataResponseCode)
795 execution.setVariable("L3HLAB_rollback", true)
796 def msg = commonExceptionUtil.mapSDNCAdapterExceptionToErrorResponse(response, execution)
797 taskProcessor.commonWorkflowException(execution, intDataResponseCode, "Received error from SDN-C: " + msg)
801 taskProcessor.logWarn('sdncAdapter did not complete successfully, sdncAdapter Success Indicator was false ')
802 execution.setVariable("L3HLAB_rollback", true)
803 def msg = commonExceptionUtil.mapSDNCAdapterExceptionToErrorResponse(response, execution)
804 taskProcessor.commonWorkflowException(execution, responseCode, msg)
807 if (response == null || response.trim().equals("")) {
808 taskProcessor.logWarn('sdncAdapter workflow response is empty');
809 execution.setVariable("L3HLAB_rollback", true)
810 def msg = commonExceptionUtil.buildException("Exception occurred while validating SDNC response " , execution)
811 taskProcessor.commonWorkflowException(execution, intResponseCode, msg)
814 execution.setVariable(prefix+'sdncResponseSuccess', true)
815 taskProcessor.logDebug('Exited ' + method, isDebugLogEnabled)
816 } catch (BpmnError e) {
818 } catch (Exception e) {
819 taskProcessor.logError('Caught exception in ' + method, e)
820 execution.setVariable(prefix+"ResponseCode",400)
821 execution.setVariable("L3HLAB_rollback", true)
822 def msg = commonExceptionUtil.buildException("Exception occurred while validating SDNC response: " + e.getMessage(), execution)
823 taskProcessor.commonWorkflowException(execution, 400, msg)
828 * Decode XML - replace & < and > with '&', '<' and '>'
829 * @param xml - the xml to be decoded
831 private String decodeXML(String xml) {
832 def String decodedXml = xml.replaceAll("&", "&")
833 decodedXml = decodedXml.replaceAll("<", "<")
834 decodedXml = decodedXml.replaceAll(">", ">")