Add SO APIs to Nokia VNFM adapter
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / restapi / SoV2Api.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 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
17
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;
28
29 import static javax.servlet.http.HttpServletResponse.SC_CREATED;
30 import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
31
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.*;
36
37 /**
38  * Responsible for providing the Nokia sVNFM REST APIs
39  */
40 @Controller
41 @RequestMapping(value = BASE_URL + "/so/v2")
42 public class SoV2Api {
43     private static Logger logger = getLogger(SoV2Api.class);
44
45     private final SoV2LifecycleManager soLifecycleManager;
46
47     @Autowired
48     SoV2Api(SoV2LifecycleManager lifecycleManager) {
49         this.soLifecycleManager = lifecycleManager;
50     }
51
52     /**
53      * Create the VNF
54      *
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
59      */
60     @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = POST, consumes = APPLICATION_JSON_VALUE)
61     @ResponseBody
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);
66     }
67
68     /**
69      * Query the VNF
70      *
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
75      */
76     @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = POST, consumes = APPLICATION_JSON_VALUE)
77     @ResponseBody
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);
81     }
82
83     /**
84      * Terminate the VNF
85      *
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
90      */
91     @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = DELETE, consumes = APPLICATION_JSON_VALUE)
92     @ResponseBody
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);
97     }
98
99     /**
100      * Update the VNF
101      *
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
106      */
107     @RequestMapping(value = "/vnfs/{vnfIdInAai}", method = PUT, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
108     @ResponseBody
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);
112     }
113
114     /**
115      * Rollback update VNF
116      *
117      * @param request      the rollback request
118      * @param httpResponse the HTTP response
119      */
120     @RequestMapping(value = "/vnfs/{vnfIdInAai}/rollback", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
121     @ResponseBody
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);
125     }
126
127     /**
128      * Create the VF module
129      *
130      * @param request      the creation request
131      * @param vnfIdInAai   the identifier of the VNF in A&AI
132      * @param httpResponse the HTTP response
133      */
134     @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}", method = POST, consumes = APPLICATION_JSON_VALUE)
135     @ResponseBody
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);
140     }
141
142     /**
143      * Terminate the VF module
144      *
145      * @param request      the termination request
146      * @param vnfIdInAai   the identifier of the VNF in A&AI
147      * @param httpResponse the HTTP response
148      */
149     @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}", method = DELETE, consumes = APPLICATION_JSON_VALUE)
150     @ResponseBody
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);
155     }
156
157     /**
158      * Update the VF module
159      *
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
164      */
165     @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}", method = PUT, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
166     @ResponseBody
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);
170     }
171
172     /**
173      * Rollback update VNF
174      *
175      * @param request      the rollback request
176      * @param httpResponse the HTTP response
177      */
178     @RequestMapping(value = "/vfmodule/{vnfIdInAai}/{vfModuleId}/rollback", method = PUT, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
179     @ResponseBody
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);
183     }
184
185     /**
186      * Provides a probe for SO to test health of VNFM adapter
187      *
188      * @param httpResponse the HTTP response
189      */
190     @RequestMapping(value = "/ping", method = GET)
191     public void testLcnConnectivity(HttpServletResponse httpResponse) {
192         httpResponse.setStatus(HttpServletResponse.SC_OK);
193     }
194 }