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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
22 import groovy.xml.XmlUtil
25 import org.openecomp.mso.bpmn.core.json.JsonUtils
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
29 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse;
35 import java.util.UUID;
37 import org.camunda.bpm.engine.delegate.BpmnError
38 import org.camunda.bpm.engine.runtime.Execution
39 import org.json.JSONObject;
40 import org.json.JSONArray;
41 import org.apache.commons.lang3.*
42 import org.apache.commons.codec.binary.Base64;
43 import org.springframework.web.util.UriUtils;
46 * This groovy class supports the <class>DeleteViprAtmService.bpmn</class> process.
49 public class DeleteGenericMacroServiceNetworkVnf extends AbstractServiceTaskProcessor {
51 String Prefix="DELVAS_"
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 JsonUtils jsonUtil = new JsonUtils()
54 VidUtils vidUtils = new VidUtils()
55 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
56 NetworkUtils networkUtils = new NetworkUtils()
59 * This method is executed during the preProcessRequest task of the <class>DeleteViprAtmService.bpmn</class> process.
62 public InitializeProcessVariables(Execution execution){
63 /* Initialize all the process variables in this block */
65 execution.setVariable("deleteViprAtmServiceRequest", "")
66 execution.setVariable("msoRequestId", "")
67 execution.setVariable("DELVAS_vnfsDeletedCount", 0)
68 execution.setVariable("DELVAS_vnfsCount", 0)
69 execution.setVariable("DELVAS_networksCount", 0)
70 execution.setVariable("DELVAS_networksDeletedCount", 0)
73 // **************************************************
74 // Pre or Prepare Request Section
75 // **************************************************
77 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
80 public void preProcessRequest (Execution execution) {
81 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
82 execution.setVariable("prefix",Prefix)
84 utils.log("DEBUG", " ***** Inside preProcessRequest DeleteViprAtmService Request ***** ", isDebugEnabled)
87 // initialize flow variables
88 InitializeProcessVariables(execution)
90 // check for incoming json message/input
91 String deleteViprAtmServiceRequest = execution.getVariable("bpmnRequest")
92 utils.logAudit(deleteViprAtmServiceRequest)
93 execution.setVariable("deleteViprAtmServiceRequest", deleteViprAtmServiceRequest);
94 println 'deleteViprAtmServiceRequest - ' + deleteViprAtmServiceRequest
97 String requestId = execution.getVariable("mso-request-id")
98 execution.setVariable("msoRequestId", requestId)
100 String serviceInstanceId = execution.getVariable("serviceInstanceId")
101 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
102 String dataErrorMessage = " Element 'serviceInstanceId' is missing. "
103 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
106 String requestAction = execution.getVariable("requestAction")
107 execution.setVariable("requestAction", requestAction)
109 String source = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestInfo.source")
110 if ((source == null) || (source.isEmpty())) {
111 execution.setVariable("source", "VID")
113 execution.setVariable("source", source)
116 // extract globalSubscriberId
117 String globalSubscriberId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
119 // global-customer-id is optional on Delete
121 execution.setVariable("globalSubscriberId", globalSubscriberId)
122 execution.setVariable("globalCustomerId", globalSubscriberId)
124 String suppressRollback = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestInfo.suppressRollback")
125 execution.setVariable("disableRollback", suppressRollback)
126 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
128 String productFamilyId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestInfo.productFamilyId")
129 execution.setVariable("productFamilyId", productFamilyId)
130 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
132 // extract subscriptionServiceType
133 String subscriptionServiceType = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
134 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
135 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
137 // extract cloud configuration
138 String lcpCloudRegionId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
139 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
140 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
141 String tenantId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.cloudConfiguration.tenantId")
142 execution.setVariable("tenantId", tenantId)
143 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
145 String sdncVersion = "1702"
146 execution.setVariable("sdncVersion", sdncVersion)
147 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
149 //For Completion Handler & Fallout Handler
151 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
152 <request-id>${requestId}</request-id>
153 <action>DELETE</action>
154 <source>${source}</source>
157 execution.setVariable("DELVAS_requestInfo", requestInfo)
159 //Setting for Generic Sub Flows
160 execution.setVariable("GENGS_type", "service-instance")
162 utils.log("DEBUG", " ***** Completed preProcessRequest DeleteViprAtmService Request ***** ", isDebugEnabled)
164 } catch (BpmnError e) {
166 } catch (Exception ex){
167 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
172 public void sendSyncResponse (Execution execution) {
173 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
175 utils.log("DEBUG", " ***** Inside sendSyncResponse of DeleteViprAtmService ***** ", isDebugEnabled)
178 String serviceInstanceId = execution.getVariable("serviceInstanceId")
179 String requestId = execution.getVariable("mso-request-id")
181 // RESTResponse (for API Handler (APIH) Reply Task)
182 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
184 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
185 sendWorkflowResponse(execution, 202, syncResponse)
186 } catch (Exception ex) {
187 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
192 public void prepareServiceInstanceDelete (Execution execution) {
193 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
194 utils.log("DEBUG", " ***** Inside prepareServiceInstanceDelete() of DeleteViprAtmService ***** ", isDebugEnabled)
198 String serviceInstanceId = execution.getVariable("serviceInstanceId")
200 // confirm if ServiceInstance was found
201 if ( !execution.getVariable("GENGS_FoundIndicator") )
203 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Service Instance was not found in AAI by id: " + serviceInstanceId
204 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
207 // get variable within incoming json
208 String deleteViprAtmServiceRequest = execution.getVariable("deleteViprAtmServiceRequest");
210 // get SI extracted by GenericGetService
211 String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");
213 utils.log("DEBUG", "serviceInstanceAaiRecord: "+serviceInstanceAaiRecord, isDebugEnabled)
215 String relationship = ""
217 relationship = networkUtils.getFirstNodeXml(serviceInstanceAaiRecord, "relationship-list")
218 } catch (Exception ex) {
219 //no relationships found
221 utils.log("DEBUG", " relationship string - " + relationship, isDebugEnabled)
224 int networksCount = 0
226 if (relationship != null && relationship.length() > 0){
227 relationship = relationship.trim().replace("tag0:","").replace(":tag0","")
229 // Check if Network TableREf is present, then build a List of network policy
230 List relatedVnfIdList = networkUtils.getRelatedVnfIdList(relationship)
231 vnfsCount = relatedVnfIdList.size()
232 execution.setVariable("DELVAS_vnfsCount", vnfsCount)
233 utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
234 execution.setVariable("DELVAS_relatedVnfIdList", relatedVnfIdList)
236 // Check if Network TableREf is present, then build a List of network policy
237 List relatedNetworkIdList = networkUtils.getRelatedNetworkIdList(relationship)
238 networksCount = relatedNetworkIdList.size()
239 execution.setVariable("DELVAS_networksCount", networksCount)
240 utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
241 execution.setVariable("DELVAS_relatedNetworkIdList", relatedNetworkIdList)
242 execution.setVariable("relatedNetworkIdListString", relatedNetworkIdList.toString())
244 execution.setVariable("DELVAS_vnfsCount", 0)
245 utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
246 execution.setVariable("DELVAS_networksCount", 0)
247 utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
250 utils.log("DEBUG", " ***** Completed prepareServiceInstanceDelete() of DeleteViprAtmService ***** ", isDebugEnabled)
251 } catch (Exception ex) {
252 sendSyncError(execution)
253 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. prepareServiceInstanceDelete() - " + ex.getMessage()
254 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
255 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
260 // *******************************
262 // *******************************
263 public void prepareVnfAndModulesDelete (Execution execution) {
264 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
267 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
269 List vnfList = execution.getVariable("DELVAS_relatedVnfIdList")
270 Integer vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
271 String vnfModelInfoString = ""
273 if (vnfList.size() > 0 ) {
274 vnfId = vnfList.get(vnfsDeletedCount.intValue())
277 execution.setVariable("vnfId", vnfId)
278 utils.log("DEBUG", "need to delete vnfId:" + vnfId, isDebugEnabled)
280 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
281 } catch (Exception ex) {
282 // try error in method block
283 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstanceMacro flow. Unexpected Error from method prepareVnfAndModulesDelete() - " + ex.getMessage()
284 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
288 // *******************************
289 // Validate Vnf request Section -> increment count
290 // *******************************
291 public void validateVnfDelete (Execution execution) {
292 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
295 utils.log("DEBUG", " ***** Inside validateVnfDelete of DeleteViprAtmService ***** ", isDebugEnabled)
297 String vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
300 execution.setVariable("DELVAS_vnfsDeletedCount", vnfsDeletedCount)
302 utils.log("DEBUG", " ***** Completed validateVnfDelete of DeleteViprAtmService ***** "+" vnf # "+vnfsDeletedCount, isDebugEnabled)
303 } catch (Exception ex) {
304 // try error in method block
305 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected Error from method validateVnfDelete() - " + ex.getMessage()
306 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
310 // *******************************
311 // Generate Network request Section
312 // *******************************
313 public void prepareNetworkDelete (Execution execution) {
314 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
317 utils.log("DEBUG", " ***** Inside prepareNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
319 List networkList = execution.getVariable("DELVAS_relatedNetworkIdList")
320 utils.log("DEBUG", "array networkList from execution: "+ networkList, isDebugEnabled)
322 if (networkList == null || networkList.size() < 1){
323 networkList = Arrays.asList(execution.getVariable("relatedNetworkIdListString"))
324 utils.log("DEBUG", "array from string networkList: "+ networkList, isDebugEnabled)
327 Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
329 String networkId = ""
330 if (networkList.size() > 0) {
331 networkId = (String) networkList.get(networksDeletedCount.intValue())
334 execution.setVariable("networkId", networkId)
335 utils.log("DEBUG", "need to delete networkId:" + networkId, isDebugEnabled)
337 utils.log("DEBUG", " ***** Completed prepareNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
338 } catch (Exception ex) {
339 // try error in method block
340 String exceptionMessage = q"Bpmn error encountered in DeleteViprAtmService flow. Unexpected Error from method prepareNetworkDelete() - " + ex.getMessage()
341 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
345 // *******************************
346 // Validate Network request Section
347 // *******************************
348 public void validateNetworkDelete (Execution execution) {
349 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
352 utils.log("DEBUG", " ***** Inside validateNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
354 Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
355 networksDeletedCount++
357 execution.setVariable("DELVAS_networksDeletedCount", networksDeletedCount)
359 utils.log("DEBUG", " ***** Completed validateNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
360 } catch (Exception ex) {
361 // try error in method block
362 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected Error from method validateNetworkDelete() - " + ex.getMessage()
363 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
368 // *****************************************
369 // Prepare Completion request Section
370 // *****************************************
371 public void postProcessResponse (Execution execution) {
372 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
373 utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteViprAtmService ***** ", isDebugEnabled)
376 String source = execution.getVariable("source")
377 String requestId = execution.getVariable("msoRequestId")
379 String msoCompletionRequest =
380 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
381 xmlns:ns="http://org.openecomp/mso/request/types/v1">
382 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
383 <request-id>${requestId}</request-id>
384 <action>DELETE</action>
385 <source>${source}</source>
387 <aetgt:status-message>vIPR ATM Service Instance has been deleted successfully.</aetgt:status-message>
388 <aetgt:mso-bpel-name>BPMN Service Instance macro action: DELETE</aetgt:mso-bpel-name>
389 </aetgt:MsoCompletionRequest>"""
392 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
394 utils.logAudit(xmlMsoCompletionRequest)
395 execution.setVariable("DELVAS_Success", true)
396 execution.setVariable("DELVAS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
397 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
398 } catch (BpmnError e) {
401 } catch (Exception ex) {
402 // try error in method block
403 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
404 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
408 public void prepareFalloutRequest(Execution execution){
409 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
410 utils.log("DEBUG", " *** STARTED DeleteViprAtmService prepareFalloutRequest Process *** ", isDebugEnabled)
413 WorkflowException wfex = execution.getVariable("WorkflowException")
414 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
415 String requestInfo = execution.getVariable("DELVAS_requestInfo")
416 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
418 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
420 execution.setVariable("DELVAS_falloutRequest", falloutRequest)
421 } catch (Exception ex) {
422 utils.log("DEBUG", "Error Occured in DeleteViprAtmService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
423 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteViprAtmService prepareFalloutRequest Process")
425 utils.log("DEBUG", "*** COMPLETED DeleteViprAtmService prepareFalloutRequest Process ***", isDebugEnabled)
429 public void sendSyncError (Execution execution) {
430 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
431 utils.log("DEBUG", " ***** Inside sendSyncError() of DeleteServiceInstanceInfra ***** ", isDebugEnabled)
434 String errorMessage = ""
435 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
436 WorkflowException wfe = execution.getVariable("WorkflowException")
437 errorMessage = wfe.getErrorMessage()
439 errorMessage = "Sending Sync Error."
442 String buildworkflowException =
443 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
444 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
445 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
446 </aetgt:WorkflowException>"""
448 utils.logAudit(buildworkflowException)
449 sendWorkflowResponse(execution, 500, buildworkflowException)
450 } catch (Exception ex) {
451 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
455 public void processJavaException(Execution execution){
456 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
457 execution.setVariable("prefix",Prefix)
459 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
460 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
461 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
462 execution.setVariable("DELVAS_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
463 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
465 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
468 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
469 execution.setVariable("DELVAS_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
470 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
472 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)