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