fa7cec4cd63af2f7f72e3ef3bac300e6a06ddf2b
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / restapi / LcmApi.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 org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
19 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager;
20 import org.onap.vnfmdriver.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 javax.servlet.http.HttpServletResponse;
30
31 import static org.apache.http.HttpStatus.SC_CREATED;
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.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.GET;
36 import static org.springframework.web.bind.annotation.RequestMethod.POST;
37
38 /**
39  * Responsible for providing the Nokia sVNFM REST APIs
40  */
41 @Controller
42 @RequestMapping(value = BASE_URL)
43 public class LcmApi {
44     private static Logger logger = getLogger(LcmApi.class);
45
46     private final LifecycleManager lifecycleManager;
47     private final JobManager jobManager;
48
49     @Autowired
50     LcmApi(LifecycleManager lifecycleManager, JobManager jobManager) {
51         this.lifecycleManager = lifecycleManager;
52         this.jobManager = jobManager;
53     }
54
55     /**
56      * Instantiate the VNF (defined further in the VF-C driver integration documentation)
57      *
58      * @param request      the instantiation request
59      * @param vnfmId       the identifier of the VNFM
60      * @param httpResponse the HTTP response
61      * @return the instantiated VNF info
62      */
63     @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
64     @ResponseBody
65     public VnfInstantiateResponse instantiateVnf(@RequestBody VnfInstantiateRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
66         logger.info("REST: Instantiate VNF");
67         VnfInstantiateResponse response = lifecycleManager.instantiate(vnfmId, request, httpResponse);
68         httpResponse.setStatus(SC_CREATED);
69         return response;
70     }
71
72     /**
73      * Terminate the VNF (defined further in the VF-C driver integration documentation)
74      *
75      * @param request       the instantiation request
76      * @param vnfmId        the identifier of the VNFM
77      * @param vnfInstanceId the identifer of the VNF
78      * @param httpResponse  the HTTP response
79      * @return the job representing the VNF termination operation
80      */
81     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
82     @ResponseBody
83     public JobInfo terminateVnf(@RequestBody VnfTerminateRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
84         logger.info("REST: Terminate VNF");
85         return lifecycleManager.terminateVnf(vnfmId, vnfInstanceId, request, httpResponse);
86     }
87
88     /**
89      * Query the VNF (defined further in the VF-C driver integration documentation)
90      *
91      * @param vnfmId        the identifier of the VNFM
92      * @param vnfInstanceId the identifer of the VNF
93      * @param httpResponse  the HTTP response
94      * @return the VNF info
95      */
96     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = GET, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
97     @ResponseBody
98     public VnfInfo queryVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
99         logger.info("REST: Query VNF");
100         return lifecycleManager.queryVnf(vnfmId, vnfInstanceId);
101     }
102
103     /**
104      * Query the job (defined further in the VF-C driver integration documentation)
105      *
106      * @param jobId        the identifer of the job
107      * @param vnfmId       the identifier of the VNFM
108      * @param httpResponse the HTTP response
109      * @return the instantiated VNF info
110      */
111     @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
112     @ResponseBody
113     public JobDetailInfo getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
114         logger.debug("REST: Query job");
115         return jobManager.getJob(vnfmId, jobId);
116     }
117
118     /**
119      * Scale the VNF (defined further in the VF-C driver integration documentation)
120      *
121      * @param request       the scaling request
122      * @param vnfmId        the identifier of the VNFM
123      * @param vnfInstanceId the identifier of the VNF
124      * @param httpResponse  the HTTP response
125      * @return the job representing the scaling operation
126      */
127     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
128     @ResponseBody
129     public JobInfo scaleVnf(@RequestBody VnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
130         logger.info("REST: Scale VNF");
131         return lifecycleManager.scaleVnf(vnfmId, vnfInstanceId, request, httpResponse);
132     }
133
134     /**
135      * Heal the VNF (defined further in the VF-C driver integration documentation)
136      *
137      * @param request       the healing request
138      * @param vnfmId        the identifier of the VNFM
139      * @param vnfInstanceId the identifier of the VNF
140      * @param httpResponse  the HTTP response
141      * @return the job representing the healing operation
142      */
143     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
144     @ResponseBody
145     public JobInfo healVnf(@RequestBody VnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
146         logger.info("REST: Heal VNF");
147         return lifecycleManager.healVnf(vnfmId, vnfInstanceId, request, httpResponse);
148     }
149 }