2 * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
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.openo.msb.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;
26 import javax.ws.rs.DELETE;
27 import javax.ws.rs.GET;
28 import javax.ws.rs.POST;
29 import javax.ws.rs.PUT;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.QueryParam;
33 import javax.ws.rs.core.Context;
34 import javax.ws.rs.core.MediaType;
35 import javax.ws.rs.core.Response;
36 import javax.ws.rs.core.UriInfo;
38 import org.apache.http.HttpStatus;
39 import org.openo.msb.api.CustomRouteInfo;
40 import org.openo.msb.wrapper.CustomRouteServiceWrapper;
42 import com.codahale.metrics.annotation.Timed;
45 @Api(tags = { "CustomRoute" })
46 @Produces(MediaType.APPLICATION_JSON)
47 public class CustomRouteResource {
50 UriInfo uriInfo; // actual uri info
54 @ApiOperation(value = "get all CustomRoute ", code = HttpStatus.SC_OK,response = CustomRouteInfo.class, responseContainer = "List")
55 @ApiResponses(value = {@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "get CustomRouteInfo List fail", response = String.class)})
56 @Produces(MediaType.APPLICATION_JSON)
58 public CustomRouteInfo[] getCustomRoutes() {
59 return CustomRouteServiceWrapper.getInstance().getAllCustomRouteInstances();
64 @ApiOperation(value = "add one CustomRoute ", code = HttpStatus.SC_CREATED,response = CustomRouteInfo.class)
65 @ApiResponses(value = {
66 @ApiResponse(code = HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE, message = "Unprocessable CustomRouteInfo Entity ", response = String.class),
67 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "add CustomRouteInfo fail", response = String.class),
68 @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = "Unprocessable CustomRouteInfo JSON REQUEST", response = String.class)})
69 @Produces(MediaType.APPLICATION_JSON)
71 public Response addCustomRoute(
72 @ApiParam(value = "CustomRoute Instance Info", required = true) CustomRouteInfo customRouteInfo) {
73 CustomRouteInfo new_customRouteInfo = CustomRouteServiceWrapper.getInstance().saveCustomRouteInstance(customRouteInfo,"");
75 uriInfo.getAbsolutePathBuilder()
76 .path("/instance?serviceName=" + new_customRouteInfo.getServiceName()).build();
77 return Response.created(returnURI).entity(new_customRouteInfo).build();
83 @ApiOperation(value = "get one CustomRoute ",code = HttpStatus.SC_OK, response = CustomRouteInfo.class)
84 @ApiResponses(value = {
85 @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "CustomRoute not found", response = String.class),
86 @ApiResponse(code = HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE, message = "Unprocessable CustomRoute Entity ", response = String.class),
87 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "get CustomRoute fail", response = String.class)})
88 @Produces(MediaType.APPLICATION_JSON)
90 public CustomRouteInfo getCustomRoute(
91 @ApiParam(value = "CustomRoute serviceName", required = false) @QueryParam("serviceName") String serviceName) {
94 return CustomRouteServiceWrapper.getInstance().getCustomRouteInstance(serviceName);
100 @ApiOperation(value = "update one CustomRoute by serviceName", code = HttpStatus.SC_CREATED,response = CustomRouteInfo.class)
101 @ApiResponses(value = {
102 @ApiResponse(code = HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE, message = "Unprocessable CustomRoute Entity ", response = String.class),
103 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "update CustomRoute fail", response = String.class),
104 @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = "Unprocessable CustomRoute JSON REQUEST", response = String.class)})
105 @Produces(MediaType.APPLICATION_JSON)
107 public Response updateCustomRoute(
108 @ApiParam(value = "CustomRoute serviceName", required = true) @QueryParam("serviceName") String serviceName,
109 @ApiParam(value = "CustomRoute Instance Info", required = true) CustomRouteInfo customRoute) {
111 CustomRouteInfo new_customRouteInfo= CustomRouteServiceWrapper.getInstance().updateCustomRouteInstance(serviceName,customRoute,"");
113 return Response.created(uriInfo.getAbsolutePathBuilder().build()).entity(new_customRouteInfo).build();
119 @ApiOperation(value = "delete one CustomRoute by serviceName", code = HttpStatus.SC_NO_CONTENT)
120 @ApiResponses(value = {
121 @ApiResponse(code = HttpStatus.SC_NO_CONTENT, message = "delete customRoute succeed "),
122 @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "customRoute not found", response = String.class),
123 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "delete customRoute fail", response = String.class)})
124 @Produces(MediaType.APPLICATION_JSON)
126 public void deleteCustomRoute(
127 @ApiParam(value = "CustomRoute serviceName", required = true) @QueryParam("serviceName") String serviceName) {
129 CustomRouteServiceWrapper.getInstance().deleteCustomRoute(serviceName,"*","");
135 @ApiOperation(value = "update one CustomRoute status by serviceName ",code = HttpStatus.SC_CREATED, response = CustomRouteInfo.class)
136 @ApiResponses(value = {
137 @ApiResponse(code = HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE, message = "Unprocessable customRoute Entity ", response = String.class),
138 @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "customRoute not found", response = String.class),
139 @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = "update status fail", response = String.class)})
140 @Produces(MediaType.APPLICATION_JSON)
142 public Response updateCustomRouteStatus(
143 @ApiParam(value = "CustomRoute serviceName", required = true) @QueryParam("serviceName") String serviceName,
144 @ApiParam(value = "CustomRoute status,1:abled 0:disabled", required = true) @QueryParam("status") String status) {
146 CustomRouteInfo new_customRouteInfo = CustomRouteServiceWrapper.getInstance().updateCustomRouteStatus(serviceName,status);
147 return Response.created(uriInfo.getAbsolutePathBuilder().build()).entity(new_customRouteInfo).build();