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