diff options
author | HÃ¥kon Hallingstad <hakon.hallingstad@gmail.com> | 2023-02-27 08:55:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 08:55:44 +0100 |
commit | 5dd75af7450b3b345926178514e911a103af5407 (patch) | |
tree | 8836d199726e9d7c26146822115333fae17aa7b8 /configserver/src/main | |
parent | f762f23fa853e21e506521e72376bf4e2017af3e (diff) | |
parent | 4d06ae9365e15fdb3791f93805f93cfe0d035f67 (diff) |
Merge pull request #26142 from vespa-engine/hmusum/configserver-cleanup-2
Hmusum/configserver cleanup 2
Diffstat (limited to 'configserver/src/main')
5 files changed, 28 insertions, 58 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); } |