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 * Modifications Copyright (c) 2019 Samsung
10 * ================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License")
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 package org.onap.so.bpmn.infrastructure.scripts
27 import static org.apache.commons.lang3.StringUtils.*
29 import org.apache.commons.lang3.*
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.delegate.DelegateExecution
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.common.scripts.VidUtils
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.bpmn.core.UrnPropertiesReader
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
41 import org.springframework.web.util.UriUtils
46 * This groovy class supports the <class>DelE2EServiceInstance.bpmn</class> process.
49 public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
51 String Prefix="DELSI_"
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 JsonUtils jsonUtil = new JsonUtils()
54 VidUtils vidUtils = new VidUtils()
55 private static final Logger logger = LoggerFactory.getLogger( DeleteCustomE2EServiceInstance.class)
57 public void preProcessRequest (DelegateExecution execution) {
58 execution.setVariable("prefix",Prefix)
61 logger.info("Starting preProcessRequest")
64 // check for incoming json message/input
65 String siRequest = execution.getVariable("bpmnRequest")
66 logger.debug(siRequest)
69 String requestId = execution.getVariable("mso-request-id")
70 execution.setVariable("msoRequestId", requestId)
71 logger.info("Input Request:" + siRequest + " reqId:" + requestId)
73 String serviceInstanceId = execution.getVariable("serviceInstanceId")
74 if (isBlank(serviceInstanceId)) {
75 msg = "Input serviceInstanceId' is null"
76 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
81 // String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
82 // if (isBlank(productFamilyId))
84 // msg = "Input productFamilyId is null"
86 // //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
88 // execution.setVariable("productFamilyId", productFamilyId)
90 String source = jsonUtil.getJsonValue(siRequest, "source")
91 execution.setVariable("source", source)
94 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
95 if (isBlank(globalSubscriberId)) {
96 msg = "Input globalSubscriberId' is null"
99 execution.setVariable("globalSubscriberId", globalSubscriberId)
103 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
104 if (isBlank(subscriptionServiceType)) {
105 msg = "Input subscriptionServiceType is null"
107 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
109 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
111 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
112 execution.setVariable("operationId", operationId)
114 execution.setVariable("operationType", "DELETE")
115 } catch (BpmnError e) {
117 } catch (Exception ex){
118 msg = "Exception in preProcessRequest " + ex.getMessage()
120 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
122 logger.trace("Exit preProcessRequest")
125 public void sendSyncResponse (DelegateExecution execution) {
126 logger.trace("Staring sendSyncResponse")
129 String operationId = execution.getVariable("operationId")
130 String syncResponse = """{"operationId":"${operationId}"}""".trim()
131 logger.info("sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
132 sendWorkflowResponse(execution, 202, syncResponse)
134 } catch (Exception ex) {
135 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
138 logger.trace("Exit sendSyncResopnse")
141 public void sendSyncError (DelegateExecution execution) {
142 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
143 logger.info("Starting sendSyncError")
146 String errorMessage = ""
147 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
148 WorkflowException wfe = execution.getVariable("WorkflowException")
149 errorMessage = wfe.getErrorMessage()
151 errorMessage = "Sending Sync Error."
154 String buildworkflowException =
155 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
156 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
157 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
158 </aetgt:WorkflowException>"""
160 logger.info(buildworkflowException)
161 sendWorkflowResponse(execution, 500, buildworkflowException)
163 } catch (Exception ex) {
164 logger.info("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
169 public void prepareCompletionRequest (DelegateExecution execution) {
170 logger.trace("Starting prepareCompletion")
173 String requestId = execution.getVariable("msoRequestId")
174 String source = execution.getVariable("source")
175 String msoCompletionRequest =
176 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
177 xmlns:ns="http://org.onap/so/request/types/v1">
178 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
179 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
180 <action>DELETE</action>
181 <source>${MsoUtils.xmlEscape(source)}</source>
183 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
184 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
185 </aetgt:MsoCompletionRequest>"""
188 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
190 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
191 logger.info(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
193 } catch (Exception ex) {
194 String msg = " Exception in prepareCompletion:" + ex.getMessage()
196 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
198 logger.trace("Exit prepareCompletionRequest")
201 public void prepareFalloutRequest(DelegateExecution execution){
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
203 logger.trace("Starting prepareFalloutRequest ")
206 WorkflowException wfex = execution.getVariable("WorkflowException")
207 logger.info(" Input Workflow Exception: " + wfex.toString())
208 String requestId = execution.getVariable("msoRequestId")
209 String source = execution.getVariable("source")
211 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
212 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
213 <action>DELETE</action>
214 <source>${MsoUtils.xmlEscape(source)}</source>
217 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
218 execution.setVariable("falloutRequest", falloutRequest)
219 } catch (Exception ex) {
220 logger.info("Exception prepareFalloutRequest:" + ex.getMessage())
221 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
222 String requestId = execution.getVariable("msoRequestId")
223 String falloutRequest =
224 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
225 xmlns:ns="http://org.onap/so/request/types/v1"
226 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
227 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
228 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
229 <action>DELETE</action>
232 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
233 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
234 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
235 </aetgt:WorkflowException>
236 </aetgt:FalloutHandlerRequest>"""
238 execution.setVariable("falloutRequest", falloutRequest)
240 logger.trace("Exit prepareFalloutRequest")
244 // *******************************
245 // Build DB request Section
246 // *******************************
247 public void prepareDBRequest (DelegateExecution execution) {
248 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
249 execution.setVariable("prefix", Prefix)
252 logger.info("Starting prepareDBRequest")
254 String requestId = execution.getVariable("DELSI_requestId")
255 String statusMessage = "E2E Service Instance successfully deleted."
257 //TODO - verify the format for Service Instance Delete,
259 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
262 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
263 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
264 <lastModifiedBy>BPMN</lastModifiedBy>
265 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
266 <responseBody></responseBody>
267 <requestStatus>COMPLETED</requestStatus>
268 <progress>100</progress>
269 </ns:updateInfraRequest>
271 </soapenv:Envelope>"""
273 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
274 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
275 logger.info(buildDeleteDBRequestAsString)
277 } catch (Exception ex) {
278 // try error in method block
279 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
280 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
286 // *******************************
287 // Build Error Section
288 // *******************************
289 public void prepareDBRequestError (DelegateExecution execution) {
290 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
291 execution.setVariable("prefix", Prefix)
293 logger.trace("Start prepareDBRequestError")
296 String requestId = execution.getVariable("DELSI_requestId")
297 String statusMessage = ""
298 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
299 WorkflowException wfe = execution.getVariable("WorkflowException")
300 statusMessage = wfe.getErrorMessage()
303 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
306 //TODO - verify the format for Service Instance Create,
308 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
311 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
312 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
313 <lastModifiedBy>BPMN</lastModifiedBy>
314 <statusMessage>${MsoUtils.xmlEscape(statusMessage)}</statusMessage>
315 <responseBody></responseBody>
316 <requestStatus>FAILED</requestStatus>
317 </ns:updateInfraRequest>
319 </soapenv:Envelope>"""
321 String buildDBRequestAsString = utils.formatXml(dbRequest)
322 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
323 logger.info(buildDBRequestAsString)
325 } catch (Exception ex) {
326 // try error in method block
327 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
328 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
334 public void processJavaException(DelegateExecution execution) {
339 * Init the service Operation Status
341 public void prepareInitServiceOperationStatus(DelegateExecution execution){
342 logger.debug("======== STARTED prepareInitServiceOperationStatus Process ======== ")
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 logger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
352 serviceId = UriUtils.encode(serviceId,"UTF-8")
354 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
355 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
356 logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint)
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 logger.debug("Outgoing updateServiceOperStatusRequest: \n" + payload)
381 logger.error("Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e)
382 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
384 logger.debug("======== COMPLETED prepareInitServiceOperationStatus Process ======== ")