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.openecomp.mso.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.openecomp.mso.adapters.vfc.exceptions.ApplicationException;
33 import org.openecomp.mso.adapters.vfc.model.NSResourceInputParameter;
34 import org.openecomp.mso.adapters.vfc.model.NsOperationKey;
35 import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
36 import org.openecomp.mso.adapters.vfc.util.JsonUtil;
37 import org.openecomp.mso.adapters.vfc.util.ValidateUtil;
38 import org.openecomp.mso.logger.MsoLogger;
41 * The rest class for VF-c Adapter <br>
46 * @version ONAP Amsterdam Release 2017-08-28
48 @Path("/v1/vfcadapter")
49 public class VfcAdapterRest {
51 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
53 private final VfcManager driverMgr = new VfcManager();
55 public VfcAdapterRest() {
62 * @param data the http request
64 * @since ONAP Amsterdam Release
68 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
69 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
70 public Response createNfvoNs(String data) {
72 ValidateUtil.assertObjectNotNull(data);
73 LOGGER.debug("body from request is {}" + data);
74 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
75 RestfulResponse rsp = driverMgr.createNs(nsInput);
76 return buildResponse(rsp);
77 } catch(ApplicationException e) {
78 LOGGER.debug("ApplicationException: ", e);
79 return e.buildErrorResponse();
84 * Delete NS instance<br>
86 * @param servletReq http request
88 * @since ONAP Amsterdam Release
91 @Path("/ns/{nsInstanceId}")
92 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
93 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
94 public Response deleteNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
97 ValidateUtil.assertObjectNotNull(data);
98 LOGGER.debug("body from request is {}" + data);
99 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
100 RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId);
101 return buildResponse(rsp);
102 } catch(ApplicationException e) {
103 LOGGER.debug("ApplicationException: ", e);
104 return e.buildErrorResponse();
109 * Query Operation job status <br>
111 * @param servletReq The Http Request
112 * @param jobId The job id
114 * @since ONAP Amsterdam Release
117 @Path("/jobs/{jobId}")
118 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
119 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
120 public Response queryNfvoJobStatus(String data, @PathParam("jobId") String jobId) {
122 ValidateUtil.assertObjectNotNull(data);
123 LOGGER.debug("body from request is {}" + data);
124 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
125 RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId);
126 return buildResponse(rsp);
127 } catch(ApplicationException e) {
128 LOGGER.debug("ApplicationException: ", e);
129 return e.buildErrorResponse();
134 * Instantiate NS instance <br>
136 * @param servletReq The http request
137 * @param nsInstanceId The NS instance id
139 * @since ONAP Amsterdam Release
142 @Path("/ns/{nsInstanceId}/instantiate")
143 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
144 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
145 public Response instantiateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
147 ValidateUtil.assertObjectNotNull(data);
148 LOGGER.debug("body from request is {}" + data);
149 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
150 RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput);
151 return buildResponse(rsp);
152 } catch(ApplicationException e) {
153 LOGGER.debug("ApplicationException: ", e);
154 return e.buildErrorResponse();
159 * Terminate NS instance <br>
161 * @param servletReq The http request
162 * @param nsInstanceId The NS instance id
164 * @since ONAP Amsterdam Release
167 @Path("/ns/{nsInstanceId}/terminate")
168 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
169 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
170 public Response terminateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
172 ValidateUtil.assertObjectNotNull(data);
173 LOGGER.debug("body from request is {}" + data);
174 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
175 RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId);
176 return buildResponse(rsp);
177 } catch(ApplicationException e) {
178 LOGGER.debug("ApplicationException: ", e);
179 return e.buildErrorResponse();
187 * @param servletReq The http request
188 * @param nsInstanceId The NS instance id
190 * @since ONAP Amsterdam Release
193 @Path("/ns/{nsInstanceId}/scale")
194 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
195 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
196 public Response scaleNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
198 ValidateUtil.assertObjectNotNull(data);
199 LOGGER.debug("Scale Ns Request Received.Body from request is {}" + data);
200 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
201 RestfulResponse rsp = driverMgr.scaleNs(nsInstanceId, nsInput);
202 return buildResponse(rsp);
203 } catch(ApplicationException e) {
204 LOGGER.debug("ApplicationException: ", e);
205 return e.buildErrorResponse();
211 * build response from restful response <br>
213 * @param rsp general response object
215 * @since ONAP Amsterdam Release
217 private Response buildResponse(RestfulResponse rsp) {
218 return Response.status(rsp.getStatus()).entity(rsp.getResponseContent()).build();