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>DoCreateVFCNetworkServiceInstance.bpmn</class> process.
\r
45 * flow for VFC Network Service Create
\r
47 public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {
\r
49 String vfcUrl = "/vfc/rest/v1/vfcadapter"
\r
51 String host = "http://mso.mso.testlab.openecomp.org:8080"
\r
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
55 JsonUtils jsonUtil = new JsonUtils()
\r
58 * Pre Process the BPMN Flow Request
\r
60 * generate the nsOperationKey
\r
61 * generate the nsParameters
\r
63 public void preProcessRequest (Execution execution) {
\r
64 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
66 utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
\r
68 //deal with nsName and Description
\r
69 String nsServiceName = execution.getVariable("nsServiceName")
\r
70 String nsServiceDescription = execution.getVariable("nsServiceDescription")
\r
71 utils.log("INFO", "nsServiceName:" + nsServiceName + " nsServiceDescription:" + nsServiceDescription, isDebugEnabled)
\r
72 //deal with operation key
\r
73 String globalSubscriberId = execution.getVariable("globalSubscriberId")
\r
74 utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)
\r
75 String serviceType = execution.getVariable("serviceType")
\r
76 utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
\r
77 String serviceId = execution.getVariable("serviceId")
\r
78 utils.log("INFO", "serviceId:" + serviceId, isDebugEnabled)
\r
79 String operationId = execution.getVariable("operationId")
\r
80 utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
\r
81 String nodeTemplateUUID = execution.getVariable("resourceUUID")
\r
82 utils.log("INFO", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)
\r
84 * segmentInformation needed as a object of segment
\r
87 * "nodeTemplateName":"",
\r
90 * //this is the nsParameters sent to VF-C
\r
94 String nsParameters = execution.getVariable("resourceParameters")
\r
95 utils.log("INFO", "nsParameters:" + nsParameters, isDebugEnabled)
\r
96 String nsOperationKey = """{
\r
97 "globalSubscriberId":"${globalSubscriberId}",
\r
98 "serviceType":"${serviceType}",
\r
99 "serviceId":"${serviceId}",
\r
100 "operationId":"${operationId}",
\r
101 "nodeTemplateUUID":"${nodeTemplateUUID}"
\r
103 execution.setVariable("nsOperationKey", nsOperationKey);
\r
104 execution.setVariable("nsParameters", nsParameters)
\r
107 } catch (BpmnError e) {
\r
109 } catch (Exception ex){
\r
110 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
111 utils.log("INFO", msg, isDebugEnabled)
\r
112 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
114 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
120 public void createNetworkService(Execution execution) {
\r
122 String nsOperationKey = execution.getVariable("nsOperationKey");
\r
123 String nsParameters = execution.getVariable("nsParameters");
\r
124 String nsServiceName = execution.getVariable("nsServiceName")
\r
125 String nsServiceDescription = execution.getVariable("nsServiceDescription")
\r
126 String reqBody ="""{
\r
127 "nsServiceName":"${nsServiceName}",
\r
128 "nsServiceDescription":"${nsServiceDescription}",
\r
129 "nsOperationKey":${nsOperationKey},
\r
130 "nsParameters":${nsParameters}
\r
132 APIResponse apiResponse = postRequest(execution, host + vfcUrl + "/ns", reqBody)
\r
133 String returnCode = apiResponse.getStatusCode()
\r
134 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
135 String nsInstanceId = "";
\r
136 if(returnCode== "200"){
\r
137 nsInstanceId = jsonUtil.getJsonValue(aaiResponseAsString, "nsInstanceId")
\r
139 execution.setVariable("nsInstanceId", nsInstanceId)
\r
144 * instantiate NS task
\r
146 public void instantiateNetworkService(Execution execution) {
\r
147 String nsOperationKey = execution.getVariable("nsOperationKey");
\r
148 String nsParameters = execution.getVariable("nsParameters");
\r
149 String nsServiceName = execution.getVariable("nsServiceName")
\r
150 String nsServiceDescription = execution.getVariable("nsServiceDescription")
\r
151 String reqBody ="""{
\r
152 "nsServiceName":"${nsServiceName}",
\r
153 "nsServiceDescription":"${nsServiceDescription}",
\r
154 "nsOperationKey":${nsOperationKey},
\r
155 "nsParameters":${nsParameters}
\r
157 String nsInstanceId = execution.getVariable("nsInstanceId")
\r
158 String url = host + vfcUrl + "/ns/" +nsInstanceId + "/instantiate"
\r
159 APIResponse apiResponse = postRequest(execution, url, reqBody)
\r
160 String returnCode = apiResponse.getStatusCode()
\r
161 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
163 if(returnCode== "200"){
\r
164 jobId = jsonUtil.getJsonValue(aaiResponseAsString, "jobId")
\r
166 execution.setVariable("jobId", nsInstanceId)
\r
172 public void queryNSProgress(Execution execution) {
\r
173 String jobId = execution.getVariable("jobId")
\r
174 String nsOperationKey = execution.getVariable("nsOperationKey");
\r
175 String url = host + vfcUrl + "/jobs/" + jobId
\r
176 APIResponse apiResponse = postRequest(execution, url, nsOperationKey)
\r
177 String returnCode = apiResponse.getStatusCode()
\r
178 String aaiResponseAsString = apiResponse.getResponseBodyAsString()
\r
179 String operationStatus = "error"
\r
180 if(returnCode== "200"){
\r
181 operationStatus = jsonUtil.getJsonValue(aaiResponseAsString, "responseDescriptor.status")
\r
183 execution.setVariable("operationStatus", operationStatus)
\r
189 public void timeDelay(Execution execution) {
\r
191 Thread.sleep(5000);
\r
192 } catch(InterruptedException e) {
\r
193 taskProcessor.utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)
\r
200 public void finishNSCreate(Execution execution) {
\r
201 //no need to do anything util now
\r
206 * url: the url of the request
\r
207 * requestBody: the body of the request
\r
209 private APIResponse postRequest(Execution execution, String url, String requestBody){
\r
210 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
211 utils.log("INFO"," ***** Started Execute VFC adapter Post Process *****", isDebugEnabled)
\r
212 utils.log("INFO","url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)
\r
213 APIResponse apiResponse = null
\r
215 RESTConfig config = new RESTConfig(url);
\r
216 RESTClient client = new RESTClient(config).addHeader("Content-Type", "application/json").addHeader("Accept","application/json").addHeader("Authorization","Basic QlBFTENsaWVudDpwYXNzd29yZDEk");
\r
217 apiResponse = client.httpPost(requestBody)
\r
218 utils.log("INFO","response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)
\r
219 utils.log("INFO","======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)
\r
220 }catch(Exception e){
\r
221 utils.log("ERROR","Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)
\r
222 throw new BpmnError("MSOWorkflowException")
\r