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 setBasicDBAuthHeader(execution, isDebugLogEnabled)
\r
90 def xml = execution.getVariable("CompleteMsoProcessRequest")
\r
92 utils.logAudit("CompleteMsoProcess Request: " + xml)
\r
93 utils.log("DEBUG", "Incoming Request is: "+ xml, isDebugLogEnabled)
\r
95 //mso-bpel-name from the incoming request
\r
96 def msoBpelName = utils.getNodeText1(xml,"mso-bpel-name")
\r
97 execution.setVariable("CMSO_mso-bpel-name",msoBpelName)
\r
99 //Check the incoming request type
\r
100 //Incoming request can be ACTIVE_REQUESTS (request-information node) or INFRA_ACTIVE_REQUESTS (request-info node)
\r
101 if (utils.nodeExists(xml, "request-information")) {
\r
102 execution.setVariable("CMSO_request_id-Ok", true) // Incoming request is for ACTIVE_REQUESTS
\r
105 //Check notification-url for the incoming request type
\r
106 //ACTIVE_REQUESTS may have notificationurl node
\r
107 //INFRA_ACTIVE_REQUESTS notificationurl node does not exist
\r
108 def notificationurl = ""
\r
109 if (utils.nodeExists(xml, "notification-url")) {
\r
110 notificationurl = utils.getNodeText(xml,"notification-url")
\r
111 if(notificationurl != null && !notificationurl.isEmpty()) {
\r
112 execution.setVariable("CMSO_notification-url-Ok", true)
\r
113 execution.setVariable("CMSO_notification-url",notificationurl)
\r
117 //Check request_id for the incoming request type
\r
118 //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
119 //For ACTIVE_REQUESTS payload request-id is NOT optional
\r
120 def request_id = ""
\r
121 if (utils.nodeExists(xml, "request-id")) {
\r
122 execution.setVariable("CMSO_request_id",utils.getNodeText(xml,"request-id"))
\r
126 // INFRA_ACTIVE_REQUESTS have "action" element ... mandatory
\r
127 // ACTIVE_REQUEST have "request-action" ... mandatory
\r
128 if (utils.nodeExists(xml, "request-action")) {
\r
129 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"request-action"))
\r
130 } else if (utils.nodeExists(xml, "action")) {
\r
131 execution.setVariable("CMSO_request_action",utils.getNodeText(xml,"action"))
\r
134 //Check source for the incoming request type
\r
135 //For INFRA_ACTIVE_REQUESTS payload source IS optional
\r
136 //For ACTIVE_REQUESTS payload source is NOT optional
\r
138 if (utils.nodeExists(xml, "source")) {
\r
139 execution.setVariable("CMSO_source",utils.getNodeText(xml,"source"))
\r
142 utils.log("DEBUG", "CMSO_notification-url-Ok --> " + execution.getVariable("CMSO_notification-url-Ok"), isDebugLogEnabled)
\r
143 utils.log("DEBUG", "CMSO_request_id-Ok --> " + execution.getVariable("CMSO_request_id-Ok"), isDebugLogEnabled)
\r
145 // set the DHV/Service Instantiation values if specified in the request
\r
146 execution.setVariable("CMSO_is_srv_inst_req", String.valueOf("true".equals(utils.getNodeText1(xml, "is-srv-inst-req"))))
\r
147 utils.log("DEBUG", "CMSO_is_srv_inst_req --> " + execution.getVariable("CMSO_is_srv_inst_req"), isDebugLogEnabled)
\r
148 execution.setVariable("CMSO_is_json_content", String.valueOf("JSON".equals(utils.getNodeText1(xml, "resp-content-type"))))
\r
149 utils.log("DEBUG", "CMSO_is_json_content --> " + execution.getVariable("CMSO_is_json_content"), isDebugLogEnabled)
\r
150 execution.setVariable("CMSO_service_inst_id", utils.getNodeText1(xml, "service-instance-id"))
\r
151 utils.log("DEBUG", "CMSO_service_inst_id --> " + execution.getVariable("CMSO_service_inst_id"), isDebugLogEnabled)
\r
152 execution.setVariable("CMSO_start_time", utils.getNodeText1(xml, "start-time"))
\r
153 utils.log("DEBUG", "CMSO_start_time --> " + execution.getVariable("CMSO_start_time"), isDebugLogEnabled)
\r
154 // this variable is used by the camunda flow to set the Content-Type for the async response
\r
155 if (execution.getVariable("CMSO_is_srv_inst_req").equals("true") &&
\r
156 execution.getVariable("CMSO_is_json_content").equals("true")) {
\r
157 execution.setVariable("CMSO_content_type", "application/json")
\r
159 execution.setVariable("CMSO_content_type", "text/xml")
\r
162 logDebug('Exited ' + method, isDebugLogEnabled)
\r
163 } catch (BpmnError e) {
\r
165 } catch (Exception e) {
\r
166 utils.log("DEBUG", "Exception Occured During PreProcessRequest: " + e, isDebugLogEnabled);
\r
167 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
\r
170 // utils.log("DEBUG", "*** Completed CompleteMsoProcess preProcessRequest Method ***", isDebugLogEnabled);
\r
173 public void setUpdateDBstatustoSuccessPayload (Execution execution){
\r
175 def method = getClass().getSimpleName() + '.setUpdateDBstatustoSuccessPayload(' +'execution=' + execution.getId() +')'
\r
176 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
177 logDebug('Entered ' + method, isDebugLogEnabled)
\r
181 def xml = execution.getVariable("CompleteMsoProcessRequest")
\r
183 //Get statusMessage if exists
\r
185 if(utils.nodeExists(xml, "status-message")){
\r
186 statusMessage = utils.getNodeText1(xml, "status-message")
\r
188 statusMessage = "Resource Completed Successfully"
\r
191 //Get instance Id if exist
\r
193 if(utils.nodeExists(xml, "vnfId")){
\r
194 idXml = utils.getNodeXml(xml, "vnfId")
\r
195 }else if(utils.nodeExists(xml, "networkId")){
\r
196 idXml = utils.getNodeXml(xml, "networkId")
\r
197 }else if(utils.nodeExists(xml, "serviceInstanceId")){
\r
198 idXml = utils.getNodeXml(xml, "serviceInstanceId")
\r
199 }else if(utils.nodeExists(xml, "vfModuleId")){
\r
200 idXml = utils.getNodeXml(xml, "vfModuleId")
\r
201 }else if(utils.nodeExists(xml, "volumeGroupId")){
\r
202 idXml = utils.getNodeXml(xml, "volumeGroupId")
\r
206 idXml = utils.removeXmlPreamble(idXml)
\r
207 utils.log("DEBUG", "Incoming Instance Id Xml: " + idXml, isDebugLogEnabled)
\r
209 String payload = """
\r
210 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
213 <req:updateInfraRequest>
\r
214 <requestId>${execution.getVariable("CMSO_request_id")}</requestId>
\r
215 <lastModifiedBy>${execution.getVariable("CMSO_mso-bpel-name")}</lastModifiedBy>
\r
216 <statusMessage>${statusMessage}</statusMessage>
\r
217 <requestStatus>COMPLETE</requestStatus>
\r
218 <progress>100</progress>
\r
220 </req:updateInfraRequest>
\r
222 </soapenv:Envelope>"""
\r
224 execution.setVariable("CMSO_setUpdateDBstatustoSuccessPayload", payload)
\r
225 utils.log("DEBUG", "Outgoing Update Mso Request Payload is: " + payload, isDebugLogEnabled)
\r
226 utils.logAudit("setUpdateDBstatustoSuccessPayload: " + payload)
\r
228 } catch (BpmnError e) {
\r
230 } catch (Exception e) {
\r
231 logError('Caught exception in ' + method, e)
\r
232 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
234 logDebug('Exited ' + method, isDebugLogEnabled)
\r
237 public void buildDataError (Execution execution, String message) {
\r
239 def method = getClass().getSimpleName() + '.buildDataError(' +'execution=' + execution.getId() +')'
\r
240 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
241 logDebug('Entered ' + method, isDebugLogEnabled)
\r
244 def msoCompletionResponse = """
\r
245 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1">
\r
246 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} FAILED</sdncadapterworkflow:out>
\r
247 </sdncadapterworkflow:MsoCompletionResponse>
\r
251 def xmlMsoCompletionResponse = utils.formatXml(msoCompletionResponse)
\r
252 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
\r
253 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
\r
254 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
\r
255 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompletionHandlerResponse"), isDebugLogEnabled)
\r
257 exceptionUtil.buildAndThrowWorkflowException(execution, 500, message)
\r
259 } catch (BpmnError e) {
\r
260 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
\r
262 } catch (Exception e) {
\r
263 logError('Caught exception in ' + method, e)
\r
264 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
269 public void postProcessResponse (Execution execution) {
\r
271 def method = getClass().getSimpleName() + '.postProcessResponse(' +'execution=' + execution.getId() +')'
\r
272 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
273 logDebug('Entered ' + method, isDebugLogEnabled)
\r
274 // utils.log("DEBUG", "*** Started CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
\r
277 def msoCompletionResponse = """
\r
278 <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://ecomp.com/mso/workflow/schema/v1">
\r
279 <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} completed</sdncadapterworkflow:out>
\r
280 </sdncadapterworkflow:MsoCompletionResponse>
\r
284 def xmlMsoCompletionResponse = utils.formatXML(msoCompletionResponse)
\r
285 String buildMsoCompletionResponseAsString = xmlMsoCompletionResponse.drop(38).trim()
\r
286 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
\r
287 execution.setVariable("WorkflowResponse", buildMsoCompletionResponseAsString)
\r
288 utils.logAudit("CompleteMsoProcess Response: " + buildMsoCompletionResponseAsString)
\r
289 execution.setVariable("CompleteMsoProcessResponse", buildMsoCompletionResponseAsString)
\r
290 execution.setVariable("CMSO_ResponseCode", "200")
\r
292 setSuccessIndicator(execution, true)
\r
294 utils.log("DEBUG", "@@ CompleteMsoProcess Response @@ " + "\n" + execution.getVariable("CompleteMsoProcessResponse"), isDebugLogEnabled)
\r
296 logDebug('Exited ' + method, isDebugLogEnabled)
\r
297 } catch (BpmnError e) {
\r
299 } catch (Exception e) {
\r
300 logError('Caught exception in ' + method, e)
\r
301 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
303 // utils.log("DEBUG", "*** Completed CompleteMsoProcess PostProcessRequest Method ***", isDebugLogEnabled);
\r