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 com.nokia.vfcadaptor.vnfmdriver.controller;
19 import java.io.IOException;
21 import javax.servlet.http.HttpServletResponse;
23 import org.apache.http.HttpStatus;
24 import org.apache.log4j.Logger;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.http.MediaType;
27 import org.springframework.stereotype.Controller;
28 import org.springframework.web.bind.annotation.PathVariable;
29 import org.springframework.web.bind.annotation.RequestBody;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RequestMethod;
32 import org.springframework.web.bind.annotation.ResponseBody;
34 import com.google.gson.Gson;
35 import com.nokia.vfcadaptor.exception.VnfmDriverException;
36 import com.nokia.vfcadaptor.vnfmdriver.bo.HealVnfRequest;
37 import com.nokia.vfcadaptor.vnfmdriver.bo.HealVnfResponse;
38 import com.nokia.vfcadaptor.vnfmdriver.bo.InstantiateVnfRequest;
39 import com.nokia.vfcadaptor.vnfmdriver.bo.InstantiateVnfResponse;
40 import com.nokia.vfcadaptor.vnfmdriver.bo.OperStatusVnfResponse;
41 import com.nokia.vfcadaptor.vnfmdriver.bo.QueryVnfResponse;
42 import com.nokia.vfcadaptor.vnfmdriver.bo.ScaleVnfRequest;
43 import com.nokia.vfcadaptor.vnfmdriver.bo.ScaleVnfResponse;
44 import com.nokia.vfcadaptor.vnfmdriver.bo.TerminateVnfRequest;
45 import com.nokia.vfcadaptor.vnfmdriver.bo.TerminateVnfResponse;
46 import com.nokia.vfcadaptor.vnfmdriver.inf.VnfmDriverMgmrInf;
49 @RequestMapping(value = "/nokiavnfm/v1")
50 public class VnfmDriverController {
51 private Logger logger = Logger.getLogger(VnfmDriverController.class);
54 private VnfmDriverMgmrInf vnfmDriverMgmr;
56 private Gson gson = new Gson();
58 @RequestMapping(value = "/{vnfmId}/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
60 public InstantiateVnfResponse instantiateVnf(@RequestBody InstantiateVnfRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse)
62 String jsonString = gson.toJson(request);
63 logger.info("instantiateVnf request: vnfmId = " + vnfmId + ", bodyMessage is " + jsonString);
65 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(request, vnfmId);
67 httpResponse.setStatus(HttpStatus.SC_CREATED);
72 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
74 public TerminateVnfResponse terminateVnf(@RequestBody TerminateVnfRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
76 String jsonString = gson.toJson(request);
77 logger.info("terminateVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId + ", bodyMessage is " + jsonString);
80 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(request, vnfmId, vnfInstanceId);
81 httpResponse.setStatus(HttpStatus.SC_CREATED);
84 catch(VnfmDriverException e)
87 httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
88 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
89 } catch (IOException e1) {
98 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
100 public QueryVnfResponse queryVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
102 logger.info("queryVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId);
105 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
106 httpResponse.setStatus(HttpStatus.SC_CREATED);
109 catch(VnfmDriverException e)
112 httpResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
113 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
114 } catch (IOException e1) {
121 @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
123 public OperStatusVnfResponse getOperStatus(@PathVariable("vnfmId") String vnfmId,@PathVariable("jobId") String jobId, HttpServletResponse httpResponse)
125 logger.info("getOperStatus request: vnfmId = " + vnfmId + ", jobId = " + jobId);
128 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, jobId);
129 httpResponse.setStatus(HttpStatus.SC_CREATED);
132 catch(VnfmDriverException e)
135 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
136 } catch (IOException e1) {
145 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
147 public ScaleVnfResponse scaleVnf(@RequestBody ScaleVnfRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
149 String jsonString = gson.toJson(request);
150 logger.info("scaleVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId + ", bodyMessage is " + jsonString);
153 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
154 httpResponse.setStatus(HttpStatus.SC_CREATED);
157 catch(VnfmDriverException e)
160 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
161 } catch (IOException e1) {
170 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
172 public HealVnfResponse healVnf(@RequestBody HealVnfRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletResponse httpResponse)
174 String jsonString = gson.toJson(request);
175 logger.info("healVnf request: vnfmId = " + vnfmId + ", vnfInstanceId = " + vnfInstanceId + ", bodyMessage is " + jsonString);
178 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
179 httpResponse.setStatus(HttpStatus.SC_CREATED);
182 catch(VnfmDriverException e)
185 httpResponse.sendError(e.getHttpStatus(), e.getMessage());
186 } catch (IOException e1) {