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.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
18 import javax.servlet.http.HttpServletResponse;
19 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.so.SoV2LifecycleManager;
20 import org.onap.vnfmadapter.so.v2.model.*;
21 import org.slf4j.Logger;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.PathVariable;
25 import org.springframework.web.bind.annotation.RequestBody;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.ResponseBody;
29 import static javax.servlet.http.HttpServletResponse.SC_CREATED;
30 import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.Constants.BASE_URL;
33 import static org.slf4j.LoggerFactory.getLogger;
34 import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
35 import static org.springframework.web.bind.annotation.RequestMethod.*;
38 * Responsible for providing the Nokia sVNFM REST APIs
41 @RequestMapping(value = BASE_URL + "/so/v2")
42 public class SoV2Api {
43 private static Logger logger = getLogger(SoV2Api.class);
45 private final SoV2LifecycleManager soLifecycleManager;
48 SoV2Api(SoV2LifecycleManager lifecycleManager) {
49 this.soLifecycleManager = lifecycleManager;
55 * @param request the creation request
56 * @param vnfIdInAai the identifier of the VNF in A&AI
57 * @param httpResponse the HTTP response
58 * @return the descriptor of the created VNF
60 @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = POST, consumes = APPLICATION_JSON_VALUE)
62 public void createVnf(@RequestBody SoV2VnfCreateRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, HttpServletResponse httpResponse) {
63 logger.info("REST: Create the VNF");
64 soLifecycleManager.createVnf(vnfIdInAai, request, httpResponse);
65 httpResponse.setStatus(SC_NO_CONTENT);
71 * @param request the creation request
72 * @param vnfIdInAai the identifier of the VNF in A&AI
73 * @param httpResponse the HTTP response
74 * @return the descriptor of the created VNF
76 @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = POST, consumes = APPLICATION_JSON_VALUE)
78 public SoV2VnfQueryResponse queryVnf(@RequestBody SoV2VnfQueryRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, HttpServletResponse httpResponse) {
79 logger.info("REST: Create the VNF");
80 return soLifecycleManager.queryVnf(vnfIdInAai, request, httpResponse);
86 * @param request the termination request
87 * @param vnfIdInAai the identifier of the VNF in A&AI
88 * @param httpResponse the HTTP response
89 * @return the job representing the VNF termination operation
91 @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = DELETE, consumes = APPLICATION_JSON_VALUE)
93 public void delete(@RequestBody SoV2VnfDeleteRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, HttpServletResponse httpResponse) {
94 logger.info("REST: Deactivate the VNF");
95 soLifecycleManager.delete(vnfIdInAai, request, httpResponse);
96 httpResponse.setStatus(SC_NO_CONTENT);
102 * @param request the creation request
103 * @param vnfIdInAai the identifier of the VNF in A&AI
104 * @param httpResponse the HTTP response
105 * @return the descriptor of the created VNF
107 @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = PUT, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
109 public SoV2VnfUpdateResponse updateVnf(@RequestBody SoV2VnfUpdateRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, HttpServletResponse httpResponse) {
110 logger.info("REST: Update the VNF");
111 return soLifecycleManager.updateVnf(vnfIdInAai, request, httpResponse);
115 * Rollback update VNF
117 * @param request the rollback request
118 * @param httpResponse the HTTP response
120 @RequestMapping(value = "/vnfs/{vnfIdInAai}/rollback", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
122 public void rollback(@RequestBody SoV2RollbackVnfUpdate request, @PathVariable("vnfIdInAai") String vnfIdInAai, HttpServletResponse httpResponse) {
123 logger.info("REST: Create the VF");
124 soLifecycleManager.rollback(vnfIdInAai, request, httpResponse);
128 * Create the VF module
130 * @param request the creation request
131 * @param vnfIdInAai the identifier of the VNF in A&AI
132 * @param httpResponse the HTTP response
134 @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}", method = POST, consumes = APPLICATION_JSON_VALUE)
136 public void createVfModule(@RequestBody SoV2VfModuleCreateRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, @PathVariable("vfModuleId") String vfModuleId, HttpServletResponse httpResponse) {
137 logger.info("REST: Create the VF");
138 soLifecycleManager.createVfModule(vnfIdInAai, vfModuleId, request, httpResponse);
139 httpResponse.setStatus(SC_CREATED);
143 * Terminate the VF module
145 * @param request the termination request
146 * @param vnfIdInAai the identifier of the VNF in A&AI
147 * @param httpResponse the HTTP response
149 @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}", method = DELETE, consumes = APPLICATION_JSON_VALUE)
151 public void deleteVfModule(@RequestBody SoV2VnfDeleteRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, @PathVariable("vfModuleId") String vfModuleId, HttpServletResponse httpResponse) {
152 logger.info("REST: Deactivate the VNF");
153 soLifecycleManager.deleteVfModule(vnfIdInAai, vfModuleId, request, httpResponse);
154 httpResponse.setStatus(SC_NO_CONTENT);
158 * Update the VF module
160 * @param request the creation request
161 * @param vnfIdInAai the identifier of the VNF in A&AI
162 * @param httpResponse the HTTP response
163 * @return the descriptor of the created VNF
165 @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}", method = PUT, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
167 public SoV2VnfUpdateResponse updateVfModule(@RequestBody SoV2VnfUpdateRequest request, @PathVariable("vnfIdInAai") String vnfIdInAai, @PathVariable("vfModuleId") String vfModuleId, HttpServletResponse httpResponse) {
168 logger.info("REST: Update the VNF");
169 return soLifecycleManager.updateVfModule(vnfIdInAai, vfModuleId, request, httpResponse);
173 * Rollback update VNF
175 * @param request the rollback request
176 * @param httpResponse the HTTP response
178 @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}/rollback", method = PUT, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
180 public void rollbackVfModuleUpdate(@RequestBody SoV2RollbackVnfUpdate request, @PathVariable("vnfIdInAai") String vnfIdInAai, HttpServletResponse httpResponse) {
181 logger.info("REST: Roll back VF module update");
182 soLifecycleManager.rollback(vnfIdInAai, request, httpResponse);
186 * Provides a probe for SO to test health of VNFM adapter
188 * @param httpResponse the HTTP response
190 @RequestMapping(value = "/ping", method = GET)
191 public void testLcnConnectivity(HttpServletResponse httpResponse) {
192 httpResponse.setStatus(HttpServletResponse.SC_OK);