2 * Copyright 2016-2017, Nokia Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
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;
30 import static javax.servlet.http.HttpServletResponse.SC_CREATED;
31 import static java.util.Optional.empty;
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;
40 * Responsible for providing the Nokia sVNFM REST APIs
43 @RequestMapping(value = BASE_URL)
45 private static Logger logger = getLogger(LcmApi.class);
47 private final LifecycleManager lifecycleManager;
48 private final JobManager jobManager;
51 LcmApi(LifecycleManager lifecycleManager, JobManager jobManager) {
52 this.lifecycleManager = lifecycleManager;
53 this.jobManager = jobManager;
57 * Instantiate the VNF (defined further in the VF-C driver integration documentation)
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
64 @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);
74 * Terminate the VNF (defined further in the VF-C driver integration documentation)
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
82 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
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);
90 * Query the VNF (defined further in the VF-C driver integration documentation)
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
97 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = GET, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);
105 * Query the job (defined further in the VF-C driver integration documentation)
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
112 @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
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);
120 * Scale the VNF (defined further in the VF-C driver integration documentation)
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
128 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);
136 * Heal the VNF (defined further in the VF-C driver integration documentation)
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
144 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);