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.Constants.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;
47 SoApi(SoLifecycleManager lifecycleManager) {
48 this.soLifecycleManager = lifecycleManager;
54 * @param request the creation request
55 * @param vnfmId the identifier of the VNFM
56 * @param httpResponse the HTTP response
57 * @return the descriptor of the created VNF
59 @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
61 public SoVnfCreationResponse createVnf(@RequestBody SoVnfCreationRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
62 logger.info("REST: Create the VNF");
63 SoVnfCreationResponse response = soLifecycleManager.create(vnfmId, request);
64 httpResponse.setStatus(SC_CREATED);
71 * @param request the activation request
72 * @param vnfmId the identifier of the VNFM
73 * @param httpResponse the HTTP response
74 * @return the descriptor of the created VNF
76 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
78 public SoJobHandler activateVnf(@RequestBody SoVnfActivationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
79 logger.info("REST: Activate the VNF");
80 return soLifecycleManager.activate(vnfmId, vnfId, request, httpResponse);
84 * Execute custom operation on the VNF
86 * @param request the custom operation request
87 * @param vnfmId the identifier of the VNFM
88 * @param httpResponse the HTTP response
89 * @return the descriptor of the created VNF
91 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/customOperation", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
93 public SoJobHandler executeCustomOperation(@RequestBody SoVnfCustomOperation request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
94 logger.info("REST: Execute custom operation on the VNF");
95 return soLifecycleManager.customOperation(vnfmId, vnfId, request, httpResponse);
101 * @param request the termination request
102 * @param vnfmId the identifier of the VNFM
103 * @param vnfId the identifier of the VNF
104 * @param httpResponse the HTTP response
105 * @return the job representing the VNF termination operation
107 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
109 public SoJobHandler deactivateVnf(@RequestBody SoVnfTerminationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
110 logger.info("REST: Deactivate the VNF");
111 return soLifecycleManager.deactivate(vnfmId, vnfId, request, httpResponse);
117 * @param vnfmId the identifier of the VNFM
118 * @param vnfId the identifier of the VNF
119 * @param httpResponse the HTTP response
121 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = DELETE)
122 public void deleteVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
123 logger.info("REST: Delete the VNF");
124 soLifecycleManager.delete(vnfmId, vnfId);
125 httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
131 * @param jobId the identifier of the job
132 * @param vnfmId the identifier of the VNFM
133 * @param httpResponse the HTTP response
134 * @return the instantiated VNF info
136 @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
138 public SoJobDetail getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
139 logger.trace("REST: Query the job");
140 return soLifecycleManager.getJobDetails(vnfmId, jobId);
144 * Scale the VNF (defined further in the VF-C driver integration documentation)
146 * @param request the scaling request
147 * @param vnfmId the identifier of the VNFM
148 * @param vnfId the identifier of the VNF
149 * @param httpResponse the HTTP response
150 * @return the job representing the scaling operation
152 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
154 public SoJobHandler scaleVnf(@RequestBody SoVnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
155 logger.info("REST: Scale the VNF");
156 return soLifecycleManager.scale(vnfmId, vnfId, request, httpResponse);
160 * Heal the VNF (defined further in the VF-C driver integration documentation)
162 * @param request the healing request
163 * @param vnfmId the identifier of the VNFM
164 * @param vnfInstanceId the identifier of the VNF
165 * @param httpResponse the HTTP response
166 * @return the job representing the healing operation
168 @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
170 public SoJobHandler healVnf(@RequestBody SoVnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
171 logger.info("REST: Heal the VNF");
172 return soLifecycleManager.heal(vnfmId, vnfInstanceId, request, httpResponse);