2 * Copyright 2016-2017 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;
25 import org.eclipse.jetty.http.HttpStatus;
26 import org.onap.aai.esr.entity.aai.SdncData;
27 import org.onap.aai.esr.entity.rest.ThirdPartySdncRestData;
28 import org.onap.aai.esr.exception.ExtsysException;
29 import org.onap.aai.esr.handle.SdncHandler;
30 import org.onap.aai.esr.util.ExtsysDbUtil;
31 import org.onap.aai.esr.util.RestResponseUtil;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import java.util.ArrayList;
36 import java.util.List;
37 import javax.ws.rs.Consumes;
38 import javax.ws.rs.DELETE;
39 import javax.ws.rs.GET;
40 import javax.ws.rs.POST;
41 import javax.ws.rs.PUT;
42 import javax.ws.rs.Path;
43 import javax.ws.rs.PathParam;
44 import javax.ws.rs.Produces;
45 import javax.ws.rs.core.MediaType;
46 import javax.ws.rs.core.Response;
48 @Path("/sdncontrollers")
49 @Api(tags = {" sdnc Management "})
50 public class SdncManager {
52 SdncHandler handler = new SdncHandler();
53 private static final Logger LOGGER = LoggerFactory.getLogger(SdncManager.class);
60 @ApiOperation(value = "get all sdnc ")
61 @Produces(MediaType.APPLICATION_JSON)
62 @ApiResponses(value = {
63 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
64 response = String.class),
65 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
66 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
67 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
68 response = String.class)})
70 public Response querysdncList() {
71 LOGGER.info("start query all sdnc!");
74 list = handler.getAll();
75 } catch (ExtsysException error) {
76 LOGGER.error("query all sdnc failed.errorMsg:" + error.getErrorMsg());
77 return RestResponseUtil.getErrorResponse(error);
79 if (list == null || list.size() <= 0) {
80 LOGGER.info("query all sdnc end.no match condition record");
81 return RestResponseUtil.getSuccessResponse(new ArrayList<ThirdPartySdncRestData>());
83 LOGGER.info("query all sdnc end.size:" + list.size());
84 ArrayList<ThirdPartySdncRestData> restList = new ArrayList<ThirdPartySdncRestData>();
85 for (int i = 0; i < list.size(); i++) {
86 // restList.add(new ThirdPartySdncRestData(list.get(i)));
87 restList.add(new ThirdPartySdncRestData());
89 return RestResponseUtil.getSuccessResponse(restList);
99 @ApiOperation(value = "get sdnc by id")
100 @Produces(MediaType.APPLICATION_JSON)
101 @ApiResponses(value = {
102 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
103 response = String.class),
104 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
105 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
106 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
107 response = String.class)})
109 public Response querysdncById(@ApiParam(value = "sdnc id") @PathParam("sdncId") String sdncId) {
110 LOGGER.info("start query sdnc by id." + sdncId);
113 list = handler.getSdncById(sdncId);
114 } catch (ExtsysException error) {
115 LOGGER.error("query sdnc failed.errorMsg:" + error.getErrorMsg());
116 return RestResponseUtil.getErrorResponse(error);
118 if (list == null || list.size() <= 0) {
119 LOGGER.info("query sdnc end.no match condition record");
120 return RestResponseUtil.getSuccessResponse(null);
122 LOGGER.info("query sdnc end.info:" + ExtsysDbUtil.objectToString(list));
123 // return RestResponseUtil.getSuccessResponse(new ThirdPartySdncRestData(list.get(0)));
124 return RestResponseUtil.getSuccessResponse(new ThirdPartySdncRestData());
133 @ApiOperation(value = "delete a sdnc")
134 @ApiResponses(value = {
135 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
136 response = String.class),
137 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
138 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
139 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
140 response = String.class)})
142 public Response delsdnc(@ApiParam(value = "sdnc id") @PathParam("sdncId") String sdncId) {
143 LOGGER.info("start delete sdnc .id:" + sdncId);
145 handler.delete(sdncId);
146 } catch (ExtsysException error) {
147 LOGGER.error("delete sdnc failed.errorMsg:" + error.getErrorMsg());
148 return RestResponseUtil.getErrorResponse(error);
150 LOGGER.info(" delete sdnc end !");
151 return Response.noContent().build();
159 @Consumes(MediaType.APPLICATION_JSON)
160 @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
161 @ApiOperation(value = "update a sdnc")
162 @ApiResponses(value = {
163 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
164 response = String.class),
165 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
166 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
167 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
168 response = String.class)})
170 public Response updatesdncs(@ApiParam(value = "sdnc", required = true) SdncData sdnc,
171 @ApiParam(value = "sdnc id", required = true) @PathParam("sdncId") String sdncId) {
172 LOGGER.info("start update sdnc .id:" + sdncId + " info:" + ExtsysDbUtil.objectToString(sdnc));
175 newData = handler.update(sdnc, sdncId);
176 } catch (ExtsysException error) {
177 LOGGER.error("update sdnc failed.errorMsg:" + error.getErrorMsg());
178 return RestResponseUtil.getErrorResponse(error);
180 LOGGER.info(" update sdnc end !");
181 // return RestResponseUtil.getSuccessResponse(new ThirdPartySdncRestData(newData));
182 return RestResponseUtil.getSuccessResponse(new ThirdPartySdncRestData());
190 @Consumes(MediaType.APPLICATION_JSON)
191 @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
192 @ApiOperation(value = "create a sdnc")
193 @ApiResponses(value = {
194 @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found",
195 response = String.class),
196 @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415,
197 message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
198 @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error",
199 response = String.class)})
201 public Response addsdncs(@ApiParam(value = "sdnc", required = true) SdncData sdnc) {
202 LOGGER.info("start add sdnc" + " info:" + ExtsysDbUtil.objectToString(sdnc));
205 sdncData = handler.add(sdnc);
206 } catch (ExtsysException error) {
207 LOGGER.error("add sdnc failed.errorMsg:" + error.getErrorMsg());
208 return RestResponseUtil.getErrorResponse(error);
210 LOGGER.info(" add sdnc end !");
211 // return RestResponseUtil.getCreateSussceeResponse(new ThirdPartySdncRestData(sdncData));
212 return RestResponseUtil.getCreateSussceeResponse(new ThirdPartySdncRestData());