diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-01-11 08:51:44 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-01-11 08:51:44 +0100 |
commit | c7e73035cdca34fae6ac6f8223bfa4ce87e3a5e0 (patch) | |
tree | 5a29a3a9c82b207cab8734a628392f4f08428507 /configserver | |
parent | 27df4676badba2e64c81734da77460c4c724f46b (diff) |
Use just one host registry with application id as key
Diffstat (limited to 'configserver')
24 files changed, 203 insertions, 160 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java index 454366e8fae..23f4fdead62 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java @@ -9,6 +9,7 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; +import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.session.SessionPreparer; @@ -46,4 +47,5 @@ public interface GlobalComponentRegistry { FlagSource getFlagSource(); ExecutorService getZkCacheExecutor(); SecretStore getSecretStore(); + HostRegistry hostRegistry(); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java index ce0641a7b47..c9022e49f2d 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java @@ -11,6 +11,7 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; +import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; @@ -50,6 +51,7 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry private final SecretStore secretStore; private final StripedExecutor<TenantName> zkWatcherExecutor; private final ExecutorService zkCacheExecutor; + private final HostRegistry hostRegistry; @SuppressWarnings("WeakerAccess") @Inject @@ -66,7 +68,8 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry Zone zone, ConfigServerDB configServerDB, FlagSource flagSource, - SecretStore secretStore) { + SecretStore secretStore, + HostRegistry hostRegistry) { this.curator = curator; this.configCurator = configCurator; this.metrics = metrics; @@ -83,6 +86,7 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry this.secretStore = secretStore; this.zkWatcherExecutor = new StripedExecutor<>(); this.zkCacheExecutor = Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(TenantRepository.class.getName())); + this.hostRegistry = hostRegistry; } @Override @@ -139,4 +143,8 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry public SecretStore getSecretStore() { return secretStore; } + + @Override + public HostRegistry hostRegistry() { return hostRegistry; } + } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java index 773a4862033..7cdb596780a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java @@ -1,8 +1,7 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.TenantName; import com.yahoo.vespa.config.server.application.ApplicationSet; import java.util.Collection; @@ -17,21 +16,21 @@ import java.util.Collection; public interface ReloadListener { /** - * Signal the listener that hosts used by by a particular tenant. + * Signals the listener that hosts used by a particular tenant. * - * @param tenant Name of tenant. + * @param applicationId application id * @param newHosts a {@link Collection} of hosts used by tenant. */ - void hostsUpdated(TenantName tenant, Collection<String> newHosts); + void hostsUpdated(ApplicationId applicationId, Collection<String> newHosts); /** - * Verify that given hosts are available for use by tenant. + * Verifies that given hosts are available for use by tenant. * - * @param tenant tenant that wants to allocate hosts. + * @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(TenantName tenant, Collection<String> newHosts); + void verifyHostsAreAvailable(ApplicationId applicationId, Collection<String> newHosts); /** * Configs has been activated for an application: Either an application 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 2616f270bf8..b126b006212 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 @@ -61,7 +61,7 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica private final TenantName tenant; private final ReloadListener reloadListener; private final ConfigResponseFactory responseFactory; - private final HostRegistry<ApplicationId> hostRegistry; + private final HostRegistry hostRegistry; private final ApplicationMapper applicationMapper = new ApplicationMapper(); private final MetricUpdater tenantMetricUpdater; private final Clock clock; @@ -69,7 +69,7 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica public TenantApplications(TenantName tenant, Curator curator, StripedExecutor<TenantName> zkWatcherExecutor, ExecutorService zkCacheExecutor, Metrics metrics, ReloadListener reloadListener, - ConfigserverConfig configserverConfig, HostRegistry<ApplicationId> hostRegistry, + ConfigserverConfig configserverConfig, HostRegistry hostRegistry, TenantFileSystemDirs tenantFileSystemDirs, Clock clock) { this.database = new ApplicationCuratorDatabase(tenant, curator); this.tenant = tenant; @@ -95,7 +95,7 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica componentRegistry.getMetrics(), componentRegistry.getReloadListener(), componentRegistry.getConfigserverConfig(), - new HostRegistry<>(), + new HostRegistry(), new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName), componentRegistry.getClock()); } @@ -221,7 +221,10 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica } private void notifyReloadListeners(ApplicationSet applicationSet) { - reloadListener.hostsUpdated(tenant, hostRegistry.getAllHosts()); + if (applicationSet.getAllApplications().isEmpty()) throw new IllegalArgumentException("application set cannot be empty"); + + reloadListener.hostsUpdated(applicationSet.getAllApplications().get(0).toApplicationInfo().getApplicationId(), + hostRegistry.getAllHosts()); reloadListener.configActivated(applicationSet); } @@ -270,7 +273,7 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica } private void reloadListenersOnRemove(ApplicationId applicationId) { - reloadListener.hostsUpdated(tenant, hostRegistry.getAllHosts()); + reloadListener.hostsUpdated(applicationId, hostRegistry.getAllHosts()); reloadListener.applicationRemoved(applicationId); } @@ -381,9 +384,9 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica } @Override - public void verifyHosts(ApplicationId key, Collection<String> newHosts) { - hostRegistry.verifyHosts(key, newHosts); - reloadListener.verifyHostsAreAvailable(tenant, newHosts); + public void verifyHosts(ApplicationId applicationId, Collection<String> newHosts) { + hostRegistry.verifyHosts(applicationId, newHosts); + reloadListener.verifyHostsAreAvailable(applicationId, newHosts); } public HostValidator<ApplicationId> getHostValidator() { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java index ec37f2598e0..1fc9d34e153 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.host; import java.util.*; @@ -7,6 +7,9 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import com.google.common.collect.Collections2; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.TenantName; + import java.util.logging.Level; /** @@ -15,20 +18,20 @@ import java.util.logging.Level; * * @author Ulf Lilleengen */ -public class HostRegistry<T> implements HostValidator<T> { +public class HostRegistry implements HostValidator<ApplicationId> { private static final Logger log = Logger.getLogger(HostRegistry.class.getName()); - private final Map<String, T> host2KeyMap = new ConcurrentHashMap<>(); + private final Map<String, ApplicationId> host2KeyMap = new ConcurrentHashMap<>(); - public T getKeyForHost(String hostName) { + public ApplicationId getKeyForHost(String hostName) { return host2KeyMap.get(hostName); } - public synchronized void update(T key, Collection<String> newHosts) { + public synchronized void update(ApplicationId key, Collection<String> newHosts) { verifyHosts(key, newHosts); Collection<String> currentHosts = getHostsForKey(key); - log.log(Level.FINE, () -> "Setting hosts for key '" + key + "', " + + log.log(Level.INFO, () -> "Setting hosts for key '" + key + "', " + "newHosts: " + newHosts + ", " + "currentHosts: " + currentHosts); Collection<String> removedHosts = getRemovedHosts(newHosts, currentHosts); @@ -37,7 +40,7 @@ public class HostRegistry<T> implements HostValidator<T> { } @Override - public synchronized void verifyHosts(T key, Collection<String> newHosts) { + public synchronized void verifyHosts(ApplicationId key, Collection<String> newHosts) { for (String host : newHosts) { if (hostAlreadyTaken(host, key)) { throw new IllegalArgumentException("'" + key + "' tried to allocate host '" + host + @@ -46,22 +49,26 @@ public class HostRegistry<T> implements HostValidator<T> { } } - public synchronized void removeHostsForKey(T key) { + public synchronized void removeHostsForKey(ApplicationId key) { host2KeyMap.entrySet().removeIf(entry -> entry.getValue().equals(key)); } + public synchronized void removeHostsForKey(TenantName key) { + host2KeyMap.entrySet().removeIf(entry -> entry.getValue().tenant().equals(key)); + } + public synchronized Collection<String> getAllHosts() { return Collections.unmodifiableCollection(new ArrayList<>(host2KeyMap.keySet())); } - synchronized Collection<String> getHostsForKey(T key) { + synchronized Collection<String> getHostsForKey(ApplicationId key) { return host2KeyMap.entrySet().stream() .filter(entry -> entry.getValue().equals(key)) .map(Map.Entry::getKey) .collect(Collectors.toSet()); } - private boolean hostAlreadyTaken(String host, T key) { + private boolean hostAlreadyTaken(String host, ApplicationId key) { return host2KeyMap.containsKey(host) && !key.equals(host2KeyMap.get(host)); } @@ -76,7 +83,7 @@ public class HostRegistry<T> implements HostValidator<T> { } } - private void addHosts(T key, Collection<String> newHosts) { + private void addHosts(ApplicationId key, Collection<String> newHosts) { for (String host : newHosts) { log.log(Level.FINE, () -> "Adding " + host); host2KeyMap.put(host, key); 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 8e589537ced..370ae72bbbd 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 @@ -91,7 +91,7 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { private final DelayedConfigResponses delayedConfigResponses; - private final HostRegistry<TenantName> hostRegistry; + private final HostRegistry hostRegistry; private final Map<TenantName, Tenant> tenants = new ConcurrentHashMap<>(); private final Map<ApplicationId, ApplicationState> applicationStateMap = new ConcurrentHashMap<>(); private final SuperModelRequestHandler superModelRequestHandler; @@ -121,7 +121,7 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { */ @Inject public RpcServer(ConfigserverConfig config, SuperModelRequestHandler superModelRequestHandler, - MetricUpdaterFactory metrics, HostRegistry<TenantName> hostRegistry, + MetricUpdaterFactory metrics, HostRegistry hostRegistry, HostLivenessTracker hostLivenessTracker, FileServer fileServer, RpcAuthorizer rpcAuthorizer, RpcRequestHandlerProvider handlerProvider) { this.superModelRequestHandler = superModelRequestHandler; @@ -302,14 +302,14 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { } @Override - public void hostsUpdated(TenantName tenant, Collection<String> newHosts) { + public void hostsUpdated(ApplicationId applicationId, Collection<String> newHosts) { log.log(Level.FINE, "Updating hosts in tenant host registry '" + hostRegistry + "' with " + newHosts); - hostRegistry.update(tenant, newHosts); + hostRegistry.update(applicationId, newHosts); } @Override - public void verifyHostsAreAvailable(TenantName tenant, Collection<String> newHosts) { - hostRegistry.verifyHosts(tenant, newHosts); + public void verifyHostsAreAvailable(ApplicationId applicationId, Collection<String> newHosts) { + hostRegistry.verifyHosts(applicationId, newHosts); } @Override @@ -333,8 +333,8 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { Optional<TenantName> resolveTenant(JRTServerConfigRequest request, Trace trace) { if ("*".equals(request.getConfigKey().getConfigId())) return Optional.of(ApplicationId.global().tenant()); String hostname = request.getClientHostName(); - TenantName tenant = hostRegistry.getKeyForHost(hostname); - if (tenant == null) { + ApplicationId applicationId = hostRegistry.getKeyForHost(hostname); + if (applicationId == null) { if (GetConfigProcessor.logDebug(trace)) { String message = "Did not find tenant for host '" + hostname + "', using " + TenantName.defaultName(); log.log(Level.FINE, message); @@ -343,7 +343,7 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { } return Optional.empty(); } - return Optional.of(tenant); + return Optional.of(applicationId.tenant()); } public ConfigResponse resolveConfig(JRTServerConfigRequest request, GetConfigContext context, Optional<Version> vespaVersion) { @@ -424,7 +424,8 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { @Override public void onTenantDelete(TenantName tenant) { - log.log(Level.FINE, TenantRepository.logPre(tenant)+"Tenant deleted, removing request handler and cleaning host registry"); + log.log(Level.FINE, TenantRepository.logPre(tenant) + + "Tenant deleted, removing request handler and cleaning host registry"); tenants.remove(tenant); hostRegistry.removeHostsForKey(tenant); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/DefaultRpcAuthorizerProvider.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/DefaultRpcAuthorizerProvider.java index 5e2eb56c542..242c401de92 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/DefaultRpcAuthorizerProvider.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/DefaultRpcAuthorizerProvider.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.config.server.rpc.security; import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.security.NodeIdentifier; import com.yahoo.container.di.componentgraph.Provider; @@ -22,7 +23,7 @@ public class DefaultRpcAuthorizerProvider implements Provider<RpcAuthorizer> { @Inject public DefaultRpcAuthorizerProvider(ConfigserverConfig config, NodeIdentifier nodeIdentifier, - HostRegistry<TenantName> hostRegistry, + HostRegistry hostRegistry, RequestHandlerProvider handlerProvider) { boolean useMultiTenantAuthorizer = TransportSecurityUtils.isTransportSecurityEnabled() && config.multitenant() && config.hostedVespa(); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizer.java index 9e2ea0b34c3..8353e3fab1f 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizer.java @@ -43,12 +43,12 @@ public class MultiTenantRpcAuthorizer implements RpcAuthorizer { private static final Logger log = Logger.getLogger(MultiTenantRpcAuthorizer.class.getName()); private final NodeIdentifier nodeIdentifier; - private final HostRegistry<TenantName> hostRegistry; + private final HostRegistry hostRegistry; private final RequestHandlerProvider handlerProvider; private final Executor executor; public MultiTenantRpcAuthorizer(NodeIdentifier nodeIdentifier, - HostRegistry<TenantName> hostRegistry, + HostRegistry hostRegistry, RequestHandlerProvider handlerProvider, int threadPoolSize) { this(nodeIdentifier, @@ -58,7 +58,7 @@ public class MultiTenantRpcAuthorizer implements RpcAuthorizer { } MultiTenantRpcAuthorizer(NodeIdentifier nodeIdentifier, - HostRegistry<TenantName> hostRegistry, + HostRegistry hostRegistry, RequestHandlerProvider handlerProvider, Executor executor) { this.nodeIdentifier = nodeIdentifier; @@ -106,14 +106,14 @@ public class MultiTenantRpcAuthorizer implements RpcAuthorizer { return; // global config access ok } else { String hostname = configRequest.getClientHostName(); - Optional<TenantName> tenantName = Optional.ofNullable(hostRegistry.getKeyForHost(hostname)); - if (tenantName.isEmpty()) { + ApplicationId applicationId = hostRegistry.getKeyForHost(hostname); + if (applicationId == null) { if (isConfigKeyForSentinelConfig(configKey)) { return; // config processor will return empty sentinel config for unknown nodes } throw new AuthorizationException(Type.SILENT, String.format("Host '%s' not found in host registry for [%s]", hostname, configKey)); } - RequestHandler tenantHandler = getTenantHandler(tenantName.get()); + RequestHandler tenantHandler = getTenantHandler(applicationId.tenant()); ApplicationId resolvedApplication = tenantHandler.resolveApplicationId(hostname); ApplicationId peerOwner = applicationId(peerIdentity); if (peerOwner.equals(resolvedApplication)) { 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 471b1b15920..896c2efaa56 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 @@ -229,7 +229,7 @@ public class TenantRepository { componentRegistry.getMetrics(), componentRegistry.getReloadListener(), componentRegistry.getConfigserverConfig(), - new HostRegistry<>(), + componentRegistry.hostRegistry(), new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName), componentRegistry.getClock()); SessionRepository sessionRepository = new SessionRepository(tenantName, diff --git a/configserver/src/test/apps/app-jdisc-only-restart/hosts.xml b/configserver/src/test/apps/app-jdisc-only-restart/hosts.xml index f4256c9fc81..ab70b288ba6 100644 --- a/configserver/src/test/apps/app-jdisc-only-restart/hosts.xml +++ b/configserver/src/test/apps/app-jdisc-only-restart/hosts.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> <hosts> - <host name="mytesthost"> + <host name="mytesthost2"> <alias>node1</alias> </host> </hosts> diff --git a/configserver/src/test/apps/app-jdisc-only/hosts.xml b/configserver/src/test/apps/app-jdisc-only/hosts.xml index f4256c9fc81..ab70b288ba6 100644 --- a/configserver/src/test/apps/app-jdisc-only/hosts.xml +++ b/configserver/src/test/apps/app-jdisc-only/hosts.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> <hosts> - <host name="mytesthost"> + <host name="mytesthost2"> <alias>node1</alias> </host> </hosts> diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java index 0cab49a9f00..cb91a01ab55 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java @@ -192,7 +192,7 @@ public class ApplicationRepositoryTest { PrepareResult result = prepareAndActivate(testAppJdiscOnlyRestart); assertTrue(result.configChangeActions().getRefeedActions().isEmpty()); assertTrue(result.configChangeActions().getRestartActions().isEmpty()); - assertEquals(HostFilter.hostname("mytesthost"), provisioner.lastRestartFilter()); + assertEquals(HostFilter.hostname("mytesthost2"), provisioner.lastRestartFilter()); } @Test @@ -345,7 +345,7 @@ public class ApplicationRepositoryTest { // Deploy another app (with id fooId) ApplicationId fooId = applicationId(tenant2); PrepareParams prepareParams2 = new PrepareParams.Builder().applicationId(fooId).build(); - deployApp(testApp, prepareParams2); + deployApp(testAppJdiscOnly, prepareParams2); assertNotNull(applicationRepository.getActiveSession(fooId)); // Delete app with id fooId, should not affect original app @@ -530,14 +530,14 @@ public class ApplicationRepositoryTest { list.add(new NetworkPorts.Allocation(19081, "logserver", "admin/logserver", "unused/1")); list.add(new NetworkPorts.Allocation(19082, "logserver", "admin/logserver", "unused/2")); list.add(new NetworkPorts.Allocation(19083, "logserver", "admin/logserver", "unused/3")); - list.add(new NetworkPorts.Allocation(19089, "logd", "hosts/mytesthost/logd", "http")); - list.add(new NetworkPorts.Allocation(19090, "configproxy", "hosts/mytesthost/configproxy", "rpc")); - list.add(new NetworkPorts.Allocation(19092, "metricsproxy-container", "admin/metrics/mytesthost", "http")); - list.add(new NetworkPorts.Allocation(19093, "metricsproxy-container", "admin/metrics/mytesthost", "http/1")); - list.add(new NetworkPorts.Allocation(19094, "metricsproxy-container", "admin/metrics/mytesthost", "rpc/admin")); - list.add(new NetworkPorts.Allocation(19095, "metricsproxy-container", "admin/metrics/mytesthost", "rpc/metrics")); - list.add(new NetworkPorts.Allocation(19097, "config-sentinel", "hosts/mytesthost/sentinel", "rpc")); - list.add(new NetworkPorts.Allocation(19098, "config-sentinel", "hosts/mytesthost/sentinel", "http")); + list.add(new NetworkPorts.Allocation(19089, "logd", "hosts/mytesthost2/logd", "http")); + list.add(new NetworkPorts.Allocation(19090, "configproxy", "hosts/mytesthost2/configproxy", "rpc")); + list.add(new NetworkPorts.Allocation(19092, "metricsproxy-container", "admin/metrics/mytesthost2", "http")); + list.add(new NetworkPorts.Allocation(19093, "metricsproxy-container", "admin/metrics/mytesthost2", "http/1")); + list.add(new NetworkPorts.Allocation(19094, "metricsproxy-container", "admin/metrics/mytesthost2", "rpc/admin")); + list.add(new NetworkPorts.Allocation(19095, "metricsproxy-container", "admin/metrics/mytesthost2", "rpc/metrics")); + list.add(new NetworkPorts.Allocation(19097, "config-sentinel", "hosts/mytesthost2/sentinel", "rpc")); + list.add(new NetworkPorts.Allocation(19098, "config-sentinel", "hosts/mytesthost2/sentinel", "http")); list.add(new NetworkPorts.Allocation(19099, "slobrok", "admin/slobrok.0", "rpc")); list.add(new NetworkPorts.Allocation(19100, "container", "container/container.0", "http/1")); list.add(new NetworkPorts.Allocation(19101, "container", "container/container.0", "messaging")); @@ -547,7 +547,7 @@ public class ApplicationRepositoryTest { AllocatedHosts info = session.getAllocatedHosts(); assertNotNull(info); assertThat(info.getHosts().size(), is(1)); - assertTrue(info.getHosts().contains(new HostSpec("mytesthost", + assertTrue(info.getHosts().contains(new HostSpec("mytesthost2", Collections.emptyList(), Optional.empty()))); Optional<NetworkPorts> portsCopy = info.getHosts().iterator().next().networkPorts(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java index 2be18674e44..4f6642610dd 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java @@ -64,8 +64,9 @@ public class InjectedGlobalComponentRegistryTest { .configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath()) .configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath())); sessionPreparer = new SessionTest.MockSessionPreparer(); + HostRegistry hostRegistry = new HostRegistry(); rpcServer = new RpcServer(configserverConfig, null, Metrics.createTestMetrics(), - new HostRegistry<>(), new ConfigRequestHostLivenessTracker(), + hostRegistry, new ConfigRequestHostLivenessTracker(), new FileServer(temporaryFolder.newFolder("filereferences")), new NoopRpcAuthorizer(), new RpcRequestHandlerProvider()); defRepo = new StaticConfigDefinitionRepo(); @@ -73,9 +74,11 @@ public class InjectedGlobalComponentRegistryTest { HostProvisionerProvider hostProvisionerProvider = HostProvisionerProvider.withProvisioner(new MockProvisioner()); zone = Zone.defaultZone(); globalComponentRegistry = - new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, sessionPreparer, rpcServer, configserverConfig, - defRepo, permanentApplicationPackage, hostProvisionerProvider, zone, - new ConfigServerDB(configserverConfig), new InMemoryFlagSource(), new MockSecretStore()); + new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, sessionPreparer, + rpcServer, configserverConfig, defRepo, permanentApplicationPackage, + hostProvisionerProvider, zone, + new ConfigServerDB(configserverConfig), new InMemoryFlagSource(), + new MockSecretStore(), hostRegistry); } @Test diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java b/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java index 3bc68533d02..cbff99c04dc 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java @@ -14,6 +14,7 @@ import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.config.server.application.TenantApplicationsTest; import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; +import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; @@ -59,6 +60,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { private final ExecutorService zkCacheExecutor; private final SecretStore secretStore; private final FlagSource flagSource; + private final HostRegistry hostRegistry; private TestComponentRegistry(Curator curator, ConfigCurator configCurator, Metrics metrics, ModelFactoryRegistry modelFactoryRegistry, @@ -73,7 +75,8 @@ public class TestComponentRegistry implements GlobalComponentRegistry { Zone zone, Clock clock, SecretStore secretStore, - FlagSource flagSource) { + FlagSource flagSource, + HostRegistry hostRegistry) { this.curator = curator; this.configCurator = configCurator; this.metrics = metrics; @@ -93,6 +96,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { this.zkCacheExecutor = new InThreadExecutorService(); this.secretStore = secretStore; this.flagSource = flagSource; + this.hostRegistry = hostRegistry; } public static class Builder { @@ -114,6 +118,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { private Zone zone = Zone.defaultZone(); private Clock clock = Clock.systemUTC(); private FlagSource flagSource = new InMemoryFlagSource(); + private HostRegistry hostRegistry = new HostRegistry(); public Builder configServerConfig(ConfigserverConfig configserverConfig) { this.configserverConfig = configserverConfig; @@ -170,6 +175,11 @@ public class TestComponentRegistry implements GlobalComponentRegistry { return this; } + public Builder hostRegistry(HostRegistry hostRegistry) { + this.hostRegistry = hostRegistry; + return this; + } + public TestComponentRegistry build() { final PermanentApplicationPackage permApp = this.permanentApplicationPackage .orElse(new PermanentApplicationPackage(configserverConfig)); @@ -185,7 +195,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { return new TestComponentRegistry(curator, ConfigCurator.create(curator), metrics, modelFactoryRegistry, permApp, fileDistributionProvider, configserverConfig, sessionPreparer, hostProvisioner, defRepo, reloadListener, tenantListener, - zone, clock, secretStore, flagSource); + zone, clock, secretStore, flagSource, hostRegistry); } } @@ -240,6 +250,11 @@ public class TestComponentRegistry implements GlobalComponentRegistry { return secretStore; } + @Override + public HostRegistry hostRegistry() { + return hostRegistry; + } + public FileDistributionFactory getFileDistributionFactory() { return fileDistributionFactory; } } 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 947308962d4..ddbe97f4389 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 @@ -151,12 +151,12 @@ public class TenantApplicationsTest { } @Override - public void hostsUpdated(TenantName tenant, Collection<String> newHosts) { - tenantHosts.put(tenant.value(), newHosts); + public void hostsUpdated(ApplicationId applicationId, Collection<String> newHosts) { + tenantHosts.put(applicationId.tenant().value(), newHosts); } @Override - public void verifyHostsAreAvailable(TenantName tenant, Collection<String> newHosts) { + public void verifyHostsAreAvailable(ApplicationId applicationId, Collection<String> newHosts) { } @Override diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/host/HostRegistryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/host/HostRegistryTest.java index 63dfb1d01bd..173e9f3e148 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/host/HostRegistryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/host/HostRegistryTest.java @@ -1,37 +1,44 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.host; +import com.yahoo.config.provision.ApplicationId; +import org.junit.Test; + import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.junit.Test; - import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; /** * @author Ulf Lilleengen */ public class HostRegistryTest { + + private final ApplicationId foo = ApplicationId.from("foo", "app1", "default"); + private final ApplicationId bar = ApplicationId.from("bar", "app2", "default"); + @Test public void old_hosts_are_removed() { - HostRegistry<String> reg = new HostRegistry<>(); + HostRegistry reg = new HostRegistry(); assertNull(reg.getKeyForHost("foo.com")); - reg.update("fookey", List.of("foo.com", "bar.com", "baz.com")); - assertGetKey(reg, "foo.com", "fookey"); - assertGetKey(reg, "bar.com", "fookey"); - assertGetKey(reg, "baz.com", "fookey"); + reg.update(foo, List.of("foo.com", "bar.com", "baz.com")); + assertGetKey(reg, "foo.com", foo); + assertGetKey(reg, "bar.com", foo); + assertGetKey(reg, "baz.com", foo); assertThat(reg.getAllHosts().size(), is(3)); - reg.update("fookey", List.of("bar.com", "baz.com")); + reg.update(foo, List.of("bar.com", "baz.com")); assertNull(reg.getKeyForHost("foo.com")); - assertGetKey(reg, "bar.com", "fookey"); - assertGetKey(reg, "baz.com", "fookey"); + assertGetKey(reg, "bar.com", foo); + assertGetKey(reg, "baz.com", foo); assertThat(reg.getAllHosts().size(), is(2)); assertThat(reg.getAllHosts(), contains("bar.com", "baz.com")); - reg.removeHostsForKey("fookey"); + reg.removeHostsForKey(foo); assertThat(reg.getAllHosts().size(), is(0)); assertNull(reg.getKeyForHost("foo.com")); assertNull(reg.getKeyForHost("bar.com")); @@ -39,51 +46,51 @@ public class HostRegistryTest { @Test public void multiple_keys_are_handled() { - HostRegistry<String> reg = new HostRegistry<>(); - reg.update("fookey", List.of("foo.com", "bar.com")); - reg.update("barkey", List.of("baz.com", "quux.com")); - assertGetKey(reg, "foo.com", "fookey"); - assertGetKey(reg, "bar.com", "fookey"); - assertGetKey(reg, "baz.com", "barkey"); - assertGetKey(reg, "quux.com", "barkey"); + HostRegistry reg = new HostRegistry(); + reg.update(foo, List.of("foo.com", "bar.com")); + reg.update(bar, List.of("baz.com", "quux.com")); + assertGetKey(reg, "foo.com", foo); + assertGetKey(reg, "bar.com", foo); + assertGetKey(reg, "baz.com", bar); + assertGetKey(reg, "quux.com", bar); } @Test(expected = IllegalArgumentException.class) public void keys_cannot_overlap() { - HostRegistry<String> reg = new HostRegistry<>(); - reg.update("fookey", List.of("foo.com", "bar.com")); - reg.update("barkey", List.of("bar.com", "baz.com")); + HostRegistry reg = new HostRegistry(); + reg.update(foo, List.of("foo.com", "bar.com")); + reg.update(bar, List.of("bar.com", "baz.com")); } @Test public void all_hosts_are_returned() { - HostRegistry<String> reg = new HostRegistry<>(); - reg.update("fookey", List.of("foo.com", "bar.com")); - reg.update("barkey", List.of("baz.com", "quux.com")); + HostRegistry reg = new HostRegistry(); + reg.update(foo, List.of("foo.com", "bar.com")); + reg.update(bar, List.of("baz.com", "quux.com")); assertThat(reg.getAllHosts().size(), is(4)); } @Test public void ensure_that_collection_is_copied() { - HostRegistry<String> reg = new HostRegistry<>(); + HostRegistry reg = new HostRegistry(); List<String> hosts = new ArrayList<>(List.of("foo.com", "bar.com", "baz.com")); - reg.update("fookey", hosts); - assertThat(reg.getHostsForKey("fookey").size(), is(3)); + reg.update(foo, hosts); + assertThat(reg.getHostsForKey(foo).size(), is(3)); hosts.remove(2); - assertThat(reg.getHostsForKey("fookey").size(), is(3)); + assertThat(reg.getHostsForKey(foo).size(), is(3)); } @Test public void ensure_that_underlying_hosts_do_not_change() { - HostRegistry<String> reg = new HostRegistry<>(); - reg.update("fookey", List.of("foo.com", "bar.com", "baz.com")); + HostRegistry reg = new HostRegistry(); + reg.update(foo, List.of("foo.com", "bar.com", "baz.com")); Collection<String> hosts = reg.getAllHosts(); assertThat(hosts.size(), is(3)); - reg.update("fookey", List.of("foo.com")); + reg.update(foo, List.of("foo.com")); assertThat(hosts.size(), is(3)); } - private void assertGetKey(HostRegistry<String> reg, String host, String expectedKey) { + private void assertGetKey(HostRegistry reg, String host, ApplicationId expectedKey) { assertNotNull(reg.getKeyForHost(host)); assertThat(reg.getKeyForHost(host), is(expectedKey)); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index a0c63c8bba1..3fb999e85f7 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -76,6 +76,7 @@ import static org.mockito.Mockito.when; public class ApplicationHandlerTest { private static final File testApp = new File("src/test/apps/app"); + private static final File testAppJdiscOnly = new File("src/test/apps/app-jdisc-only"); private final static TenantName mytenantName = TenantName.from("mytenant"); private final static ApplicationId myTenantApplicationId = ApplicationId.from(mytenantName, ApplicationName.defaultName(), InstanceName.defaultName()); @@ -150,7 +151,7 @@ public class ApplicationHandlerTest { .instanceName("quux") .build(); PrepareParams prepareParams2 = new PrepareParams.Builder().applicationId(fooId).build(); - applicationRepository.deploy(testApp, prepareParams2); + applicationRepository.deploy(testAppJdiscOnly, prepareParams2); assertApplicationExists(fooId, Zone.defaultZone()); deleteAndAssertOKResponseMocked(fooId, true); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java index 9bd7a25faf2..a072bf62852 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java @@ -56,7 +56,8 @@ public class TenantsMaintainerTest { assertNotNull(tenantRepository.getTenant(TenantName.defaultName())); assertNotNull(tenantRepository.getTenant(TenantRepository.HOSTED_VESPA_TENANT)); - // Add tenant again and deploy + // Delete app, add tenant again and deploy + tester.applicationRepository().delete(applicationId(shouldNotBeDeleted)); tenantRepository.addTenant(shouldBeDeleted); tester.deployApp(applicationPackage, prepareParams(shouldBeDeleted)); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpcServer.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpcServer.java index 6db2e8006ed..997633eeb53 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpcServer.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpcServer.java @@ -37,7 +37,7 @@ public class MockRpcServer extends RpcServer { super(createConfig(port), null, Metrics.createTestMetrics(), - new HostRegistry<>(), + new HostRegistry(), new ConfigRequestHostLivenessTracker(), new FileServer(tempDir), new NoopRpcAuthorizer(), 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 735eae2700f..5a41eff3cc9 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 @@ -64,31 +64,19 @@ public class RpcServerTest { try (RpcTester tester = new RpcTester(applicationId, temporaryFolder)) { ApplicationRepository applicationRepository = tester.applicationRepository(); applicationRepository.deploy(testApp, new PrepareParams.Builder().applicationId(applicationId).build()); - TenantApplications applicationRepo = tester.tenant().getApplicationRepo(); - RemoteSession activeSession = applicationRepository.getActiveRemoteSession(applicationId); - ApplicationSet applicationSet = tester.tenant().getSessionRepository().ensureApplicationLoaded(activeSession); - applicationRepo.activateApplication(applicationSet, activeSession.getSessionId()); testPrintStatistics(tester); testGetConfig(tester); testEnabled(tester); testApplicationNotLoadedErrorWhenAppDeleted(tester); - testEmptySentinelConfigWhenAppDeletedOnHostedVespa(); } } - private void testApplicationNotLoadedErrorWhenAppDeleted(RpcTester tester) throws InterruptedException, IOException { - tester.rpcServer().onTenantDelete(tenantName); - tester.rpcServer().onTenantsLoaded(); + private void testApplicationNotLoadedErrorWhenAppDeleted(RpcTester tester) { + tester.applicationRepository().delete(applicationId); JRTClientConfigRequest clientReq = createSimpleRequest(); tester.performRequest(clientReq.getRequest()); assertFalse(clientReq.validateResponse()); assertThat(clientReq.errorCode(), is(ErrorCode.APPLICATION_NOT_LOADED)); - tester.stopRpc(); - tester.createAndStartRpcServer(); - tester.rpcServer().onTenantsLoaded(); - clientReq = createSimpleRequest(); - tester.performRequest(clientReq.getRequest()); - assertTrue(clientReq.validateResponse()); } @Test 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 c044978ab42..8284aacc97e 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 @@ -12,7 +12,6 @@ import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; import com.yahoo.net.HostName; import com.yahoo.test.ManualClock; -import com.yahoo.vespa.config.GenerationCounter; import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.MemoryGenerationCounter; import com.yahoo.vespa.config.server.MockProvisioner; @@ -55,14 +54,15 @@ public class RpcTester implements AutoCloseable { private final ManualClock clock = new ManualClock(Instant.ofEpochMilli(100)); private final String myHostname = HostName.getLocalhost(); private final HostLivenessTracker hostLivenessTracker = new ConfigRequestHostLivenessTracker(clock); - private final GenerationCounter generationCounter; private final Spec spec; - private RpcServer rpcServer; + private final RpcServer rpcServer; private Thread t; private Supervisor sup; + private final ApplicationId applicationId; private final TenantName tenantName; private final TenantRepository tenantRepository; + private final HostRegistry hostRegistry = new HostRegistry(); private final ApplicationRepository applicationRepository; private final List<Integer> allocatedPorts = new ArrayList<>(); @@ -75,6 +75,7 @@ public class RpcTester implements AutoCloseable { RpcTester(ApplicationId applicationId, TemporaryFolder temporaryFolder, ConfigserverConfig.Builder configBuilder) throws InterruptedException, IOException { this.temporaryFolder = temporaryFolder; + this.applicationId = applicationId; this.tenantName = applicationId.tenant(); int port = allocatePort(); spec = createSpec(port); @@ -83,23 +84,27 @@ public class RpcTester implements AutoCloseable { .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath()) .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()); configserverConfig = new ConfigserverConfig(configBuilder); + rpcServer = createRpcServer(configserverConfig); TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder() .configDefinitionRepo(new TestConfigDefinitionRepo()) .configServerConfig(configserverConfig) + .reloadListener(rpcServer) + .hostRegistry(hostRegistry) .build(); tenantRepository = new TenantRepository(componentRegistry); tenantRepository.addTenant(tenantName); + startRpcServer(); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) + .withConfigserverConfig(configserverConfig) .withProvisioner(new MockProvisioner()) .withOrchestrator(new OrchestratorMock()) .build(); - generationCounter = new MemoryGenerationCounter(); - createAndStartRpcServer(); assertFalse(hostLivenessTracker.lastRequestFrom(myHostname).isPresent()); } public void close() { + rpcServer.stop(); for (Integer port : allocatedPorts) { PortRangeAllocator.releasePort(port); } @@ -111,23 +116,25 @@ public class RpcTester implements AutoCloseable { return port; } - void createAndStartRpcServer() throws IOException { - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); - hostRegistry.update(tenantName, List.of("localhost")); - rpcServer = new RpcServer(configserverConfig, - new SuperModelRequestHandler(new TestConfigDefinitionRepo(), - configserverConfig, - new SuperModelManager( - configserverConfig, - Zone.defaultZone() , - generationCounter, - new InMemoryFlagSource())), - Metrics.createTestMetrics(), - hostRegistry, - hostLivenessTracker, - new FileServer(temporaryFolder.newFolder()), - new NoopRpcAuthorizer(), - new RpcRequestHandlerProvider()); + RpcServer createRpcServer(ConfigserverConfig config) throws IOException { + return new RpcServer(config, + new SuperModelRequestHandler(new TestConfigDefinitionRepo(), + configserverConfig, + new SuperModelManager( + config, + Zone.defaultZone(), + new MemoryGenerationCounter(), + new InMemoryFlagSource())), + Metrics.createTestMetrics(), + hostRegistry, + hostLivenessTracker, + new FileServer(temporaryFolder.newFolder()), + new NoopRpcAuthorizer(), + new RpcRequestHandlerProvider()); + } + + void startRpcServer() { + hostRegistry.update(applicationId, List.of("localhost")); rpcServer.onTenantCreate(tenantRepository.getTenant(tenantName)); t = new Thread(rpcServer); t.start(); @@ -162,7 +169,7 @@ public class RpcTester implements AutoCloseable { void performRequest(Request req) { clock.advance(Duration.ofMillis(10)); - sup.connect(spec).invokeSync(req, 120.0); + sup.connect(spec).invokeSync(req, 10.0); if (req.methodName().equals(RpcServer.getConfigMethodName)) assertEquals(clock.instant(), hostLivenessTracker.lastRequestFrom(myHostname).get()); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizerTest.java index 9e1edb35b8f..12debc347de 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/security/MultiTenantRpcAuthorizerTest.java @@ -7,7 +7,6 @@ import com.yahoo.config.FileReference; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.NodeType; -import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.security.NodeIdentifier; import com.yahoo.config.provision.security.NodeIdentifierException; import com.yahoo.config.provision.security.NodeIdentity; @@ -66,7 +65,7 @@ public class MultiTenantRpcAuthorizerTest { @Test public void configserver_can_access_files_and_config() throws InterruptedException, ExecutionException { RpcAuthorizer authorizer = createAuthorizer(new NodeIdentity.Builder(NodeType.config).build(), - new HostRegistry<>()); + new HostRegistry()); Request configRequest = createConfigRequest(new ConfigKey<>("name", "configid", "namespace"), HOSTNAME); authorizer.authorizeConfigRequest(configRequest) @@ -83,8 +82,8 @@ public class MultiTenantRpcAuthorizerTest { .applicationId(APPLICATION_ID) .build(); - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); - hostRegistry.update(APPLICATION_ID.tenant(), List.of(HOSTNAME.value())); + HostRegistry hostRegistry = new HostRegistry(); + hostRegistry.update(APPLICATION_ID, List.of(HOSTNAME.value())); RpcAuthorizer authorizer = createAuthorizer(identity, hostRegistry); @@ -99,7 +98,7 @@ public class MultiTenantRpcAuthorizerTest { @Test public void proxy_node_can_access_lbservice_config() throws ExecutionException, InterruptedException { - RpcAuthorizer authorizer = createAuthorizer(new NodeIdentity.Builder(NodeType.proxy).build(), new HostRegistry<>()); + RpcAuthorizer authorizer = createAuthorizer(new NodeIdentity.Builder(NodeType.proxy).build(), new HostRegistry()); Request configRequest = createConfigRequest( new ConfigKey<>(LbServicesConfig.CONFIG_DEF_NAME, "*", LbServicesConfig.CONFIG_DEF_NAMESPACE), @@ -110,7 +109,7 @@ public class MultiTenantRpcAuthorizerTest { @Test public void tenant_node_cannot_access_lbservice_config() throws ExecutionException, InterruptedException { - RpcAuthorizer authorizer = createAuthorizer(new NodeIdentity.Builder(NodeType.tenant).build(), new HostRegistry<>()); + RpcAuthorizer authorizer = createAuthorizer(new NodeIdentity.Builder(NodeType.tenant).build(), new HostRegistry()); Request configRequest = createConfigRequest( new ConfigKey<>(LbServicesConfig.CONFIG_DEF_NAME, "*", LbServicesConfig.CONFIG_DEF_NAMESPACE), @@ -129,8 +128,8 @@ public class MultiTenantRpcAuthorizerTest { .applicationId(APPLICATION_ID) .build(); - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); - hostRegistry.update(APPLICATION_ID.tenant(), List.of(HOSTNAME.value())); + HostRegistry hostRegistry = new HostRegistry(); + hostRegistry.update(APPLICATION_ID, List.of(HOSTNAME.value())); RpcAuthorizer authorizer = createAuthorizer(identity, hostRegistry); @@ -149,8 +148,8 @@ public class MultiTenantRpcAuthorizerTest { .applicationId(EVIL_APP_ID) .build(); - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); - hostRegistry.update(APPLICATION_ID.tenant(), List.of(HOSTNAME.value())); + HostRegistry hostRegistry = new HostRegistry(); + hostRegistry.update(APPLICATION_ID, List.of(HOSTNAME.value())); RpcAuthorizer authorizer = createAuthorizer(identity, hostRegistry); @@ -169,7 +168,7 @@ public class MultiTenantRpcAuthorizerTest { .applicationId(EVIL_APP_ID) .build(); - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); + HostRegistry hostRegistry = new HostRegistry(); RpcAuthorizer authorizer = createAuthorizer(identity, hostRegistry); @@ -188,8 +187,8 @@ public class MultiTenantRpcAuthorizerTest { .applicationId(EVIL_APP_ID) .build(); - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); - hostRegistry.update(EVIL_APP_ID.tenant(), List.of(HOSTNAME.value())); + HostRegistry hostRegistry = new HostRegistry(); + hostRegistry.update(EVIL_APP_ID, List.of(HOSTNAME.value())); RpcAuthorizer authorizer = createAuthorizer(identity, hostRegistry); @@ -208,7 +207,7 @@ public class MultiTenantRpcAuthorizerTest { .applicationId(APPLICATION_ID) .build(); - HostRegistry<TenantName> hostRegistry = new HostRegistry<>(); + HostRegistry hostRegistry = new HostRegistry(); RpcAuthorizer authorizer = createAuthorizer(identity, hostRegistry); @@ -219,7 +218,7 @@ public class MultiTenantRpcAuthorizerTest { } - private static RpcAuthorizer createAuthorizer(NodeIdentity identity, HostRegistry<TenantName> hostRegistry) { + private static RpcAuthorizer createAuthorizer(NodeIdentity identity, HostRegistry hostRegistry) { return new MultiTenantRpcAuthorizer( new StaticNodeIdentifier(identity), hostRegistry, diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java index 76958264d84..90d3bddc88d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java @@ -187,7 +187,7 @@ public class SessionPreparerTest { @Test(expected = InvalidApplicationException.class) public void require_exception_for_overlapping_host() throws IOException { FilesApplicationPackage app = getApplicationPackage(testApp); - HostRegistry<ApplicationId> hostValidator = new HostRegistry<>(); + HostRegistry hostValidator = new HostRegistry(); hostValidator.update(applicationId("foo"), Collections.singletonList("mytesthost")); preparer.prepare(hostValidator, new BaseDeployLogger(), new PrepareParams.Builder().applicationId(applicationId("default")).build(), Optional.empty(), Instant.now(), app.getAppDir(), app, createSessionZooKeeperClient()); @@ -200,7 +200,7 @@ public class SessionPreparerTest { if (level.equals(Level.WARNING) && message.contains("The host mytesthost is already in use")) logged.append("ok"); }; FilesApplicationPackage app = getApplicationPackage(testApp); - HostRegistry<ApplicationId> hostValidator = new HostRegistry<>(); + HostRegistry hostValidator = new HostRegistry(); ApplicationId applicationId = applicationId(); hostValidator.update(applicationId, Collections.singletonList("mytesthost")); preparer.prepare(hostValidator, logger, new PrepareParams.Builder().applicationId(applicationId).build(), @@ -367,7 +367,7 @@ public class SessionPreparerTest { private PrepareResult prepare(File app, PrepareParams params, long sessionId) throws IOException { FilesApplicationPackage applicationPackage = getApplicationPackage(app); - return preparer.prepare(new HostRegistry<>(), getLogger(), params, + return preparer.prepare(new HostRegistry(), getLogger(), params, Optional.empty(), Instant.now(), applicationPackage.getAppDir(), applicationPackage, createSessionZooKeeperClient(sessionId)); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java index bfcfc7d6e43..c7612937d47 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java @@ -60,6 +60,7 @@ public class SessionRepositoryTest { private static final TenantName tenantName = TenantName.defaultName(); private static final ApplicationId applicationId = ApplicationId.from(tenantName.value(), "testApp", "default"); private static final File testApp = new File("src/test/apps/app"); + private static final File appJdiscOnly = new File("src/test/apps/app-jdisc-only"); private MockCurator curator; private TenantRepository tenantRepository; @@ -135,7 +136,7 @@ public class SessionRepositoryTest { // tenant is "newTenant" TenantName newTenant = TenantName.from("newTenant"); tenantRepository.addTenant(newTenant); - long sessionId = deploy(ApplicationId.from(newTenant.value(), "testapp", "default")); + long sessionId = deploy(ApplicationId.from(newTenant.value(), "testapp", "default"), appJdiscOnly); SessionRepository sessionRepository2 = tenantRepository.getTenant(newTenant).getSessionRepository(); assertNotNull(sessionRepository2.getLocalSession(sessionId)); } |