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.runtime.Execution
\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 (Execution execution) {
\r
63 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
64 execution.setVariable("prefix",Prefix)
\r
67 utils.log("DEBUG", " *** 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("DEBUG", "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("DEBUG", 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("DEBUG", 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)
\r
149 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
\r
150 execution.setVariable("serviceInputParams", inputMap)
\r
152 } catch (BpmnError e) {
\r
154 } catch (Exception ex){
\r
155 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
156 utils.log("DEBUG", msg, isDebugEnabled)
\r
157 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
159 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
162 public void sendSyncResponse (Execution execution) {
\r
163 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
164 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
\r
167 String requestId = execution.getVariable("msoRequestId")
\r
168 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
170 // RESTResponse (for API Handler (APIH) Reply Task)
\r
171 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
172 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
173 sendWorkflowResponse(execution, 202, syncResponse)
\r
175 } catch (Exception ex) {
\r
176 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
\r
177 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
179 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
182 public void sendSyncError (Execution execution) {
\r
183 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
184 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
\r
187 String errorMessage = ""
\r
188 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
189 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
190 errorMessage = wfe.getErrorMessage()
\r
192 errorMessage = "Sending Sync Error."
\r
195 String buildworkflowException =
\r
196 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
197 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
198 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
199 </aetgt:WorkflowException>"""
\r
201 utils.logAudit(buildworkflowException)
\r
202 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
204 } catch (Exception ex) {
\r
205 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
210 public void prepareCompletionRequest (Execution execution) {
\r
211 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
212 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
\r
215 String requestId = execution.getVariable("msoRequestId")
\r
216 String source = execution.getVariable("source")
\r
217 String msoCompletionRequest =
\r
218 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
219 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
220 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
221 <request-id>${requestId}</request-id>
\r
222 <action>DELETE</action>
\r
223 <source>${source}</source>
\r
225 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
\r
226 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
\r
227 </aetgt:MsoCompletionRequest>"""
\r
230 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
232 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
233 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
235 } catch (Exception ex) {
\r
236 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
237 utils.log("DEBUG", msg, isDebugEnabled)
\r
238 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
240 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
243 public void prepareFalloutRequest(Execution execution){
\r
244 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
245 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
248 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
249 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
250 String requestId = execution.getVariable("msoRequestId")
\r
251 String source = execution.getVariable("source")
\r
252 String requestInfo =
\r
253 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
254 <request-id>${requestId}</request-id>
\r
255 <action>DELETE</action>
\r
256 <source>${source}</source>
\r
259 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
260 execution.setVariable("falloutRequest", falloutRequest)
\r
261 } catch (Exception ex) {
\r
262 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
263 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
264 String requestId = execution.getVariable("msoRequestId")
\r
265 String falloutRequest =
\r
266 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
267 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
268 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
269 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
270 <request-id>${requestId}</request-id>
\r
271 <action>DELETE</action>
\r
272 <source>VID</source>
\r
274 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
275 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
276 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
277 </aetgt:WorkflowException>
\r
278 </aetgt:FalloutHandlerRequest>"""
\r
280 execution.setVariable("falloutRequest", falloutRequest)
\r
282 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r
286 // *******************************
\r
287 // Build DB request Section
\r
288 // *******************************
\r
289 public void prepareDBRequest (Execution execution) {
\r
290 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
291 execution.setVariable("prefix", Prefix)
\r
294 utils.log("DEBUG", " ***** Inside prepareDBRequest of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
296 String requestId = execution.getVariable("DELSI_requestId")
\r
297 String statusMessage = "E2E Service Instance successfully deleted."
\r
299 //TODO - verify the format for Service Instance Delete,
\r
301 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
304 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
305 <requestId>${requestId}</requestId>
\r
306 <lastModifiedBy>BPMN</lastModifiedBy>
\r
307 <statusMessage>${statusMessage}</statusMessage>
\r
308 <responseBody></responseBody>
\r
309 <requestStatus>COMPLETED</requestStatus>
\r
310 <progress>100</progress>
\r
311 </ns:updateInfraRequest>
\r
313 </soapenv:Envelope>"""
\r
315 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
316 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
\r
317 utils.logAudit(buildDeleteDBRequestAsString)
\r
319 } catch (Exception ex) {
\r
320 // try error in method block
\r
321 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
\r
322 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
328 // *******************************
\r
329 // Build Error Section
\r
330 // *******************************
\r
331 public void prepareDBRequestError (Execution execution) {
\r
332 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
333 execution.setVariable("prefix", Prefix)
\r
335 utils.log("DEBUG", " ***** Inside prepareDBRequestError of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
338 String requestId = execution.getVariable("DELSI_requestId")
\r
339 String statusMessage = ""
\r
340 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
341 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
342 statusMessage = wfe.getErrorMessage()
\r
345 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
\r
348 //TODO - verify the format for Service Instance Create,
\r
350 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
353 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
354 <requestId>${requestId}</requestId>
\r
355 <lastModifiedBy>BPMN</lastModifiedBy>
\r
356 <statusMessage>${statusMessage}</statusMessage>
\r
357 <responseBody></responseBody>
\r
358 <requestStatus>FAILED</requestStatus>
\r
359 </ns:updateInfraRequest>
\r
361 </soapenv:Envelope>"""
\r
363 String buildDBRequestAsString = utils.formatXml(dbRequest)
\r
364 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
\r
365 utils.logAudit(buildDBRequestAsString)
\r
367 } catch (Exception ex) {
\r
368 // try error in method block
\r
369 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
\r
370 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
\r