b2c833bb1e913ff3ef141e6d9ae593e51b8a0492
[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.DriverProperties.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     //private final LifecycleManager d;
47     @Autowired
48     SoApi(SoLifecycleManager lifecycleManager) {
49         this.soLifecycleManager = lifecycleManager;
50     }
51
52     /**
53      * Create the VNF
54      *
55      * @param request      the creation request
56      * @param vnfmId       the identifier of the VNFM
57      * @param httpResponse the HTTP response
58      * @return the descriptor of the created VNF
59      */
60     @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
61     @ResponseBody
62     public SoVnfCreationResponse createVnf(@RequestBody SoVnfCreationRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
63         logger.info("REST: Create the VNF");
64         SoVnfCreationResponse response = soLifecycleManager.create(vnfmId, request);
65         httpResponse.setStatus(SC_CREATED);
66         return response;
67     }
68
69     /**
70      * Activate the VNF
71      *
72      * @param request      the activation request
73      * @param vnfmId       the identifier of the VNFM
74      * @param httpResponse the HTTP response
75      * @return the descriptor of the created VNF
76      */
77     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
78     @ResponseBody
79     public SoJobHandler activateVnf(@RequestBody SoVnfActivationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
80         logger.info("REST: Create the VNF");
81         return soLifecycleManager.activate(vnfmId, vnfId, request, httpResponse);
82     }
83
84     /**
85      * Execute custom operation on the VNF
86      *
87      * @param request      the custom operation request
88      * @param vnfmId       the identifier of the VNFM
89      * @param httpResponse the HTTP response
90      * @return the descriptor of the created VNF
91      */
92     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/customOperation", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
93     @ResponseBody
94     public SoJobHandler executeCustomOperation(@RequestBody SoVnfCustomOperation request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
95         logger.info("REST: Create the VNF");
96         return soLifecycleManager.customOperation(vnfmId, vnfId, request, httpResponse);
97     }
98
99     /**
100      * Terminate the VNF
101      *
102      * @param request      the termination request
103      * @param vnfmId       the identifier of the VNFM
104      * @param vnfId        the identifier of the VNF
105      * @param httpResponse the HTTP response
106      * @return the job representing the VNF termination operation
107      */
108     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
109     @ResponseBody
110     public SoJobHandler deactivateVnf(@RequestBody SoVnfTerminationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
111         logger.info("REST: Deactivate VNF");
112         return soLifecycleManager.deactivate(vnfmId, vnfId, request, httpResponse);
113     }
114
115     /**
116      * Delete the VNF
117      *
118      * @param vnfmId       the identifier of the VNFM
119      * @param vnfId        the identifier of the VNF
120      * @param httpResponse the HTTP response
121      */
122     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = DELETE)
123     public void deleteVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
124         logger.info("REST: Delete VNF");
125         soLifecycleManager.delete(vnfmId, vnfId);
126         httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
127     }
128
129     /**
130      * Query the job
131      *
132      * @param jobId        the identifier of the job
133      * @param vnfmId       the identifier of the VNFM
134      * @param httpResponse the HTTP response
135      * @return the instantiated VNF info
136      */
137     @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
138     @ResponseBody
139     public SoJobDetail getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
140         logger.debug("REST: Query the job");
141         return soLifecycleManager.getJobDetails(vnfmId, jobId);
142     }
143
144     /**
145      * Scale the VNF (defined further in the VF-C driver integration documentation)
146      *
147      * @param request      the scaling request
148      * @param vnfmId       the identifier of the VNFM
149      * @param vnfId        the identifier of the VNF
150      * @param httpResponse the HTTP response
151      * @return the job representing the scaling operation
152      */
153     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
154     @ResponseBody
155     public SoJobHandler scaleVnf(@RequestBody SoVnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
156         logger.info("REST: Scale the VNF");
157         return soLifecycleManager.scale(vnfmId, vnfId, request, httpResponse);
158     }
159
160     /**
161      * Heal the VNF (defined further in the VF-C driver integration documentation)
162      *
163      * @param request       the healing request
164      * @param vnfmId        the identifier of the VNFM
165      * @param vnfInstanceId the identifier of the VNF
166      * @param httpResponse  the HTTP response
167      * @return the job representing the healing operation
168      */
169     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
170     @ResponseBody
171     public SoJobHandler healVnf(@RequestBody SoVnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
172         logger.info("REST: Heal the VNF");
173         return soLifecycleManager.heal(vnfmId, vnfInstanceId, request, httpResponse);
174     }
175 }