Fix sonar issues
[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         //FIXME
68
69         VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(vnfmId, request, httpResponse);
70         httpResponse.setStatus(SC_CREATED);
71         return response;
72     }
73
74     /**
75      * Terminate the VNF (defined further in the VF-C driver integration documentation)
76      *
77      * @param request       the instantiation request
78      * @param vnfmId        the identifier of the VNFM
79      * @param vnfInstanceId the identifer of the VNF
80      * @param httpResponse  the HTTP response
81      * @return the job representing the VNF termination operation
82      */
83     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
84     @ResponseBody
85     public JobInfo terminateVnf(@RequestBody VnfTerminateRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
86         logger.info("REST: Terminate VNF");
87         return lifecycleManager.terminateVnf(vnfmId, vnfInstanceId, request, httpResponse);
88     }
89
90     /**
91      * Query the VNF (defined further in the VF-C driver integration documentation)
92      *
93      * @param vnfmId        the identifier of the VNFM
94      * @param vnfInstanceId the identifer of the VNF
95      * @param httpResponse  the HTTP response
96      * @return the VNF info
97      */
98     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = GET, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
99     @ResponseBody
100     public VnfInfo queryVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
101         logger.info("REST: Query VNF");
102         return lifecycleManager.queryVnf(vnfmId, vnfInstanceId);
103     }
104
105     /**
106      * Query the job (defined further in the VF-C driver integration documentation)
107      *
108      * @param jobId        the identifer of the job
109      * @param vnfmId       the identifier of the VNFM
110      * @param httpResponse the HTTP response
111      * @return the instantiated VNF info
112      */
113     @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
114     @ResponseBody
115     public JobDetailInfo getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
116         logger.debug("REST: Query job");
117         return jobManager.getJob(vnfmId, jobId);
118     }
119
120     /**
121      * Scale the VNF (defined further in the VF-C driver integration documentation)
122      *
123      * @param request       the scaling request
124      * @param vnfmId        the identifier of the VNFM
125      * @param vnfInstanceId the identifier of the VNF
126      * @param httpResponse  the HTTP response
127      * @return the job representing the scaling operation
128      */
129     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
130     @ResponseBody
131     public JobInfo scaleVnf(@RequestBody VnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
132         logger.info("REST: Scale VNF");
133         return lifecycleManager.scaleVnf(vnfmId, vnfInstanceId, request, httpResponse);
134     }
135
136     /**
137      * Heal the VNF (defined further in the VF-C driver integration documentation)
138      *
139      * @param request       the healing request
140      * @param vnfmId        the identifier of the VNFM
141      * @param vnfInstanceId the identifier of the VNF
142      * @param httpResponse  the HTTP response
143      * @return the job representing the healing operation
144      */
145     @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
146     @ResponseBody
147     public JobInfo healVnf(@RequestBody VnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
148         logger.info("REST: Heal VNF");
149         return lifecycleManager.healVnf(vnfmId, vnfInstanceId, request, httpResponse);
150     }
151 }