2 * Copyright 2016 ZTE, Inc. and others.
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.msb.apiroute.resources;
18 import io.swagger.annotations.Api;
19 import io.swagger.annotations.ApiOperation;
20 import io.swagger.annotations.ApiParam;
21 import io.swagger.annotations.ApiResponse;
22 import io.swagger.annotations.ApiResponses;
25 import java.util.List;
27 import javax.ws.rs.DELETE;
28 import javax.ws.rs.DefaultValue;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.POST;
31 import javax.ws.rs.PUT;
32 import javax.ws.rs.Path;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.QueryParam;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38 import javax.ws.rs.core.UriInfo;
40 import org.apache.http.HttpStatus;
41 import org.onap.msb.apiroute.api.CustomRouteInfo;
42 import org.onap.msb.apiroute.wrapper.CustomRouteServiceWrapper;
44 import com.codahale.metrics.annotation.Timed;
47 @Api(tags = { "CustomRoute" })
48 @Produces(MediaType.APPLICATION_JSON)
49 public class CustomRouteResource {
52 UriInfo uriInfo; // actual uri info
56 @ApiOperation(value = "get all CustomRoute ", code = HttpStatus.SC_OK,response = CustomRouteInfo.class, responseContainer = "List")
57 @ApiResponses(value = {@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "get CustomRouteInfo List fail", response = String.class)})
58 @Produces(MediaType.APPLICATION_JSON)
60 public List<CustomRouteInfo> getCustomRoutes(@ApiParam(value = "Route Way", required = false) @QueryParam("routeWay") @DefaultValue("ip")String routeWay) {
61 return CustomRouteServiceWrapper.getInstance().getAllCustomRouteInstances(routeWay);
66 @ApiOperation(value = "add one CustomRoute ", code = HttpStatus.SC_CREATED,response = CustomRouteInfo.class)
67 @ApiResponses(value = {
68 @ApiResponse(code = HttpStatus.SC_UNPROCESSABLE_ENTITY, message = "Unprocessable CustomRouteInfo Entity ", response = String.class),
69 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "add CustomRouteInfo fail", response = String.class),
70 @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = "Unprocessable CustomRouteInfo JSON REQUEST", response = String.class)})
71 @Produces(MediaType.APPLICATION_JSON)
73 public Response addCustomRoute(
74 @ApiParam(value = "CustomRoute Instance Info", required = true) CustomRouteInfo customRouteInfo,
75 @ApiParam(value = "Route Way", required = false) @QueryParam("routeWay") @DefaultValue("ip")String routeWay) {
76 CustomRouteInfo new_customRouteInfo = CustomRouteServiceWrapper.getInstance().saveCustomRouteInstance4Rest(customRouteInfo,routeWay);
77 URI returnURI =uriInfo.getAbsolutePathBuilder().path("/instance?serviceName=" + new_customRouteInfo.getServiceName()).build();
78 return Response.created(returnURI).entity(new_customRouteInfo).build();
84 @ApiOperation(value = "get one CustomRoute ",code = HttpStatus.SC_OK, response = CustomRouteInfo.class)
85 @ApiResponses(value = {
86 @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "CustomRoute not found", response = String.class),
87 @ApiResponse(code = HttpStatus.SC_UNPROCESSABLE_ENTITY, message = "Unprocessable CustomRoute Entity ", response = String.class),
88 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "get CustomRoute fail", response = String.class)})
89 @Produces(MediaType.APPLICATION_JSON)
91 public CustomRouteInfo getCustomRoute(
92 @ApiParam(value = "CustomRoute serviceName", required = false) @QueryParam("serviceName") String serviceName,
93 @ApiParam(value = "CustomRoute host", required = false) @QueryParam("host") String host,
94 @ApiParam(value = "CustomRoute Publish port", required = false) @QueryParam("publish_port") @DefaultValue("")String publish_port,
95 @ApiParam(value = "Route Way", required = false) @QueryParam("routeWay") @DefaultValue("ip")String routeWay) {
98 return CustomRouteServiceWrapper.getInstance().getCustomRouteInstance(serviceName,host,publish_port,routeWay);
104 @ApiOperation(value = "update one CustomRoute by serviceName", code = HttpStatus.SC_CREATED,response = CustomRouteInfo.class)
105 @ApiResponses(value = {
106 @ApiResponse(code = HttpStatus.SC_UNPROCESSABLE_ENTITY, message = "Unprocessable CustomRoute Entity ", response = String.class),
107 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "update CustomRoute fail", response = String.class),
108 @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = "Unprocessable CustomRoute JSON REQUEST", response = String.class)})
109 @Produces(MediaType.APPLICATION_JSON)
111 public Response updateCustomRoute(
112 @ApiParam(value = "CustomRoute serviceName", required = true) @QueryParam("serviceName") String serviceName,
113 @ApiParam(value = "CustomRoute Instance Info", required = true) CustomRouteInfo customRoute,
114 @ApiParam(value = "Route Way", required = false) @QueryParam("routeWay") @DefaultValue("ip")String routeWay
117 CustomRouteInfo new_customRouteInfo= CustomRouteServiceWrapper.getInstance().saveCustomRouteInstance4Rest(customRoute,routeWay);
119 return Response.created(uriInfo.getAbsolutePathBuilder().build()).entity(new_customRouteInfo).build();
125 @ApiOperation(value = "delete one CustomRoute by serviceName", code = HttpStatus.SC_NO_CONTENT)
126 @ApiResponses(value = {
127 @ApiResponse(code = HttpStatus.SC_NO_CONTENT, message = "delete customRoute succeed "),
128 @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "customRoute not found", response = String.class),
129 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "delete customRoute fail", response = String.class)})
130 @Produces(MediaType.APPLICATION_JSON)
132 public void deleteCustomRoute(
133 @ApiParam(value = "CustomRoute serviceName", required = true) @QueryParam("serviceName") String serviceName,
134 @ApiParam(value = "CustomRoute host", required = false) @QueryParam("host") String host,
135 @ApiParam(value = "CustomRoute Publish port", required = false) @QueryParam("publish_port") @DefaultValue("")String publish_port,
136 @ApiParam(value = "Route Way", required = false) @QueryParam("routeWay") @DefaultValue("ip")String routeWay) {
138 CustomRouteServiceWrapper.getInstance().deleteCustomRoute(serviceName,host,publish_port,routeWay);
144 @ApiOperation(value = "update one CustomRoute status by serviceName ",code = HttpStatus.SC_CREATED, response = CustomRouteInfo.class)
145 @ApiResponses(value = {
146 @ApiResponse(code = HttpStatus.SC_UNPROCESSABLE_ENTITY, message = "Unprocessable customRoute Entity ", response = String.class),
147 @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "customRoute not found", response = String.class),
148 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "update status fail", response = String.class)})
149 @Produces(MediaType.APPLICATION_JSON)
151 public Response updateCustomRouteStatus(
152 @ApiParam(value = "CustomRoute serviceName", required = true) @QueryParam("serviceName") String serviceName,
153 @ApiParam(value = "CustomRoute host", required = false) @QueryParam("host") String host,
154 @ApiParam(value = "CustomRoute status,1:abled 0:disabled", required = true) @QueryParam("status") String status,
155 @ApiParam(value = "CustomRoute Publish port", required = false) @QueryParam("publish_port") @DefaultValue("")String publish_port,
156 @ApiParam(value = "Route Way", required = false) @QueryParam("routeWay") @DefaultValue("ip")String routeWay) {
158 CustomRouteInfo new_customRouteInfo = CustomRouteServiceWrapper.getInstance().updateCustomRouteStatus(serviceName,host,publish_port,status,routeWay);
159 return Response.created(uriInfo.getAbsolutePathBuilder().build()).entity(new_customRouteInfo).build();