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.MessageEnum;
39 import org.openecomp.mso.logger.MsoLogger;
42 * The rest class for VF-c Adapter <br>
47 * @version ONAP Amsterdam Release 2017-08-28
49 @Path("/v1/vfcadapter")
50 public class VfcAdapterRest {
52 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
54 private final VfcManager driverMgr = new VfcManager();
56 public VfcAdapterRest() {
63 * @param data the http request
65 * @since ONAP Amsterdam Release
69 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
70 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
71 public Response createNfvoNs(String data) {
73 ValidateUtil.assertObjectNotNull(data);
74 LOGGER.info(MessageEnum.RA_NS_EXC, "Create NS Request Received.Body from request is :\n" + data, "org.openecomp.mso.adapters.vfc.VfcAdapterRest", "VFC Adapter");
75 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
76 RestfulResponse rsp = driverMgr.createNs(nsInput);
77 return buildResponse(rsp);
78 } catch(ApplicationException e) {
79 LOGGER.debug("ApplicationException: ", e);
80 return e.buildErrorResponse();
85 * Delete NS instance<br>
87 * @param servletReq http request
89 * @since ONAP Amsterdam Release
92 @Path("/ns/{nsInstanceId}")
93 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
94 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
95 public Response deleteNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
98 ValidateUtil.assertObjectNotNull(data);
99 LOGGER.info(MessageEnum.RA_NS_EXC, "Delete NS Request Received.Body from request is :\n" + data, "org.openecomp.mso.adapters.vfc.VfcAdapterRest", "VFC Adapter");
100 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
101 RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId);
102 return buildResponse(rsp);
103 } catch(ApplicationException e) {
104 LOGGER.debug("ApplicationException: ", e);
105 return e.buildErrorResponse();
110 * Query Operation job status <br>
112 * @param servletReq The Http Request
113 * @param jobId The job id
115 * @since ONAP Amsterdam Release
118 @Path("/jobs/{jobId}")
119 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
120 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
121 public Response queryNfvoJobStatus(String data, @PathParam("jobId") String jobId) {
123 ValidateUtil.assertObjectNotNull(data);
124 LOGGER.info(MessageEnum.RA_NS_EXC, "Query Job Request Received.Body from request is :\n" + data, "org.openecomp.mso.adapters.vfc.VfcAdapterRest", "VFC Adapter");
125 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
126 RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId);
127 return buildResponse(rsp);
128 } catch(ApplicationException e) {
129 LOGGER.debug("ApplicationException: ", e);
130 return e.buildErrorResponse();
135 * Instantiate NS instance <br>
137 * @param servletReq The http request
138 * @param nsInstanceId The NS instance id
140 * @since ONAP Amsterdam Release
143 @Path("/ns/{nsInstanceId}/instantiate")
144 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
145 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
146 public Response instantiateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
148 ValidateUtil.assertObjectNotNull(data);
149 LOGGER.info(MessageEnum.RA_NS_EXC, "Instantiate Ns Request Received.Body from request is :\n" + data, "org.openecomp.mso.adapters.vfc.VfcAdapterRest", "VFC Adapter");
150 NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class);
151 RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput);
152 return buildResponse(rsp);
153 } catch(ApplicationException e) {
154 LOGGER.debug("ApplicationException: ", e);
155 return e.buildErrorResponse();
160 * Terminate NS instance <br>
162 * @param servletReq The http request
163 * @param nsInstanceId The NS instance id
165 * @since ONAP Amsterdam Release
168 @Path("/ns/{nsInstanceId}/terminate")
169 @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
170 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
171 public Response terminateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) {
173 ValidateUtil.assertObjectNotNull(data);
174 LOGGER.info(MessageEnum.RA_NS_EXC, "Terminate Ns Request Received.Body from request is :\n" + data, "org.openecomp.mso.adapters.vfc.VfcAdapterRest", "VFC Adapter");
175 NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class);
176 RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId);
177 return buildResponse(rsp);
178 } catch(ApplicationException e) {
179 LOGGER.debug("ApplicationException: ", e);
180 return e.buildErrorResponse();
185 * build response from restful response <br>
187 * @param rsp general response object
189 * @since ONAP Amsterdam Release
191 private Response buildResponse(RestfulResponse rsp) {
192 return Response.status(rsp.getStatus()).entity(rsp.getResponseContent()).build();