More actuator endpoints

This commit is contained in:
Spencer Gibb
2017-01-20 20:56:36 -07:00
parent a9c0c0eb9b
commit e07801b098
2 changed files with 37 additions and 13 deletions

View File

@@ -1,10 +1,15 @@
package org.springframework.cloud.gateway.actuate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.gateway.api.RouteReader;
import org.springframework.cloud.gateway.config.Route;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -15,29 +20,48 @@ import org.springframework.web.bind.annotation.RestController;
//@ConfigurationProperties(prefix = "endpoints.gateway")
@RestController
@RequestMapping("/admin/gateway")
public class GatewayEndpoint {
private RouteReader routeReader;/*extends AbstractEndpoint<Map<String, Object>> {*/
public class GatewayEndpoint {/*extends AbstractEndpoint<Map<String, Object>> {*/
public GatewayEndpoint(RouteReader routeReader) {
private RouteReader routeReader;
private List<GlobalFilter> globalFilters;
public GatewayEndpoint(RouteReader routeReader, List<GlobalFilter> globalFilters) {
//super("gateway");
this.routeReader = routeReader;
this.globalFilters = globalFilters;
}
/*@Override
public Map<String, Object> invoke() {
HashMap<String, Object> map = new HashMap<>();
ArrayList<String> filterNames = new ArrayList<>();
for (GlobalFilter filter : this.filters) {
filterNames.add(filter.getClass().getName());
}
map.put("filters", filterNames);
return map;
}*/
@GetMapping("/globalfilters")
public Map<String, Object> globalfilters() {
HashMap<String, Object> filters = new HashMap<>();
for (GlobalFilter filter : this.globalFilters) {
Integer order = null;
if (filter instanceof Ordered) {
order = ((Ordered)filter).getOrder();
}
filters.put(filter.getClass().getName(), order);
}
return filters;
}
@GetMapping("/routes")
public List<Route> routes() {
return this.routeReader.getRoutes();
}
@GetMapping("/routes/{id}")
public Route routes(@PathVariable String id) {
return this.routeReader.getRoutes().stream()
.filter(route -> route.getId().equals(id))
.findFirst().get();
}
//TODO: add combined routes for a filter
}

View File

@@ -229,8 +229,8 @@ public class GatewayAutoConfiguration {
protected static class GatewayActuatorConfiguration {
@Bean
public GatewayEndpoint gatewayEndpoint(RouteReader routeReader) {
return new GatewayEndpoint(routeReader);
public GatewayEndpoint gatewayEndpoint(RouteReader routeReader, List<GlobalFilter> globalFilters) {
return new GatewayEndpoint(routeReader, globalFilters);
}
}