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 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
56 execution.setVariable("prefix",Prefix)
59 msoLogger.info("Starting preProcessRequest")
62 // check for incoming json message/input
63 String siRequest = execution.getVariable("bpmnRequest")
64 msoLogger.debug(siRequest)
67 String requestId = execution.getVariable("mso-request-id")
68 execution.setVariable("msoRequestId", requestId)
69 msoLogger.info("Input Request:" + siRequest + " reqId:" + requestId)
71 String serviceInstanceId = execution.getVariable("serviceInstanceId")
72 if (isBlank(serviceInstanceId)) {
73 msg = "Input serviceInstanceId' is null"
74 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
79 // String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
80 // if (isBlank(productFamilyId))
82 // msg = "Input productFamilyId is null"
83 // utils.log("INFO", msg, isDebugEnabled)
84 // //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
86 // execution.setVariable("productFamilyId", productFamilyId)
88 String source = jsonUtil.getJsonValue(siRequest, "source")
89 execution.setVariable("source", source)
92 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
93 if (isBlank(globalSubscriberId)) {
94 msg = "Input globalSubscriberId' is null"
97 execution.setVariable("globalSubscriberId", globalSubscriberId)
101 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
102 if (isBlank(subscriptionServiceType)) {
103 msg = "Input subscriptionServiceType is null"
105 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
109 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
110 execution.setVariable("operationId", operationId)
112 execution.setVariable("operationType", "DELETE")
113 } catch (BpmnError e) {
115 } catch (Exception ex){
116 msg = "Exception in preProcessRequest " + ex.getMessage()
118 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
120 msoLogger.trace("Exit preProcessRequest")
123 public void sendSyncResponse (DelegateExecution execution) {
124 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
125 msoLogger.trace("Staring sendSyncResponse")
128 String operationId = execution.getVariable("operationId")
129 String syncResponse = """{"operationId":"${operationId}"}""".trim()
130 msoLogger.info("sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
131 sendWorkflowResponse(execution, 202, syncResponse)
133 } catch (Exception ex) {
134 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
135 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
137 msoLogger.trace("Exit sendSyncResopnse")
140 public void sendSyncError (DelegateExecution execution) {
141 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
142 msoLogger.info("Starting sendSyncError")
145 String errorMessage = ""
146 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
147 WorkflowException wfe = execution.getVariable("WorkflowException")
148 errorMessage = wfe.getErrorMessage()
150 errorMessage = "Sending Sync Error."
153 String buildworkflowException =
154 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
155 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
156 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
157 </aetgt:WorkflowException>"""
159 msoLogger.info(buildworkflowException)
160 sendWorkflowResponse(execution, 500, buildworkflowException)
162 } catch (Exception ex) {
163 msoLogger.info("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
168 public void prepareCompletionRequest (DelegateExecution execution) {
169 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
170 msoLogger.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 msoLogger.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 msoLogger.trace("Exit prepareCompletionRequest")
201 public void prepareFalloutRequest(DelegateExecution execution){
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
203 msoLogger.trace("Starting prepareFalloutRequest ")
206 WorkflowException wfex = execution.getVariable("WorkflowException")
207 msoLogger.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 msoLogger.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 msoLogger.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 msoLogger.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 msoLogger.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 msoLogger.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 msoLogger.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 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
343 utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
345 String serviceId = execution.getVariable("serviceInstanceId")
346 String operationId = execution.getVariable("operationId")
348 String result = "processing"
349 String progress = "0"
351 String operationContent = "Prepare service creation"
352 utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
353 serviceId = UriUtils.encode(serviceId,"UTF-8")
355 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
356 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
357 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
360 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
361 xmlns:ns="http://org.onap.so/requestsdb">
364 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
365 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
366 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
367 <operationType>DELETE</operationType>
368 <userId>${MsoUtils.xmlEscape(userId)}</userId>
369 <result>${MsoUtils.xmlEscape(result)}</result>
370 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
371 <progress>${MsoUtils.xmlEscape(progress)}</progress>
372 <reason>${MsoUtils.xmlEscape(reason)}</reason>
373 </ns:updateServiceOperationStatus>
375 </soapenv:Envelope>"""
377 payload = utils.formatXml(payload)
378 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
379 utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
382 utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
383 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
385 utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)