3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts;
25 import static org.apache.commons.lang3.StringUtils.*;
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.common.scripts.VidUtils
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import org.onap.so.logger.MsoLogger
38 import org.springframework.web.util.UriUtils;
43 * This groovy class supports the <class>DelE2EServiceInstance.bpmn</class> process.
46 public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
48 String Prefix="DELSI_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
51 VidUtils vidUtils = new VidUtils()
52 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteCustomE2EServiceInstance.class);
54 public void preProcessRequest (DelegateExecution execution) {
55 execution.setVariable("prefix",Prefix)
58 msoLogger.info("Starting preProcessRequest")
61 // check for incoming json message/input
62 String siRequest = execution.getVariable("bpmnRequest")
63 msoLogger.debug(siRequest)
66 String requestId = execution.getVariable("mso-request-id")
67 execution.setVariable("msoRequestId", requestId)
68 msoLogger.info("Input Request:" + siRequest + " reqId:" + requestId)
70 String serviceInstanceId = execution.getVariable("serviceInstanceId")
71 if (isBlank(serviceInstanceId)) {
72 msg = "Input serviceInstanceId' is null"
73 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
78 // String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
79 // if (isBlank(productFamilyId))
81 // msg = "Input productFamilyId is null"
82 // utils.log("INFO", msg, isDebugEnabled)
83 // //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
85 // execution.setVariable("productFamilyId", productFamilyId)
87 String source = jsonUtil.getJsonValue(siRequest, "source")
88 execution.setVariable("source", source)
91 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
92 if (isBlank(globalSubscriberId)) {
93 msg = "Input globalSubscriberId' is null"
96 execution.setVariable("globalSubscriberId", globalSubscriberId)
100 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
101 if (isBlank(subscriptionServiceType)) {
102 msg = "Input subscriptionServiceType is null"
104 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
108 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
109 execution.setVariable("operationId", operationId)
111 execution.setVariable("operationType", "DELETE")
112 } catch (BpmnError e) {
114 } catch (Exception ex){
115 msg = "Exception in preProcessRequest " + ex.getMessage()
117 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
119 msoLogger.trace("Exit preProcessRequest")
122 public void sendSyncResponse (DelegateExecution execution) {
123 msoLogger.trace("Staring sendSyncResponse")
126 String operationId = execution.getVariable("operationId")
127 String syncResponse = """{"operationId":"${operationId}"}""".trim()
128 msoLogger.info("sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
129 sendWorkflowResponse(execution, 202, syncResponse)
131 } catch (Exception ex) {
132 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
133 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
135 msoLogger.trace("Exit sendSyncResopnse")
138 public void sendSyncError (DelegateExecution execution) {
139 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
140 msoLogger.info("Starting sendSyncError")
143 String errorMessage = ""
144 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
145 WorkflowException wfe = execution.getVariable("WorkflowException")
146 errorMessage = wfe.getErrorMessage()
148 errorMessage = "Sending Sync Error."
151 String buildworkflowException =
152 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
153 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
154 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
155 </aetgt:WorkflowException>"""
157 msoLogger.info(buildworkflowException)
158 sendWorkflowResponse(execution, 500, buildworkflowException)
160 } catch (Exception ex) {
161 msoLogger.info("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
166 public void prepareCompletionRequest (DelegateExecution execution) {
167 msoLogger.trace("Starting prepareCompletion")
170 String requestId = execution.getVariable("msoRequestId")
171 String source = execution.getVariable("source")
172 String msoCompletionRequest =
173 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
174 xmlns:ns="http://org.onap/so/request/types/v1">
175 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
176 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
177 <action>DELETE</action>
178 <source>${MsoUtils.xmlEscape(source)}</source>
180 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
181 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
182 </aetgt:MsoCompletionRequest>"""
185 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
187 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
188 msoLogger.info(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
190 } catch (Exception ex) {
191 String msg = " Exception in prepareCompletion:" + ex.getMessage()
193 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
195 msoLogger.trace("Exit prepareCompletionRequest")
198 public void prepareFalloutRequest(DelegateExecution execution){
199 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
200 msoLogger.trace("Starting prepareFalloutRequest ")
203 WorkflowException wfex = execution.getVariable("WorkflowException")
204 msoLogger.info(" Input Workflow Exception: " + wfex.toString())
205 String requestId = execution.getVariable("msoRequestId")
206 String source = execution.getVariable("source")
208 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
209 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
210 <action>DELETE</action>
211 <source>${MsoUtils.xmlEscape(source)}</source>
214 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
215 execution.setVariable("falloutRequest", falloutRequest)
216 } catch (Exception ex) {
217 msoLogger.info("Exception prepareFalloutRequest:" + ex.getMessage())
218 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
219 String requestId = execution.getVariable("msoRequestId")
220 String falloutRequest =
221 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
222 xmlns:ns="http://org.onap/so/request/types/v1"
223 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
224 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
225 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
226 <action>DELETE</action>
229 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
230 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
231 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
232 </aetgt:WorkflowException>
233 </aetgt:FalloutHandlerRequest>"""
235 execution.setVariable("falloutRequest", falloutRequest)
237 msoLogger.trace("Exit prepareFalloutRequest")
241 // *******************************
242 // Build DB request Section
243 // *******************************
244 public void prepareDBRequest (DelegateExecution execution) {
245 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
246 execution.setVariable("prefix", Prefix)
249 msoLogger.info("Starting prepareDBRequest")
251 String requestId = execution.getVariable("DELSI_requestId")
252 String statusMessage = "E2E Service Instance successfully deleted."
254 //TODO - verify the format for Service Instance Delete,
256 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
259 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
260 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
261 <lastModifiedBy>BPMN</lastModifiedBy>
262 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
263 <responseBody></responseBody>
264 <requestStatus>COMPLETED</requestStatus>
265 <progress>100</progress>
266 </ns:updateInfraRequest>
268 </soapenv:Envelope>"""
270 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
271 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
272 msoLogger.info(buildDeleteDBRequestAsString)
274 } catch (Exception ex) {
275 // try error in method block
276 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
277 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
283 // *******************************
284 // Build Error Section
285 // *******************************
286 public void prepareDBRequestError (DelegateExecution execution) {
287 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
288 execution.setVariable("prefix", Prefix)
290 msoLogger.trace("Start prepareDBRequestError")
293 String requestId = execution.getVariable("DELSI_requestId")
294 String statusMessage = ""
295 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
296 WorkflowException wfe = execution.getVariable("WorkflowException")
297 statusMessage = wfe.getErrorMessage()
300 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
303 //TODO - verify the format for Service Instance Create,
305 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
308 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
309 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
310 <lastModifiedBy>BPMN</lastModifiedBy>
311 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
312 <responseBody></responseBody>
313 <requestStatus>FAILED</requestStatus>
314 </ns:updateInfraRequest>
316 </soapenv:Envelope>"""
318 String buildDBRequestAsString = utils.formatXml(dbRequest)
319 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
320 msoLogger.info(buildDBRequestAsString)
322 } catch (Exception ex) {
323 // try error in method block
324 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
325 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
331 public void processJavaException(DelegateExecution execution) {
336 * Init the service Operation Status
338 public void prepareInitServiceOperationStatus(DelegateExecution execution){
339 msoLogger.debug("======== STARTED prepareInitServiceOperationStatus Process ======== ")
341 String serviceId = execution.getVariable("serviceInstanceId")
342 String operationId = execution.getVariable("operationId")
344 String result = "processing"
345 String progress = "0"
347 String operationContent = "Prepare service creation"
348 msoLogger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
349 serviceId = UriUtils.encode(serviceId,"UTF-8")
351 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
352 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
353 msoLogger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint)
356 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
357 xmlns:ns="http://org.onap.so/requestsdb">
360 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
361 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
362 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
363 <operationType>DELETE</operationType>
364 <userId>${MsoUtils.xmlEscape(userId)}</userId>
365 <result>${MsoUtils.xmlEscape(result)}</result>
366 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
367 <progress>${MsoUtils.xmlEscape(progress)}</progress>
368 <reason>${MsoUtils.xmlEscape(reason)}</reason>
369 </ns:updateServiceOperationStatus>
371 </soapenv:Envelope>"""
373 payload = utils.formatXml(payload)
374 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
375 msoLogger.debug("Outgoing updateServiceOperStatusRequest: \n" + payload)
378 msoLogger.error("Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e)
379 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
381 msoLogger.debug("======== COMPLETED prepareInitServiceOperationStatus Process ======== ")