diff options
author | jonmv <venstad@gmail.com> | 2023-03-30 11:40:45 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-03-30 11:40:45 +0200 |
commit | ff2963cfaa55ef530a8ec041ca2a3aeb2ba97212 (patch) | |
tree | 437bb1112e74ee3cdd823126d4b746c7084058f9 /service-monitor/src | |
parent | 73f5b777ba374c3a0a92ca661ce8cbb35beb509f (diff) |
Use DomainName instead of the stricter HostName in duper-model
Diffstat (limited to 'service-monitor/src')
10 files changed, 41 insertions, 50 deletions
diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java index 3a9c2b1f1e7..d76b4ecc0b5 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java @@ -1,10 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.duper; +import ai.vespa.http.DomainName; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.HostName; import java.util.logging.Level; import com.yahoo.vespa.service.monitor.DuperModelListener; @@ -26,8 +26,8 @@ public class DuperModel { private static Logger logger = Logger.getLogger(DuperModel.class.getName()); private final Map<ApplicationId, ApplicationInfo> applicationsById = new HashMap<>(); - private final Map<HostName, ApplicationId> idsByHostname = new HashMap<>(); - private final Map<ApplicationId, HashSet<HostName>> hostnamesById = new HashMap<>(); + private final Map<DomainName, ApplicationId> idsByHostname = new HashMap<>(); + private final Map<ApplicationId, HashSet<DomainName>> hostnamesById = new HashMap<>(); private final List<DuperModelListener> listeners = new ArrayList<>(); private boolean isComplete = false; @@ -67,7 +67,7 @@ public class DuperModel { return Optional.ofNullable(applicationsById.get(applicationId)); } - public Optional<ApplicationInfo> getApplicationInfo(HostName hostName) { + public Optional<ApplicationInfo> getApplicationInfo(DomainName hostName) { return Optional.ofNullable(idsByHostname.get(hostName)).map(applicationsById::get); } @@ -76,12 +76,12 @@ public class DuperModel { } /** Note: Returns an empty set for unknown application. */ - public Set<HostName> getHostnames(ApplicationId applicationId) { - HashSet<HostName> set = hostnamesById.get(applicationId); + public Set<DomainName> getHostnames(ApplicationId applicationId) { + HashSet<DomainName> set = hostnamesById.get(applicationId); return set == null ? Set.of() : Set.copyOf(set); } - public Optional<ApplicationId> getApplicationId(HostName hostname) { + public Optional<ApplicationId> getApplicationId(DomainName hostname) { return Optional.ofNullable(idsByHostname.get(hostname)); } @@ -103,7 +103,7 @@ public class DuperModel { } public void remove(ApplicationId applicationId) { - Set<HostName> hostnames = hostnamesById.remove(applicationId); + Set<DomainName> hostnames = hostnamesById.remove(applicationId); if (hostnames != null) { hostnames.forEach(idsByHostname::remove); } @@ -117,11 +117,11 @@ public class DuperModel { /** Update hostnamesById and idsByHostname based on a new applicationInfo. */ private void updateHostnameVsIdMaps(ApplicationInfo applicationInfo, ApplicationId id) { - Set<HostName> removedHosts = new HashSet<>(hostnamesById.computeIfAbsent(id, k -> new HashSet<>())); + Set<DomainName> removedHosts = new HashSet<>(hostnamesById.computeIfAbsent(id, k -> new HashSet<>())); applicationInfo.getModel().getHosts().stream() .map(HostInfo::getHostname) - .map(HostName::of) + .map(DomainName::of) .forEach(hostname -> { if (!removedHosts.remove(hostname)) { // hostname has been added @@ -135,7 +135,7 @@ public class DuperModel { logger.log(Level.WARNING, hostname + " has been reassigned from " + previousId.toFullString() + " to " + id.toFullString()); - Set<HostName> previousHostnames = hostnamesById.get(previousId); + Set<DomainName> previousHostnames = hostnamesById.get(previousId); if (previousHostnames != null) { previousHostnames.remove(hostname); } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java index b8c980a8760..400c4f4b907 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java @@ -1,14 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.duper; -import com.yahoo.component.annotation.Inject; +import ai.vespa.http.DomainName; import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.component.annotation.Inject; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.SuperModel; import com.yahoo.config.model.api.SuperModelListener; import com.yahoo.config.model.api.SuperModelProvider; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.HostName; import com.yahoo.vespa.service.monitor.CriticalRegion; import com.yahoo.vespa.service.monitor.DuperModelInfraApi; import com.yahoo.vespa.service.monitor.DuperModelListener; @@ -133,7 +133,7 @@ public class DuperModelManager implements DuperModelProvider, DuperModelInfraApi } @Override - public void infraApplicationActivated(ApplicationId applicationId, List<HostName> hostnames) { + public void infraApplicationActivated(ApplicationId applicationId, List<DomainName> hostnames) { InfraApplication application = supportedInfraApplications.get(applicationId); if (application == null) { throw new IllegalArgumentException("There is no infrastructure application with ID '" + applicationId + "'"); @@ -172,7 +172,7 @@ public class DuperModelManager implements DuperModelProvider, DuperModelInfraApi return lockedSupplier(() -> duperModel.getApplicationInfo(applicationId)); } - public Optional<ApplicationInfo> getApplicationInfo(HostName hostname) { + public Optional<ApplicationInfo> getApplicationInfo(DomainName hostname) { return lockedSupplier(() -> duperModel.getApplicationInfo(hostname)); } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java index e82e2cc0265..07f9d7bddc5 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.duper; +import ai.vespa.http.DomainName; import com.yahoo.component.Version; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.HostInfo; @@ -9,7 +10,6 @@ import com.yahoo.config.model.api.ServiceInfo; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Capacity; import com.yahoo.config.provision.ClusterSpec; -import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.applicationmodel.ApplicationInstanceId; import com.yahoo.vespa.applicationmodel.ClusterId; @@ -93,12 +93,12 @@ public abstract class InfraApplication implements InfraApplicationApi { return new TenantId(application.id().tenant().value()); } - public ApplicationInfo makeApplicationInfo(List<HostName> hostnames) { + public ApplicationInfo makeApplicationInfo(List<DomainName> hostnames) { List<HostInfo> hostInfos = hostnames.stream().map(this::makeHostInfo).toList(); return new ApplicationInfo(application.id(), 0, new HostsModel(hostInfos)); } - private HostInfo makeHostInfo(HostName hostname) { + private HostInfo makeHostInfo(DomainName hostname) { PortInfo portInfo = new PortInfo(healthPort, StateV1HealthModel.HTTP_HEALTH_PORT_TAGS); Map<String, String> properties = new HashMap<>(); @@ -116,7 +116,7 @@ public abstract class InfraApplication implements InfraApplicationApi { return new HostInfo(hostname.value(), Collections.singletonList(serviceInfo)); } - public ConfigId configIdFor(HostName hostname) { + public ConfigId configIdFor(DomainName hostname) { // Not necessarily unique, but service monitor doesn't require it to be unique. return new ConfigId(String.format("%s/%s", clusterSpecId.value(), prefixTo(hostname.value(), '.'))); } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/model/ServiceMonitorImpl.java b/service-monitor/src/main/java/com/yahoo/vespa/service/model/ServiceMonitorImpl.java index 815f8de26b4..53db7cc135c 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/model/ServiceMonitorImpl.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/model/ServiceMonitorImpl.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.model; +import ai.vespa.http.DomainName; import com.yahoo.component.annotation.Inject; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.provision.ApplicationId; @@ -68,7 +69,7 @@ public class ServiceMonitorImpl implements ServiceMonitor, AntiServiceMonitor { @Override public Optional<ApplicationInstanceReference> getApplicationInstanceReference(HostName hostname) { - return duperModelManager.getApplicationInfo(toConfigProvisionHostName(hostname)) + return duperModelManager.getApplicationInfo(DomainName.of(hostname.s())) .map(ApplicationInfo::getApplicationId) .map(modelGenerator::toApplicationInstanceReference); } @@ -113,11 +114,7 @@ public class ServiceMonitorImpl implements ServiceMonitor, AntiServiceMonitor { } private Optional<ApplicationInfo> getApplicationInfo(HostName hostname) { - return duperModelManager.getApplicationInfo(toConfigProvisionHostName(hostname)); + return duperModelManager.getApplicationInfo(DomainName.of(hostname.s())); } - /** The duper model uses HostName from config.provision. */ - private static com.yahoo.config.provision.HostName toConfigProvisionHostName(HostName hostname) { - return com.yahoo.config.provision.HostName.of(hostname.s()); - } } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/DuperModelInfraApi.java b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/DuperModelInfraApi.java index 91782d5a582..783f0a27e51 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/DuperModelInfraApi.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/DuperModelInfraApi.java @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.monitor; +import ai.vespa.http.DomainName; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.HostName; import java.util.List; import java.util.Optional; @@ -24,7 +24,7 @@ public interface DuperModelInfraApi { boolean infraApplicationIsActive(ApplicationId applicationId); /** Update the DuperModel: A supported infrastructure application has been (re)activated or is active. */ - void infraApplicationActivated(ApplicationId applicationId, List<HostName> hostnames); + void infraApplicationActivated(ApplicationId applicationId, List<DomainName> hostnames); /** Update the DuperModel: A supported infrastructure application has been removed or is not active. */ void infraApplicationRemoved(ApplicationId applicationId); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java index 6cf7d4d9f26..ad7f0f188c0 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java @@ -1,17 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.duper; +import ai.vespa.http.DomainName; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.SuperModel; import com.yahoo.config.model.api.SuperModelListener; import com.yahoo.config.model.api.SuperModelProvider; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.HostName; import org.junit.Test; import org.mockito.ArgumentCaptor; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import static com.yahoo.vespa.service.duper.DuperModelManager.configServerApplication; @@ -64,7 +63,7 @@ public class DuperModelManagerTest { makeManager(false); ApplicationId id = proxyHostApplication.getApplicationId(); - List<HostName> proxyHostHosts = Stream.of("proxyhost1", "proxyhost2").map(HostName::of).toList(); + List<DomainName> proxyHostHosts = Stream.of("proxyhost1", "proxyhost2").map(DomainName::of).toList(); verify(duperModel, times(0)).add(any()); manager.infraApplicationActivated(id, proxyHostHosts); verify(duperModel, times(1)).add(any()); @@ -91,12 +90,12 @@ public class DuperModelManagerTest { } private void testEnabledConfigServerLikeInfraApplication(ApplicationId firstId, ApplicationId secondId) { - List<HostName> hostnames1 = Stream.of("node11", "node12").map(HostName::of).toList(); + List<DomainName> hostnames1 = Stream.of("node11", "node12").map(DomainName::of).toList(); manager.infraApplicationActivated(firstId, hostnames1); verify(duperModel, times(1)).add(any()); // Adding the second config server like application will be ignored - List<HostName> hostnames2 = Stream.of("node21", "node22").map(HostName::of).toList(); + List<DomainName> hostnames2 = Stream.of("node21", "node22").map(DomainName::of).toList(); assertThrows(IllegalArgumentException.class, () -> manager.infraApplicationActivated(secondId, hostnames2)); verify(duperModel, times(1)).add(any()); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java index f7ee64b52a6..2cfbc0307b7 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/health/HealthMonitorManagerTest.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.health; +import ai.vespa.http.DomainName; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.provision.HostName; import com.yahoo.vespa.applicationmodel.ServiceStatus; @@ -14,7 +15,6 @@ import org.junit.Before; import org.junit.Test; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.Assert.assertEquals; @@ -48,7 +48,7 @@ public class HealthMonitorManagerTest { public void infrastructureApplication() { ProxyHostApplication proxyHostApplication = new ProxyHostApplication(); when(duperModel.isSupportedInfraApplication(proxyHostApplication.getApplicationId())).thenReturn(true); - List<HostName> hostnames = Stream.of("proxyhost1", "proxyhost2").map(HostName::of).toList(); + List<DomainName> hostnames = Stream.of("proxyhost1", "proxyhost2").map(DomainName::of).toList(); ApplicationInfo proxyHostApplicationInfo = proxyHostApplication.makeApplicationInfo(hostnames); manager.applicationActivated(proxyHostApplicationInfo); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthModelTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthModelTest.java index 18b56f76e88..01b7930a74f 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthModelTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/health/StateV1HealthModelTest.java @@ -1,10 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.health; +import ai.vespa.http.DomainName; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.PortInfo; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.HostName; import com.yahoo.vespa.applicationmodel.ClusterId; import com.yahoo.vespa.applicationmodel.ConfigId; import com.yahoo.vespa.applicationmodel.ServiceStatus; @@ -18,7 +18,6 @@ import org.junit.Test; import java.time.Duration; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.Assert.assertEquals; @@ -38,7 +37,7 @@ public class StateV1HealthModelTest { private final Duration requestTimeout = Duration.ofSeconds(2); private final Duration keepAlive = Duration.ofSeconds(3); private final ProxyHostApplication proxyHostApplication = new ProxyHostApplication(); - private final List<HostName> hostnames = Stream.of("host1", "host2").map(HostName::of).toList(); + private final List<DomainName> hostnames = Stream.of("host1", "host2").map(DomainName::of).toList(); private final ApplicationInfo proxyHostApplicationInfo = proxyHostApplication.makeApplicationInfo(hostnames); private final StateV1HealthModel model = new StateV1HealthModel(healthStaleness, requestTimeout, keepAlive, executor); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/model/ApplicationInstanceGeneratorTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ApplicationInstanceGeneratorTest.java index a2532590f52..e85a00d732c 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/model/ApplicationInstanceGeneratorTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/model/ApplicationInstanceGeneratorTest.java @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.model; +import ai.vespa.http.DomainName; import com.yahoo.config.model.api.ApplicationInfo; -import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.applicationmodel.ApplicationInstance; import com.yahoo.vespa.applicationmodel.ServiceStatus; @@ -12,7 +12,6 @@ import com.yahoo.vespa.service.monitor.ServiceStatusProvider; import org.junit.Test; import java.util.List; -import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -34,7 +33,7 @@ public class ApplicationInstanceGeneratorTest { when(statusProvider.getStatus(any(), any(), any(), any())).thenReturn(new ServiceStatusInfo(ServiceStatus.NOT_CHECKED)); Zone zone = mock(Zone.class); ApplicationInfo configServer = configServerApplication.makeApplicationInfo( - configServerList.stream().map(HostName::of).toList()); + configServerList.stream().map(DomainName::of).toList()); ApplicationInstance applicationInstance = new ApplicationInstanceGenerator(configServer, zone) .makeApplicationInstance(statusProvider); diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ConfigserverUtil.java b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ConfigserverUtil.java index 498a9dfc15e..7367b8c5992 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ConfigserverUtil.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/monitor/ConfigserverUtil.java @@ -1,11 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.monitor; +import ai.vespa.http.DomainName; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.provision.HostName; import com.yahoo.vespa.service.duper.ConfigServerApplication; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -13,6 +15,7 @@ import java.util.stream.Stream; * @author hakon */ public class ConfigserverUtil { + /** Create a ConfigserverConfig with the given settings. */ public static ConfigserverConfig create( boolean multitenant, @@ -31,16 +34,10 @@ public class ConfigserverUtil { return create(true, "cfg1", "cfg2", "cfg3"); } - public static ApplicationInfo makeConfigServerApplicationInfo( - String configServerHostname1, - String configServerHostname2, - String configServerHostname3) { - return new ConfigServerApplication().makeApplicationInfo( - Stream.of(configServerHostname1, configServerHostname2, configServerHostname3) - .map(HostName::of).toList()); - } - public static ApplicationInfo makeExampleConfigServer() { - return makeConfigServerApplicationInfo("cfg1", "cfg2", "cfg3"); + return new ConfigServerApplication().makeApplicationInfo(List.of(DomainName.of("cfg1"), + DomainName.of("cfg2"), + DomainName.of("cfg3"))); } + } |