2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.infrastructure.scripts;
\r
23 import static org.apache.commons.lang3.StringUtils.*;
\r
24 import groovy.xml.XmlUtil
\r
25 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
28 import org.openecomp.mso.bpmn.core.WorkflowException
\r
29 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
30 import org.openecomp.mso.rest.APIResponse
\r
32 import java.util.UUID;
\r
34 import org.camunda.bpm.engine.delegate.BpmnError
\r
35 import org.camunda.bpm.engine.runtime.Execution
\r
36 import org.apache.commons.lang3.*
\r
37 import org.apache.commons.codec.binary.Base64;
\r
38 import org.springframework.web.util.UriUtils
\r
39 import org.openecomp.mso.rest.RESTClient
\r
40 import org.openecomp.mso.rest.RESTConfig
\r
41 import org.openecomp.mso.rest.APIResponse;
\r
44 * This groovy class supports the <class>DODeleteVFCNetworkServiceInstance.bpmn</class> process.
\r
45 * flow for E2E ServiceInstance Delete
\r
47 public class DODeleteVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {
\r
49 String deleteUrl = "/vfc/vfcadapters/v1/ns/{nsInstanceId}"
\r
51 String terminateUrl = "/vfcvfcadatpers/v1/ns/{nsInstanceId}/terminate"
\r
53 String queryJobUrl = "/vfc/vfcadatpers/v1/jobs/{jobId}"
\r
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
57 JsonUtils jsonUtil = new JsonUtils()
\r
60 * Pre Process the BPMN Flow Request
\r
62 * generate the nsOperationKey
\r
64 public void preProcessRequest (Execution execution) {
\r
65 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
67 utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
\r
69 //deal with operation key
\r
70 String globalSubscriberId = execution.getVariable("globalSubscriberId")
\r
71 utils.log("DEBUG", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)
\r
72 String serviceType = execution.getVariable("serviceType")
\r
73 utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)
\r
74 String serviceId = execution.getVariable("serviceId")
\r
75 utils.log("DEBUG", "serviceId:" + serviceId, isDebugEnabled)
\r
76 String operationId = execution.getVariable("operationId")
\r
77 utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)
\r
78 String nodeTemplateUUID = execution.getVariable("nodeTemplateUUID")
\r
79 utils.log("DEBUG", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)
\r
80 String nsInstanceId = execution.getVariable("nsInstanceId")
\r
81 utils.log("DEBUG", "nsInstanceId:" + nsInstanceId, isDebugEnabled)
\r
82 String nsOperationKey = "{\"globalSubscriberId\":\"" + globalSubscriberId + "\",\"serviceType:\""
\r
83 + serviceType + "\",\"serviceId\":\"" + serviceId + "\",\"operationId\":\"" + operationId
\r
84 +"\",\"nodeTemplateUUID\":\"" + nodeTemplateUUID + "\"}";
\r
85 execution.setVariable("nsOperationKey", nsOperationKey);
\r
86 } catch (BpmnError e) {
\r
88 } catch (Exception ex){
\r
89 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
90 utils.log("DEBUG", msg, isDebugEnabled)
\r
91 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
93 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
99 public void deleteNetworkService(Execution execution) {
\r
100 String nsOperationKey = excution.getVariable("nsOperationKey");
\r
101 String url = deleteUrl.replaceAll("{nsInstanceId}", execution.getVariable("nsInstanceId"))
\r
102 APIResponse apiResponse = deleteRequest(url, reqBody)
\r
103 String returnCode = apiResponse.getStatusCode()
\r
104 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
105 String operationStatus = "error";
\r
106 if(returnCode== "200"){
\r
107 operationStatus = "finished"
\r
109 execution.setVariable("operationStatus", operationStatus)
\r
113 * instantiate NS task
\r
115 public void terminateNetworkService(Execution execution) {
\r
116 String nsOperationKey = execution.getVariable("nsOperationKey")
\r
117 String url = terminateUrl.replaceAll("{nsInstanceId}", execution.getVariable("nsInstanceId"))
\r
118 APIResponse apiResponse = postRequest(url, reqBody)
\r
119 String returnCode = apiResponse.getStatusCode()
\r
120 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
122 if(returnCode== "200"){
\r
123 jobId = jsonUtil.getJsonValue(aaiResponseAsString, "jobId")
\r
125 execution.setVariable("jobId", nsInstanceId)
\r
131 public void queryNSProgress(Execution execution) {
\r
132 String jobId = execution.getVariable("jobId")
\r
133 String nsOperationKey = excution.getVariable("nsOperationKey");
\r
134 String url = queryJobUrl.replaceAll("{jobId}", execution.getVariable("jobId"))
\r
135 APIResponse createRsp = postRequest(url, nsOperationKey)
\r
136 String returnCode = apiResponse.getStatusCode()
\r
137 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
138 String operationProgress = "100"
\r
139 if(returnCode== "200"){
\r
140 operationProgress = jsonUtil.getJsonValue(aaiResponseAsString, "responseDescriptor.progress")
\r
142 exection.setVariable("operationProgress", operationProgress)
\r
148 public void timeDelay(Execution execution) {
\r
150 Thread.sleep(5000);
\r
151 } catch(InterruptedException e) {
\r
152 taskProcessor.utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)
\r
159 public void finishNSDelete(Execution execution) {
\r
160 //no need to do anything util now
\r
165 * url: the url of the request
\r
166 * requestBody: the body of the request
\r
168 private APIResponse postRequest(String url, String requestBody){
\r
169 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
170 taskProcessor.logDebug( " ======== Started Execute VFC adapter Post Process ======== ", isDebugEnabled)
\r
171 taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)
\r
172 APIResponse apiResponse = null
\r
174 RESTConfig config = new RESTConfig(url);
\r
175 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");
\r
176 apiResponse = client.httpPost(requestBody)
\r
177 taskProcessor.logDebug( "response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)
\r
178 taskProcessor.logDebug( "======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)
\r
179 }catch(Exception e){
\r
180 taskProcessor.utils.log("ERROR", "Exception occured while executing VF-C Post Call. Exception is: \n" + e, isDebugEnabled)
\r
181 throw new BpmnError("MSOWorkflowException")
\r
187 * url: the url of the request
\r
188 * requestBody: the body of the request
\r
190 private APIResponse deleteRequest(String url, String requestBody){
\r
191 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
192 taskProcessor.logDebug( " ======== Started Execute VFC adapter Delete Process ======== ", isDebugEnabled)
\r
193 taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)
\r
194 APIResponse apiResponse = null
\r
196 RESTConfig config = new RESTConfig(url);
\r
197 RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");
\r
198 apiResponse = client.httpDelete(requestBody)
\r
199 taskProcessor.logDebug( "response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)
\r
200 taskProcessor.logDebug( "======== Completed Execute VF-C adapter Delete Process ======== ", isDebugEnabled)
\r
201 }catch(Exception e){
\r
202 taskProcessor.utils.log("ERROR", "Exception occured while executing VF-C Post Call. Exception is: \n" + e, isDebugEnabled)
\r
203 throw new BpmnError("MSOWorkflowException")
\r