update the serviceId and location for statically configured routes that are also part of serviceDiscovery.

fixes gh-199
This commit is contained in:
Spencer Gibb
2015-02-09 17:30:23 -07:00
parent 96335e1d24
commit 18b346def1
3 changed files with 27 additions and 3 deletions

View File

@@ -153,16 +153,17 @@ public class ProxyRouteLocator implements RouteLocator {
// Ignore specifically ignored services and those that were manually
// configured
String key = "/" + serviceId + "/**";
ZuulRoute route = new ZuulRoute(key, serviceId);
if (staticServices.containsKey(serviceId)
&& staticServices.get(serviceId).getUrl() == null) {
// Explicitly configured with no URL, cannot be ignored
routesMap.put(key, route);
// all static routes are already in routesMap, just update
ZuulRoute staticRoute = staticServices.get(serviceId);
staticRoute.updateRoute(key, serviceId);
}
if (!PatternMatchUtils.simpleMatch(ignored, serviceId)
&& !routesMap.containsKey(key)) {
// Not ignored
routesMap.put(key, route);
routesMap.put(key, new ZuulRoute(key, serviceId));
}
}
}

View File

@@ -102,6 +102,10 @@ public class ZuulProperties {
}
public ZuulRoute(String path, String location) {
updateRoute(path, location);
}
public void updateRoute(String path, String location) {
this.id = extractId(path);
this.path = path;
setLocation(location);

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Before;
@@ -31,6 +32,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.MockitoAnnotations.initMocks;
@@ -257,6 +259,23 @@ public class ProxyRouteLocatorTests {
assertNotNull("routes ignored foo", serviceId);
}
@Test
public void testIgnoredRoutePropertiesRemain() {
ZuulRoute route = new ZuulRoute("/foo/**");
route.setStripPrefix(true);
route.setRetryable(Boolean.TRUE);
this.properties.getRoutes().put("foo", route);
ProxyRouteLocator routeLocator = new ProxyRouteLocator("/", this.discovery,
this.properties);
this.properties.setIgnoredServices(Collections.singletonList("*"));
given(this.discovery.getServices()).willReturn(Collections.singletonList("foo"));
LinkedHashMap<String, ZuulRoute> routes = routeLocator.locateRoutes();
ZuulRoute actual = routes.get(getMapping("foo"));
assertNotNull("routes ignored foo", actual);
assertTrue("stripPrefix is wrong", actual.isStripPrefix());
assertEquals("retryable is wrong", Boolean.TRUE, actual.getRetryable());
}
@Test
public void testIgnoredRouteIncludedIfConfiguredAndNotDiscovered() {
this.properties.getRoutes()