2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.common.scripts
\r
23 import org.apache.commons.lang3.*
\r
24 import org.camunda.bpm.engine.delegate.BpmnError
\r
25 import org.camunda.bpm.engine.runtime.Execution
\r
28 public class CompleteMsoProcess extends AbstractServiceTaskProcessor {
\r
30 String Prefix="CMSO_"
\r
31 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
33 // Complete MSO Request processing
\r
34 public initializeProcessVariables(Execution execution){
\r
36 def method = getClass().getSimpleName() + '.initializeProcessVariables(' +'execution=' + execution.getId() +')'
\r
37 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
38 logDebug('Entered ' + method, isDebugLogEnabled)
\r
41 /* Initialize all the process request variables in this block */
\r
42 execution.setVariable("prefix",Prefix)
\r
43 execution.setVariable("CMSO_request_id","")
\r
44 execution.setVariable("CMSO_notification-url","")
\r
45 execution.setVariable("CMSO_mso-bpel-name","")
\r
46 execution.setVariable("CMSO_request_action","")
\r
47 execution.setVariable("CMSO_notification-url-Ok", false)
\r
48 execution.setVariable("CMSO_request_id-Ok", false)
\r
50 //updateRequest Adapter process variables
\r
51 execution.setVariable("CMSO_updateRequestResponse", "")
\r
52 execution.setVariable("CMSO_updateRequestResponseCode", "")
\r
53 execution.setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "")
\r
55 //Set DB adapter variables here
\r
56 execution.setVariable("CMSO_updateDBStatusToSuccessPayload", "")
\r
57 execution.setVariable("CMSO_updateInfraRequestDBPayload", "")
\r
58 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "")
\r
61 execution.setVariable("BasicAuthHeaderValue","")
\r
63 //Response variables
\r
64 execution.setVariable("CompletionHandlerResponse","")
\r
65 execution.setVariable("CMSO_ErrorResponse", null)
\r
66 execution.setVariable("CMSO_ResponseCode", "")
\r
68 setSuccessIndicator(execution, false)
\r
70 } catch (BpmnError e) {
\r
72 } catch (Exception e) {
\r
73 logError('Caught exception in ' + method, e)
\r
74 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
79 public void preProcessRequest (Execution execution) {
\r
81 initializeProcessVariables(execution)
\r
82 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
\r
83 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
84 // utils.log("DEBUG", "*** Started CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
\r
85 logDebug('Entered ' + method, isDebugLogEnabled)
\r
87 def xml = execution.getVariable("CompleteMsoProcessRequest")
\r
89 utils.logAudit("CompleteMsoProcess Request: " + xml)
\r
90 utils.log("DEBUG", "Incoming Request is: "+ xml, isDebugLogEnabled)
\r
92 //mso-bpel-name from the incoming request
\r
93 def msoBpelName = utils.getNodeText1(xml,"mso-bpel-name")
\r
94 execution.setVariable("CMSO_mso-bpel-name",msoBpelName)
\r
96 //Check the incoming request type
\r
97 //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node)
\r
98 if (utils.nodeExists(xml, "request-information")) {
\r
99 execution.setVariable("CMSO_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS
\r
102 //Check notification-url for the incoming request type
\r
103 //ACTIVE_REQUESTS may have notificationurl node
\r
104 //INFRA_ACTIVE_REQUESTS notificationurl node does not exist
\r
105 def notificationurl = ""
\r
106 if (utils.nodeExists(xml, "notification-url")) {
\r
107 notificationurl = utils.getNodeText(xml,"notification-url")
\r
108 if(notificationurl != null && !notificationurl.isEmpty()) {
\r
109 execution.setVariable("CMSO_notification-url-Ok", true)
\r
110 execution.setVariable("CMSO_notification-url",notificationurl)
\r
114 //Check request_id for the incoming request type
\r
115 //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)
\r
116 //For ACTIVE_REQUESTS payload request-id is NOT optional
\r
117 def request_id = ""
\r
118 if (utils.nodeExists(xml, "request-id")) {
\r
119 execution.setVariable("CMSO_request_id",utils.getNodeText(xml,"request-id"))
\r
123 // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory
\r
124 // ACTIVE_REQUEST have "request-action" ... mandatory
\r
125 if (utils.nodeExists(xml, "request-action")) {
\r
126 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"request-action"))
\r
127 } else if (utils.nodeExists(xml, "action")) {
\r
128 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"action"))
\r
131 //Check source for the incoming request type
\r
132 //For INFRA_ACTIVE_REQUESTS payload source IS optional
\r
133 //For ACTIVE_REQUESTS payload source is NOT optional
\r
135 if (utils.nodeExists(xml, "source")) {
\r
136 execution.setVariable("CMSO_source",utils.getNodeText(xml,"source"))
\r
139 utils.log("DEBUG", "CMSO_notification-url-Ok --> " + execution.getVariable("CMSO_notification-url-Ok"), isDebugLogEnabled)
\r
140 utils.log("DEBUG", "CMSO_request_id-Ok --> " + execution.getVariable("CMSO_request_id-Ok"), isDebugLogEnabled)
\r
142 // set the DHV/Service Instantiation values if specified in the request
\r
143 execution.setVariable("CMSO_is_srv_inst_req", String.valueOf("true".equals(utils.getNodeText1(xml, "is-srv-inst-req"))))
\r
144 utils.log("DEBUG", "CMSO_is_srv_inst_req --> " + execution.getVariable("CMSO_is_srv_inst_req"), isDebugLogEnabled)
\r
145 execution.setVariable("CMSO_is_json_content", String.valueOf("JSON".equals(utils.getNodeText1(xml, "resp-content-type"))))
\r
146 utils.log("DEBUG", "CMSO_is_json_content --> " + execution.getVariable("CMSO_is_json_content"), isDebugLogEnabled)
\r
147 execution.setVariable("CMSO_service_inst_id", utils.getNodeText1(xml, "service-instance-id"))
\r
148 utils.log("DEBUG", "CMSO_service_inst_id --> " + execution.getVariable("CMSO_service_inst_id"), isDebugLogEnabled)
\r
149 execution.setVariable("CMSO_start_time", utils.getNodeText1(xml, "start-time"))
\r
150 utils.log("DEBUG", "CMSO_start_time --> " + execution.getVariable("CMSO_start_time"), isDebugLogEnabled)
\r
151 // this variable is used by the camunda flow to set the Content-Type for the async response
\r
152 if (execution.getVariable("CMSO_is_srv_inst_req").equals("true") &&
\r
153 execution.getVariable("CMSO_is_json_content").equals("true")) {
\r
154 execution.setVariable("CMSO_content_type", "application/json")
\r
156 execution.setVariable("CMSO_content_type", "text/xml")
\r
159 logDebug('Exited ' + method, isDebugLogEnabled)
\r
160 } catch (BpmnError e) {
\r
162 } catch (Exception e) {
\r
163 utils.log("DEBUG", "Exception Occured During PreProcessRequest: " + e, isDebugLogEnabled);
\r
164 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
167 // utils.log("DEBUG", "*** Completed CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
\r
170 public void postProcessResponse (Execution execution) {
\r
172 def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')'
\r
173 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
174 logDebug('Entered ' + method, isDebugLogEnabled)
\r
175 // utils.log("DEBUG", "*** Started CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
\r
178 def msoCompletionResponse = """
\r
179 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1">
\r
180 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} completed</sdncadapterworkflow:out>
\r
181 </sdncadapterworkflow:MsoCompletionResponse>
\r
185 def xmlMsoCompletionResponse = utils.formatXML(msoCompletionResponse)
\r
186 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
\r
187 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
\r
188 execution.setVariable("WorkflowResponse", buildMsoCompletionResponseAsString)
\r
189 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
\r
190 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
\r
191 execution.setVariable("CMSO_ResponseCode", "200")
\r
193 setSuccessIndicator(execution, true)
\r
195 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompleteMsoProcessResponse"), isDebugLogEnabled)
\r
197 logDebug('Exited ' + method, isDebugLogEnabled)
\r
198 } catch (BpmnError e) {
\r
200 } catch (Exception e) {
\r
201 logError('Caught exception in ' + method, e)
\r
202 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
204 // utils.log("DEBUG", "*** Completed CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
\r
208 public void updateDBStatusToSuccessPayload (Execution execution){
\r
209 def method = getClass().getSimpleName() + '.updateDBStatusToSuccessPayload(' +'execution=' + execution.getId() +')'
\r
210 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
211 logDebug('Entered ' + method, isDebugLogEnabled)
\r
214 // Catalog DB headers Authorization
\r
215 String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
\r
216 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugLogEnabled)
\r
218 def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
\r
219 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
\r
220 } catch (IOException ex) {
\r
221 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
\r
222 utils.log("DEBUG", dataErrorMessage, isDebugLogEnabled)
\r
223 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
228 String payload = """
\r
229 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
233 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
\r
234 <lastModifiedBy>BPEL</lastModifiedBy>
\r
235 <status>COMPLETED</status>
\r
236 </req:updateStatus>
\r
238 </soapenv:Envelope>
\r
240 execution.setVariable("CMSO_updateDBStatusToSuccessPayload", payload)
\r
241 utils.logAudit("updateDBStatusToSuccessPayload: " + payload)
\r
242 logDebug('Exited ' + method, isDebugLogEnabled)
\r
243 //println("CMSO_updateDBStatusToSuccessPayload --> " + execution.getVariable("CMSO_updateDBStatusToSuccessPayload"))
\r
245 } catch (BpmnError e) {
\r
247 } catch (Exception e) {
\r
248 logError('Caught exception in ' + method, e)
\r
249 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
253 public void setUpdateDBstatustoSuccessPayload (Execution execution){
\r
255 def method = getClass().getSimpleName() + '.setUpdateDBstatustoSuccessPayload(' +'execution=' + execution.getId() +')'
\r
256 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
257 logDebug('Entered ' + method, isDebugLogEnabled)
\r
260 String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
\r
261 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugLogEnabled)
\r
263 def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
\r
264 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
\r
265 } catch (IOException ex) {
\r
266 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
\r
267 utils.log("DEBUG", dataErrorMessage, isDebugLogEnabled)
\r
268 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
273 def xml = execution.getVariable("CompleteMsoProcessRequest")
\r
275 //Get statusMessage if exists
\r
277 if(utils.nodeExists(xml, "status-message")){
\r
278 statusMessage = utils.getNodeText1(xml, "status-message")
\r
280 statusMessage = "Resource Completed Successfully"
\r
283 //Get instance Id if exist
\r
285 if(utils.nodeExists(xml, "vnfId")){
\r
286 idXml = utils.getNodeXml(xml, "vnfId")
\r
287 }else if(utils.nodeExists(xml, "networkId")){
\r
288 idXml = utils.getNodeXml(xml, "networkId")
\r
289 }else if(utils.nodeExists(xml, "serviceInstanceId")){
\r
290 idXml = utils.getNodeXml(xml, "serviceInstanceId")
\r
291 }else if(utils.nodeExists(xml, "vfModuleId")){
\r
292 idXml = utils.getNodeXml(xml, "vfModuleId")
\r
293 }else if(utils.nodeExists(xml, "volumeGroupId")){
\r
294 idXml = utils.getNodeXml(xml, "volumeGroupId")
\r
298 idXml = utils.removeXmlPreamble(idXml)
\r
299 utils.log("DEBUG", "Incoming Instance Id Xml: " + idXml, isDebugLogEnabled)
\r
301 String payload = """
\r
302 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
305 <req:updateInfraRequest>
\r
306 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
\r
307 <lastModifiedBy>${execution.getVariable("CMSO_mso-bpel-name")}</lastModifiedBy>
\r
308 <statusMessage>${statusMessage}</statusMessage>
\r
309 <requestStatus>COMPLETE</requestStatus>
\r
310 <progress>100</progress>
\r
312 </req:updateInfraRequest>
\r
314 </soapenv:Envelope>"""
\r
316 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", payload)
\r
317 utils.log("DEBUG", "Outgoing Update Mso Request Payload is: " + payload, isDebugLogEnabled)
\r
318 utils.logAudit("setUpdateDBstatustoSuccessPayload: " + payload)
\r
320 } catch (BpmnError e) {
\r
322 } catch (Exception e) {
\r
323 logError('Caught exception in ' + method, e)
\r
324 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
326 logDebug('Exited ' + method, isDebugLogEnabled)
\r
329 public void buildDataError (Execution execution, String message) {
\r
331 def method = getClass().getSimpleName() + '.buildDataError(' +'execution=' + execution.getId() +')'
\r
332 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
333 logDebug('Entered ' + method, isDebugLogEnabled)
\r
336 def msoCompletionResponse = """
\r
337 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1">
\r
338 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} FAILED</sdncadapterworkflow:out>
\r
339 </sdncadapterworkflow:MsoCompletionResponse>
\r
343 def xmlMsoCompletionResponse = utils.formatXml(msoCompletionResponse)
\r
344 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
\r
345 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
\r
346 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
\r
347 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompletionHandlerResponse"), isDebugLogEnabled)
\r
349 exceptionUtil.buildAndThrowWorkflowException(execution, 500, message)
\r
351 } catch (BpmnError e) {
\r
352 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
\r
354 } catch (Exception e) {
\r
355 logError('Caught exception in ' + method, e)
\r
356 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r