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 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;
39 * Responsible for providing the Nokia sVNFM REST APIs
42 @RequestMapping(value = BASE_URL)
44 private static Logger logger = getLogger(LcmApi.class);
46 private final LifecycleManager lifecycleManager;
47 private final JobManager jobManager;
50 LcmApi(LifecycleManager lifecycleManager, JobManager jobManager) {
51 this.lifecycleManager = lifecycleManager;
52 this.jobManager = jobManager;
56 * Instantiate the VNF (defined further in the VF-C driver integration documentation)
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
63 @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
65 public VnfInstantiateResponse instantiateVnf(@RequestBody VnfInstantiateRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
66 logger.info("REST: Instantiate VNF");
67 VnfInstantiateResponse response = lifecycleManager.instantiate(vnfmId, request, httpResponse);
68 httpResponse.setStatus(SC_CREATED);
73 * Terminate the VNF (defined further in the VF-C driver integration documentation)
75 * @param request the instantiation request
76 * @param vnfmId the identifier of the VNFM
77 * @param vnfInstanceId the identifer of the VNF
78 * @param httpResponse the HTTP response
79 * @return the job representing the VNF termination operation
81 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
83 public JobInfo terminateVnf(@RequestBody VnfTerminateRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
84 logger.info("REST: Terminate VNF");
85 return lifecycleManager.terminateVnf(vnfmId, vnfInstanceId, request, httpResponse);
89 * Query the VNF (defined further in the VF-C driver integration documentation)
91 * @param vnfmId the identifier of the VNFM
92 * @param vnfInstanceId the identifer of the VNF
93 * @param httpResponse the HTTP response
94 * @return the VNF info
96 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = GET, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
98 public VnfInfo queryVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
99 logger.info("REST: Query VNF");
100 return lifecycleManager.queryVnf(vnfmId, vnfInstanceId);
104 * Query the job (defined further in the VF-C driver integration documentation)
106 * @param jobId the identifer of the job
107 * @param vnfmId the identifier of the VNFM
108 * @param httpResponse the HTTP response
109 * @return the instantiated VNF info
111 @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
113 public JobDetailInfo getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
114 logger.debug("REST: Query job");
115 return jobManager.getJob(vnfmId, jobId);
119 * Scale the VNF (defined further in the VF-C driver integration documentation)
121 * @param request the scaling request
122 * @param vnfmId the identifier of the VNFM
123 * @param vnfInstanceId the identifier of the VNF
124 * @param httpResponse the HTTP response
125 * @return the job representing the scaling operation
127 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
129 public JobInfo scaleVnf(@RequestBody VnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
130 logger.info("REST: Scale VNF");
131 return lifecycleManager.scaleVnf(vnfmId, vnfInstanceId, request, httpResponse);
135 * Heal the VNF (defined further in the VF-C driver integration documentation)
137 * @param request the healing request
138 * @param vnfmId the identifier of the VNFM
139 * @param vnfInstanceId the identifier of the VNF
140 * @param httpResponse the HTTP response
141 * @return the job representing the healing operation
143 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
145 public JobInfo healVnf(@RequestBody VnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
146 logger.info("REST: Heal VNF");
147 return lifecycleManager.healVnf(vnfmId, vnfInstanceId, request, httpResponse);