9578e75fa84da985f4fcba875a5d47eec88cd38d
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / cbam / controller / CbamController.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.controller;
18
19 import java.io.IOException;
20
21 import org.apache.http.client.ClientProtocolException;
22 import org.apache.http.impl.client.HttpClientBuilder;
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMOperExecutVnfRequest;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMOperExecutVnfResponse;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ProblemDetails;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfInfo;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.http.MediaType;
46 import org.springframework.stereotype.Controller;
47 import org.springframework.web.bind.annotation.PathVariable;
48 import org.springframework.web.bind.annotation.RequestMapping;
49 import org.springframework.web.bind.annotation.RequestMethod;
50 import org.springframework.web.bind.annotation.ResponseBody;
51
52 import com.google.gson.Gson;
53
54 @Controller
55 @RequestMapping(value = "/vnfm/lcm/v3")
56 public class CbamController {
57         private static final Logger logger = LogManager.getLogger("CbamController");
58         @Autowired 
59         private AdaptorEnv adaptorEnv;
60         
61         @Autowired
62         private HttpClientBuilder httpClientBuilder;
63         
64         private Gson gson = new Gson();
65         
66         @RequestMapping(value = "/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
67     @ResponseBody
68     public CBAMCreateVnfResponse createVnf(CBAMInstantiateVnfRequest request) throws ClientProtocolException, IOException
69     {
70                  CBAMCreateVnfResponse response = new  CBAMCreateVnfResponse();
71                         String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamCreateVnfPath);
72                         HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
73                         
74                         String responseStr = processor.process(url);
75                         
76                         logger.info("CbamMgmrImpl -> createVnf, responseStr is " + responseStr);
77                         
78                         CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
79                         
80                         
81                 return response;
82     }
83         @RequestMapping(value = "/vnfs/{vnfInstanceId}/instantiate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
84     @ResponseBody
85     public CBAMInstantiateVnfResponse initiateVnf(CBAMInstantiateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
86     {
87                 CBAMInstantiateVnfResponse response = new CBAMInstantiateVnfResponse();
88                 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamInstantiateVnfPath,vnfInstanceId);
89                 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
90                 
91                 String responseStr = processor.process(url);
92                 
93                 logger.info("CbamMgmrImpl -> initiateVnf, responseStr is " + responseStr);
94                 
95                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
96                 
97                 
98         return response;
99     }
100         
101         @RequestMapping(value = "/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
102     @ResponseBody
103     public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
104     {
105                 CBAMTerminateVnfResponse response = new CBAMTerminateVnfResponse();
106                 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamTerminateVnfPath,vnfInstanceId);
107                 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
108                 
109                 String responseStr = processor.process(url);
110                 
111                 logger.info("CbamMgmrImpl -> terminateVnf, responseStr is " + responseStr);
112                 
113                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
114         return response;
115     }
116         
117         @RequestMapping(value = "/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
118     @ResponseBody
119     public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
120     {
121                 CBAMScaleVnfResponse response = new CBAMScaleVnfResponse();
122                 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamScaleVnfPath,vnfInstanceId);
123                 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
124                 
125                 String responseStr = processor.process(url);
126                 
127                 logger.info("CbamMgmrImpl -> scaleVnf, responseStr is " + responseStr);
128                 
129                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
130         return response;
131     }
132
133         @RequestMapping(value = "/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
134     @ResponseBody
135     public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
136     {
137                  CBAMHealVnfResponse response = new  CBAMHealVnfResponse();
138                  String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamHealVnfPath,vnfInstanceId);
139                         HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
140                         
141                         String responseStr = processor.process(url);
142                         
143                         logger.info("CbamMgmrImpl -> healVnf, responseStr is " + responseStr);
144                         
145                         CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
146         return response;
147     }
148         
149         
150         @RequestMapping(value = "/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
151     @ResponseBody
152     public CBAMQueryVnfResponse queryVnf(@PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
153     {
154                 CBAMQueryVnfResponse response = new  CBAMQueryVnfResponse();
155                 String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamQueryVnfPath, vnfInstanceId);
156                 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
157                 
158                 String responseStr = processor.process(url);
159                 
160                 logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
161                 
162                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
163                 
164                 
165         return response;
166     }
167         
168         
169         @RequestMapping(value = "/operation_executions/{operationExecutionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
170     @ResponseBody
171     public CBAMOperExecutVnfResponse operVnf(@PathVariable("operationExecutionId") String operationExecutionId) throws ClientProtocolException, IOException
172     {
173                 CBAMOperExecutVnfResponse response = new  CBAMOperExecutVnfResponse();
174                  String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamGetOperStatusPath,operationExecutionId);
175                         HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
176                         
177                         String responseStr = processor.process(url);
178                         
179                         logger.info("CbamMgmrImpl -> operVnf, responseStr is " + responseStr);
180                         
181                         CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
182         return response;
183     }
184         
185         
186         
187
188 }