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>DeleteGenericMacroServiceNetworkVnf.bpmn</class> process.
62 public InitializeProcessVariables(Execution execution){
63 /* Initialize all the process variables in this block */
65 execution.setVariable("DeleteGenericMacroServiceNetworkVnfRequest", "")
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 DeleteGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)
87 // initialize flow variables
88 InitializeProcessVariables(execution)
90 // check for incoming json message/input
91 String DeleteGenericMacroServiceNetworkVnfRequest = execution.getVariable("bpmnRequest")
92 utils.logAudit(DeleteGenericMacroServiceNetworkVnfRequest)
93 execution.setVariable("DeleteGenericMacroServiceNetworkVnfRequest", DeleteGenericMacroServiceNetworkVnfRequest);
94 println 'DeleteGenericMacroServiceNetworkVnfRequest - ' + DeleteGenericMacroServiceNetworkVnfRequest
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(DeleteGenericMacroServiceNetworkVnfRequest, "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(DeleteGenericMacroServiceNetworkVnfRequest, "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(DeleteGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.suppressRollback")
125 execution.setVariable("disableRollback", suppressRollback)
126 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
128 String productFamilyId = jsonUtil.getJsonValue(DeleteGenericMacroServiceNetworkVnfRequest, "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(DeleteGenericMacroServiceNetworkVnfRequest, "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(DeleteGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
139 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
140 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
141 String tenantId = jsonUtil.getJsonValue(DeleteGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.tenantId")
142 execution.setVariable("tenantId", tenantId)
143 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
145 String sdncVersion = "1707"
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 DeleteGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)
164 } catch (BpmnError e) {
166 } catch (Exception ex){
167 String exceptionMessage = "Bpmn error encountered in DeleteGenericMacroServiceNetworkVnf 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 DeleteGenericMacroServiceNetworkVnf ***** ", 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 DeleteGenericMacroServiceNetworkVnf 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 DeleteGenericMacroServiceNetworkVnf ***** ", 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 DeleteGenericMacroServiceNetworkVnf 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 DeleteGenericMacroServiceNetworkVnfRequest = execution.getVariable("DeleteGenericMacroServiceNetworkVnfRequest");
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)
243 execution.setVariable("DELVAS_vnfsCount", 0)
244 utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
245 execution.setVariable("DELVAS_networksCount", 0)
246 utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
249 utils.log("DEBUG", " ***** Completed prepareServiceInstanceDelete() of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
250 } catch (Exception ex) {
251 sendSyncError(execution)
252 String exceptionMessage = "Bpmn error encountered in DeleteGenericMacroServiceNetworkVnf flow. prepareServiceInstanceDelete() - " + ex.getMessage()
253 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
254 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
259 // *******************************
261 // *******************************
262 public void prepareVnfAndModulesDelete (Execution execution) {
263 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
266 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
268 List vnfList = execution.getVariable("DELVAS_relatedVnfIdList")
269 Integer vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
270 String vnfModelInfoString = ""
272 if (vnfList.size() > 0 ) {
273 vnfId = vnfList.get(vnfsDeletedCount.intValue())
276 execution.setVariable("vnfId", vnfId)
277 utils.log("DEBUG", "need to delete vnfId:" + vnfId, isDebugEnabled)
279 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
280 } catch (Exception ex) {
281 // try error in method block
282 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstanceMacro flow. Unexpected Error from method prepareVnfAndModulesDelete() - " + ex.getMessage()
283 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
287 // *******************************
288 // Validate Vnf request Section -> increment count
289 // *******************************
290 public void validateVnfDelete (Execution execution) {
291 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
294 utils.log("DEBUG", " ***** Inside validateVnfDelete of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
296 String vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
299 execution.setVariable("DELVAS_vnfsDeletedCount", vnfsDeletedCount)
301 utils.log("DEBUG", " ***** Completed validateVnfDelete of DeleteGenericMacroServiceNetworkVnf ***** "+" vnf # "+vnfsDeletedCount, isDebugEnabled)
302 } catch (Exception ex) {
303 // try error in method block
304 String exceptionMessage = "Bpmn error encountered in DeleteGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateVnfDelete() - " + ex.getMessage()
305 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
309 // *******************************
310 // Generate Network request Section
311 // *******************************
312 public void prepareNetworkDelete (Execution execution) {
313 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
316 utils.log("DEBUG", " ***** Inside prepareNetworkDelete of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
318 List networkList = execution.getVariable("DELVAS_relatedNetworkIdList")
319 Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
321 String networkId = ""
322 if (networkList.size() > 0) {
323 networkId = networkList.get(networksDeletedCount.intValue())
326 execution.setVariable("networkId", networkId)
327 utils.log("DEBUG", "need to delete networkId:" + networkId, isDebugEnabled)
329 utils.log("DEBUG", " ***** Completed prepareNetworkDelete of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
330 } catch (Exception ex) {
331 // try error in method block
332 String exceptionMessage = q"Bpmn error encountered in DeleteGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareNetworkDelete() - " + ex.getMessage()
333 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
337 // *******************************
338 // Validate Network request Section
339 // *******************************
340 public void validateNetworkDelete (Execution execution) {
341 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
344 utils.log("DEBUG", " ***** Inside validateNetworkDelete of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
346 Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
347 networksDeletedCount++
349 execution.setVariable("DELVAS_networksDeletedCount", networksDeletedCount)
351 utils.log("DEBUG", " ***** Completed validateNetworkDelete of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
352 } catch (Exception ex) {
353 // try error in method block
354 String exceptionMessage = "Bpmn error encountered in DeleteGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkDelete() - " + ex.getMessage()
355 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
360 // *****************************************
361 // Prepare Completion request Section
362 // *****************************************
363 public void postProcessResponse (Execution execution) {
364 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
365 utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
368 String source = execution.getVariable("source")
369 String requestId = execution.getVariable("msoRequestId")
371 String msoCompletionRequest =
372 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
373 xmlns:ns="http://org.openecomp/mso/request/types/v1">
374 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
375 <request-id>${requestId}</request-id>
376 <action>DELETE</action>
377 <source>${source}</source>
379 <aetgt:status-message>vIPR ATM Service Instance has been deleted successfully.</aetgt:status-message>
380 <aetgt:mso-bpel-name>BPMN Service Instance macro action: DELETE</aetgt:mso-bpel-name>
381 </aetgt:MsoCompletionRequest>"""
384 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
386 utils.logAudit(xmlMsoCompletionRequest)
387 execution.setVariable("DELVAS_Success", true)
388 execution.setVariable("DELVAS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
389 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
390 } catch (BpmnError e) {
393 } catch (Exception ex) {
394 // try error in method block
395 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
396 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
400 public void prepareFalloutRequest(Execution execution){
401 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
402 utils.log("DEBUG", " *** STARTED DeleteGenericMacroServiceNetworkVnf prepareFalloutRequest Process *** ", isDebugEnabled)
405 WorkflowException wfex = execution.getVariable("WorkflowException")
406 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
407 String requestInfo = execution.getVariable("DELVAS_requestInfo")
408 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
410 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
412 execution.setVariable("DELVAS_falloutRequest", falloutRequest)
413 } catch (Exception ex) {
414 utils.log("DEBUG", "Error Occured in DeleteGenericMacroServiceNetworkVnf prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
415 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteGenericMacroServiceNetworkVnf prepareFalloutRequest Process")
417 utils.log("DEBUG", "*** COMPLETED DeleteGenericMacroServiceNetworkVnf prepareFalloutRequest Process ***", isDebugEnabled)
421 public void sendSyncError (Execution execution) {
422 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
423 utils.log("DEBUG", " ***** Inside sendSyncError() of DeleteServiceInstanceInfra ***** ", isDebugEnabled)
426 String errorMessage = ""
427 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
428 WorkflowException wfe = execution.getVariable("WorkflowException")
429 errorMessage = wfe.getErrorMessage()
431 errorMessage = "Sending Sync Error."
434 String buildworkflowException =
435 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
436 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
437 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
438 </aetgt:WorkflowException>"""
440 utils.logAudit(buildworkflowException)
441 sendWorkflowResponse(execution, 500, buildworkflowException)
442 } catch (Exception ex) {
443 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
447 public void processJavaException(Execution execution){
448 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
449 execution.setVariable("prefix",Prefix)
451 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
452 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
453 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
454 execution.setVariable("DELVAS_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
455 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
457 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
460 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
461 execution.setVariable("DELVAS_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
462 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
464 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)