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 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;
29 import javax.servlet.http.HttpServletResponse;
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;
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");
70 VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(vnfmId, request, httpResponse);
71 httpResponse.setStatus(SC_CREATED);
76 * Terminate the VNF (defined further in the VF-C driver integration documentation)
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
84 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
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);
92 * Query the VNF (defined further in the VF-C driver integration documentation)
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
99 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = GET, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);
107 * Query the job (defined further in the VF-C driver integration documentation)
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
114 @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
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);
122 * Scale the VNF (defined further in the VF-C driver integration documentation)
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
130 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);
138 * Heal the VNF (defined further in the VF-C driver integration documentation)
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
146 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
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);