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
21 package org.openecomp.mso.bpmn.common.scripts
\r
23 import static org.apache.commons.lang3.StringUtils.*
\r
25 import org.apache.commons.lang3.*
\r
26 import org.camunda.bpm.engine.delegate.BpmnError
\r
27 import org.camunda.bpm.engine.runtime.Execution
\r
28 import org.openecomp.mso.rest.APIResponse
\r
29 import org.springframework.web.util.UriUtils
\r
33 * This class supports the GenericDeleteService Sub Flow.
\r
34 * This Generic sub flow can be used by any flow for the
\r
35 * goal of deleting a Service-Instance or Service-Subscription.
\r
36 * The calling flow must set the GENDS_type variable as "service-instance"
\r
37 * or "service-subscription".
\r
39 * If the resource-version is not provided by the calling flow
\r
40 * then this sub flow will query the service-instance or
\r
41 * service-subscription, prior to deleting it, in order to
\r
42 * obtain this resource version. Upon successful completion of
\r
43 * this sub flow the GENDS_SuccessIndicator will be true. A
\r
44 * MSOWorkflowException will be thrown if an error occurs within this flow.
\r
46 * Please map variables to the corresponding variable names
\r
49 * Note - if this sub flow receives a Not Found (404) response
\r
50 * from AAI at any time this will be considered an acceptable
\r
54 * Variable Mapping Below
\r
56 * In Mapping Variables:
\r
57 * For Service-Instance:
\r
58 * @param - GENDS_serviceInstanceId
\r
59 * @param - GENDS_serviceType
\r
60 * @param - GENDS_globalCustomerId
\r
61 * @param - GENDS_type
\r
62 * @param (Optional) - GENDS_resourceVersion
\r
64 * For Service-Subscription:
\r
65 * @param - GENDS_serviceType
\r
66 * @param - GENDS_globalCustomerId
\r
67 * @param - GENDS_type
\r
68 * @param (Optional) - GENDS_resourceVersion
\r
71 * Out Mapping Variables:
\r
72 * @param - GENDS_FoundIndicator
\r
73 * @param - WorkflowException
\r
77 class GenericDeleteService extends AbstractServiceTaskProcessor{
\r
79 String Prefix = "GENDS_"
\r
80 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
83 * This method validates the incoming variables and
\r
84 * determines if the resource version was provided
\r
86 * @param - execution
\r
88 public void preProcessRequest(Execution execution) {
\r
89 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
90 execution.setVariable("prefix",Prefix)
\r
91 utils.log("DEBUG", " *** STARTED GenericDeleteService PreProcessRequest Process*** ", isDebugEnabled)
\r
93 execution.setVariable("GENDS_resourceVersionProvidedFlag", true)
\r
94 execution.setVariable("GENDS_SuccessIndicator", false)
\r
95 execution.setVariable("GENDS_FoundIndicator", false)
\r
99 String globalCustomerId = execution.getVariable("GENDS_globalCustomerId")
\r
100 String serviceInstanceId = execution.getVariable("GENDS_serviceInstanceId")
\r
101 String serviceType = execution.getVariable("GENDS_serviceType")
\r
102 String type = execution.getVariable("GENDS_type")
\r
105 utils.log("DEBUG", "Incoming GENDS_type is: " + type, isDebugEnabled)
\r
106 if(isBlank(globalCustomerId) || isBlank(serviceType)){
\r
107 utils.log("DEBUG", "Incoming Required Variable is null!", isDebugEnabled)
\r
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Required Variable is Missing or Null!")
\r
110 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
111 utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
\r
112 if(type.equalsIgnoreCase("service-instance")){
\r
113 if(isBlank(serviceInstanceId)){
\r
114 utils.log("DEBUG", "Incoming Required Variable is null!", isDebugEnabled)
\r
115 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Required Variable is Missing or Null!")
\r
117 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
\r
118 utils.log("DEBUG", "Preparing Delete Service-Instance Process", isDebugEnabled)
\r
120 }else if(type.equalsIgnoreCase("service-subscription")){
\r
121 utils.log("DEBUG", "Preparing Delete Service-Subscription Process", isDebugEnabled)
\r
123 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Type is Invalid. Please Specify Type as service-instance or service-subscription")
\r
127 String resourceVersion = execution.getVariable('GENDS_resourceVersion')
\r
128 if(isBlank(resourceVersion)){
\r
129 utils.log("DEBUG", "Service Instance Resource Version is NOT Provided", isDebugEnabled)
\r
130 execution.setVariable("GENDS_resourceVersionProvidedFlag", false)
\r
132 utils.log("DEBUG", "Incoming SI Resource Version is: " + resourceVersion, isDebugEnabled)
\r
136 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Incoming GENDS_type is null. Variable is Required.")
\r
138 }catch(BpmnError b){
\r
139 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
141 }catch(Exception e){
\r
142 utils.log("ERROR", " Error encountered within GenericDeleteService PreProcessRequest method!" + e, isDebugEnabled)
\r
143 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in GenericDeleteService PreProcessRequest")
\r
146 utils.log("DEBUG", "*** COMPLETED GenericDeleteService PreProcessRequest Process ***", isDebugEnabled)
\r
150 * This method executes a GET call to AAI for the service instance
\r
151 * or service-subscription so that the objects's resource-version
\r
154 * @param - execution
\r
156 public void getServiceResourceVersion(Execution execution){
\r
157 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
158 execution.setVariable("prefix",Prefix)
\r
159 utils.log("DEBUG", " *** STARTED GenericDeleteService GetServiceResourceVersion Process*** ", isDebugEnabled)
\r
161 String serviceType = execution.getVariable("GENDS_serviceType")
\r
162 utils.log("DEBUG", " Incoming GENDS_serviceType is: " + serviceType, isDebugEnabled)
\r
163 String globalCustomerId = execution.getVariable("GENDS_globalCustomerId")
\r
164 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
165 String type = execution.getVariable("GENDS_type")
\r
166 String serviceEndpoint = ""
\r
168 if(type.equalsIgnoreCase("service-instance")){
\r
169 String serviceInstanceId = execution.getVariable("GENDS_serviceInstanceId")
\r
170 utils.log("DEBUG", " Incoming GENDS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
\r
171 serviceEndpoint = UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8")
\r
173 }else if(type.equalsIgnoreCase("service-subscription")){
\r
174 serviceEndpoint = UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8")
\r
177 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
\r
178 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
179 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
180 logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
\r
182 String serviceAaiPath = "${aai_endpoint}${aai_uri}/" + serviceEndpoint
\r
184 execution.setVariable("GENDS_serviceAaiPath", serviceAaiPath)
\r
185 utils.log("DEBUG", "GET Service Instance AAI Path is: " + "\n" + serviceAaiPath, isDebugEnabled)
\r
186 utils.logAudit("GenericDeleteService GET AAI Path: " + serviceAaiPath)
\r
188 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, serviceAaiPath)
\r
189 int responseCode = response.getStatusCode()
\r
190 execution.setVariable("GENDS_getServiceResponseCode", responseCode)
\r
191 utils.log("DEBUG", " GET Service Instance response code is: " + responseCode, isDebugEnabled)
\r
192 utils.logAudit("GET Service Instance response code: " + responseCode)
\r
194 String aaiResponse = response.getResponseBodyAsString()
\r
195 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
\r
196 execution.setVariable("GENDS_getServiceResponse", aaiResponse)
\r
198 utils.logAudit("GET Service Instance response : " + aaiResponse)
\r
200 if(responseCode == 200 || responseCode == 202){
\r
201 utils.log("DEBUG", "GET Service Received a Good Response: \n" + aaiResponse, isDebugEnabled)
\r
202 execution.setVariable("GENDS_SuccessIndicator", true)
\r
203 execution.setVariable("GENDS_FoundIndicator", true)
\r
204 String resourceVersion = utils.getNodeText1(aaiResponse, "resource-version")
\r
205 execution.setVariable("GENDS_resourceVersion", resourceVersion)
\r
206 utils.log("DEBUG", type + " Resource Version is: " + resourceVersion, isDebugEnabled)
\r
208 }else if(responseCode == 404){
\r
209 utils.log("DEBUG", "GET Service Received a Not Found (404) Response", isDebugEnabled)
\r
210 execution.setVariable("GENDS_SuccessIndicator", true)
\r
211 execution.setVariable("WorkflowResponse", " ") // for junits
\r
214 utils.log("DEBUG", " GET Service Received a Bad Response: \n" + aaiResponse, isDebugEnabled)
\r
215 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
\r
216 throw new BpmnError("MSOWorkflowException")
\r
218 }catch(BpmnError b){
\r
219 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
221 }catch(Exception e){
\r
222 utils.log("DEBUG", " Error encountered within GenericDeleteService GetServiceResourceVersion method!" + e, isDebugEnabled)
\r
223 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During GetServiceResourceVersion")
\r
225 utils.log("DEBUG", " *** COMPLETED GenericDeleteService GetServiceResourceVersion Process*** ", isDebugEnabled)
\r
229 * This method executes a DELETE call to AAI for the provided
\r
230 * service-instance or service-subscription.
\r
232 * @param - execution
\r
234 public void deleteServiceObject(Execution execution){
\r
235 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
236 execution.setVariable("prefix",Prefix)
\r
237 utils.log("DEBUG", " *** STARTED GenericDeleteService DeleteServiceObject Process*** ", isDebugEnabled)
\r
239 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
240 String type = execution.getVariable("GENDS_type")
\r
241 String serviceAaiPath = execution.getVariable("GENDS_serviceAaiPath")
\r
242 String serviceEndpoint = ""
\r
244 if(isEmpty(serviceAaiPath)){
\r
245 String serviceType = execution.getVariable("GENDS_serviceType")
\r
246 utils.log("DEBUG", " Incoming GENDS_serviceType is: " + serviceType, isDebugEnabled)
\r
247 String globalCustomerId = execution.getVariable("GENDS_globalCustomerId")
\r
248 utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)
\r
249 if(type.equalsIgnoreCase("service-instance")){
\r
250 String serviceInstanceId = execution.getVariable("GENDS_serviceInstanceId")
\r
251 utils.log("DEBUG", " Incoming GENDS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
\r
252 serviceEndpoint = UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8")
\r
254 }else if(type.equalsIgnoreCase("service-subscription")){
\r
255 serviceEndpoint = UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8")
\r
258 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
\r
259 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
\r
260 logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
\r
262 serviceAaiPath = "${aai_endpoint}${aai_uri}/" + serviceEndpoint
\r
265 String resourceVersion = execution.getVariable("GENDS_resourceVersion")
\r
266 utils.log("DEBUG", "Incoming Resource Version is: " + resourceVersion, isDebugEnabled)
\r
267 if(resourceVersion !=null){
\r
268 serviceAaiPath = serviceAaiPath +'?resource-version=' + UriUtils.encode(resourceVersion,"UTF-8")
\r
271 execution.setVariable("GENDS_deleteServiceAaiPath", serviceAaiPath)
\r
272 utils.log("DEBUG", "DELETE Service AAI Path is: " + "\n" + serviceAaiPath, isDebugEnabled)
\r
273 utils.logAudit("DELETE Service AAI Path: " + serviceAaiPath)
\r
275 APIResponse response = aaiUriUtil.executeAAIDeleteCall(execution, serviceAaiPath)
\r
276 int responseCode = response.getStatusCode()
\r
277 execution.setVariable("GENDS_deleteServiceResponseCode", responseCode)
\r
278 utils.log("DEBUG", " DELETE Service response code is: " + responseCode, isDebugEnabled)
\r
279 utils.logAudit("DELETE Service Response Code: " + responseCode)
\r
281 String aaiResponse = response.getResponseBodyAsString()
\r
282 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
\r
283 execution.setVariable("GENDS_deleteServiceResponse", aaiResponse)
\r
284 utils.logAudit("DELETE Service Response: " + aaiResponse)
\r
287 if(responseCode == 200 || responseCode == 204){
\r
288 utils.log("DEBUG", " DELETE Service Received a Good Response", isDebugEnabled)
\r
289 execution.setVariable("GENDS_FoundIndicator", true)
\r
290 }else if(responseCode == 404){
\r
291 utils.log("DEBUG", " DELETE Service Received a Not Found (404) Response", isDebugEnabled)
\r
292 execution.setVariable("GENDS_FoundIndicator", false)
\r
294 utils.log("DEBUG", "DELETE Service Received a BAD REST Response: \n" + aaiResponse, isDebugEnabled)
\r
295 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
\r
296 throw new BpmnError("MSOWorkflowException")
\r
298 }catch(BpmnError b){
\r
299 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
301 }catch(Exception e){
\r
302 utils.log("DEBUG", " Error encountered within GenericDeleteService DeleteServiceObject method!" + e, isDebugEnabled)
\r
303 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During Delete Service Object")
\r
305 utils.log("DEBUG", " *** COMPLETED GenericDeleteService DeleteServiceObject Process*** ", isDebugEnabled)
\r