2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
23 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
24 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
25 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
26 import org.openecomp.mso.bpmn.common.scripts.VidUtils
27 import org.openecomp.mso.bpmn.core.WorkflowException
28 import org.openecomp.mso.bpmn.core.json.JsonUtils;
29 import org.openecomp.mso.rest.APIResponse
30 import java.util.UUID;
31 import org.camunda.bpm.engine.delegate.BpmnError
32 import org.camunda.bpm.engine.delegate.DelegateExecution
33 import org.apache.commons.lang3.*
34 import org.apache.commons.codec.binary.Base64;
35 import org.springframework.web.util.UriUtils
36 import groovy.xml.XmlUtil
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()
48 public InitializeProcessVariables(DelegateExecution execution){
50 execution.setVariable(Prefix + "Success", false)
52 execution.setVariable(Prefix + "CompleteMsoProcessRequest", "")
53 execution.setVariable(Prefix + "FalloutHandlerRequest", "")
54 execution.setVariable(Prefix + "isSilentSuccess", false)
58 // **************************************************
59 // Pre or Prepare Request Section
60 // **************************************************
62 public void preProcessRequest (DelegateExecution execution) {
63 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
64 execution.setVariable("prefix",Prefix)
66 utils.log("DEBUG", " ***** Inside preProcessRequest() of " + groovyClassName + " ***** ", isDebugEnabled)
69 // initialize flow variables
70 InitializeProcessVariables(execution)
72 String sdncVersion = execution.getVariable("sdncVersion")
73 if (sdncVersion == null || sdncVersion == '1610') {
74 // 'a-la-cart' default, sdncVersion = '1610'
75 execution.setVariable("sdncVersion", "1610")
76 String bpmnRequest = execution.getVariable("bpmnRequest")
77 // set 'disableRollback'
78 if (bpmnRequest != null) {
79 String disableRollback = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.requestInfo.suppressRollback")
80 if (disableRollback != null) {
81 execution.setVariable("disableRollback", disableRollback)
82 utils.log("DEBUG", "Received 'suppressRollback': " + disableRollback , isDebugEnabled)
84 execution.setVariable("disableRollback", false)
86 utils.log("DEBUG", " Set 'disableRollback' : " + execution.getVariable("disableRollback") , isDebugEnabled)
88 String dataErrorMessage = " Invalid 'bpmnRequest' request."
89 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
90 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
94 // 'macro' test ONLY, sdncVersion = '1702'
95 utils.log("DEBUG", " 'disableRollback' : " + execution.getVariable("disableRollback") , isDebugEnabled)
98 // get/set 'msoRequestId' and 'mso-request-id'
99 String requestId = execution.getVariable("msoRequestId")
100 if (requestId != null) {
101 execution.setVariable("mso-request-id", requestId)
103 requestId = execution.getVariable("mso-request-id")
105 execution.setVariable(Prefix + "requestId", requestId)
107 // get/set 'requestId'
108 if (execution.getVariable("requestId") == null) {
109 execution.setVariable("requestId", requestId)
112 // set action to "DELETE"
113 execution.setVariable("action", "DELETE")
115 //Place holder for additional code.
118 // userParams??? 1) pre-loads indicator, 2) 'auto-activation'
119 // Tag/Value parameters
121 // Map: 'networkInputParams': 'auto-activation''
123 // "requestParameters": {
126 // "name": "someUserParam1",
127 // "value": "someValue1"
132 // String userParams = //use json util to extract "userParams"//
133 // execution.setVariable("networkInputParams", userParams)
134 // else: execution.setVariable("networkInputParams", null)
138 } catch (Exception ex){
139 sendSyncError(execution)
140 String exceptionMessage = "Exception Encountered in " + groovyClassName + ", PreProcessRequest() - " + ex.getMessage()
141 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
142 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
148 public void getNetworkModelInfo (DelegateExecution execution) {
149 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
150 execution.setVariable("prefix", Prefix)
152 utils.log("DEBUG", " ***** Inside getNetworkModelInfo() of DeleteNetworkInstance ***** ", isDebugEnabled)
156 // For Ala-Carte (sdnc = 1610):
157 // 1. the Network ModelInfo is expected to be sent
158 // via requestDetails.modelInfo (modelType = network), ex: modelCustomizationId.
159 // 2. the Service ModelInfo is expected to be sent but will be IGNORE
160 // via requestDetails.relatedInstanceList.relatedInstance.modelInfo (modelType = service)
162 } catch (Exception ex) {
163 sendSyncError(execution)
164 String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstance flow. getNetworkModelInfo() - " + ex.getMessage()
165 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
166 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
172 public void sendSyncResponse (DelegateExecution execution) {
173 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
174 execution.setVariable("prefix",Prefix)
176 utils.log("DEBUG", " ***** Inside sendSyncResponse() of DeleteNetworkInstance ***** ", isDebugEnabled)
179 String requestId = execution.getVariable("mso-request-id")
180 String serviceInstanceId = execution.getVariable("serviceInstanceId")
182 // RESTResponse (for API Handler (APIH) Reply Task)
183 String deleteNetworkRestRequest = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
185 utils.log("DEBUG", " sendSyncResponse to APIH - " + "\n" + deleteNetworkRestRequest, isDebugEnabled)
187 sendWorkflowResponse(execution, 202, deleteNetworkRestRequest)
189 } catch (Exception ex) {
191 String exceptionMessage = "Exception Encountered in DeleteNetworkInstance, sendSyncResponse() - " + ex.getMessage()
192 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
193 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
199 public void prepareCompletion (DelegateExecution execution) {
200 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
201 execution.setVariable("prefix",Prefix)
203 utils.log("DEBUG", " ***** Inside prepareCompletion() of CreateNetworkInstance ***** ", isDebugEnabled)
207 String requestId = execution.getVariable("mso-request-id")
208 String source = execution.getVariable(Prefix + "source")
210 String msoCompletionRequest =
211 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
212 xmlns:ns="http://org.openecomp/mso/request/types/v1">
213 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
214 <request-id>${requestId}</request-id>
215 <action>DELETE</action>
218 <aetgt:status-message>Network has been deleted successfully.</aetgt:status-message>
219 <aetgt:mso-bpel-name>BPMN Network action: DELETE</aetgt:mso-bpel-name>
220 </aetgt:MsoCompletionRequest>"""
223 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
226 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
227 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
229 } catch (Exception ex) {
230 String exceptionMessage = " Bpmn error encountered in CreateNetworkInstance flow. prepareCompletion() - " + ex.getMessage()
231 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
232 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
239 public void prepareDBRequestError (DelegateExecution execution) {
240 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
241 execution.setVariable("prefix", Prefix)
244 utils.log("DEBUG", " ***** Inside prepareDBRequestError of DeleteNetworkInstance ***** ", isDebugEnabled)
246 // set DB Header Authorization
247 setBasicDBAuthHeader(execution, isDebugEnabled)
249 WorkflowException wfe = execution.getVariable("WorkflowException")
250 String statusMessage = wfe.getErrorMessage()
251 String requestId = execution.getVariable(Prefix +"requestId")
254 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
257 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
258 <requestId>${requestId}</requestId>
259 <lastModifiedBy>BPMN</lastModifiedBy>
260 <statusMessage>${statusMessage}</statusMessage>
261 <responseBody></responseBody>
262 <requestStatus>FAILED</requestStatus>
263 <progress></progress>
264 <vnfOutputs><network-outputs xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:aetgt="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"/></vnfOutputs>
265 </ns:updateInfraRequest>
267 </soapenv:Envelope>"""
269 execution.setVariable(Prefix + "deleteDBRequest", dbRequest)
270 utils.log("DEBUG", " DB Adapter Request - " + "\n" + dbRequest, isDebugEnabled)
272 } catch (Exception ex) {
274 String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstance, prepareDBRequestError() - " + ex.getMessage()
275 logError(exceptionMessage)
276 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
277 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
283 // **************************************************
284 // Post or Validate Response Section
285 // **************************************************
287 public void postProcessResponse (DelegateExecution execution) {
288 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
289 execution.setVariable("prefix", Prefix)
291 utils.log("DEBUG", " ***** Inside postProcessResponse() of DeleteNetworkInstance ***** ", isDebugEnabled)
294 if (execution.getVariable("CMSO_ResponseCode") == "200") {
295 execution.setVariable(Prefix + "Success", true)
296 utils.log("DEBUG", " ***** DeleteNetworkInstance Success ***** ", isDebugEnabled)
297 // Place holder for additional code.
300 execution.setVariable(Prefix + "Success", false)
301 utils.log("DEBUG", " ***** DeleteNetworkInstance Failed in CompletionMsoProces flow!. ***** ", isDebugEnabled)
306 } catch (Exception ex) {
307 String exceptionMessage = " Bpmn error encountered in DeleteNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
308 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
316 // *******************************
317 // Build Error Section
318 // *******************************
320 // Prepare for FalloutHandler
321 public void buildErrorResponse (DelegateExecution execution) {
322 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
323 execution.setVariable("prefix", Prefix)
325 utils.log("DEBUG", " ***** Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler. *****", isDebugEnabled)
327 String dbReturnCode = execution.getVariable(Prefix + "dbReturnCode")
328 utils.log("DEBUG", " ***** DB Update Response Code : " + dbReturnCode, isDebugEnabled)
329 utils.log("DEBUG", " ***** DB Update Response String: " + '\n' + execution.getVariable(Prefix + "deleteDBResponse"), isDebugEnabled)
331 String falloutHandlerRequest = ""
332 String requestId = execution.getVariable("mso-request-id")
333 String source = execution.getVariable(Prefix + "source")
334 execution.setVariable(Prefix + "Success", false)
336 WorkflowException wfe = execution.getVariable("WorkflowException")
337 String errorCode = String.valueOf(wfe.getErrorCode())
338 String errorMessage = wfe.getErrorMessage()
340 falloutHandlerRequest =
341 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
342 xmlns:ns="http://org.openecomp/mso/request/types/v1"
343 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
344 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
345 <request-id>${requestId}</request-id>
346 <action>DELETE</action>
347 <source>${source}</source>
349 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
350 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
351 <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
352 </aetgt:WorkflowException>
353 </aetgt:FalloutHandlerRequest>"""
355 utils.logAudit(falloutHandlerRequest)
356 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
357 utils.log("ERROR", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
359 } catch (Exception ex) {
361 String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstance, buildErrorResponse() - " + ex.getMessage()
362 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
363 falloutHandlerRequest =
364 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
365 xmlns:ns="http://org.openecomp/mso/request/types/v1"
366 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
367 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
368 <request-id>${requestId}</request-id>
369 <action>DELEtE</action>
370 <source>${source}</source>
372 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
373 <aetgt:ErrorMessage>${exceptionMessage}</aetgt:ErrorMessage>
374 <aetgt:ErrorCode>9999</aetgt:ErrorCode>
375 </aetgt:WorkflowException>
376 </aetgt:FalloutHandlerRequest>"""
377 execution.setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
378 utils.log("DEBUG", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
383 public void sendSyncError (DelegateExecution execution) {
384 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
385 execution.setVariable("prefix", Prefix)
388 String requestId = execution.getVariable("mso-request-id")
389 String serviceInstanceId = execution.getVariable("serviceInstanceId")
391 // RESTResponse (for API Handler (APIH) Reply Task)
392 String deleteNetworkRestError = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
394 utils.log("DEBUG", " sendSyncResponse to APIH - " + "\n" + deleteNetworkRestError, isDebugEnabled)
396 sendWorkflowResponse(execution, 500, deleteNetworkRestError)
398 } catch (Exception ex) {
399 utils.log("DEBUG", " Sending Sync Error Activity Failed - DeleteNetworkInstance, sendSyncError(): " + "\n" + ex.getMessage(), isDebugEnabled)
403 public void processJavaException(DelegateExecution execution){
404 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
405 execution.setVariable("prefix",Prefix)
407 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
408 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
409 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
410 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
411 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
414 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
415 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
416 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
418 utils.log("DEBUG", "Completed processJavaException Method of " + Prefix, isDebugEnabled)