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.onap.so.SoLifecycleManager;
20 import org.onap.vnfmadapter.so.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 static javax.servlet.http.HttpServletResponse.SC_CREATED;
31 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
32 import static org.slf4j.LoggerFactory.getLogger;
33 import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
34 import static org.springframework.web.bind.annotation.RequestMethod.*;
37 * Responsible for providing the Nokia sVNFM REST APIs
40 @RequestMapping(value = BASE_URL + "/so")
42 private static Logger logger = getLogger(SoApi.class);
44 private final SoLifecycleManager soLifecycleManager;
46 //private final LifecycleManager d;
48 SoApi(SoLifecycleManager lifecycleManager) {
49 this.soLifecycleManager = lifecycleManager;
55 * @param request the creation request
56 * @param vnfmId the identifier of the VNFM
57 * @param httpResponse the HTTP response
58 * @return the descriptor of the created VNF
60 @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
62 public SoVnfCreationResponse createVnf(@RequestBody SoVnfCreationRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
63 logger.info("REST: Create the VNF");
64 SoVnfCreationResponse response = soLifecycleManager.create(vnfmId, request);
65 httpResponse.setStatus(SC_CREATED);
72 * @param request the activation request
73 * @param vnfmId the identifier of the VNFM
74 * @param httpResponse the HTTP response
75 * @return the descriptor of the created VNF
77 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
79 public SoJobHandler activateVnf(@RequestBody SoVnfActivationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
80 logger.info("REST: Create the VNF");
81 return soLifecycleManager.activate(vnfmId, vnfId, request, httpResponse);
85 * Execute custom operation on the VNF
87 * @param request the custom operation request
88 * @param vnfmId the identifier of the VNFM
89 * @param httpResponse the HTTP response
90 * @return the descriptor of the created VNF
92 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/customOperation", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
94 public SoJobHandler executeCustomOperation(@RequestBody SoVnfCustomOperation request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
95 logger.info("REST: Create the VNF");
96 return soLifecycleManager.customOperation(vnfmId, vnfId, request, httpResponse);
102 * @param request the termination request
103 * @param vnfmId the identifier of the VNFM
104 * @param vnfId the identifier of the VNF
105 * @param httpResponse the HTTP response
106 * @return the job representing the VNF termination operation
108 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
110 public SoJobHandler deactivateVnf(@RequestBody SoVnfTerminationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
111 logger.info("REST: Deactivate VNF");
112 return soLifecycleManager.deactivate(vnfmId, vnfId, request, httpResponse);
118 * @param vnfmId the identifier of the VNFM
119 * @param vnfId the identifier of the VNF
120 * @param httpResponse the HTTP response
122 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = DELETE)
123 public void deleteVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
124 logger.info("REST: Delete VNF");
125 soLifecycleManager.delete(vnfmId, vnfId);
126 httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
132 * @param jobId the identifier of the job
133 * @param vnfmId the identifier of the VNFM
134 * @param httpResponse the HTTP response
135 * @return the instantiated VNF info
137 @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
139 public SoJobDetail getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
140 logger.debug("REST: Query the job");
141 return soLifecycleManager.getJobDetails(vnfmId, jobId);
145 * Scale the VNF (defined further in the VF-C driver integration documentation)
147 * @param request the scaling request
148 * @param vnfmId the identifier of the VNFM
149 * @param vnfId the identifier of the VNF
150 * @param httpResponse the HTTP response
151 * @return the job representing the scaling operation
153 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
155 public SoJobHandler scaleVnf(@RequestBody SoVnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
156 logger.info("REST: Scale the VNF");
157 return soLifecycleManager.scale(vnfmId, vnfId, request, httpResponse);
161 * Heal the VNF (defined further in the VF-C driver integration documentation)
163 * @param request the healing request
164 * @param vnfmId the identifier of the VNFM
165 * @param vnfInstanceId the identifier of the VNF
166 * @param httpResponse the HTTP response
167 * @return the job representing the healing operation
169 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
171 public SoJobHandler healVnf(@RequestBody SoVnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
172 logger.info("REST: Heal the VNF");
173 return soLifecycleManager.heal(vnfmId, vnfInstanceId, request, httpResponse);