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 java.text.SimpleDateFormat
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.runtime.Execution
30 public class CompleteMsoProcess extends AbstractServiceTaskProcessor {
33 ExceptionUtil exceptionUtil = new ExceptionUtil()
35 // Complete MSO Request processing
36 public initializeProcessVariables(Execution execution){
38 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
39 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
40 logDebug('Entered ' + method, isDebugLogEnabled)
43 /* Initialize all the process request variables in this block */
44 execution.setVariable("prefix",Prefix)
45 //execution.setVariable("getLayer3ServiceDetailsV1Response","")
46 execution.setVariable("CMSO_request_id","")
47 execution.setVariable("CMSO_notification-url","")
48 execution.setVariable("CMSO_mso-bpel-name","")
49 execution.setVariable("CMSO_request_action","")
51 execution.setVariable("CMSO_notification-url-Ok", false)
52 execution.setVariable("CMSO_request_id-Ok", false)
54 //These variabels are for Get Mso Aai Password Adapter
55 execution.setVariable("CMSO_deliveryStatus", false)
57 //updateRequest Adapter process variables
58 execution.setVariable("CMSO_updateRequestResponse", "")
59 execution.setVariable("CMSO_updateRequestResponseCode", "")
60 execution.setVariable("CMSO_updateFinalNotifyAckStatusSuccessPayload", "")
61 execution.setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "")
62 execution.setVariable("CMSO_gSendManagedNetworkStatusNotificationResponse", "")
64 //Set DB adapter variables here
65 execution.setVariable("CMSO_updateFinalStatusSuccessPayload", "")
66 execution.setVariable("CMSO_updateDBStatusToSuccessPayload", "")
67 execution.setVariable("CMSO_updateInfraRequestDBPayload", "")
68 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "")
69 execution.setVariable("CMSO_setUpdateFinalNotifyAckStatusPayload", "")
71 //NotifyOMXSuccessFailureViaCSI Adapter variables
72 execution.setVariable("CMSO_notifyOMXSuccessFailureViaCSIPayload", "")
73 execution.setVariable("CMSO_notifyOMXSuccessFailureViaCSIResponseCode", null)
74 execution.setVariable("CMSO_notifyOMXSuccessFailureViaCSIResponse", "")
77 execution.setVariable("BasicAuthHeaderValue","")
80 execution.setVariable("CompletionHandlerResponse","")
81 execution.setVariable("CMSO_ErrorResponse", null)
82 execution.setVariable("CMSO_ResponseCode", "")
84 setSuccessIndicator(execution, false)
86 } catch (BpmnError e) {
88 } catch (Exception e) {
89 logError('Caught exception in ' + method, e)
90 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
95 public void preProcessRequest (Execution execution) {
97 initializeProcessVariables(execution)
98 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
99 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
100 utils.log("DEBUG", "*** Started CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
101 logDebug('Entered ' + method, isDebugLogEnabled)
103 def xml = execution.getVariable("CompleteMsoProcessRequest")
105 utils.logAudit("CompleteMsoProcess Request: " + xml)
106 utils.log("DEBUG", "Incoming Request is: "+ xml, isDebugLogEnabled)
108 //mso-bpel-name from the incoming request
109 def msoBpelName = utils.getNodeText1(xml,"mso-bpel-name")
110 execution.setVariable("CMSO_mso-bpel-name",msoBpelName)
112 //Check the incoming request type
113 //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node)
114 if (utils.nodeExists(xml, "request-information")) {
115 execution.setVariable("CMSO_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS
118 //Check notification-url for the incoming request type
119 //ACTIVE_REQUESTS may have notificationurl node
120 //INFRA_ACTIVE_REQUESTS notificationurl node does not exist
121 def notificationurl = ""
122 if (utils.nodeExists(xml, "notification-url")) {
123 notificationurl = utils.getNodeText(xml,"notification-url")
124 if(notificationurl != null && !notificationurl.isEmpty()) {
125 execution.setVariable("CMSO_notification-url-Ok", true)
126 execution.setVariable("CMSO_notification-url",notificationurl)
130 //Check request_id for the incoming request type
131 //For INFRA_ACTIVE_REQUESTS payload request-id IS optional (Not sure why this is option since req id is primary key ... also tried exe through SOAP UI to check if MSO code handles null like auto generated seq not it does not)
132 //For ACTIVE_REQUESTS payload request-id is NOT optional
134 if (utils.nodeExists(xml, "request-id")) {
135 execution.setVariable("CMSO_request_id",utils.getNodeText(xml,"request-id"))
139 // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory
140 // ACTIVE_REQUEST have "request-action" ... mandatory
141 if (utils.nodeExists(xml, "request-action")) {
142 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"request-action"))
143 } else if (utils.nodeExists(xml, "action")) {
144 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"action"))
147 //Check source for the incoming request type
148 //For INFRA_ACTIVE_REQUESTS payload source IS optional
149 //For ACTIVE_REQUESTS payload source is NOT optional
151 if (utils.nodeExists(xml, "source")) {
152 execution.setVariable("CMSO_source",utils.getNodeText(xml,"source"))
155 utils.log("DEBUG", "CMSO_notification-url-Ok --> " + execution.getVariable("CMSO_notification-url-Ok"), isDebugLogEnabled)
156 utils.log("DEBUG", "CMSO_request_id-Ok --> " + execution.getVariable("CMSO_request_id-Ok"), isDebugLogEnabled)
158 logDebug('Exited ' + method, isDebugLogEnabled)
159 } catch (BpmnError e) {
161 } catch (Exception e) {
162 utils.log("DEBUG", "Exception Occured During PreProcessRequest: " + e, isDebugLogEnabled);
163 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
166 utils.log("DEBUG", "*** Completed CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
169 public void postProcessResponse (Execution execution) {
171 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
172 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
173 logDebug('Entered ' + method, isDebugLogEnabled)
174 utils.log("DEBUG", "*** Started CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
177 def msoCompletionResponse = """
178 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1">
179 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} completed</sdncadapterworkflow:out>
180 </sdncadapterworkflow:MsoCompletionResponse>
184 def xmlMsoCompletionResponse = utils.formatXML(msoCompletionResponse)
185 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
186 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
187 execution.setVariable("WorkflowResponse", buildMsoCompletionResponseAsString)
188 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
189 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
190 execution.setVariable("CMSO_ResponseCode", "200")
192 setSuccessIndicator(execution, true)
194 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompleteMsoProcessResponse"), isDebugLogEnabled)
196 logDebug('Exited ' + method, isDebugLogEnabled)
197 } catch (BpmnError e) {
199 } catch (Exception e) {
200 logError('Caught exception in ' + method, e)
201 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
203 utils.log("DEBUG", "*** Completed CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
207 public void updateFinalNotifyAckStatusSuccessPayload (Execution execution){
208 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
209 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
210 logDebug('Entered ' + method, isDebugLogEnabled)
213 def deliveryStatus = execution.getVariable("CMSO_deliveryStatus")
214 String responseStatus = ""
215 String responseCode = ""
216 String responseBodyXml = ""
218 if(deliveryStatus == true){
219 responseStatus = "SUCCESS"
221 responseBodyXml = """<responseBody>${execution.getVariable("CMSO_gSendManagedNetworkStatusNotificationResponse")}</responseBody>"""
223 responseStatus = "FAILED"
224 responseCode = execution.getVariable("CCDStatusCode")
228 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
232 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
233 <lastModifiedBy>BPEL</lastModifiedBy>
234 <responseStatus>${responseStatus}</responseStatus>
235 <responseCode>${responseCode}</responseCode>
239 </soapenv:Envelope>"""
241 execution.setVariable("CMSO_updateFinalNotifyAckStatusSuccessPayload", payload)
242 utils.logAudit("updateFinalNotifyAckStatusPayload: " + payload)
243 logDebug('Exited ' + method, isDebugLogEnabled)
245 } catch (BpmnError e) {
247 } catch (Exception e) {
248 logError('Caught exception in ' + method, e)
249 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
254 public String updateFinalStatusSuccessPayload (Execution execution){
256 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
257 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
258 logDebug('Entered ' + method, isDebugLogEnabled)
261 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
265 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
266 <lastModifiedBy>BPEL</lastModifiedBy>
267 <responseStatus>SUCCESS</responseStatus>
272 execution.setVariable("CMSO_updateFinalStatusSuccessPayload", payload)
273 utils.logAudit("updateFinalStatusSuccessPayload: " + payload)
274 logDebug('Exited ' + method, isDebugLogEnabled)
275 //println("CMSO_updateFinalStatusSuccessPayload --> " + execution.getVariable("CMSO_updateFinalStatusSuccessPayload"))
277 return execution.getVariable("CMSO_updateFinalStatusSuccessPayload")
279 } catch (BpmnError e) {
281 } catch (Exception e) {
282 logError('Caught exception in ' + method, e)
283 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
287 public void updateDBStatusToSuccessPayload (Execution execution){
288 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
289 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
290 logDebug('Entered ' + method, isDebugLogEnabled)
294 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
298 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
299 <lastModifiedBy>BPEL</lastModifiedBy>
300 <status>COMPLETED</status>
305 execution.setVariable("CMSO_updateDBStatusToSuccessPayload", payload)
306 utils.logAudit("updateDBStatusToSuccessPayload: " + payload)
307 logDebug('Exited ' + method, isDebugLogEnabled)
308 //println("CMSO_updateDBStatusToSuccessPayload --> " + execution.getVariable("CMSO_updateDBStatusToSuccessPayload"))
310 } catch (BpmnError e) {
312 } catch (Exception e) {
313 logError('Caught exception in ' + method, e)
314 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
318 public void setUpdateDBstatustoSuccessPayload (Execution execution){
320 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
321 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
322 logDebug('Entered ' + method, isDebugLogEnabled)
325 def xml = execution.getVariable("CompleteMsoProcessRequest")
327 //Get statusMessage if exists
329 if(utils.nodeExists(xml, "status-message")){
330 statusMessage = utils.getNodeText1(xml, "status-message")
332 statusMessage = "Resource Completed Successfully"
335 //Get instance Id if exist
337 if(utils.nodeExists(xml, "vnfId")){
338 idXml = utils.getNodeXml(xml, "vnfId")
339 }else if(utils.nodeExists(xml, "networkId")){
340 idXml = utils.getNodeXml(xml, "networkId")
341 }else if(utils.nodeExists(xml, "serviceInstanceId")){
342 idXml = utils.getNodeXml(xml, "serviceInstanceId")
343 }else if(utils.nodeExists(xml, "vfModuleId")){
344 idXml = utils.getNodeXml(xml, "vfModuleId")
345 }else if(utils.nodeExists(xml, "volumeGroupId")){
346 idXml = utils.getNodeXml(xml, "volumeGroupId")
350 idXml = utils.removeXmlPreamble(idXml)
351 utils.log("DEBUG", "Incoming Instance Id Xml: " + idXml, isDebugLogEnabled)
354 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
357 <req:updateInfraRequest>
358 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
359 <lastModifiedBy>${execution.getVariable("CMSO_mso-bpel-name")}</lastModifiedBy>
360 <statusMessage>${statusMessage}</statusMessage>
361 <requestStatus>COMPLETE</requestStatus>
362 <progress>100</progress>
364 </req:updateInfraRequest>
366 </soapenv:Envelope>"""
368 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", payload)
369 utils.log("DEBUG", "Outgoing Update Mso Request Payload is: " + payload, isDebugLogEnabled)
370 utils.logAudit("setUpdateDBstatustoSuccessPayload: " + payload)
372 } catch (BpmnError e) {
374 } catch (Exception e) {
375 logError('Caught exception in ' + method, e)
376 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
378 logDebug('Exited ' + method, isDebugLogEnabled)
381 public String updateFinalNotifyAckStatusPayload (Execution execution){
383 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
384 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
385 logDebug('Entered ' + method, isDebugLogEnabled)
388 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://com.att.mso/requestsdb">
391 <req:updateResponseStatus>
392 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
393 <lastModifiedBy>BPEL</lastModifiedBy>
394 <responseStatus>SENDING_FINAL_NOTIFY</responseStatus>
395 </req:updateResponseStatus>
399 execution.setVariable("CMSO_setUpdateFinalNotifyAckStatusPayload", payload)
400 utils.logAudit("updateFinalNotifyAckStatusPayload: " + payload)
401 logDebug('Exited ' + method, isDebugLogEnabled)
403 return execution.getVariable("CMSO_setUpdateFinalNotifyAckStatusPayload")
405 } catch (BpmnError e) {
407 } catch (Exception e) {
408 logError('Caught exception in ' + method, e)
409 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
414 // public void decryptMsoPassword (Execution execution) {
416 // def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
417 // def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
418 // logDebug('Entered ' + method, isDebugLogEnabled)
420 // def encryptedPwd=execution.getVariable("URN_mso_csi_pwd")
421 // def msoKey = execution.getVariable("URN_mso_msoKey")
423 // String basicAuthValue = utils.getBasicAuth(encryptedPwd, msoKey)
424 // execution.setVariable("BasicAuthHeaderValueCSI",basicAuthValue)
425 // logDebug('Exited ' + method, isDebugLogEnabled)
426 // } catch (BpmnError e) {
428 // } catch (IOException e) {
429 // logError('Caught exception in ' + method, e)
430 // workflowException(execution, 'Internal Error', 2000)
434 public String notifyOMXSuccessFailureViaCSIPayload (Execution execution) {
439 public String notifyCCDSuccessPayload (Execution execution) {
441 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
442 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
443 logDebug('Entered ' + method, isDebugLogEnabled)
447 <ns:status-notification xmlns:ns="http://ecomp.att.com/mso/statusnotification/schema/v1" xmlns:msoservtypes="http://ecomp.att.com/mso/request/types/v1">
448 <msoservtypes:request-id>${execution.getVariable("CMSO_request_id")}</msoservtypes:request-id>
449 <msoservtypes:request-action>${execution.getVariable("CMSO_request_action")}</msoservtypes:request-action>
450 <msoservtypes:source>${execution.getVariable("CMSO_source")}</msoservtypes:source>
451 <msoservtypes:ack-final-indicator>Y</msoservtypes:ack-final-indicator>
452 </ns:status-notification>
454 execution.setVariable("CMSO_notifyCCDSuccessPayload", payload)
455 utils.logAudit("notifyCCDSuccessPayload: " + payload)
456 logDebug('Exited ' + method, isDebugLogEnabled)
458 return execution.getVariable("CMSO_notifyCCDSuccessPayload")
460 } catch (BpmnError e) {
462 } catch (Exception e) {
463 logError('Caught exception in ' + method, e)
464 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
470 public void buildDataError (Execution execution, String message) {
472 def method = getClass().getSimpleName() + '.sendResponse(' +'execution=' + execution.getId() +')'
473 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
474 logDebug('Entered ' + method, isDebugLogEnabled)
477 def msoCompletionResponse = """
478 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1">
479 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} FAILED</sdncadapterworkflow:out>
480 </sdncadapterworkflow:MsoCompletionResponse>
484 def xmlMsoCompletionResponse = utils.formatXml(msoCompletionResponse)
485 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
486 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
487 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
488 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompletionHandlerResponse"), isDebugLogEnabled)
490 exceptionUtil.buildAndThrowWorkflowException(execution, 500, message)
492 } catch (BpmnError e) {
493 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
495 } catch (Exception e) {
496 logError('Caught exception in ' + method, e)
497 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)