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.delegate.DelegateExecution
\r
28 public class CompleteMsoProcess extends AbstractServiceTaskProcessor {
31 ExceptionUtil exceptionUtil = new ExceptionUtil()
33 // Complete MSO Request processing
34 public initializeProcessVariables(DelegateExecution execution){
\r
36 def method = getClass().getSimpleName() + '.initializeProcessVariables(' +'execution=' + execution.getId() +')'
37 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
38 logDebug('Entered ' + method, isDebugLogEnabled)
41 /* Initialize all the process request variables in this block */
42 execution.setVariable("prefix",Prefix)
43 execution.setVariable("CMSO_request_id","")
44 execution.setVariable("CMSO_notification-url","")
45 execution.setVariable("CMSO_mso-bpel-name","")
46 execution.setVariable("CMSO_request_action","")
47 execution.setVariable("CMSO_notification-url-Ok", false)
48 execution.setVariable("CMSO_request_id-Ok", false)
50 //updateRequest Adapter process variables
51 execution.setVariable("CMSO_updateRequestResponse", "")
52 execution.setVariable("CMSO_updateRequestResponseCode", "")
53 execution.setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "")
55 //Set DB adapter variables here
56 execution.setVariable("CMSO_updateDBStatusToSuccessPayload", "")
57 execution.setVariable("CMSO_updateInfraRequestDBPayload", "")
58 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "")
61 execution.setVariable("BasicAuthHeaderValue","")
64 execution.setVariable("CompletionHandlerResponse","")
65 execution.setVariable("CMSO_ErrorResponse", null)
66 execution.setVariable("CMSO_ResponseCode", "")
68 setSuccessIndicator(execution, false)
70 } catch (BpmnError e) {
72 } catch (Exception e) {
73 logError('Caught exception in ' + method, e)
74 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
79 public void preProcessRequest (DelegateExecution execution) {
\r
81 initializeProcessVariables(execution)
82 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
83 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
84 // utils.log("DEBUG", "*** Started CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
85 logDebug('Entered ' + method, isDebugLogEnabled)
87 setBasicDBAuthHeader(execution, isDebugLogEnabled)
90 def xml = execution.getVariable("CompleteMsoProcessRequest")
92 utils.logAudit("CompleteMsoProcess Request: " + xml)
93 utils.log("DEBUG", "Incoming Request is: "+ xml, isDebugLogEnabled)
95 //mso-bpel-name from the incoming request
96 def msoBpelName = utils.getNodeText1(xml,"mso-bpel-name")
97 execution.setVariable("CMSO_mso-bpel-name",msoBpelName)
99 //Check the incoming request type
100 //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node)
101 if (utils.nodeExists(xml, "request-information")) {
102 execution.setVariable("CMSO_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS
105 //Check for rehome indicator
106 def rehomeIndicator = utils.getNodeText1(xml,"rehomeDone")
107 execution.setVariable("rehomeDone", rehomeIndicator)
109 //Check notification-url for the incoming request type
110 //ACTIVE_REQUESTS may have notificationurl node
111 //INFRA_ACTIVE_REQUESTS notificationurl node does not exist
112 def notificationurl = ""
113 if (utils.nodeExists(xml, "notification-url")) {
114 notificationurl = utils.getNodeText(xml,"notification-url")
115 if(notificationurl != null && !notificationurl.isEmpty()) {
116 execution.setVariable("CMSO_notification-url-Ok", true)
117 execution.setVariable("CMSO_notification-url",notificationurl)
121 //Check request_id for the incoming request type
122 //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)
123 //For ACTIVE_REQUESTS payload request-id is NOT optional
125 if (utils.nodeExists(xml, "request-id")) {
126 execution.setVariable("CMSO_request_id",utils.getNodeText(xml,"request-id"))
130 // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory
131 // ACTIVE_REQUEST have "request-action" ... mandatory
132 if (utils.nodeExists(xml, "request-action")) {
133 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"request-action"))
134 } else if (utils.nodeExists(xml, "action")) {
135 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"action"))
138 //Check source for the incoming request type
139 //For INFRA_ACTIVE_REQUESTS payload source IS optional
140 //For ACTIVE_REQUESTS payload source is NOT optional
142 if (utils.nodeExists(xml, "source")) {
143 execution.setVariable("CMSO_source",utils.getNodeText(xml,"source"))
146 utils.log("DEBUG", "CMSO_notification-url-Ok --> " + execution.getVariable("CMSO_notification-url-Ok"), isDebugLogEnabled)
147 utils.log("DEBUG", "CMSO_request_id-Ok --> " + execution.getVariable("CMSO_request_id-Ok"), isDebugLogEnabled)
149 // set the DHV/Service Instantiation values if specified in the request
150 execution.setVariable("CMSO_is_srv_inst_req", String.valueOf("true".equals(utils.getNodeText1(xml, "is-srv-inst-req"))))
151 utils.log("DEBUG", "CMSO_is_srv_inst_req --> " + execution.getVariable("CMSO_is_srv_inst_req"), isDebugLogEnabled)
152 execution.setVariable("CMSO_is_json_content", String.valueOf("JSON".equals(utils.getNodeText1(xml, "resp-content-type"))))
153 utils.log("DEBUG", "CMSO_is_json_content --> " + execution.getVariable("CMSO_is_json_content"), isDebugLogEnabled)
154 execution.setVariable("CMSO_service_inst_id", utils.getNodeText1(xml, "service-instance-id"))
155 utils.log("DEBUG", "CMSO_service_inst_id --> " + execution.getVariable("CMSO_service_inst_id"), isDebugLogEnabled)
156 execution.setVariable("CMSO_start_time", utils.getNodeText1(xml, "start-time"))
157 utils.log("DEBUG", "CMSO_start_time --> " + execution.getVariable("CMSO_start_time"), isDebugLogEnabled)
158 // this variable is used by the camunda flow to set the Content-Type for the async response
159 if (execution.getVariable("CMSO_is_srv_inst_req").equals("true") &&
160 execution.getVariable("CMSO_is_json_content").equals("true")) {
161 execution.setVariable("CMSO_content_type", "application/json")
163 execution.setVariable("CMSO_content_type", "text/xml")
166 logDebug('Exited ' + method, isDebugLogEnabled)
167 } catch (BpmnError e) {
169 } catch (Exception e) {
170 utils.log("DEBUG", "Exception Occured During PreProcessRequest: " + e, isDebugLogEnabled);
171 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
174 // utils.log("DEBUG", "*** Completed CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
177 public void setUpdateDBstatustoSuccessPayload (DelegateExecution execution){
\r
179 def method = getClass().getSimpleName() + '.setUpdateDBstatustoSuccessPayload(' +'execution=' + execution.getId() +')'
180 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
181 logDebug('Entered ' + method, isDebugLogEnabled)
185 def xml = execution.getVariable("CompleteMsoProcessRequest")
187 //Get statusMessage if exists
189 if(utils.nodeExists(xml, "status-message")){
190 statusMessage = utils.getNodeText1(xml, "status-message")
192 statusMessage = "Resource Completed Successfully"
195 //Get instance Id if exist
197 if(utils.nodeExists(xml, "vnfId")){
198 idXml = utils.getNodeXml(xml, "vnfId")
199 }else if(utils.nodeExists(xml, "networkId")){
200 idXml = utils.getNodeXml(xml, "networkId")
201 }else if(utils.nodeExists(xml, "configurationId")){
202 idXml = utils.getNodeXml(xml, "configurationId")
203 }else if(utils.nodeExists(xml, "serviceInstanceId")){
204 idXml = utils.getNodeXml(xml, "serviceInstanceId")
205 }else if(utils.nodeExists(xml, "vfModuleId")){
206 idXml = utils.getNodeXml(xml, "vfModuleId")
207 }else if(utils.nodeExists(xml, "volumeGroupId")){
208 idXml = utils.getNodeXml(xml, "volumeGroupId")
212 idXml = utils.removeXmlPreamble(idXml)
213 utils.log("DEBUG", "Incoming Instance Id Xml: " + idXml, isDebugLogEnabled)
216 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
219 <req:updateInfraRequest>
220 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
221 <lastModifiedBy>${execution.getVariable("CMSO_mso-bpel-name")}</lastModifiedBy>
222 <statusMessage>${statusMessage}</statusMessage>
223 <requestStatus>COMPLETE</requestStatus>
224 <progress>100</progress>
226 </req:updateInfraRequest>
228 </soapenv:Envelope>"""
230 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", payload)
231 utils.log("DEBUG", "Outgoing Update Mso Request Payload is: " + payload, isDebugLogEnabled)
232 utils.logAudit("setUpdateDBstatustoSuccessPayload: " + payload)
234 } catch (BpmnError e) {
236 } catch (Exception e) {
237 logError('Caught exception in ' + method, e)
238 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
240 logDebug('Exited ' + method, isDebugLogEnabled)
243 public void buildDataError (DelegateExecution execution, String message) {
\r
245 def method = getClass().getSimpleName() + '.buildDataError(' +'execution=' + execution.getId() +')'
246 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
247 logDebug('Entered ' + method, isDebugLogEnabled)
250 def msoCompletionResponse = """
251 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1">
252 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} FAILED</sdncadapterworkflow:out>
253 </sdncadapterworkflow:MsoCompletionResponse>
257 def xmlMsoCompletionResponse = utils.formatXml(msoCompletionResponse)
258 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
259 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
260 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
261 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompletionHandlerResponse"), isDebugLogEnabled)
263 exceptionUtil.buildAndThrowWorkflowException(execution, 500, message)
265 } catch (BpmnError e) {
266 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
268 } catch (Exception e) {
269 logError('Caught exception in ' + method, e)
270 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
275 public void postProcessResponse (DelegateExecution execution) {
\r
277 def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')'
278 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
279 logDebug('Entered ' + method, isDebugLogEnabled)
280 // utils.log("DEBUG", "*** Started CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
283 def msoCompletionResponse = """
284 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://ecomp.com/mso/workflow/schema/v1">
285 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} completed</sdncadapterworkflow:out>
286 </sdncadapterworkflow:MsoCompletionResponse>
290 def xmlMsoCompletionResponse = utils.formatXML(msoCompletionResponse)
291 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
292 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
293 execution.setVariable("WorkflowResponse", buildMsoCompletionResponseAsString)
294 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
295 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
296 execution.setVariable("CMSO_ResponseCode", "200")
298 setSuccessIndicator(execution, true)
300 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompleteMsoProcessResponse"), isDebugLogEnabled)
302 logDebug('Exited ' + method, isDebugLogEnabled)
303 } catch (BpmnError e) {
305 } catch (Exception e) {
306 logError('Caught exception in ' + method, e)
307 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
309 // utils.log("DEBUG", "*** Completed CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);