2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
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 org.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.NetworkUtils
31 import org.onap.so.bpmn.common.scripts.VidUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.logging.filter.base.ErrorCode;
35 import org.onap.so.logger.MessageEnum
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
39 public class DeleteNetworkInstance extends AbstractServiceTaskProcessor {
40 String Prefix="DELNI_"
41 String groovyClassName = "DeleteNetworkInstance"
42 ExceptionUtil exceptionUtil = new ExceptionUtil()
43 JsonUtils jsonUtil = new JsonUtils()
44 VidUtils vidUtils = new VidUtils(this)
45 NetworkUtils networkUtils = new NetworkUtils()
47 private static final Logger logger = LoggerFactory.getLogger( DeleteNetworkInstance.class);
50 public InitializeProcessVariables(DelegateExecution execution){
52 execution.setVariable(Prefix + "Success", false)
54 execution.setVariable(Prefix + "CompleteMsoProcessRequest", "")
55 execution.setVariable(Prefix + "FalloutHandlerRequest", "")
56 execution.setVariable(Prefix + "isSilentSuccess", false)
60 // **************************************************
61 // Pre or Prepare Request Section
62 // **************************************************
64 public void preProcessRequest (DelegateExecution execution) {
65 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
66 execution.setVariable("prefix",Prefix)
68 logger.trace("Inside preProcessRequest() of " + groovyClassName + "")
71 // initialize flow variables
72 InitializeProcessVariables(execution)
74 String sdncVersion = execution.getVariable("sdncVersion")
75 if (sdncVersion == null || sdncVersion == '1610') {
76 // 'a-la-cart' default, sdncVersion = '1610'
77 execution.setVariable("sdncVersion", "1610")
78 String bpmnRequest = execution.getVariable("bpmnRequest")
79 // set 'disableRollback'
80 if (bpmnRequest != null) {
81 String disableRollback = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.requestInfo.suppressRollback")
82 if (disableRollback != null) {
83 execution.setVariable("disableRollback", disableRollback)
84 logger.debug("Received 'suppressRollback': " + disableRollback )
86 execution.setVariable("disableRollback", false)
88 logger.debug(" Set 'disableRollback' : " + execution.getVariable("disableRollback") )
90 String dataErrorMessage = " Invalid 'bpmnRequest' request."
91 logger.debug(dataErrorMessage)
92 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
96 // 'macro' test ONLY, sdncVersion = '1702'
97 logger.debug(" 'disableRollback' : " + execution.getVariable("disableRollback") )
100 // get/set 'msoRequestId' and 'mso-request-id'
101 String requestId = execution.getVariable("msoRequestId")
102 if (requestId != null) {
103 execution.setVariable("mso-request-id", requestId)
105 requestId = execution.getVariable("mso-request-id")
107 execution.setVariable(Prefix + "requestId", requestId)
109 // get/set 'requestId'
110 if (execution.getVariable("requestId") == null) {
111 execution.setVariable("requestId", requestId)
114 // set action to "DELETE"
115 execution.setVariable("action", "DELETE")
117 //Place holder for additional code.
120 // userParams??? 1) pre-loads indicator, 2) 'auto-activation'
121 // Tag/Value parameters
123 // Map: 'networkInputParams': 'auto-activation''
125 // "requestParameters": {
128 // "name": "someUserParam1",
129 // "value": "someValue1"
134 // String userParams = //use json util to extract "userParams"//
135 // execution.setVariable("networkInputParams", userParams)
136 // else: execution.setVariable("networkInputParams", null)
140 } catch (Exception ex){
141 sendSyncError(execution)
142 String exceptionMessage = "Exception Encountered in " + groovyClassName + ", PreProcessRequest() - " + ex.getMessage()
143 logger.debug(exceptionMessage)
144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
150 public void getNetworkModelInfo (DelegateExecution execution) {
151 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
152 execution.setVariable("prefix", Prefix)
154 logger.trace("Inside getNetworkModelInfo() of DeleteNetworkInstance")
158 // For Ala-Carte (sdnc = 1610):
159 // 1. the Network ModelInfo is expected to be sent
160 // via requestDetails.modelInfo (modelType = network), ex: modelCustomizationId.
161 // 2. the Service ModelInfo is expected to be sent but will be IGNORE
162 // via requestDetails.relatedInstanceList.relatedInstance.modelInfo (modelType = service)
164 } catch (Exception ex) {
165 sendSyncError(execution)
166 String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstance flow. getNetworkModelInfo() - " + ex.getMessage()
167 logger.debug(exceptionMessage)
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
174 public void sendSyncResponse (DelegateExecution execution) {
175 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
176 execution.setVariable("prefix",Prefix)
178 logger.trace("Inside sendSyncResponse() of DeleteNetworkInstance")
181 String requestId = execution.getVariable("mso-request-id")
182 String serviceInstanceId = execution.getVariable("serviceInstanceId")
184 // RESTResponse (for API Handler (APIH) Reply Task)
185 String deleteNetworkRestRequest = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
187 logger.debug(" sendSyncResponse to APIH - " + "\n" + deleteNetworkRestRequest)
189 sendWorkflowResponse(execution, 202, deleteNetworkRestRequest)
191 } catch (Exception ex) {
193 String exceptionMessage = "Exception Encountered in DeleteNetworkInstance, sendSyncResponse() - " + ex.getMessage()
194 logger.debug(exceptionMessage)
195 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
201 public void prepareCompletion (DelegateExecution execution) {
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
203 execution.setVariable("prefix",Prefix)
205 logger.trace("Inside prepareCompletion() of CreateNetworkInstance")
209 String requestId = execution.getVariable("mso-request-id")
210 String source = execution.getVariable(Prefix + "source")
212 String msoCompletionRequest =
213 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
214 xmlns:ns="http://org.onap/so/request/types/v1">
215 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
216 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
217 <action>DELETE</action>
220 <aetgt:status-message>Network has been deleted successfully.</aetgt:status-message>
221 <aetgt:mso-bpel-name>BPMN Network action: DELETE</aetgt:mso-bpel-name>
222 </aetgt:MsoCompletionRequest>"""
225 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
228 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
229 logger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
231 } catch (Exception ex) {
232 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. prepareCompletion() - " + ex.getMessage()
233 logger.debug(exceptionMessage)
234 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
241 public void prepareDBRequestError (DelegateExecution execution) {
242 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
243 execution.setVariable("prefix", Prefix)
246 logger.trace("Inside prepareDBRequestError of DeleteNetworkInstance")
248 // set DB Header Authorization
249 setBasicDBAuthHeader(execution, isDebugEnabled)
251 WorkflowException wfe = execution.getVariable("WorkflowException")
252 String statusMessage = wfe.getErrorMessage()
253 String requestId = execution.getVariable(Prefix +"requestId")
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>FAILED</requestStatus>
265 <progress></progress>
266 <vnfOutputs><network-outputs xmlns="http://org.onap/so/infra/vnf-request/v1" xmlns:aetgt="http://org.onap/so/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"/></vnfOutputs>
267 </ns:updateInfraRequest>
269 </soapenv:Envelope>"""
271 execution.setVariable(Prefix + "deleteDBRequest", dbRequest)
272 logger.debug(" DB Adapter Request - " + "\n" + dbRequest)
274 } catch (Exception ex) {
276 String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstance, prepareDBRequestError() - " + ex.getMessage()
277 logger.debug(exceptionMessage)
278 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
284 // **************************************************
285 // Post or Validate Response Section
286 // **************************************************
288 public void postProcessResponse (DelegateExecution execution) {
289 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
290 execution.setVariable("prefix", Prefix)
292 logger.trace("Inside postProcessResponse() of DeleteNetworkInstance")
295 if (execution.getVariable("CMSO_ResponseCode") == "200") {
296 execution.setVariable(Prefix + "Success", true)
297 logger.trace("DeleteNetworkInstance Success")
298 // Place holder for additional code.
301 execution.setVariable(Prefix + "Success", false)
302 logger.trace("DeleteNetworkInstance Failed in CompletionMsoProces flow!.")
307 } catch (Exception ex) {
308 String exceptionMessage = " Bpmn error encountered in DeleteNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
309 logger.debug(exceptionMessage)
310 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
317 // *******************************
318 // Build Error Section
319 // *******************************
321 // Prepare for FalloutHandler
322 public void buildErrorResponse (DelegateExecution execution) {
323 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
324 execution.setVariable("prefix", Prefix)
326 logger.trace("Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler.")
328 String dbReturnCode = execution.getVariable(Prefix + "dbReturnCode")
329 logger.debug("DB Update Response Code : " + dbReturnCode)
330 logger.debug("DB Update Response String: " + '\n' + execution.getVariable(Prefix + "deleteDBResponse"))
332 String falloutHandlerRequest = ""
333 String requestId = execution.getVariable("mso-request-id")
334 String source = execution.getVariable(Prefix + "source")
335 execution.setVariable(Prefix + "Success", false)
337 WorkflowException wfe = execution.getVariable("WorkflowException")
338 String errorCode = String.valueOf(wfe.getErrorCode())
339 String errorMessage = wfe.getErrorMessage()
341 falloutHandlerRequest =
342 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
343 xmlns:ns="http://org.onap/so/request/types/v1"
344 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
345 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
346 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
347 <action>DELETE</action>
348 <source>${MsoUtils.xmlEscape(source)}</source>
350 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
351 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
352 <aetgt:ErrorCode>${MsoUtils.xmlEscape(errorCode)}</aetgt:ErrorCode>
353 </aetgt:WorkflowException>
354 </aetgt:FalloutHandlerRequest>"""
356 logger.debug(falloutHandlerRequest)
357 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
358 logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
359 "Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, "BPMN",
360 ErrorCode.UnknownError.getValue())
362 } catch (Exception ex) {
364 String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstance, buildErrorResponse() - " + ex.getMessage()
365 logger.debug(exceptionMessage)
366 falloutHandlerRequest =
367 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
368 xmlns:ns="http://org.onap/so/request/types/v1"
369 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
370 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
371 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
372 <action>DELEtE</action>
373 <source>${MsoUtils.xmlEscape(source)}</source>
375 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
376 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(exceptionMessage)}</aetgt:ErrorMessage>
377 <aetgt:ErrorCode>9999</aetgt:ErrorCode>
378 </aetgt:WorkflowException>
379 </aetgt:FalloutHandlerRequest>"""
380 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
381 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
382 "Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest,"BPMN",
383 ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex)
388 public void sendSyncError (DelegateExecution execution) {
389 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
390 execution.setVariable("prefix", Prefix)
393 String requestId = execution.getVariable("mso-request-id")
394 String serviceInstanceId = execution.getVariable("serviceInstanceId")
396 // RESTResponse (for API Handler (APIH) Reply Task)
397 String deleteNetworkRestError = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
399 logger.debug(" sendSyncResponse to APIH - " + "\n" + deleteNetworkRestError)
401 sendWorkflowResponse(execution, 500, deleteNetworkRestError)
403 } catch (Exception ex) {
404 logger.debug(" Sending Sync Error Activity Failed - DeleteNetworkInstance, sendSyncError(): " + "\n" + ex.getMessage())
408 public void processJavaException(DelegateExecution execution){
409 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
410 execution.setVariable("prefix",Prefix)
412 logger.debug("Caught a Java Exception")
413 logger.debug("Started processJavaException Method")
414 logger.debug("Variables List: " + execution.getVariables())
415 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
416 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
419 logger.debug("Caught Exception during processJavaException Method: " + e)
420 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
421 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
423 logger.debug("Completed processJavaException Method of " + Prefix)