2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.core.json.JsonUtils
28 import org.onap.so.client.HttpClient
29 import org.onap.so.client.HttpClientFactory
30 import org.onap.so.client.aai.AAIObjectType
31 import org.onap.so.client.aai.entities.uri.AAIResourceUri
32 import org.onap.so.client.aai.entities.uri.AAIUriFactory
33 import org.onap.so.logger.MsoLogger
34 import org.onap.so.utils.TargetEntity
35 import org.onap.so.bpmn.core.UrnPropertiesReader
37 import javax.ws.rs.core.Response
39 * This groovy class supports the <class>DoDeleteVFCNetworkServiceInstance.bpmn</class> process.
40 * flow for E2E ServiceInstance Delete
42 public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVFCNetworkServiceInstance.class);
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtil = new JsonUtils()
48 private final HttpClientFactory httpClientFactory = new HttpClientFactory()
51 * Pre Process the BPMN Flow Request
53 * generate the nsOperationKey
55 public void preProcessRequest (DelegateExecution execution) {
58 msoLogger.trace("preProcessRequest() ")
60 //deal with operation key
61 String globalSubscriberId = execution.getVariable("globalSubscriberId")
62 msoLogger.info("globalSubscriberId:" + globalSubscriberId)
63 String serviceType = execution.getVariable("serviceType")
64 msoLogger.info("serviceType:" + serviceType)
65 String serviceId = execution.getVariable("serviceId")
66 msoLogger.info("serviceId:" + serviceId)
67 String operationId = execution.getVariable("operationId")
68 msoLogger.info("serviceType:" + serviceType)
69 String nodeTemplateUUID = execution.getVariable("resourceTemplateId")
70 msoLogger.info("nodeTemplateUUID:" + nodeTemplateUUID)
71 String nsInstanceId = execution.getVariable("resourceInstanceId")
72 msoLogger.info("nsInstanceId:" + nsInstanceId)
73 execution.setVariable("nsInstanceId",nsInstanceId)
74 String nsOperationKey = """{
75 "globalSubscriberId":"${globalSubscriberId}",
76 "serviceType":"${serviceType}",
77 "serviceId":"${serviceId}",
78 "operationId":"${operationId}",
79 "nodeTemplateUUID":"${nodeTemplateUUID}"
81 execution.setVariable("nsOperationKey", nsOperationKey);
82 msoLogger.info("nsOperationKey:" + nsOperationKey)
84 String vfcAdapterUrl = UrnPropertiesReader.getVariable("mso.adapters.vfc.rest.endpoint", execution)
86 if (vfcAdapterUrl == null || vfcAdapterUrl.isEmpty()) {
87 msg = getProcessKey(execution) + ': mso:adapters:vfcc:rest:endpoint URN mapping is not defined'
91 while (vfcAdapterUrl.endsWith('/')) {
92 vfcAdapterUrl = vfcAdapterUrl.substring(0, vfcAdapterUrl.length()-1)
95 execution.setVariable("vfcAdapterUrl", vfcAdapterUrl)
97 } catch (BpmnError e) {
99 } catch (Exception ex){
100 msg = "Exception in preProcessRequest " + ex.getMessage()
102 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
104 msoLogger.trace("Exit preProcessRequest ")
108 * unwind NS from AAI relationship
110 public void deleteNSRelationship(DelegateExecution execution) {
111 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
112 utils.log("INFO"," ***** deleteNSRelationship *****", isDebugEnabled)
113 String nsInstanceId = execution.getVariable("resourceInstanceId")
114 if(nsInstanceId == null || nsInstanceId == ""){
115 utils.log("INFO"," Delete NS failed", isDebugEnabled)
118 String globalSubscriberId = execution.getVariable("globalSubscriberId")
119 String serviceType = execution.getVariable("serviceType")
120 String serviceId = execution.getVariable("serviceId")
121 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceId)
122 AAIResourceUri nsServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nsInstanceId)
124 getAAIClient().disconnect(serviceInstanceUri, nsServiceInstanceUri)
126 exceptionUtil.buildAndThrowWorkflowException(execution,25000,"Exception occured while NS disconnect call: " + e.getMessage())
128 utils.log("INFO"," *****Exit deleteNSRelationship *****", isDebugEnabled)
134 public void deleteNetworkService(DelegateExecution execution) {
136 msoLogger.trace("deleteNetworkService start ")
137 String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
138 String nsOperationKey = execution.getVariable("nsOperationKey");
139 String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId")
140 Response apiResponse = deleteRequest(execution, url, nsOperationKey)
141 String returnCode = apiResponse.getStatus()
142 String operationStatus = "error";
143 if(returnCode== "200" || returnCode== "202"){
144 operationStatus = "finished"
146 execution.setVariable("operationStatus", operationStatus)
148 msoLogger.trace("deleteNetworkService end ")
154 public void terminateNetworkService(DelegateExecution execution) {
156 msoLogger.trace("terminateNetworkService start ")
157 String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
158 String nsOperationKey = execution.getVariable("nsOperationKey")
159 String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId") + "/terminate"
160 Response apiResponse = postRequest(execution, url, nsOperationKey)
161 String returnCode = apiResponse.getStatus()
162 String aaiResponseAsString = apiResponse.readEntity(String.class)
164 if(returnCode== "200" || returnCode== "202"){
165 jobId = jsonUtil.getJsonValue(aaiResponseAsString, "jobId")
167 execution.setVariable("jobId", jobId)
168 msoLogger.trace("terminateNetworkService end ")
174 public void queryNSProgress(DelegateExecution execution) {
176 msoLogger.trace("queryNSProgress start ")
177 String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
178 String jobId = execution.getVariable("jobId")
179 String nsOperationKey = execution.getVariable("nsOperationKey");
180 String url = vfcAdapterUrl + "/jobs/" + execution.getVariable("jobId")
181 Response apiResponse = postRequest(execution, url, nsOperationKey)
182 String returnCode = apiResponse.getStatus()
183 String apiResponseAsString = apiResponse.readEntity(String.class)
184 String operationProgress = "100"
185 if(returnCode== "200"){
186 operationProgress = jsonUtil.getJsonValue(apiResponseAsString, "responseDescriptor.progress")
188 execution.setVariable("operationProgress", operationProgress)
189 msoLogger.trace("queryNSProgress end ")
195 public void timeDelay(DelegateExecution execution) {
198 } catch(InterruptedException e) {
199 msoLogger.info("Time Delay exception" + e)
206 public void finishNSDelete(DelegateExecution execution) {
207 //no need to do anything util now
212 * url: the url of the request
213 * requestBody: the body of the request
215 private Response postRequest(DelegateExecution execution, String urlString, String requestBody){
217 msoLogger.trace("Started Execute VFC adapter Post Process ")
218 msoLogger.info("url:"+urlString +"\nrequestBody:"+ requestBody)
219 Response apiResponse = null
221 URL url = new URL(urlString);
223 // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
224 // user 'bepl' authHeader is the same with mso.db.auth
225 String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution)
226 HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.VNF_ADAPTER)
227 httpClient.addAdditionalHeader("Accept", "application/json")
228 httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
230 apiResponse = httpClient.post(requestBody)
232 msoLogger.debug("response code:"+ apiResponse.getStatus() +"\nresponse body:"+ apiResponse.readEntity(String.class))
234 msoLogger.trace("Completed Execute VF-C adapter Post Process ")
236 msoLogger.error("Exception occured while executing VF-C Post Call. Exception is: \n" + e.getMessage());
237 throw new BpmnError("MSOWorkflowException")
243 * url: the url of the request
244 * requestBody: the body of the request
246 private Response deleteRequest(DelegateExecution execution, String url, String requestBody){
248 msoLogger.trace("Started Execute VFC adapter Delete Process ")
249 msoLogger.info("url:"+url +"\nrequestBody:"+ requestBody)
253 URL Url = new URL(url)
254 // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
255 // user 'bepl' authHeader is the same with mso.db.auth
256 String basicAuthValuedb = UrnPropertiesReader.getVariable("mso.db.auth", execution)
257 HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.VNF_ADAPTER)
258 httpClient.addAdditionalHeader("Accept", "application/json")
259 httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
260 httpClient.addAdditionalHeader("Content-Type", "application/json")
261 r = httpClient.delete(requestBody)
263 msoLogger.trace("Completed Execute VF-C adapter Delete Process ")
265 msoLogger.error("Exception occured while executing VF-C Post Call. Exception is: \n" + e.getMessage());
266 throw new BpmnError("MSOWorkflowException")