diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2017-12-11 15:58:12 +0100 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2017-12-11 15:58:12 +0100 |
commit | 836b1c2081fac4fa1284412d8064c66c701250a7 (patch) | |
tree | 596515cc2d815eb795aad3afb5f25fad599c5723 /controller-server | |
parent | 9c357854f8945738dd513d6fe7b598c81cda9e77 (diff) |
Replaced ZoneId getZone(ZoneId zoneId) with hasZone(ZoneId zoneId)
Diffstat (limited to 'controller-server')
7 files changed, 20 insertions, 22 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index 3f64562f2d2..b6653a9412c 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -656,7 +656,7 @@ public class ApplicationController { deploymentSpec.zones().stream() .filter(zone -> zone.environment() == Environment.prod) .forEach(zone -> { - if ( ! controller.zoneRegistry().getZone(zone.environment(), zone.region().orElse(null)).isPresent()) + if ( ! controller.zoneRegistry().hasZone(ZoneId.from(zone.environment(), zone.region().orElse(null)))) throw new IllegalArgumentException("Zone " + zone + " in deployment spec was not found in this system!"); }); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java index 71a0a7f6297..1a411e4f9e2 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java @@ -9,6 +9,7 @@ import com.yahoo.component.Vtag; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.SystemName; +import com.yahoo.config.provision.ZoneId; import com.yahoo.vespa.hosted.controller.api.identifiers.AthenzDomain; import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; import com.yahoo.vespa.hosted.controller.api.identifiers.Property; @@ -157,8 +158,8 @@ public class Controller extends AbstractComponent { return elkUrl(zoneRegistry.getLogServerUri(deploymentId.zone().environment(), deploymentId.zone().region()), deploymentId); } - public List<URI> getConfigServerUris(Environment environment, RegionName region) { - return zoneRegistry.getConfigServerUris(environment, region); + public List<URI> getConfigServerUris(ZoneId zoneId) { + return zoneRegistry.getConfigServerUris(zoneId); } public ZoneRegistry zoneRegistry() { return zoneRegistry; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java index c9ce0b76520..e67b96c22ad 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ConfigServerRestExecutorImpl.java @@ -54,11 +54,10 @@ public class ConfigServerRestExecutorImpl implements ConfigServerRestExecutor { return createDiscoveryResponse(proxyRequest); } - Environment environment = Environment.from(proxyRequest.getEnvironment()); - RegionName region = RegionName.from(proxyRequest.getRegion()); + ZoneId zoneId = ZoneId.from(proxyRequest.getEnvironment(), proxyRequest.getRegion()); // Make a local copy of the list as we want to manipulate it in case of ping problems. - final List<URI> allServers = new ArrayList<>(zoneRegistry.getConfigServerUris(environment, region)); + List<URI> allServers = new ArrayList<>(zoneRegistry.getConfigServerUris(zoneId)); StringBuilder errorBuilder = new StringBuilder(); if (queueFirstServerIfDown(allServers)) { diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 4e3b96b40df..f132e6ff0fe 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -579,7 +579,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { ApplicationView applicationView = controller.getApplicationView(tenantName, applicationName, instanceName, environment, region); ServiceApiResponse response = new ServiceApiResponse(ZoneId.from(environment, region), new ApplicationId.Builder().tenant(tenantName).applicationName(applicationName).instanceName(instanceName).build(), - controller.getConfigServerUris(Environment.from(environment), RegionName.from(region)), + controller.getConfigServerUris(ZoneId.from(environment, region)), request.getUri()); response.setResponse(applicationView); return response; @@ -589,7 +589,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { Map<?,?> result = controller.getServiceApiResponse(tenantName, applicationName, instanceName, environment, region, serviceName, restPath); ServiceApiResponse response = new ServiceApiResponse(ZoneId.from(environment, region), new ApplicationId.Builder().tenant(tenantName).applicationName(applicationName).instanceName(instanceName).build(), - controller.getConfigServerUris(Environment.from(environment), RegionName.from(region)), + controller.getConfigServerUris(ZoneId.from(environment, region)), request.getUri()); response.setResponse(result, serviceName, restPath); return response; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java index 3f85b0116ad..772dd1f6cb1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java @@ -76,14 +76,12 @@ public class ZoneApiHandler extends LoggingRequestHandler { private HttpResponse proxy(HttpRequest request) { Path path = new Path(request.getUri().getPath()); - if (!path.matches("/zone/v2/{environment}/{region}/{*}")) { + if ( ! path.matches("/zone/v2/{environment}/{region}/{*}")) { return notFound(path); } - Environment environment = Environment.from(path.get("environment")); - RegionName region = RegionName.from(path.get("region")); - Optional<ZoneId> zone = zoneRegistry.getZone(environment, region); - if (!zone.isPresent()) { - throw new IllegalArgumentException("No such zone: " + environment.value() + "." + region.value()); + ZoneId zoneId = ZoneId.from(path.get("environment"), path.get("region")); + if ( ! zoneRegistry.hasZone(zoneId)) { + throw new IllegalArgumentException("No such zone: " + zoneId.value()); } try { return proxy.handle(new ProxyRequest(request, "/zone/v2/")); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java index 0e07f7b7589..876bd5fe029 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java @@ -120,8 +120,9 @@ public class VersionStatus { private static ListMap<Version, String> findConfigServerVersions(Controller controller) { List<URI> configServers = controller.zoneRegistry().zones().stream() + // TODO: Filter properly. .filter(zone -> ! zone.region().equals(RegionName.from("us-east-2a"))) - .flatMap(zone -> controller.getConfigServerUris(zone.environment(), zone.region()).stream()) + .flatMap(zone -> controller.getConfigServerUris(zone).stream()) .collect(Collectors.toList()); ListMap<Version, String> versions = new ListMap<>(); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java index 53af74bf542..086e9ff2d1b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java @@ -67,22 +67,21 @@ public class ZoneRegistryMock extends AbstractComponent implements ZoneRegistry } @Override - public Optional<ZoneId> getZone(Environment environment, RegionName region) { - return zones().stream().filter(z -> z.environment().equals(environment) && - z.region().equals(region)).findFirst(); + public boolean hasZone(ZoneId zoneId) { + return zones.contains(zoneId); } @Override - public List<URI> getConfigServerUris(Environment environment, RegionName region) { - return getZone(environment, region) - .map(z -> URI.create(String.format("http://cfg.%s.%s.test", environment.value(), region.value()))) + public List<URI> getConfigServerUris(ZoneId zoneId) { + return Optional.of(zoneId) + .map(z -> URI.create(String.format("http://cfg.%s.test", zoneId.value()))) .map(Collections::singletonList) .orElse(Collections.emptyList()); } @Override public Optional<URI> getLogServerUri(Environment environment, RegionName region) { - return getZone(environment, region) + return Optional.of(ZoneId.from(environment, region)) .map(z -> URI.create(String.format("http://log.%s.%s.test", environment.value(), region.value()))); } |