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
33 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\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
44 import static org.apache.commons.lang3.StringUtils.*
\r
47 * This groovy class supports the <class>DeleteVcpeResCustService.bpmn</class> process.
\r
52 public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor {
\r
54 private static final String DebugFlag = "isDebugLogEnabled"
\r
56 String Prefix = "DVRCS_"
\r
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
58 JsonUtils jsonUtil = new JsonUtils()
\r
59 VidUtils vidUtils = new VidUtils()
\r
60 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
\r
61 NetworkUtils networkUtils = new NetworkUtils()
\r
64 * This method is executed during the preProcessRequest task of the <class>DeleteVcpeResCustService.bpmn</class> process.
\r
67 public InitializeProcessVariables(Execution execution){
\r
68 /* Initialize all the process variables in this block */
\r
70 execution.setVariable("DeleteVcpeResCustServiceRequest", "")
\r
71 execution.setVariable("msoRequestId", "")
\r
72 execution.setVariable(Prefix+"vnfsDeletedCount", 0)
\r
73 execution.setVariable(Prefix+"vnfsCount", 0)
\r
76 // **************************************************
\r
77 // Pre or Prepare Request Section
\r
78 // **************************************************
\r
80 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
83 public void preProcessRequest (Execution execution) {
\r
84 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
85 execution.setVariable("prefix",Prefix)
\r
87 utils.log("DEBUG", " ***** Inside preProcessRequest DeleteVcpeResCustService Request ***** ", isDebugEnabled)
\r
90 // initialize flow variables
\r
91 InitializeProcessVariables(execution)
\r
93 // check for incoming json message/input
\r
94 String DeleteVcpeResCustServiceRequest = execution.getVariable("bpmnRequest")
\r
95 utils.logAudit(DeleteVcpeResCustServiceRequest)
\r
96 execution.setVariable("DeleteVcpeResCustServiceRequest", DeleteVcpeResCustServiceRequest);
\r
97 println 'DeleteVcpeResCustServiceRequest - ' + DeleteVcpeResCustServiceRequest
\r
99 // extract requestId
\r
100 String requestId = execution.getVariable("mso-request-id")
\r
101 execution.setVariable("msoRequestId", requestId)
\r
103 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
104 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
\r
105 String dataErrorMessage = " Element 'serviceInstanceId' is missing. "
\r
106 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
109 String requestAction = execution.getVariable("requestAction")
\r
110 execution.setVariable("requestAction", requestAction)
\r
112 String source = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.source")
\r
113 if ((source == null) || (source.isEmpty())) {
\r
116 execution.setVariable("source", source)
\r
118 // extract globalSubscriberId
\r
119 String globalSubscriberId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
121 // global-customer-id is optional on Delete
\r
123 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
124 execution.setVariable("globalCustomerId", globalSubscriberId)
\r
126 String suppressRollback = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.suppressRollback")
\r
127 execution.setVariable("disableRollback", suppressRollback)
\r
128 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
\r
130 String productFamilyId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.productFamilyId")
\r
131 execution.setVariable("productFamilyId", productFamilyId)
\r
132 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
\r
134 // extract subscriptionServiceType
\r
135 String subscriptionServiceType = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
136 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
137 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
\r
139 // extract cloud configuration
\r
140 String cloudConfiguration = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.cloudConfiguration")
\r
141 execution.setVariable("cloudConfiguration", cloudConfiguration)
\r
142 utils.log("DEBUG","cloudConfiguration: "+ cloudConfiguration, isDebugEnabled)
\r
143 String lcpCloudRegionId = jsonUtil.getJsonValue(cloudConfiguration, "lcpCloudRegionId")
\r
144 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
145 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
146 String tenantId = jsonUtil.getJsonValue(cloudConfiguration, "tenantId")
\r
147 execution.setVariable("tenantId", tenantId)
\r
148 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
150 String sdncVersion = "1707"
\r
151 execution.setVariable("sdncVersion", sdncVersion)
\r
152 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
154 //For Completion Handler & Fallout Handler
\r
155 String requestInfo =
\r
156 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
157 <request-id>${requestId}</request-id>
\r
158 <action>DELETE</action>
\r
159 <source>${source}</source>
\r
162 execution.setVariable(Prefix+"requestInfo", requestInfo)
\r
164 //Setting for Generic Sub Flows
\r
165 execution.setVariable("GENGS_type", "service-instance")
\r
167 utils.log("DEBUG", " ***** Completed preProcessRequest DeleteVcpeResCustServiceRequest Request ***** ", isDebugEnabled)
\r
169 } catch (BpmnError e) {
\r
171 } catch (Exception ex){
\r
172 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
\r
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
177 public void sendSyncResponse(Execution execution) {
\r
178 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
180 utils.log("DEBUG", " ***** Inside sendSyncResponse of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
183 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
184 String requestId = execution.getVariable("mso-request-id")
\r
186 // RESTResponse (for API Handler (APIH) Reply Task)
\r
187 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
189 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
190 sendWorkflowResponse(execution, 202, syncResponse)
\r
191 } catch (Exception ex) {
\r
192 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
193 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
197 public void prepareServiceDelete(Execution execution) {
\r
198 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
199 utils.log("DEBUG", " ***** Inside prepareServiceDelete() of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
203 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
205 // confirm if ServiceInstance was found
\r
206 if ( !execution.getVariable("GENGS_FoundIndicator") )
\r
208 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId
\r
209 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
212 // get variable within incoming json
\r
213 String DeleteVcpeResCustServiceRequest = execution.getVariable("DeleteVcpeResCustServiceRequest");
\r
215 // get SI extracted by GenericGetService
\r
216 String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");
\r
218 utils.log("DEBUG", "serviceInstanceAaiRecord: "+serviceInstanceAaiRecord, isDebugEnabled)
\r
219 serviceInstanceAaiRecord = utils.removeXmlNamespaces(serviceInstanceAaiRecord)
\r
221 def (TXC_found, TXC_id) = new Tuple(false, null)
\r
222 def (BRG_found, BRG_id) = new Tuple(false, null)
\r
223 List relatedVnfIdList = []
\r
225 for(Node rel: utils.getMultNodeObjects(serviceInstanceAaiRecord, "relationship")) {
\r
226 def relto = utils.getChildNodeText(rel, "related-to")
\r
227 def relink = utils.getChildNodeText(rel, "related-link")
\r
228 utils.log("DEBUG", "check: "+relto+" link: "+relink, isDebugEnabled)
\r
230 if(isBlank(relto) || isBlank(relink)) {
\r
232 } else if(relto == "generic-vnf") {
\r
233 def id = relink.substring(relink.indexOf("/generic-vnf/")+13)
\r
234 if(id.endsWith("/")) {
\r
235 id = id.substring(0, id.length()-1)
\r
238 relatedVnfIdList.add(id)
\r
240 } else if(relto == "allotted-resource") {
\r
241 def (type, id) = getAaiAr(execution, relink)
\r
243 if(isBlank(type) || isBlank(id)) {
\r
245 } else if(type == "TunnelXConn") {
\r
246 utils.log("DEBUG","TunnelXConn AR found", isDebugEnabled)
\r
250 } else if(type == "BRG") {
\r
251 utils.log("DEBUG","BRG AR found", isDebugEnabled)
\r
258 execution.setVariable(Prefix+"TunnelXConn", TXC_found)
\r
259 execution.setVariable("TXC_allottedResourceId", TXC_id)
\r
260 utils.log("DEBUG", "TXC_allottedResourceId: " + TXC_id, isDebugEnabled)
\r
262 execution.setVariable(Prefix+"BRG", BRG_found)
\r
263 execution.setVariable("BRG_allottedResourceId", BRG_id)
\r
264 utils.log("DEBUG", "BRG_allottedResourceId: " + BRG_id, isDebugEnabled)
\r
266 int vnfsCount = relatedVnfIdList.size()
\r
267 execution.setVariable(Prefix+"vnfsCount", vnfsCount)
\r
268 utils.log("DEBUG", " "+Prefix+"vnfsCount : " + vnfsCount, isDebugEnabled)
\r
269 if(vnfsCount > 0) {
\r
270 execution.setVariable(Prefix+"relatedVnfIdList", relatedVnfIdList)
\r
273 utils.log("DEBUG", " ***** Completed prepareServiceDelete() of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
274 } catch (BpmnError e){
\r
276 } catch (Exception ex) {
\r
277 sendSyncError(execution)
\r
278 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. prepareServiceDelete() - " + ex.getMessage()
\r
279 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
280 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
284 private getAaiAr(Execution execution, String relink) {
\r
285 def isDebugEnabled = execution.getVariable(DebugFlag)
\r
286 AaiUtil aaiUtil = new AaiUtil(this)
\r
287 String aaiEndpoint = execution.getVariable("URN_aai_endpoint") + relink
\r
289 utils.log("DEBUG", "get AR info " + aaiEndpoint, isDebugEnabled)
\r
290 APIResponse response = aaiUtil.executeAAIGetCall(execution, aaiEndpoint)
\r
292 int responseCode = response.getStatusCode()
\r
293 utils.log("DEBUG", "get AR info responseCode:" + responseCode, isDebugEnabled)
\r
295 String aaiResponse = response.getResponseBodyAsString()
\r
296 utils.log("DEBUG", "get AR info " + aaiResponse, isDebugEnabled)
\r
298 if(responseCode < 200 || responseCode >= 300 || isBlank(aaiResponse)) {
\r
299 return new Tuple2(null, null)
\r
302 def type = utils.getNodeText1(aaiResponse, "type")
\r
303 def id = utils.getNodeText1(aaiResponse, "id")
\r
305 return new Tuple2(type, id)
\r
309 // *******************************
\r
311 // *******************************
\r
312 public void prepareVnfAndModulesDelete (Execution execution) {
\r
313 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
314 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesDelete of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
317 List vnfList = execution.getVariable(Prefix+"relatedVnfIdList")
\r
318 int vnfsDeletedCount = execution.getVariable(Prefix+"vnfsDeletedCount")
\r
319 String vnfModelInfoString = ""
\r
321 if (vnfList.size() > 0 ) {
\r
322 vnfId = vnfList.get(vnfsDeletedCount.intValue())
\r
325 execution.setVariable("vnfId", vnfId)
\r
326 utils.log("DEBUG", "need to delete vnfId:" + vnfId, isDebugEnabled)
\r
328 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesDelete of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
329 } catch (Exception ex) {
\r
330 // try error in method block
\r
331 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesDelete() - " + ex.getMessage()
\r
332 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
336 // *******************************
\r
337 // Validate Vnf request Section -> increment count
\r
338 // *******************************
\r
339 public void validateVnfDelete (Execution execution) {
\r
340 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
341 utils.log("DEBUG", " ***** Inside validateVnfDelete of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
344 int vnfsDeletedCount = execution.getVariable(Prefix+"vnfsDeletedCount")
\r
347 execution.setVariable(Prefix+"vnfsDeletedCount", vnfsDeletedCount)
\r
349 utils.log("DEBUG", " ***** Completed validateVnfDelete of DeleteVcpeResCustService ***** "+" vnf # "+vnfsDeletedCount, isDebugEnabled)
\r
350 } catch (Exception ex) {
\r
351 // try error in method block
\r
352 String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected Error from method validateVnfDelete() - " + ex.getMessage()
\r
353 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
358 // *****************************************
\r
359 // Prepare Completion request Section
\r
360 // *****************************************
\r
361 public void postProcessResponse (Execution execution) {
\r
362 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
363 utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
366 String source = execution.getVariable("source")
\r
367 String requestId = execution.getVariable("msoRequestId")
\r
369 String msoCompletionRequest =
\r
370 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
371 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
372 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
373 <request-id>${requestId}</request-id>
\r
374 <action>DELETE</action>
\r
375 <source>${source}</source>
\r
377 <aetgt:status-message>vCPE Res Cust Service Instance has been deleted successfully.</aetgt:status-message>
\r
378 <aetgt:mso-bpel-name>BPMN Service Instance macro action: DELETE</aetgt:mso-bpel-name>
\r
379 </aetgt:MsoCompletionRequest>"""
\r
382 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
384 utils.logAudit(xmlMsoCompletionRequest)
\r
385 execution.setVariable(Prefix+"Success", true)
\r
386 execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)
\r
387 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
388 } catch (BpmnError e) {
\r
391 } catch (Exception ex) {
\r
392 // try error in method block
\r
393 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
\r
394 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
398 public void prepareFalloutRequest(Execution execution){
\r
399 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
400 utils.log("DEBUG", " *** STARTED DeleteVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
\r
403 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
404 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
405 String requestInfo = execution.getVariable(Prefix+"requestInfo")
\r
406 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
\r
408 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
410 execution.setVariable(Prefix+"falloutRequest", falloutRequest)
\r
411 } catch (Exception ex) {
\r
412 utils.log("DEBUG", "Error Occured in DeleteVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
\r
413 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVcpeResCustService prepareFalloutRequest Process")
\r
415 utils.log("DEBUG", "*** COMPLETED DeleteVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
\r
419 public void sendSyncError (Execution execution) {
\r
420 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
421 utils.log("DEBUG", " ***** Inside sendSyncError() of DeleteVcpeResCustService ***** ", isDebugEnabled)
\r
424 String errorMessage = ""
\r
425 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
426 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
427 errorMessage = wfe.getErrorMessage()
\r
429 errorMessage = "Sending Sync Error."
\r
432 String buildworkflowException =
\r
433 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
434 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
435 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
436 </aetgt:WorkflowException>"""
\r
438 utils.logAudit(buildworkflowException)
\r
439 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
440 } catch (Exception ex) {
\r
441 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
445 public void processJavaException(Execution execution){
\r
446 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
447 execution.setVariable("prefix",Prefix)
\r
449 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
\r
450 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
451 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
452 execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
\r
453 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
454 }catch(BpmnError b){
\r
455 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
457 }catch(Exception e){
\r
458 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
459 execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
\r
460 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
\r
462 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
\r