eb6c289fdbfdaf4e34e4e7cc2299f3d7899b743e
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / restapi / SoApi.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.SoLifecycleManager;
20 import org.onap.vnfmadapter.so.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
31 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.Constants.BASE_URL;
32 import static org.slf4j.LoggerFactory.getLogger;
33 import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
34 import static org.springframework.web.bind.annotation.RequestMethod.*;
35
36 /**
37  * Responsible for providing the Nokia sVNFM REST APIs
38  */
39 @Controller
40 @RequestMapping(value = BASE_URL + "/so")
41 public class SoApi {
42     private static Logger logger = getLogger(SoApi.class);
43
44     private final SoLifecycleManager soLifecycleManager;
45
46     @Autowired
47     SoApi(SoLifecycleManager lifecycleManager) {
48         this.soLifecycleManager = lifecycleManager;
49     }
50
51     /**
52      * Create the VNF
53      *
54      * @param request      the creation request
55      * @param vnfmId       the identifier of the VNFM
56      * @param httpResponse the HTTP response
57      * @return the descriptor of the created VNF
58      */
59     @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
60     @ResponseBody
61     public SoVnfCreationResponse createVnf(@RequestBody SoVnfCreationRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
62         logger.info("REST: Create the VNF");
63         SoVnfCreationResponse response = soLifecycleManager.create(vnfmId, request);
64         httpResponse.setStatus(SC_CREATED);
65         return response;
66     }
67
68     /**
69      * Activate the VNF
70      *
71      * @param request      the activation request
72      * @param vnfmId       the identifier of the VNFM
73      * @param httpResponse the HTTP response
74      * @return the descriptor of the created VNF
75      */
76     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
77     @ResponseBody
78     public SoJobHandler activateVnf(@RequestBody SoVnfActivationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
79         logger.info("REST: Activate the VNF");
80         return soLifecycleManager.activate(vnfmId, vnfId, request, httpResponse);
81     }
82
83     /**
84      * Execute custom operation on the VNF
85      *
86      * @param request      the custom operation request
87      * @param vnfmId       the identifier of the VNFM
88      * @param httpResponse the HTTP response
89      * @return the descriptor of the created VNF
90      */
91     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/customOperation", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
92     @ResponseBody
93     public SoJobHandler executeCustomOperation(@RequestBody SoVnfCustomOperation request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
94         logger.info("REST: Execute custom operation on the VNF");
95         return soLifecycleManager.customOperation(vnfmId, vnfId, request, httpResponse);
96     }
97
98     /**
99      * Terminate the VNF
100      *
101      * @param request      the termination request
102      * @param vnfmId       the identifier of the VNFM
103      * @param vnfId        the identifier of the VNF
104      * @param httpResponse the HTTP response
105      * @return the job representing the VNF termination operation
106      */
107     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
108     @ResponseBody
109     public SoJobHandler deactivateVnf(@RequestBody SoVnfTerminationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
110         logger.info("REST: Deactivate the VNF");
111         return soLifecycleManager.deactivate(vnfmId, vnfId, request, httpResponse);
112     }
113
114     /**
115      * Delete the VNF
116      *
117      * @param vnfmId       the identifier of the VNFM
118      * @param vnfId        the identifier of the VNF
119      * @param httpResponse the HTTP response
120      */
121     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = DELETE)
122     public void deleteVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
123         logger.info("REST: Delete the VNF");
124         soLifecycleManager.delete(vnfmId, vnfId);
125         httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
126     }
127
128     /**
129      * Query the job
130      *
131      * @param jobId        the identifier of the job
132      * @param vnfmId       the identifier of the VNFM
133      * @param httpResponse the HTTP response
134      * @return the instantiated VNF info
135      */
136     @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
137     @ResponseBody
138     public SoJobDetail getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
139         logger.trace("REST: Query the job");
140         return soLifecycleManager.getJobDetails(vnfmId, jobId);
141     }
142
143     /**
144      * Scale the VNF (defined further in the VF-C driver integration documentation)
145      *
146      * @param request      the scaling request
147      * @param vnfmId       the identifier of the VNFM
148      * @param vnfId        the identifier of the VNF
149      * @param httpResponse the HTTP response
150      * @return the job representing the scaling operation
151      */
152     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
153     @ResponseBody
154     public SoJobHandler scaleVnf(@RequestBody SoVnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
155         logger.info("REST: Scale the VNF");
156         return soLifecycleManager.scale(vnfmId, vnfId, request, httpResponse);
157     }
158
159     /**
160      * Heal the VNF (defined further in the VF-C driver integration documentation)
161      *
162      * @param request       the healing request
163      * @param vnfmId        the identifier of the VNFM
164      * @param vnfInstanceId the identifier of the VNF
165      * @param httpResponse  the HTTP response
166      * @return the job representing the healing operation
167      */
168     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
169     @ResponseBody
170     public SoJobHandler healVnf(@RequestBody SoVnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
171         logger.info("REST: Heal the VNF");
172         return soLifecycleManager.heal(vnfmId, vnfInstanceId, request, httpResponse);
173     }
174 }