2 * Copyright 2016 ZTE 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.aai.esr.resource;
18 import com.codahale.metrics.annotation.Timed;
19 import io.swagger.annotations.Api;
20 import io.swagger.annotations.ApiOperation;
21 import io.swagger.annotations.ApiParam;
22 import io.swagger.annotations.ApiResponse;
23 import io.swagger.annotations.ApiResponses;
24 import org.eclipse.jetty.http.HttpStatus;
25 import org.onap.aai.esr.entity.db.VnfmData;
26 import org.onap.aai.esr.entity.rest.VnfmRestData;
27 import org.onap.aai.esr.exception.ExtsysException;
28 import org.onap.aai.esr.handle.VnfmHandler;
29 import org.onap.aai.esr.util.ExtsysDbUtil;
30 import org.onap.aai.esr.util.RestResponseUtil;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import java.util.ArrayList;
35 import java.util.List;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.DELETE;
38 import javax.ws.rs.GET;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.PUT;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.PathParam;
43 import javax.ws.rs.Produces;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
48 @Api(tags = {" vnfm Management "})
49 public class VnfmManager {
51 VnfmHandler handler = new VnfmHandler();
52 private static final Logger LOGGER = LoggerFactory.getLogger(VnfmManager.class);
59 @ApiOperation(value = "get all vnfm ")
60 @Produces(MediaType.APPLICATION_JSON)
61 @ApiResponses(value = {
62 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
63 response = String.class),
64 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
65 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
66 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
67 response = String.class)})
69 public Response queryVnfmList() {
70 LOGGER.info("start query all vnfm!");
73 list = handler.getAll();
74 } catch (ExtsysException error) {
75 LOGGER.error("query all vnfm failed.errorMsg:" + error.getErrorMsg());
76 return RestResponseUtil.getErrorResponse(error);
78 if (list == null || list.size() <= 0) {
79 LOGGER.info("query all vnfm end.no match condition record");
80 return RestResponseUtil.getSuccessResponse(new ArrayList<VnfmRestData>());
82 LOGGER.info("query all vnfm end.size:" + list.size());
83 ArrayList<VnfmRestData> restList = new ArrayList<VnfmRestData>();
84 for (int i = 0; i < list.size(); i++) {
85 restList.add(new VnfmRestData(list.get(i)));
87 return RestResponseUtil.getSuccessResponse(restList);
97 @ApiOperation(value = "get vnfm by id")
98 @Produces(MediaType.APPLICATION_JSON)
99 @ApiResponses(value = {
100 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
101 response = String.class),
102 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
103 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
104 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
105 response = String.class)})
107 public Response queryVnfmById(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
108 LOGGER.info("start query vnfm by id." + vnfmId);
111 list = handler.getVnfmById(vnfmId);
112 } catch (ExtsysException error) {
113 LOGGER.error("query vnfm failed.errorMsg:" + error.getErrorMsg());
114 return RestResponseUtil.getErrorResponse(error);
116 if (list == null || list.size() <= 0) {
117 LOGGER.info("query vnfm end.no match condition record");
118 return RestResponseUtil.getSuccessResponse(null);
120 LOGGER.info("query vnfm end.info:" + ExtsysDbUtil.objectToString(list));
121 return RestResponseUtil.getSuccessResponse(new VnfmRestData(list.get(0)));
130 @ApiOperation(value = "delete a vnfm")
131 @ApiResponses(value = {
132 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
133 response = String.class),
134 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
135 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
136 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
137 response = String.class)})
139 public Response delVnfm(@ApiParam(value = "vnfm id") @PathParam("vnfmId") String vnfmId) {
140 LOGGER.info("start delete vnfm .id:" + vnfmId);
142 handler.delete(vnfmId);
143 } catch (ExtsysException error) {
144 LOGGER.error("delete vnfm failed.errorMsg:" + error.getErrorMsg());
145 return RestResponseUtil.getErrorResponse(error);
147 LOGGER.info(" delete vnfm end !");
148 return Response.noContent().build();
156 @Consumes(MediaType.APPLICATION_JSON)
157 @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
158 @ApiOperation(value = "update a vnfm")
159 @ApiResponses(value = {
160 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
161 response = String.class),
162 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
163 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
164 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
165 response = String.class)})
167 public Response updateVnfms(@ApiParam(value = "vnfm", required = true) VnfmData vnfm,
168 @ApiParam(value = "vnfm id", required = true) @PathParam("vnfmId") String vnfmId) {
169 LOGGER.info("start update vnfm .id:" + vnfmId + " info:" + ExtsysDbUtil.objectToString(vnfm));
172 newData = handler.update(vnfm, vnfmId);
173 } catch (ExtsysException error) {
174 LOGGER.error("update vnfm failed.errorMsg:" + error.getErrorMsg());
175 return RestResponseUtil.getErrorResponse(error);
177 LOGGER.info(" update vnfm end !");
178 return RestResponseUtil.getSuccessResponse(new VnfmRestData(newData));
186 @Consumes(MediaType.APPLICATION_JSON)
187 @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
188 @ApiOperation(value = "create a vnfm")
189 @ApiResponses(value = {
190 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
191 response = String.class),
192 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
193 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
194 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
195 response = String.class)})
197 public Response addVnfms(@ApiParam(value = "vnfm", required = true) VnfmData vnfm) {
198 LOGGER.info("start add vnfm" + " info:" + ExtsysDbUtil.objectToString(vnfm));
201 vnfmData = handler.add(vnfm);
202 } catch (ExtsysException error) {
203 LOGGER.error("add vnfm failed.errorMsg:" + error.getErrorMsg());
204 return RestResponseUtil.getErrorResponse(error);
206 LOGGER.info(" add vnfm end !");
207 return RestResponseUtil.getCreateSussceeResponse(new VnfmRestData(vnfmData));