2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.controller;
19 import java.io.IOException;
21 import org.apache.http.client.ClientProtocolException;
22 import org.apache.http.impl.client.HttpClientBuilder;
23 import org.apache.log4j.Logger;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMOperExecutVnfResponse;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.http.MediaType;
41 import org.springframework.stereotype.Controller;
42 import org.springframework.web.bind.annotation.PathVariable;
43 import org.springframework.web.bind.annotation.RequestMapping;
44 import org.springframework.web.bind.annotation.RequestMethod;
45 import org.springframework.web.bind.annotation.ResponseBody;
47 import com.google.gson.Gson;
50 @RequestMapping(value = "/vnfm/lcm/v3")
51 public class CbamController {
52 private static final Logger logger = Logger.getLogger(CbamController.class);
54 private AdaptorEnv adaptorEnv;
57 private HttpClientBuilder httpClientBuilder;
59 private Gson gson = new Gson();
61 @RequestMapping(value = "/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
63 public CBAMCreateVnfResponse createVnf(CBAMInstantiateVnfRequest request) throws ClientProtocolException, IOException
65 CBAMCreateVnfResponse response = new CBAMCreateVnfResponse();
66 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamCreateVnfPath);
67 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
69 String responseStr = processor.process(url);
71 logger.info("CbamMgmrImpl -> createVnf, responseStr is " + responseStr);
73 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
78 @RequestMapping(value = "/vnfs/{vnfInstanceId}/instantiate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
80 public CBAMInstantiateVnfResponse initiateVnf(CBAMInstantiateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
82 CBAMInstantiateVnfResponse response = new CBAMInstantiateVnfResponse();
83 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamInstantiateVnfPath,vnfInstanceId);
84 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
86 String responseStr = processor.process(url);
88 logger.info("CbamMgmrImpl -> initiateVnf, responseStr is " + responseStr);
90 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
96 @RequestMapping(value = "/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
98 public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
100 CBAMTerminateVnfResponse response = new CBAMTerminateVnfResponse();
101 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamTerminateVnfPath,vnfInstanceId);
102 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
104 String responseStr = processor.process(url);
106 logger.info("CbamMgmrImpl -> terminateVnf, responseStr is " + responseStr);
108 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
112 @RequestMapping(value = "/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
114 public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
116 CBAMScaleVnfResponse response = new CBAMScaleVnfResponse();
117 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamScaleVnfPath,vnfInstanceId);
118 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
120 String responseStr = processor.process(url);
122 logger.info("CbamMgmrImpl -> scaleVnf, responseStr is " + responseStr);
124 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
128 @RequestMapping(value = "/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
130 public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
132 CBAMHealVnfResponse response = new CBAMHealVnfResponse();
133 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamHealVnfPath,vnfInstanceId);
134 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
136 String responseStr = processor.process(url);
138 logger.info("CbamMgmrImpl -> healVnf, responseStr is " + responseStr);
140 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
145 @RequestMapping(value = "/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
147 public CBAMQueryVnfResponse queryVnf(@PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
149 CBAMQueryVnfResponse response = new CBAMQueryVnfResponse();
150 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamQueryVnfPath, vnfInstanceId);
151 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
153 String responseStr = processor.process(url);
155 logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
157 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
164 @RequestMapping(value = "/operation_executions/{operationExecutionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
166 public CBAMOperExecutVnfResponse operVnf(@PathVariable("operationExecutionId") String operationExecutionId) throws ClientProtocolException, IOException
168 CBAMOperExecutVnfResponse response = new CBAMOperExecutVnfResponse();
169 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamGetOperStatusPath,operationExecutionId);
170 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
172 String responseStr = processor.process(url);
174 logger.info("CbamMgmrImpl -> operVnf, responseStr is " + responseStr);
176 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);