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.logger.MsoLogger
37 import org.springframework.web.util.UriUtils;
42 * This groovy class supports the <class>DelE2EServiceInstance.bpmn</class> process.
45 public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
47 String Prefix="DELSI_"
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
50 VidUtils vidUtils = new VidUtils()
51 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteCustomE2EServiceInstance.class);
53 public void preProcessRequest (DelegateExecution execution) {
54 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
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 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
124 msoLogger.trace("Staring sendSyncResponse")
127 String operationId = execution.getVariable("operationId")
128 String syncResponse = """{"operationId":"${operationId}"}""".trim()
129 msoLogger.info("sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
130 sendWorkflowResponse(execution, 202, syncResponse)
132 } catch (Exception ex) {
133 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
136 msoLogger.trace("Exit sendSyncResopnse")
139 public void sendSyncError (DelegateExecution execution) {
140 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
141 msoLogger.info("Starting sendSyncError")
144 String errorMessage = ""
145 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
146 WorkflowException wfe = execution.getVariable("WorkflowException")
147 errorMessage = wfe.getErrorMessage()
149 errorMessage = "Sending Sync Error."
152 String buildworkflowException =
153 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
154 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
155 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
156 </aetgt:WorkflowException>"""
158 msoLogger.info(buildworkflowException)
159 sendWorkflowResponse(execution, 500, buildworkflowException)
161 } catch (Exception ex) {
162 msoLogger.info("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
167 public void prepareCompletionRequest (DelegateExecution execution) {
168 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
169 msoLogger.trace("Starting prepareCompletion")
172 String requestId = execution.getVariable("msoRequestId")
173 String source = execution.getVariable("source")
174 String msoCompletionRequest =
175 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
176 xmlns:ns="http://org.onap/so/request/types/v1">
177 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
178 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
179 <action>DELETE</action>
180 <source>${MsoUtils.xmlEscape(source)}</source>
182 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
183 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
184 </aetgt:MsoCompletionRequest>"""
187 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
189 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
190 msoLogger.info(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
192 } catch (Exception ex) {
193 String msg = " Exception in prepareCompletion:" + ex.getMessage()
195 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
197 msoLogger.trace("Exit prepareCompletionRequest")
200 public void prepareFalloutRequest(DelegateExecution execution){
201 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
202 msoLogger.trace("Starting prepareFalloutRequest ")
205 WorkflowException wfex = execution.getVariable("WorkflowException")
206 msoLogger.info(" Input Workflow Exception: " + wfex.toString())
207 String requestId = execution.getVariable("msoRequestId")
208 String source = execution.getVariable("source")
210 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
211 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
212 <action>DELETE</action>
213 <source>${MsoUtils.xmlEscape(source)}</source>
216 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
217 execution.setVariable("falloutRequest", falloutRequest)
218 } catch (Exception ex) {
219 msoLogger.info("Exception prepareFalloutRequest:" + ex.getMessage())
220 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
221 String requestId = execution.getVariable("msoRequestId")
222 String falloutRequest =
223 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
224 xmlns:ns="http://org.onap/so/request/types/v1"
225 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
226 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
227 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
228 <action>DELETE</action>
231 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
232 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
233 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
234 </aetgt:WorkflowException>
235 </aetgt:FalloutHandlerRequest>"""
237 execution.setVariable("falloutRequest", falloutRequest)
239 msoLogger.trace("Exit prepareFalloutRequest")
243 // *******************************
244 // Build DB request Section
245 // *******************************
246 public void prepareDBRequest (DelegateExecution execution) {
247 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
248 execution.setVariable("prefix", Prefix)
251 msoLogger.info("Starting prepareDBRequest")
253 String requestId = execution.getVariable("DELSI_requestId")
254 String statusMessage = "E2E Service Instance successfully deleted."
256 //TODO - verify the format for Service Instance Delete,
258 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
261 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
262 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
263 <lastModifiedBy>BPMN</lastModifiedBy>
264 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
265 <responseBody></responseBody>
266 <requestStatus>COMPLETED</requestStatus>
267 <progress>100</progress>
268 </ns:updateInfraRequest>
270 </soapenv:Envelope>"""
272 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
273 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
274 msoLogger.info(buildDeleteDBRequestAsString)
276 } catch (Exception ex) {
277 // try error in method block
278 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
279 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
285 // *******************************
286 // Build Error Section
287 // *******************************
288 public void prepareDBRequestError (DelegateExecution execution) {
289 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
290 execution.setVariable("prefix", Prefix)
292 msoLogger.trace("Start prepareDBRequestError")
295 String requestId = execution.getVariable("DELSI_requestId")
296 String statusMessage = ""
297 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
298 WorkflowException wfe = execution.getVariable("WorkflowException")
299 statusMessage = wfe.getErrorMessage()
302 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
305 //TODO - verify the format for Service Instance Create,
307 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
310 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
311 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
312 <lastModifiedBy>BPMN</lastModifiedBy>
313 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
314 <responseBody></responseBody>
315 <requestStatus>FAILED</requestStatus>
316 </ns:updateInfraRequest>
318 </soapenv:Envelope>"""
320 String buildDBRequestAsString = utils.formatXml(dbRequest)
321 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
322 msoLogger.info(buildDBRequestAsString)
324 } catch (Exception ex) {
325 // try error in method block
326 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
327 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
333 public void processJavaException(DelegateExecution execution) {
338 * Init the service Operation Status
340 public void prepareInitServiceOperationStatus(DelegateExecution execution){
341 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
342 utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
344 String serviceId = execution.getVariable("serviceInstanceId")
345 String operationId = execution.getVariable("operationId")
347 String result = "processing"
348 String progress = "0"
350 String operationContent = "Prepare service creation"
351 utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
352 serviceId = UriUtils.encode(serviceId,"UTF-8")
354 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
355 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
356 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
359 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
360 xmlns:ns="http://org.onap.so/requestsdb">
363 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
364 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
365 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
366 <operationType>DELETE</operationType>
367 <userId>${MsoUtils.xmlEscape(userId)}</userId>
368 <result>${MsoUtils.xmlEscape(result)}</result>
369 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
370 <progress>${MsoUtils.xmlEscape(progress)}</progress>
371 <reason>${MsoUtils.xmlEscape(reason)}</reason>
372 </ns:updateServiceOperationStatus>
374 </soapenv:Envelope>"""
376 payload = utils.formatXml(payload)
377 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
378 utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
381 utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
382 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
384 utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)