2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import groovy.xml.XmlUtil
\r
24 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
29 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
30 import org.openecomp.mso.bpmn.core.WorkflowException
\r
31 import org.openecomp.mso.rest.APIResponse;
\r
33 import java.util.UUID;
\r
34 import javax.xml.parsers.DocumentBuilder
\r
35 import javax.xml.parsers.DocumentBuilderFactory
\r
37 import org.camunda.bpm.engine.delegate.BpmnError
\r
38 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
39 import org.json.JSONObject;
\r
40 import org.apache.commons.lang3.*
\r
41 import org.apache.commons.codec.binary.Base64;
\r
42 import org.w3c.dom.Document
\r
43 import org.w3c.dom.Element
\r
44 import org.w3c.dom.Node
\r
45 import org.w3c.dom.NodeList
\r
46 import org.xml.sax.InputSource
\r
47 import static org.apache.commons.lang3.StringUtils.*;
\r
49 import org.springframework.web.util.UriUtils;
\r
52 * This groovy class supports the <class>DelE2EServiceInstance.bpmn</class> process.
\r
55 public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
\r
57 String Prefix="DELSI_"
\r
58 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
59 JsonUtils jsonUtil = new JsonUtils()
\r
60 VidUtils vidUtils = new VidUtils()
\r
62 public void preProcessRequest (DelegateExecution execution) {
\r
63 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
64 execution.setVariable("prefix",Prefix)
\r
67 utils.log("INFO", " *** preProcessRequest Request *** ", isDebugEnabled)
\r
70 // check for incoming json message/input
\r
71 String siRequest = execution.getVariable("bpmnRequest")
\r
72 utils.logAudit(siRequest)
\r
75 String requestId = execution.getVariable("mso-request-id")
\r
76 execution.setVariable("msoRequestId", requestId)
\r
77 utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
\r
79 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
80 if (isBlank(serviceInstanceId)) {
\r
81 msg = "Input serviceInstanceId' is null"
\r
82 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
85 //String xmlRequestDetails = vidUtils.getJsonRequestDetailstoXml(siRequest)
\r
86 //execution.setVariable("requestDetails", xmlRequestDetails)
\r
89 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
\r
90 if (isBlank(serviceModelInfo)) {
\r
91 msg = "Input serviceModelInfo is null"
\r
92 utils.log("DEBUG", msg, isDebugEnabled)
\r
95 execution.setVariable("serviceModelInfo", serviceModelInfo)
\r
96 //utils.log("DEBUG", "modelInfo" + serviceModelInfo, isDebugEnabled)
\r
100 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
\r
101 if (isBlank(productFamilyId))
\r
103 msg = "Input productFamilyId is null"
\r
104 utils.log("INFO", msg, isDebugEnabled)
\r
105 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
107 execution.setVariable("productFamilyId", productFamilyId)
\r
109 String source = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source")
\r
110 execution.setVariable("source", source)
\r
113 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
114 if (isBlank(globalSubscriberId)) {
\r
115 msg = "Input globalSubscriberId' is null"
\r
116 utils.log("INFO", msg, isDebugEnabled)
\r
118 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
121 //requestParameters
\r
122 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
123 if (isBlank(subscriptionServiceType)) {
\r
124 msg = "Input subscriptionServiceType is null"
\r
125 utils.log("DEBUG", msg, isDebugEnabled)
\r
126 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
128 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
132 * Extracting User Parameters from incoming Request and converting into a Map
\r
134 def jsonSlurper = new JsonSlurper()
\r
135 def jsonOutput = new JsonOutput()
\r
137 Map reqMap = jsonSlurper.parseText(siRequest)
\r
140 def userParams = reqMap.requestDetails?.requestParameters?.userParams
\r
142 Map<String, String> inputMap = [:]
\r
145 userParam -> inputMap.put(userParam.name, userParam.value.toString())
\r
148 execution.setVariable("operationType", "DELETE")
\r
150 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
\r
151 execution.setVariable("serviceInputParams", inputMap)
\r
153 } catch (BpmnError e) {
\r
155 } catch (Exception ex){
\r
156 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
157 utils.log("INFO", msg, isDebugEnabled)
\r
158 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
160 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
163 public void sendSyncResponse (DelegateExecution execution) {
\r
164 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
165 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
\r
168 String requestId = execution.getVariable("msoRequestId")
\r
169 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
171 // RESTResponse (for API Handler (APIH) Reply Task)
\r
172 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
173 utils.log("INFO", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
174 sendWorkflowResponse(execution, 202, syncResponse)
\r
176 } catch (Exception ex) {
\r
177 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
\r
178 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
180 utils.log("INFO"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
183 public void sendSyncError (DelegateExecution execution) {
\r
184 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
185 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
\r
188 String errorMessage = ""
\r
189 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
190 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
191 errorMessage = wfe.getErrorMessage()
\r
193 errorMessage = "Sending Sync Error."
\r
196 String buildworkflowException =
\r
197 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
198 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
199 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
200 </aetgt:WorkflowException>"""
\r
202 utils.logAudit(buildworkflowException)
\r
203 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
205 } catch (Exception ex) {
\r
206 utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
211 public void prepareCompletionRequest (DelegateExecution execution) {
\r
212 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
213 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
\r
216 String requestId = execution.getVariable("msoRequestId")
\r
217 String source = execution.getVariable("source")
\r
218 String msoCompletionRequest =
\r
219 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
220 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
221 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
222 <request-id>${requestId}</request-id>
\r
223 <action>DELETE</action>
\r
224 <source>${source}</source>
\r
226 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
\r
227 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
\r
228 </aetgt:MsoCompletionRequest>"""
\r
231 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
233 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
234 utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
236 } catch (Exception ex) {
\r
237 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
238 utils.log("INFO", msg, isDebugEnabled)
\r
239 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
241 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
244 public void prepareFalloutRequest(DelegateExecution execution){
\r
245 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
246 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
249 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
250 utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
251 String requestId = execution.getVariable("msoRequestId")
\r
252 String source = execution.getVariable("source")
\r
253 String requestInfo =
\r
254 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
255 <request-id>${requestId}</request-id>
\r
256 <action>DELETE</action>
\r
257 <source>${source}</source>
\r
260 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
261 execution.setVariable("falloutRequest", falloutRequest)
\r
262 } catch (Exception ex) {
\r
263 utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
264 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
265 String requestId = execution.getVariable("msoRequestId")
\r
266 String falloutRequest =
\r
267 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
268 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
269 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
270 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
271 <request-id>${requestId}</request-id>
\r
272 <action>DELETE</action>
\r
273 <source>VID</source>
\r
275 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
276 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
277 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
278 </aetgt:WorkflowException>
\r
279 </aetgt:FalloutHandlerRequest>"""
\r
281 execution.setVariable("falloutRequest", falloutRequest)
\r
283 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r
287 // *******************************
\r
288 // Build DB request Section
\r
289 // *******************************
\r
290 public void prepareDBRequest (DelegateExecution execution) {
\r
291 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
292 execution.setVariable("prefix", Prefix)
\r
295 utils.log("INFO", " ***** Inside prepareDBRequest of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
297 String requestId = execution.getVariable("DELSI_requestId")
\r
298 String statusMessage = "E2E Service Instance successfully deleted."
\r
300 //TODO - verify the format for Service Instance Delete,
\r
302 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
305 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
306 <requestId>${requestId}</requestId>
\r
307 <lastModifiedBy>BPMN</lastModifiedBy>
\r
308 <statusMessage>${statusMessage}</statusMessage>
\r
309 <responseBody></responseBody>
\r
310 <requestStatus>COMPLETED</requestStatus>
\r
311 <progress>100</progress>
\r
312 </ns:updateInfraRequest>
\r
314 </soapenv:Envelope>"""
\r
316 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
317 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
\r
318 utils.logAudit(buildDeleteDBRequestAsString)
\r
320 } catch (Exception ex) {
\r
321 // try error in method block
\r
322 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
\r
323 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
329 // *******************************
\r
330 // Build Error Section
\r
331 // *******************************
\r
332 public void prepareDBRequestError (DelegateExecution execution) {
\r
333 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
334 execution.setVariable("prefix", Prefix)
\r
336 utils.log("INFO", " ***** Inside prepareDBRequestError of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
339 String requestId = execution.getVariable("DELSI_requestId")
\r
340 String statusMessage = ""
\r
341 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
342 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
343 statusMessage = wfe.getErrorMessage()
\r
346 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
\r
349 //TODO - verify the format for Service Instance Create,
\r
351 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
354 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
355 <requestId>${requestId}</requestId>
\r
356 <lastModifiedBy>BPMN</lastModifiedBy>
\r
357 <statusMessage>${statusMessage}</statusMessage>
\r
358 <responseBody></responseBody>
\r
359 <requestStatus>FAILED</requestStatus>
\r
360 </ns:updateInfraRequest>
\r
362 </soapenv:Envelope>"""
\r
364 String buildDBRequestAsString = utils.formatXml(dbRequest)
\r
365 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
\r
366 utils.logAudit(buildDBRequestAsString)
\r
368 } catch (Exception ex) {
\r
369 // try error in method block
\r
370 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
\r
371 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
\r
377 public void processJavaException(DelegateExecution execution) {
\r