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.vcpe.scripts
\r
22 import groovy.xml.XmlUtil
\r
23 import groovy.json.*
\r
25 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
\r
26 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
27 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;
\r
28 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
\r
29 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
30 import org.openecomp.mso.bpmn.core.WorkflowException
\r
31 import org.openecomp.mso.rest.APIResponse
\r
32 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
34 import java.util.UUID;
\r
36 import org.camunda.bpm.engine.delegate.BpmnError
\r
37 import org.camunda.bpm.engine.runtime.Execution
\r
38 import org.json.JSONObject;
\r
39 import org.json.JSONArray;
\r
40 import org.apache.commons.lang3.*
\r
41 import org.apache.commons.codec.binary.Base64;
\r
42 import org.springframework.web.util.UriUtils;
\r
45 * This groovy class supports the <class>DeleteVcpeResCustService.bpmn</class> process.
\r
50 public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor {
\r
52 private static final String DebugFlag = "isDebugLogEnabled"
\r
54 String Prefix = "DVRCS_"
\r
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
56 JsonUtils jsonUtil = new JsonUtils()
\r
57 VidUtils vidUtils = new VidUtils()
\r
58 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
\r
59 NetworkUtils networkUtils = new NetworkUtils()
\r
62 * This method is executed during the preProcessRequest task of the <class>DeleteVcpeResCustService.bpmn</class> process.
\r
65 public InitializeProcessVariables(Execution execution){
\r
66 /* Initialize all the process variables in this block */
\r
68 execution.setVariable("DeleteVcpeResCustServiceRequest", "")
\r
69 execution.setVariable("msoRequestId", "")
\r
70 execution.setVariable(Prefix+"vnfsDeletedCount", 0)
\r
71 execution.setVariable(Prefix+"vnfsCount", 0)
\r
74 // **************************************************
\r
75 // Pre or Prepare Request Section
\r
76 // **************************************************
\r
78 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
81 public void preProcessRequest (Execution execution) {
\r
82 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
83 execution.setVariable("prefix",Prefix)
\r
85 utils.log("DEBUG", " ***** Inside preProcessRequest DeleteVcpeResCustService Request ***** ", isDebugEnabled)
\r
88 // initialize flow variables
\r
89 InitializeProcessVariables(execution)
\r
91 // check for incoming json message/input
\r
92 String DeleteVcpeResCustServiceRequest = execution.getVariable("bpmnRequest")
\r
93 utils.logAudit(DeleteVcpeResCustServiceRequest)
\r
94 execution.setVariable("DeleteVcpeResCustServiceRequest", DeleteVcpeResCustServiceRequest);
\r
95 println 'DeleteVcpeResCustServiceRequest - ' + DeleteVcpeResCustServiceRequest
\r
97 // extract requestId
\r
98 String requestId = execution.getVariable("mso-request-id")
\r
99 execution.setVariable("msoRequestId", requestId)
\r
101 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
102 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
\r
103 String dataErrorMessage = " Element 'serviceInstanceId' is missing. "
\r
104 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
107 String requestAction = execution.getVariable("requestAction")
\r
108 execution.setVariable("requestAction", requestAction)
\r
110 String source = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.source")
\r
111 if ((source == null) || (source.isEmpty())) {
\r
114 execution.setVariable("source", source)
\r
116 // extract globalSubscriberId
\r
117 String globalSubscriberId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "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(DeleteVcpeResCustServiceRequest, "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(DeleteVcpeResCustServiceRequest, "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(DeleteVcpeResCustServiceRequest, "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 cloudConfiguration = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.cloudConfiguration")
\r
139 execution.setVariable("cloudConfiguration", cloudConfiguration)
\r
140 utils.log("DEBUG","cloudConfiguration: "+ cloudConfiguration, isDebugEnabled)
\r
141 String lcpCloudRegionId = jsonUtil.getJsonValue(cloudConfiguration, "lcpCloudRegionId")
\r
142 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
143 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
144 String tenantId = jsonUtil.getJsonValue(cloudConfiguration, "tenantId")
\r
145 execution.setVariable("tenantId", tenantId)
\r
146 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
148 String sdncVersion = "1702"
\r
149 execution.setVariable("sdncVersion", sdncVersion)
\r
150 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
152 //For Completion Handler & Fallout Handler
\r
153 String requestInfo =
\r
154 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
155 <request-id>${requestId}</request-id>
\r
156 <action>DELETE</action>
\r
157 <source>${source}</source>
\r
160 execution.setVariable(Prefix+"requestInfo", requestInfo)
\r
162 //Setting for Generic Sub Flows
\r
163 execution.setVariable("GENGS_type", "service-instance")
\r
165 utils.log("DEBUG", " ***** Completed preProcessRequest DeleteVcpeResCustServiceRequest Request ***** ", isDebugEnabled)
\r
167 } catch (BpmnError e) {
\r
169 } catch (Exception ex){
\r
170 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
\r
171 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
175 public void sendSyncResponse(Execution execution) {
\r
176 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
178 utils.log("DEBUG", " ***** Inside sendSyncResponse of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
181 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
182 String requestId = execution.getVariable("mso-request-id")
\r
184 // RESTResponse (for API Handler (APIH) Reply Task)
\r
185 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
187 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
188 sendWorkflowResponse(execution, 202, syncResponse)
\r
189 } catch (Exception ex) {
\r
190 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
191 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
195 public void prepareServiceDelete(Execution execution) {
\r
196 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
197 utils.log("DEBUG", " ***** Inside prepareServiceInstanceDelete() of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
201 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
203 // confirm if ServiceInstance was found
\r
204 if ( !execution.getVariable("GENGS_FoundIndicator") )
\r
206 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId
\r
207 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
210 // get variable within incoming json
\r
211 String DeleteVcpeResCustServiceRequest = execution.getVariable("DeleteVcpeResCustServiceRequest");
\r
213 // get SI extracted by GenericGetService
\r
214 String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");
\r
216 utils.log("DEBUG", "serviceInstanceAaiRecord: "+serviceInstanceAaiRecord, isDebugEnabled)
\r
218 // determine if AR needs to be deleted
\r
219 boolean DVRCS_TunnelXConn = false
\r
220 boolean DVRCS_BRG = false
\r
221 String TXC_allottedResourceId
\r
222 String BRG_allottedResourceId
\r
223 XmlParser xmlParser = new XmlParser()
\r
224 def groovy.util.Node siNode = xmlParser.parseText(serviceInstanceAaiRecord)
\r
225 def groovy.util.Node arList = utils.getChildNode(siNode, 'allotted-resources')
\r
226 if (arList != null) {
\r
227 def groovy.util.NodeList ars = utils.getIdenticalChildren(arList, 'allotted-resource')
\r
228 for (groovy.util.Node ar in ars) {
\r
229 def type = utils.getChildNodeText(ar, 'type')
\r
230 if ("TunnelXConn".equals(type)) {
\r
231 utils.log("DEBUG","TunnelXConn AR found", isDebugEnabled)
\r
232 def id = utils.getChildNodeText(ar, 'id')
\r
234 DVRCS_TunnelXConn = true
\r
235 TXC_allottedResourceId = id
\r
237 } else if ("BRG".equals(type)) {
\r
238 utils.log("DEBUG","FW AR found", isDebugEnabled)
\r
239 def id = utils.getChildNodeText(ar, 'id')
\r
242 BRG_allottedResourceId = id
\r
247 execution.setVariable(Prefix+"TunnelXConn", DVRCS_TunnelXConn)
\r
248 utils.log("DEBUG", Prefix+"TunnelXConn : " + DVRCS_TunnelXConn, isDebugEnabled)
\r
249 execution.setVariable("TXC_allottedResourceId", TXC_allottedResourceId)
\r
250 utils.log("DEBUG", "TXC_allottedResourceId : " + TXC_allottedResourceId, isDebugEnabled)
\r
252 execution.setVariable(Prefix+"BRG", DVRCS_BRG)
\r
253 utils.log("DEBUG", Prefix+"BRG : " + DVRCS_BRG, isDebugEnabled)
\r
254 execution.setVariable("BRG_allottedResourceId", BRG_allottedResourceId)
\r
255 utils.log("DEBUG", "BRG_allottedResourceId : " + BRG_allottedResourceId, isDebugEnabled)
\r
257 String relationship = ""
\r
259 relationship = networkUtils.getFirstNodeXml(serviceInstanceAaiRecord, "relationship-list")
\r
260 } catch (Exception ex) {
\r
261 //no relationships found
\r
263 utils.log("DEBUG", " relationship string - " + relationship, isDebugEnabled)
\r
267 if (relationship != null && relationship.length() > 0){
\r
268 relationship = relationship.trim().replace("tag0:","").replace(":tag0","")
\r
270 // Check if Network TableREf is present, then build a List of network policy
\r
271 List relatedVnfIdList = networkUtils.getRelatedVnfIdList(relationship)
\r
272 vnfsCount = relatedVnfIdList.size()
\r
273 execution.setVariable(Prefix+"vnfsCount", vnfsCount)
\r
274 utils.log("DEBUG", " "+Prefix+"vnfsCount : " + vnfsCount, isDebugEnabled)
\r
275 execution.setVariable(Prefix+"relatedVnfIdList", relatedVnfIdList)
\r
277 execution.setVariable(Prefix+"vnfsCount", 0)
\r
278 utils.log("DEBUG", " "+Prefix+"vnfsCount : " + vnfsCount, isDebugEnabled)
\r
281 utils.log("DEBUG", " ***** Completed prepareServiceInstanceDelete() of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
282 } catch (BpmnError e){
\r
284 } catch (Exception ex) {
\r
285 sendSyncError(execution)
\r
286 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. prepareServiceInstanceDelete() - " + ex.getMessage()
\r
287 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
288 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
293 // *******************************
\r
295 // *******************************
\r
296 public void prepareVnfAndModulesDelete (Execution execution) {
\r
297 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
298 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesDelete of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
301 List vnfList = execution.getVariable(Prefix+"relatedVnfIdList")
\r
302 int vnfsDeletedCount = execution.getVariable(Prefix+"vnfsDeletedCount")
\r
303 String vnfModelInfoString = ""
\r
305 if (vnfList.size() > 0 ) {
\r
306 vnfId = vnfList.get(vnfsDeletedCount.intValue())
\r
309 execution.setVariable("vnfId", vnfId)
\r
310 utils.log("DEBUG", "need to delete vnfId:" + vnfId, isDebugEnabled)
\r
312 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesDelete of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
313 } catch (Exception ex) {
\r
314 // try error in method block
\r
315 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesDelete() - " + ex.getMessage()
\r
316 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
320 // *******************************
\r
321 // Validate Vnf request Section -> increment count
\r
322 // *******************************
\r
323 public void validateVnfDelete (Execution execution) {
\r
324 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
325 utils.log("DEBUG", " ***** Inside validateVnfDelete of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
328 int vnfsDeletedCount = execution.getVariable(Prefix+"vnfsDeletedCount")
\r
331 execution.setVariable(Prefix+"vnfsDeletedCount", vnfsDeletedCount)
\r
333 utils.log("DEBUG", " ***** Completed validateVnfDelete of DeleteVcpeResCustService ***** "+" vnf # "+vnfsDeletedCount, isDebugEnabled)
\r
334 } catch (Exception ex) {
\r
335 // try error in method block
\r
336 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected Error from method validateVnfDelete() - " + ex.getMessage()
\r
337 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
342 // *****************************************
\r
343 // Prepare Completion request Section
\r
344 // *****************************************
\r
345 public void postProcessResponse (Execution execution) {
\r
346 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
347 utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
350 String source = execution.getVariable("source")
\r
351 String requestId = execution.getVariable("msoRequestId")
\r
353 String msoCompletionRequest =
\r
354 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
355 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
356 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
357 <request-id>${requestId}</request-id>
\r
358 <action>DELETE</action>
\r
359 <source>${source}</source>
\r
361 <aetgt:status-message>vCPE Res Cust Service Instance has been deleted successfully.</aetgt:status-message>
\r
362 <aetgt:mso-bpel-name>BPMN Service Instance macro action: DELETE</aetgt:mso-bpel-name>
\r
363 </aetgt:MsoCompletionRequest>"""
\r
366 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
368 utils.logAudit(xmlMsoCompletionRequest)
\r
369 execution.setVariable(Prefix+"Success", true)
\r
370 execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)
\r
371 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
372 } catch (BpmnError e) {
\r
375 } catch (Exception ex) {
\r
376 // try error in method block
\r
377 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
\r
378 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
382 public void prepareFalloutRequest(Execution execution){
\r
383 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
384 utils.log("DEBUG", " *** STARTED DeleteVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
\r
387 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
388 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
389 String requestInfo = execution.getVariable(Prefix+"requestInfo")
\r
390 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
\r
392 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
394 execution.setVariable(Prefix+"falloutRequest", falloutRequest)
\r
395 } catch (Exception ex) {
\r
396 utils.log("DEBUG", "Error Occured in DeleteVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
\r
397 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVcpeResCustService prepareFalloutRequest Process")
\r
399 utils.log("DEBUG", "*** COMPLETED DeleteVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
\r
403 public void sendSyncError (Execution execution) {
\r
404 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
405 utils.log("DEBUG", " ***** Inside sendSyncError() of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
408 String errorMessage = ""
\r
409 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
410 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
411 errorMessage = wfe.getErrorMessage()
\r
413 errorMessage = "Sending Sync Error."
\r
416 String buildworkflowException =
\r
417 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
418 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
419 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
420 </aetgt:WorkflowException>"""
\r
422 utils.logAudit(buildworkflowException)
\r
423 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
424 } catch (Exception ex) {
\r
425 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
429 public void processJavaException(Execution execution){
\r
430 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
431 execution.setVariable("prefix",Prefix)
\r
433 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
\r
434 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
435 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
436 execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
\r
437 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
438 }catch(BpmnError b){
\r
439 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
441 }catch(Exception e){
\r
442 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
443 execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
\r
444 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
\r
446 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
\r