2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vfc;
23 import javax.ws.rs.Consumes;
24 import javax.ws.rs.DELETE;
25 import javax.ws.rs.POST;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.onap.so.adapters.vfc.exceptions.ApplicationException;
33 import org.onap.so.adapters.vfc.model.NSResourceInputParameter;
34 import org.onap.so.adapters.vfc.model.NsOperationKey;
35 import org.onap.so.adapters.vfc.model.RestfulResponse;
36 import org.onap.so.adapters.vfc.util.JsonUtil;
37 import org.onap.so.adapters.vfc.util.ValidateUtil;
38 import org.onap.so.logger.MsoLogger;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
43 * The rest class for VF-c Adapter <br>
48 * @version ONAP Amsterdam Release 2017-08-28
51 @Path("/v1/vfcadapter")
52 public class VfcAdapterRest {
54 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, VfcAdapterRest.class);
57 private VfcManager driverMgr ;
59 public VfcAdapterRest() {
66 * @param data http request
68 * @since ONAP Amsterdam Release
72 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
73 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
74 public Response createNfvoNs(String data) {
76 ValidateUtil.assertObjectNotNull(data);
77 LOGGER.debug("body from request is {}" + data);
78 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
79 RestfulResponse rsp = driverMgr.createNs(nsInput);
80 return buildResponse(rsp);
81 } catch(ApplicationException e) {
82 LOGGER.debug("ApplicationException: ", e);
83 return e.buildErrorResponse();
88 * Delete NS instance<br>
90 * @param data The http request
91 * @param nsInstanceId The NS instance id
93 * @since ONAP Amsterdam Release
96 @Path("/ns/{nsInstanceId}")
97 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
98 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
99 public Response deleteNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
102 ValidateUtil.assertObjectNotNull(data);
103 LOGGER.debug("body from request is {}" + data);
104 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
105 RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId);
106 return buildResponse(rsp);
107 } catch(ApplicationException e) {
108 LOGGER.debug("ApplicationException: ", e);
109 return e.buildErrorResponse();
114 * Query Operation job status <br>
116 * @param data The Http Request
117 * @param jobId The job id
119 * @since ONAP Amsterdam Release
122 @Path("/jobs/{jobId}")
123 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
124 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
125 public Response queryNfvoJobStatus(String data, @PathParam("jobId") String jobId) {
127 ValidateUtil.assertObjectNotNull(data);
128 LOGGER.debug("body from request is {}" + data);
129 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
130 RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId);
131 return buildResponse(rsp);
132 } catch(ApplicationException e) {
133 LOGGER.debug("ApplicationException: ", e);
134 return e.buildErrorResponse();
139 * Instantiate NS instance <br>
141 * @param data The http request
142 * @param nsInstanceId The NS instance id
144 * @since ONAP Amsterdam Release
147 @Path("/ns/{nsInstanceId}/instantiate")
148 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
149 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
150 public Response instantiateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
152 ValidateUtil.assertObjectNotNull(data);
153 LOGGER.debug("body from request is {}" + data);
154 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
155 RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput);
156 return buildResponse(rsp);
157 } catch(ApplicationException e) {
158 LOGGER.debug("ApplicationException: ", e);
159 return e.buildErrorResponse();
164 * Terminate NS instance <br>
166 * @param data The http request
167 * @param nsInstanceId The NS instance id
169 * @since ONAP Amsterdam Release
172 @Path("/ns/{nsInstanceId}/terminate")
173 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
174 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
175 public Response terminateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
177 ValidateUtil.assertObjectNotNull(data);
178 LOGGER.debug("body from request is {}" + data);
179 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
180 RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId);
181 return buildResponse(rsp);
182 } catch(ApplicationException e) {
183 LOGGER.debug("ApplicationException: ", e);
184 return e.buildErrorResponse();
192 * @param servletReq The http request
193 * @param nsInstanceId The NS instance id
195 * @since ONAP Amsterdam Release
198 @Path("/ns/{nsInstanceId}/scale")
199 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
200 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
201 public Response scaleNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
203 ValidateUtil.assertObjectNotNull(data);
204 LOGGER.debug("Scale Ns Request Received.Body from request is {}" + data);
205 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
206 RestfulResponse rsp = driverMgr.scaleNs(nsInstanceId, nsInput);
207 return buildResponse(rsp);
208 } catch(ApplicationException e) {
209 LOGGER.debug("ApplicationException: ", e);
210 return e.buildErrorResponse();
216 * build response from restful response <br>
218 * @param rsp general response object
220 * @since ONAP Amsterdam Release
222 private Response buildResponse(RestfulResponse rsp) {
223 return Response.status(rsp.getStatus()).entity(rsp.getResponseContent()).build();