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.aai.AAIObjectType
30 import org.onap.so.client.aai.entities.uri.AAIResourceUri
31 import org.onap.so.client.aai.entities.uri.AAIUriFactory
32 import org.onap.so.logger.MessageEnum
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()
50 * Pre Process the BPMN Flow Request
52 * generate the nsOperationKey
54 public void preProcessRequest (DelegateExecution execution) {
57 msoLogger.trace("preProcessRequest() ")
59 //deal with operation key
60 String globalSubscriberId = execution.getVariable("globalSubscriberId")
61 msoLogger.info("globalSubscriberId:" + globalSubscriberId)
62 String serviceType = execution.getVariable("serviceType")
63 msoLogger.info("serviceType:" + serviceType)
64 String serviceId = execution.getVariable("serviceId")
65 msoLogger.info("serviceId:" + serviceId)
66 String operationId = execution.getVariable("operationId")
67 msoLogger.info("serviceType:" + serviceType)
68 String nodeTemplateUUID = execution.getVariable("resourceTemplateId")
69 msoLogger.info("nodeTemplateUUID:" + nodeTemplateUUID)
70 String nsInstanceId = execution.getVariable("resourceInstanceId")
71 msoLogger.info("nsInstanceId:" + nsInstanceId)
72 execution.setVariable("nsInstanceId",nsInstanceId)
73 String nsOperationKey = """{
74 "globalSubscriberId":"${globalSubscriberId}",
75 "serviceType":"${serviceType}",
76 "serviceId":"${serviceId}",
77 "operationId":"${operationId}",
78 "nodeTemplateUUID":"${nodeTemplateUUID}"
80 execution.setVariable("nsOperationKey", nsOperationKey);
81 msoLogger.info("nsOperationKey:" + nsOperationKey)
83 String vfcAdapterUrl = UrnPropertiesReader.getVariable("mso.adapters.vfc.rest.endpoint", execution)
85 if (vfcAdapterUrl == null || vfcAdapterUrl.isEmpty()) {
86 msg = getProcessKey(execution) + ': mso:adapters:vfcc:rest:endpoint URN mapping is not defined'
90 while (vfcAdapterUrl.endsWith('/')) {
91 vfcAdapterUrl = vfcAdapterUrl.substring(0, vfcAdapterUrl.length()-1)
94 execution.setVariable("vfcAdapterUrl", vfcAdapterUrl)
96 } catch (BpmnError e) {
98 } catch (Exception ex){
99 msg = "Exception in preProcessRequest " + ex.getMessage()
101 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
103 msoLogger.trace("Exit preProcessRequest ")
107 * unwind NS from AAI relationship
109 public void deleteNSRelationship(DelegateExecution execution) {
110 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
111 utils.log("INFO"," ***** deleteNSRelationship *****", isDebugEnabled)
112 String nsInstanceId = execution.getVariable("resourceInstanceId")
113 if(nsInstanceId == null || nsInstanceId == ""){
114 utils.log("INFO"," Delete NS failed", isDebugEnabled)
117 String globalSubscriberId = execution.getVariable("globalSubscriberId")
118 String serviceType = execution.getVariable("serviceType")
119 String serviceId = execution.getVariable("serviceId")
120 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceId)
121 AAIResourceUri nsServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nsInstanceId)
123 getAAIClient().disconnect(serviceInstanceUri, nsServiceInstanceUri)
125 exceptionUtil.buildAndThrowWorkflowException(execution,25000,"Exception occured while NS disconnect call: " + e.getMessage())
127 utils.log("INFO"," *****Exit deleteNSRelationship *****", isDebugEnabled)
133 public void deleteNetworkService(DelegateExecution execution) {
135 msoLogger.trace("deleteNetworkService start ")
136 String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
137 String nsOperationKey = execution.getVariable("nsOperationKey");
138 String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId")
139 Response apiResponse = deleteRequest(execution, url, nsOperationKey)
140 String returnCode = apiResponse.getStatus()
141 String operationStatus = "error";
142 if(returnCode== "200" || returnCode== "202"){
143 operationStatus = "finished"
145 execution.setVariable("operationStatus", operationStatus)
147 msoLogger.trace("deleteNetworkService end ")
151 * instantiate NS task
153 public void terminateNetworkService(DelegateExecution execution) {
155 msoLogger.trace("terminateNetworkService start ")
156 String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
157 String nsOperationKey = execution.getVariable("nsOperationKey")
158 String url = vfcAdapterUrl + "/ns/" + execution.getVariable("nsInstanceId") + "/terminate"
159 Response apiResponse = postRequest(execution, url, nsOperationKey)
160 String returnCode = apiResponse.getStatus()
161 String aaiResponseAsString = apiResponse.readEntity(String.class)
163 if(returnCode== "200" || returnCode== "202"){
164 jobId = jsonUtil.getJsonValue(aaiResponseAsString, "jobId")
166 execution.setVariable("jobId", jobId)
167 msoLogger.trace("terminateNetworkService end ")
173 public void queryNSProgress(DelegateExecution execution) {
175 msoLogger.trace("queryNSProgress start ")
176 String vfcAdapterUrl = execution.getVariable("vfcAdapterUrl")
177 String jobId = execution.getVariable("jobId")
178 String nsOperationKey = execution.getVariable("nsOperationKey");
179 String url = vfcAdapterUrl + "/jobs/" + execution.getVariable("jobId")
180 Response apiResponse = postRequest(execution, url, nsOperationKey)
181 String returnCode = apiResponse.getStatus()
182 String apiResponseAsString = apiResponse.readEntity(String.class)
183 String operationProgress = "100"
184 if(returnCode== "200"){
185 operationProgress = jsonUtil.getJsonValue(apiResponseAsString, "responseDescriptor.progress")
187 execution.setVariable("operationProgress", operationProgress)
188 msoLogger.trace("queryNSProgress end ")
194 public void timeDelay(DelegateExecution execution) {
197 } catch(InterruptedException e) {
198 msoLogger.info("Time Delay exception" + e)
205 public void finishNSDelete(DelegateExecution execution) {
206 //no need to do anything util now
211 * url: the url of the request
212 * requestBody: the body of the request
214 private Response postRequest(DelegateExecution execution, String urlString, String requestBody){
216 msoLogger.trace("Started Execute VFC adapter Post Process ")
217 msoLogger.info("url:"+urlString +"\nrequestBody:"+ requestBody)
218 Response apiResponse = null
220 URL url = new URL(urlString);
222 HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
223 httpClient.addAdditionalHeader("Accept", "application/json")
224 httpClient.addAdditionalHeader("Authorization", "Basic YnBlbDpwYXNzd29yZDEk")
226 apiResponse = httpClient.post(requestBody)
228 msoLogger.debug("response code:"+ apiResponse.getStatus() +"\nresponse body:"+ apiResponse.readEntity(String.class))
230 msoLogger.trace("Completed Execute VF-C adapter Post Process ")
232 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing VF-C Post Call. Exception is: \n" + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
233 throw new BpmnError("MSOWorkflowException")
239 * url: the url of the request
240 * requestBody: the body of the request
242 private Response deleteRequest(DelegateExecution execution, String url, String requestBody){
244 msoLogger.trace("Started Execute VFC adapter Delete Process ")
245 msoLogger.info("url:"+url +"\nrequestBody:"+ requestBody)
249 URL Url = new URL(url)
250 HttpClient httpClient = new HttpClient(Url, "application/json", TargetEntity.VNF_ADAPTER)
251 httpClient.addAdditionalHeader("Accept", "application/json")
252 httpClient.addAdditionalHeader("Authorization", "Basic YnBlbDpwYXNzd29yZDEk")
253 r = httpClient.delete(requestBody)
255 msoLogger.trace("Completed Execute VF-C adapter Delete Process ")
257 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception occured while executing VF-C Post Call. Exception is: \n" + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
258 throw new BpmnError("MSOWorkflowException")