2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
22 import groovy.xml.XmlUtil
\r
23 import groovy.json.*
\r
25 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
27 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
\r
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
29 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
\r
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
31 import org.openecomp.mso.bpmn.core.WorkflowException
\r
32 import org.openecomp.mso.rest.APIResponse;
\r
35 import java.util.UUID;
\r
37 import org.camunda.bpm.engine.delegate.BpmnError
\r
38 import org.camunda.bpm.engine.runtime.Execution
\r
39 import org.json.JSONObject;
\r
40 import org.json.JSONArray;
\r
41 import org.apache.commons.lang3.*
\r
42 import org.apache.commons.codec.binary.Base64;
\r
43 import org.springframework.web.util.UriUtils;
\r
46 * This groovy class supports the <class>DeleteViprAtmService.bpmn</class> process.
\r
49 public class DeleteGenericMacroServiceNetworkVnf extends AbstractServiceTaskProcessor {
\r
51 String Prefix="DELVAS_"
\r
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
53 JsonUtils jsonUtil = new JsonUtils()
\r
54 VidUtils vidUtils = new VidUtils()
\r
55 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
\r
56 NetworkUtils networkUtils = new NetworkUtils()
\r
59 * This method is executed during the preProcessRequest task of the <class>DeleteViprAtmService.bpmn</class> process.
\r
62 public InitializeProcessVariables(Execution execution){
\r
63 /* Initialize all the process variables in this block */
\r
65 execution.setVariable("deleteViprAtmServiceRequest", "")
\r
66 execution.setVariable("msoRequestId", "")
\r
67 execution.setVariable("DELVAS_vnfsDeletedCount", 0)
\r
68 execution.setVariable("DELVAS_vnfsCount", 0)
\r
69 execution.setVariable("DELVAS_networksCount", 0)
\r
70 execution.setVariable("DELVAS_networksDeletedCount", 0)
\r
73 // **************************************************
\r
74 // Pre or Prepare Request Section
\r
75 // **************************************************
\r
77 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
80 public void preProcessRequest (Execution execution) {
\r
81 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
82 execution.setVariable("prefix",Prefix)
\r
84 utils.log("DEBUG", " ***** Inside preProcessRequest DeleteViprAtmService Request ***** ", isDebugEnabled)
\r
87 // initialize flow variables
\r
88 InitializeProcessVariables(execution)
\r
90 // check for incoming json message/input
\r
91 String deleteViprAtmServiceRequest = execution.getVariable("bpmnRequest")
\r
92 utils.logAudit(deleteViprAtmServiceRequest)
\r
93 execution.setVariable("deleteViprAtmServiceRequest", deleteViprAtmServiceRequest);
\r
94 println 'deleteViprAtmServiceRequest - ' + deleteViprAtmServiceRequest
\r
96 // extract requestId
\r
97 String requestId = execution.getVariable("mso-request-id")
\r
98 execution.setVariable("msoRequestId", requestId)
\r
100 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
101 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
\r
102 String dataErrorMessage = " Element 'serviceInstanceId' is missing. "
\r
103 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
106 String requestAction = execution.getVariable("requestAction")
\r
107 execution.setVariable("requestAction", requestAction)
\r
109 String source = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestInfo.source")
\r
110 if ((source == null) || (source.isEmpty())) {
\r
111 execution.setVariable("source", "VID")
\r
113 execution.setVariable("source", source)
\r
116 // extract globalSubscriberId
\r
117 String globalSubscriberId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
119 // global-customer-id is optional on Delete
\r
121 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
122 execution.setVariable("globalCustomerId", globalSubscriberId)
\r
124 String suppressRollback = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestInfo.suppressRollback")
\r
125 execution.setVariable("disableRollback", suppressRollback)
\r
126 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
\r
128 String productFamilyId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestInfo.productFamilyId")
\r
129 execution.setVariable("productFamilyId", productFamilyId)
\r
130 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
\r
132 // extract subscriptionServiceType
\r
133 String subscriptionServiceType = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
134 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
135 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
\r
137 // extract cloud configuration
\r
138 String lcpCloudRegionId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
\r
139 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
140 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
141 String tenantId = jsonUtil.getJsonValue(deleteViprAtmServiceRequest, "requestDetails.cloudConfiguration.tenantId")
\r
142 execution.setVariable("tenantId", tenantId)
\r
143 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
145 String sdncVersion = "1702"
\r
146 execution.setVariable("sdncVersion", sdncVersion)
\r
147 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
149 //For Completion Handler & Fallout Handler
\r
150 String requestInfo =
\r
151 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
152 <request-id>${requestId}</request-id>
\r
153 <action>DELETE</action>
\r
154 <source>${source}</source>
\r
157 execution.setVariable("DELVAS_requestInfo", requestInfo)
\r
159 //Setting for Generic Sub Flows
\r
160 execution.setVariable("GENGS_type", "service-instance")
\r
162 utils.log("DEBUG", " ***** Completed preProcessRequest DeleteViprAtmService Request ***** ", isDebugEnabled)
\r
164 } catch (BpmnError e) {
\r
166 } catch (Exception ex){
\r
167 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
\r
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
172 public void sendSyncResponse (Execution execution) {
\r
173 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
175 utils.log("DEBUG", " ***** Inside sendSyncResponse of DeleteViprAtmService ***** ", isDebugEnabled)
\r
178 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
179 String requestId = execution.getVariable("mso-request-id")
\r
181 // RESTResponse (for API Handler (APIH) Reply Task)
\r
182 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
184 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
185 sendWorkflowResponse(execution, 202, syncResponse)
\r
186 } catch (Exception ex) {
\r
187 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
\r
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
192 public void prepareServiceInstanceDelete (Execution execution) {
\r
193 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
194 utils.log("DEBUG", " ***** Inside prepareServiceInstanceDelete() of DeleteViprAtmService ***** ", isDebugEnabled)
\r
198 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
200 // confirm if ServiceInstance was found
\r
201 if ( !execution.getVariable("GENGS_FoundIndicator") )
\r
203 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Service Instance was not found in AAI by id: " + serviceInstanceId
\r
204 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
207 // get variable within incoming json
\r
208 String deleteViprAtmServiceRequest = execution.getVariable("deleteViprAtmServiceRequest");
\r
210 // get SI extracted by GenericGetService
\r
211 String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");
\r
213 utils.log("DEBUG", "serviceInstanceAaiRecord: "+serviceInstanceAaiRecord, isDebugEnabled)
\r
215 String relationship = ""
\r
217 relationship = networkUtils.getFirstNodeXml(serviceInstanceAaiRecord, "relationship-list")
\r
218 } catch (Exception ex) {
\r
219 //no relationships found
\r
221 utils.log("DEBUG", " relationship string - " + relationship, isDebugEnabled)
\r
224 int networksCount = 0
\r
226 if (relationship != null && relationship.length() > 0){
\r
227 relationship = relationship.trim().replace("tag0:","").replace(":tag0","")
\r
229 // Check if Network TableREf is present, then build a List of network policy
\r
230 List relatedVnfIdList = networkUtils.getRelatedVnfIdList(relationship)
\r
231 vnfsCount = relatedVnfIdList.size()
\r
232 execution.setVariable("DELVAS_vnfsCount", vnfsCount)
\r
233 utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
\r
234 execution.setVariable("DELVAS_relatedVnfIdList", relatedVnfIdList)
\r
236 // Check if Network TableREf is present, then build a List of network policy
\r
237 List relatedNetworkIdList = networkUtils.getRelatedNetworkIdList(relationship)
\r
238 networksCount = relatedNetworkIdList.size()
\r
239 execution.setVariable("DELVAS_networksCount", networksCount)
\r
240 utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
\r
241 execution.setVariable("DELVAS_relatedNetworkIdList", relatedNetworkIdList)
\r
243 execution.setVariable("DELVAS_vnfsCount", 0)
\r
244 utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
\r
245 execution.setVariable("DELVAS_networksCount", 0)
\r
246 utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
\r
249 utils.log("DEBUG", " ***** Completed prepareServiceInstanceDelete() of DeleteViprAtmService ***** ", isDebugEnabled)
\r
250 } catch (Exception ex) {
\r
251 sendSyncError(execution)
\r
252 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. prepareServiceInstanceDelete() - " + ex.getMessage()
\r
253 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
254 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
259 // *******************************
\r
261 // *******************************
\r
262 public void prepareVnfAndModulesDelete (Execution execution) {
\r
263 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
266 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
\r
268 List vnfList = execution.getVariable("DELVAS_relatedVnfIdList")
\r
269 Integer vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
\r
270 String vnfModelInfoString = ""
\r
272 if (vnfList.size() > 0 ) {
\r
273 vnfId = vnfList.get(vnfsDeletedCount.intValue())
\r
276 execution.setVariable("vnfId", vnfId)
\r
277 utils.log("DEBUG", "need to delete vnfId:" + vnfId, isDebugEnabled)
\r
279 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
\r
280 } catch (Exception ex) {
\r
281 // try error in method block
\r
282 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstanceMacro flow. Unexpected Error from method prepareVnfAndModulesDelete() - " + ex.getMessage()
\r
283 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
287 // *******************************
\r
288 // Validate Vnf request Section -> increment count
\r
289 // *******************************
\r
290 public void validateVnfDelete (Execution execution) {
\r
291 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
294 utils.log("DEBUG", " ***** Inside validateVnfDelete of DeleteViprAtmService ***** ", isDebugEnabled)
\r
296 String vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
\r
299 execution.setVariable("DELVAS_vnfsDeletedCount", vnfsDeletedCount)
\r
301 utils.log("DEBUG", " ***** Completed validateVnfDelete of DeleteViprAtmService ***** "+" vnf # "+vnfsDeletedCount, isDebugEnabled)
\r
302 } catch (Exception ex) {
\r
303 // try error in method block
\r
304 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected Error from method validateVnfDelete() - " + ex.getMessage()
\r
305 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
309 // *******************************
\r
310 // Generate Network request Section
\r
311 // *******************************
\r
312 public void prepareNetworkDelete (Execution execution) {
\r
313 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
316 utils.log("DEBUG", " ***** Inside prepareNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
\r
318 List networkList = execution.getVariable("DELVAS_relatedNetworkIdList")
\r
319 Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
\r
321 String networkId = ""
\r
322 if (networkList.size() > 0) {
\r
323 networkId = networkList.get(networksDeletedCount.intValue())
\r
326 execution.setVariable("networkId", networkId)
\r
327 utils.log("DEBUG", "need to delete networkId:" + networkId, isDebugEnabled)
\r
329 utils.log("DEBUG", " ***** Completed prepareNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
\r
330 } catch (Exception ex) {
\r
331 // try error in method block
\r
332 String exceptionMessage = q"Bpmn error encountered in DeleteViprAtmService flow. Unexpected Error from method prepareNetworkDelete() - " + ex.getMessage()
\r
333 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
337 // *******************************
\r
338 // Validate Network request Section
\r
339 // *******************************
\r
340 public void validateNetworkDelete (Execution execution) {
\r
341 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
344 utils.log("DEBUG", " ***** Inside validateNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
\r
346 Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
\r
347 networksDeletedCount++
\r
349 execution.setVariable("DELVAS_networksDeletedCount", networksDeletedCount)
\r
351 utils.log("DEBUG", " ***** Completed validateNetworkDelete of DeleteViprAtmService ***** ", isDebugEnabled)
\r
352 } catch (Exception ex) {
\r
353 // try error in method block
\r
354 String exceptionMessage = "Bpmn error encountered in DeleteViprAtmService flow. Unexpected Error from method validateNetworkDelete() - " + ex.getMessage()
\r
355 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
360 // *****************************************
\r
361 // Prepare Completion request Section
\r
362 // *****************************************
\r
363 public void postProcessResponse (Execution execution) {
\r
364 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
365 utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteViprAtmService ***** ", isDebugEnabled)
\r
368 String source = execution.getVariable("source")
\r
369 String requestId = execution.getVariable("msoRequestId")
\r
371 String msoCompletionRequest =
\r
372 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
373 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
374 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
375 <request-id>${requestId}</request-id>
\r
376 <action>DELETE</action>
\r
377 <source>${source}</source>
\r
379 <aetgt:status-message>vIPR ATM Service Instance has been deleted successfully.</aetgt:status-message>
\r
380 <aetgt:mso-bpel-name>BPMN Service Instance macro action: DELETE</aetgt:mso-bpel-name>
\r
381 </aetgt:MsoCompletionRequest>"""
\r
384 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
386 utils.logAudit(xmlMsoCompletionRequest)
\r
387 execution.setVariable("DELVAS_Success", true)
\r
388 execution.setVariable("DELVAS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
\r
389 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
390 } catch (BpmnError e) {
\r
393 } catch (Exception ex) {
\r
394 // try error in method block
\r
395 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
\r
396 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
400 public void prepareFalloutRequest(Execution execution){
\r
401 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
402 utils.log("DEBUG", " *** STARTED DeleteViprAtmService prepareFalloutRequest Process *** ", isDebugEnabled)
\r
405 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
406 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
407 String requestInfo = execution.getVariable("DELVAS_requestInfo")
\r
408 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
\r
410 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
412 execution.setVariable("DELVAS_falloutRequest", falloutRequest)
\r
413 } catch (Exception ex) {
\r
414 utils.log("DEBUG", "Error Occured in DeleteViprAtmService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
\r
415 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteViprAtmService prepareFalloutRequest Process")
\r
417 utils.log("DEBUG", "*** COMPLETED DeleteViprAtmService prepareFalloutRequest Process ***", isDebugEnabled)
\r
421 public void sendSyncError (Execution execution) {
\r
422 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
423 utils.log("DEBUG", " ***** Inside sendSyncError() of DeleteServiceInstanceInfra ***** ", isDebugEnabled)
\r
426 String errorMessage = ""
\r
427 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
428 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
429 errorMessage = wfe.getErrorMessage()
\r
431 errorMessage = "Sending Sync Error."
\r
434 String buildworkflowException =
\r
435 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
436 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
437 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
438 </aetgt:WorkflowException>"""
\r
440 utils.logAudit(buildworkflowException)
\r
441 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
442 } catch (Exception ex) {
\r
443 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
447 public void processJavaException(Execution execution){
\r
448 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
449 execution.setVariable("prefix",Prefix)
\r
451 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
\r
452 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
453 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
454 execution.setVariable("DELVAS_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
\r
455 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
456 }catch(BpmnError b){
\r
457 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
459 }catch(Exception e){
\r
460 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
461 execution.setVariable("DELVAS_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
\r
462 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
\r
464 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
\r