Modify database part in the deployment
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / vnfmdriver / controller / VnfmDriverController.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.vnfmdriver.controller;
18
19 import java.io.IOException;
20
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.apache.http.HttpStatus;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfmDriverMgmrInf;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.http.MediaType;
40 import org.springframework.stereotype.Controller;
41 import org.springframework.web.bind.annotation.PathVariable;
42 import org.springframework.web.bind.annotation.RequestBody;
43 import org.springframework.web.bind.annotation.RequestMapping;
44 import org.springframework.web.bind.annotation.RequestMethod;
45 import org.springframework.web.bind.annotation.ResponseBody;
46
47 import com.google.gson.Gson;
48
49 @Controller
50 @RequestMapping(value = "/api/nokiavnfmdriver/v1")
51 public class VnfmDriverController {
52         private static final Logger logger = LoggerFactory.getLogger(VnfmDriverController.class);
53         
54         @Autowired
55         private VnfmDriverMgmrInf vnfmDriverMgmr;
56         
57         private Gson gson = new Gson();
58         
59         @RequestMapping(value = "/{vnfmId}/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
60     @ResponseBody
61     public InstantiateVnfResponse instantiateVnf(@RequestBody InstantiateVnfRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse)
62     {
63                 String jsonString = gson.toJson(request);
64                 logger.info("instantiateVnf request: vnfmId = " + vnfmId + ", bodyMessage is " + jsonString);
65                 
66                 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(request, vnfmId);
67                 
68                 httpResponse.setStatus(HttpStatus.SC_CREATED);
69                 
70                 return response;
71     }
72         
73         @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
74     @ResponseBody
75     public TerminateVnfResponse terminateVnf(@RequestBody TerminateVnfRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
76     {
77                 String jsonString = gson.toJson(request);
78                 logger.info("terminateVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId + ", bodyMessage is " + jsonString);
79                 
80                 try {
81                         TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(request, vnfmId, vnfInstanceId);
82                         httpResponse.setStatus(HttpStatus.SC_CREATED);
83                         return response;
84                 }
85                 catch(VnfmDriverException e)
86                 {
87                         try {
88                                 httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
89                                 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
90                         } catch (IOException e1) {
91                                 
92                         }
93                 }
94                 
95                 return null;
96     }
97         
98         
99         @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
100     @ResponseBody
101     public QueryVnfResponse queryVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
102     {
103                 logger.info("queryVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId);
104                 
105                 try {
106                         QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
107                         httpResponse.setStatus(HttpStatus.SC_CREATED);
108                         return response;
109                 }
110                 catch(VnfmDriverException e)
111                 {
112                         try {
113                                 httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
114                                 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
115                         } catch (IOException e1) {
116                                 
117                         }
118                 }
119                 
120                 return null;
121     }
122         @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
123     @ResponseBody
124     public OperStatusVnfResponse getOperStatus(@PathVariable("vnfmId") String vnfmId,@PathVariable("jobId") String jobId, HttpServletResponse httpResponse)
125     {
126                 logger.info("getOperStatus request: vnfmId = " + vnfmId + ", jobId = " + jobId);
127                 
128                 try {
129                         OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, jobId);
130                         httpResponse.setStatus(HttpStatus.SC_CREATED);
131                         return response;
132                 }
133                 catch(VnfmDriverException e)
134                 {
135                         try {
136                                 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
137                         } catch (IOException e1) {
138                                 
139                         }
140                 }
141                 
142                 return null;
143     }
144         
145         
146         @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
147     @ResponseBody
148     public ScaleVnfResponse scaleVnf(@RequestBody ScaleVnfRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
149     {
150                 String jsonString = gson.toJson(request);
151                 logger.info("scaleVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId + ", bodyMessage is " + jsonString);
152                 
153                 try {
154                         ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
155                         httpResponse.setStatus(HttpStatus.SC_CREATED);
156                         return response;
157                 }
158                 catch(VnfmDriverException e)
159                 {
160                         try {
161                                 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
162                         } catch (IOException e1) {
163                                 
164                         }
165                 }
166                 
167                 return null;
168     }
169         
170         
171         @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
172     @ResponseBody
173     public HealVnfResponse healVnf(@RequestBody HealVnfRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
174     {
175                 String jsonString = gson.toJson(request);
176                 logger.info("healVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId + ", bodyMessage is " + jsonString);
177                 
178                 try {
179                         HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
180                         httpResponse.setStatus(HttpStatus.SC_CREATED);
181                         return response;
182                 }
183                 catch(VnfmDriverException e)
184                 {
185                         try {
186                                 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
187                         } catch (IOException e1) {
188                                 
189                         }
190                 }
191                 
192                 return null;
193     }
194
195
196 }