diff options
Diffstat (limited to 'configserver')
8 files changed, 31 insertions, 70 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigActivationListener.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigActivationListener.java index f7e9e270b9c..e52089f5400 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigActivationListener.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigActivationListener.java @@ -4,35 +4,17 @@ package com.yahoo.vespa.config.server; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.config.server.application.ApplicationSet; -import java.util.Collection; - /** * A ConfigActivationListener is used to signal to a component that config has been - * activated. It only exists because the RpcServer cannot distinguish between a - * successful activation of a new application and an activation of the same application. + * activated for an application or that an application has been removed. It only exists + * because the RpcServer cannot distinguish between a successful activation of a new + * application and an activation of the same application. * * @author Ulf Lilleengen */ public interface ConfigActivationListener { /** - * Signals the listener that hosts used by a particular tenant. - * - * @param applicationId application id - * @param newHosts a {@link Collection} of hosts used by tenant. - */ - void hostsUpdated(ApplicationId applicationId, Collection<String> newHosts); - - /** - * Verifies that given hosts are available for use by tenant. - * - * @param applicationId application id - * @param newHosts a {@link java.util.Collection} of hosts that tenant wants to allocate. - * @throws java.lang.IllegalArgumentException if one or more of the hosts are in use by another tenant. - */ - void verifyHostsAreAvailable(ApplicationId applicationId, Collection<String> newHosts); - - /** * Configs has been activated for an application: Either an application * has been deployed for the first time, or it has been externally or internally redeployed. * diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationSet.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationSet.java index ad50117e327..5650c2e7e15 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationSet.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationSet.java @@ -1,16 +1,18 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.application; +import com.yahoo.component.Version; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.component.Version; - import java.time.Instant; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; /** - * Immutable set of {@link Application}s with the same {@link ApplicationId}. With methods for getting defaults. + * Immutable set of {@link Application}s with the same {@link ApplicationId}, applications have difference vespa versions. * * @author vegard */ @@ -42,8 +44,17 @@ public final class ApplicationSet { latestVersion = this.applications.keySet().stream().max(Version::compareTo).get(); } + public static ApplicationSet fromList(List<Application> applications) { + return new ApplicationSet(applications); + } + + // For testing + public static ApplicationSet from(Application application) { + return fromList(List.of(application)); + } + /** - * Returns the specified version, or the latest if not specified, or if the given version is not + * Returns an application for the specified version, or the latest if not specified, or if the given version is not * available and the latest is a permissible substitution. * * @throws VersionDoesNotExistException if the specified version is not available and the latest version is not @@ -68,21 +79,13 @@ public final class ApplicationSet { return Optional.empty(); } - /** Returns the application for the given version, if available */ + /** Returns the application for the given version, or empty if not found */ public Optional<Application> get(Version version) { return Optional.ofNullable(applications.get(version)); } public ApplicationId getId() { return applicationId; } - public static ApplicationSet fromList(List<Application> applications) { - return new ApplicationSet(applications); - } - - public static ApplicationSet from(Application application) { - return fromList(List.of(application)); - } - public Collection<String> getAllHosts() { return applications.values().stream() .flatMap(app -> app.getModel().getHosts().stream() @@ -91,9 +94,7 @@ public final class ApplicationSet { } public void updateHostMetrics() { - for (Application application : applications.values()) { - application.updateHostMetrics(application.getModel().getHosts().size()); - } + applications.values().forEach(app -> app.updateHostMetrics(app.getModel().getHosts().size())); } public long getApplicationGeneration() { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java index b559eaaf422..8f3bc83984a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java @@ -216,10 +216,10 @@ public class TenantApplications implements RequestHandler, HostValidator { } private void notifyConfigActivationListeners(ApplicationSet applicationSet) { - if (applicationSet.getAllApplications().isEmpty()) throw new IllegalArgumentException("application set cannot be empty"); + List<Application> applications = applicationSet.getAllApplications(); + if (applications.isEmpty()) throw new IllegalArgumentException("application set cannot be empty"); - configActivationListener.hostsUpdated(applicationSet.getAllApplications().get(0).toApplicationInfo().getApplicationId(), - applicationSet.getAllHosts()); + hostRegistry.update(applications.get(0).getId(), applicationSet.getAllHosts()); configActivationListener.configActivated(applicationSet); } @@ -277,7 +277,7 @@ public class TenantApplications implements RequestHandler, HostValidator { } private void configActivationListenersOnRemove(ApplicationId applicationId) { - configActivationListener.hostsUpdated(applicationId, hostRegistry.getHosts(applicationId)); + hostRegistry.removeHosts(applicationId); configActivationListener.applicationRemoved(applicationId); } @@ -399,7 +399,6 @@ public class TenantApplications implements RequestHandler, HostValidator { @Override public void verifyHosts(ApplicationId applicationId, Collection<String> newHosts) { hostRegistry.verifyHosts(applicationId, newHosts); - configActivationListener.verifyHostsAreAvailable(applicationId, newHosts); } // TODO: Duplicate of resolveApplicationId() above diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java index aac34238b90..2d731370b70 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java @@ -44,11 +44,9 @@ import com.yahoo.vespa.filedistribution.FileDownloader; import com.yahoo.vespa.filedistribution.FileReceiver; import com.yahoo.vespa.filedistribution.FileReferenceData; import com.yahoo.vespa.filedistribution.FileReferenceDownload; - import java.nio.ByteBuffer; import java.time.Duration; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -320,17 +318,6 @@ public class RpcServer implements Runnable, ConfigActivationListener, TenantList } @Override - public void hostsUpdated(ApplicationId applicationId, Collection<String> newHosts) { - log.log(Level.FINE, () -> "Updating hosts in tenant host registry '" + hostRegistry + "' with " + newHosts); - hostRegistry.update(applicationId, newHosts); - } - - @Override - public void verifyHostsAreAvailable(ApplicationId applicationId, Collection<String> newHosts) { - hostRegistry.verifyHosts(applicationId, newHosts); - } - - @Override public void applicationRemoved(ApplicationId applicationId) { superModelRequestHandler.removeApplication(applicationId); configActivated(applicationId); @@ -350,6 +337,7 @@ public class RpcServer implements Runnable, ConfigActivationListener, TenantList */ Optional<TenantName> resolveTenant(JRTServerConfigRequest request, Trace trace) { if ("*".equals(request.getConfigKey().getConfigId())) return Optional.of(ApplicationId.global().tenant()); + String hostname = request.getClientHostName(); ApplicationId applicationId = hostRegistry.getApplicationId(hostname); if (applicationId == null) { @@ -445,7 +433,6 @@ public class RpcServer implements Runnable, ConfigActivationListener, TenantList log.log(Level.FINE, () -> TenantRepository.logPre(tenant) + "Tenant deleted, removing request handler and cleaning host registry"); tenants.remove(tenant); - hostRegistry.removeHosts(tenant); } @Override diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java index 00a10a97dc3..4833a62aa37 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java @@ -401,6 +401,7 @@ public class TenantRepository { } private void notifyRemovedTenant(TenantName name) { + hostRegistry.removeHosts(name); tenantListener.onTenantDelete(name); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java index 85e64b4a32d..728f3e8510f 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java @@ -203,15 +203,6 @@ public class TenantApplicationsTest { } @Override - public void hostsUpdated(ApplicationId applicationId, Collection<String> newHosts) { - tenantHosts.put(applicationId.tenant().value(), newHosts); - } - - @Override - public void verifyHostsAreAvailable(ApplicationId applicationId, Collection<String> newHosts) { - } - - @Override public void applicationRemoved(ApplicationId applicationId) { removed.incrementAndGet(); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java index 8607fc0e2dc..9190cbc0d8a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java @@ -38,10 +38,10 @@ import java.io.File; import java.io.IOException; import java.util.Optional; +import static com.yahoo.vespa.config.server.rpc.RpcServer.ChunkedFileReceiver.createMetaRequest; import static com.yahoo.vespa.filedistribution.FileReferenceData.CompressionType.gzip; import static com.yahoo.vespa.filedistribution.FileReferenceData.CompressionType.lz4; import static com.yahoo.vespa.filedistribution.FileReferenceData.Type.compressed; -import static com.yahoo.vespa.config.server.rpc.RpcServer.ChunkedFileReceiver.createMetaRequest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -84,7 +84,7 @@ public class RpcServerTest { public void testEmptySentinelConfigWhenAppDeletedOnHostedVespa() throws IOException, InterruptedException { ConfigserverConfig.Builder configBuilder = new ConfigserverConfig.Builder().canReturnEmptySentinelConfig(true); try (RpcTester tester = new RpcTester(applicationId, temporaryFolder, configBuilder)) { - tester.rpcServer().onTenantDelete(tenantName); + tester.hostRegistry.removeHosts(applicationId); tester.rpcServer().onTenantsLoaded(); JRTClientConfigRequest clientReq = createSentinelRequest(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java index c40af30d1f4..8770970308a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java @@ -54,7 +54,7 @@ public class RpcTester implements AutoCloseable { private final ApplicationId applicationId; private final TenantName tenantName; private final TenantRepository tenantRepository; - private final HostRegistry hostRegistry = new HostRegistry(); + final HostRegistry hostRegistry = new HostRegistry(); private final ApplicationRepository applicationRepository; private final List<Integer> allocatedPorts = new ArrayList<>(); |