StateV1HealthModel implements AutoCloseable { Map<ServiceId, HealthEndpoint> extractHealthEndpoints(ApplicationInfo application) { Map<ServiceId, HealthEndpoint> endpoints = new HashMap<>(); for (HostInfo hostInfo : application.getModel().getHosts()) { HostName hostname = HostName.from(hostInfo.getHostname()); for (ServiceInfo serviceInfo : hostInfo.getServices()) { ServiceId serviceId = ApplicationInstanceGenerator.getServiceId(application, serviceInfo); for (PortInfo portInfo : serviceInfo.getPorts()) { if (portTaggedWith(portInfo, HTTP_HEALTH_PORT_TAGS)) { StateV1HealthEndpoint endpoint = new StateV1HealthEndpoint( serviceId, hostname, portInfo.getPort(), targetHealthStaleness, requestTimeout, connectionKeepAlive, executor); endpoints.put(serviceId, endpoint); break; } } } } return endpoints; } StateV1HealthModel(Duration targetHealthStaleness,
                       Duration requestTimeout,
                       Duration connectionKeepAlive,
                       RunletExecutor executor); @Override void close(); static final List<String> HTTP_HEALTH_PORT_TAGS; }
@Test public void test() { Map<ServiceId, HealthEndpoint> endpoints = model.extractHealthEndpoints(proxyHostApplicationInfo); assertEquals(2, endpoints.size()); ApplicationId applicationId = ApplicationId.from("hosted-vespa", "proxy-host", "default"); ClusterId clusterId = new ClusterId("proxy-host"); ServiceId hostAdmin1 = new ServiceId(applicationId, clusterId, ServiceType.HOST_ADMIN, new ConfigId("proxy-host/host1")); ServiceId hostAdmin2 = new ServiceId(applicationId, clusterId, ServiceType.HOST_ADMIN, new ConfigId("proxy-host/host2")); HealthEndpoint endpoint1 = endpoints.get(hostAdmin1); assertNotNull(endpoint1); assertEquals("http: HealthEndpoint endpoint2 = endpoints.get(hostAdmin2); assertNotNull(endpoint2); assertEquals("http: Cancellable cancellable = mock(Cancellable.class); when(executor.scheduleWithFixedDelay(any(), any())).thenReturn(cancellable); try (HealthMonitor healthMonitor = endpoint1.startMonitoring()) { assertEquals(ServiceStatus.NOT_CHECKED, healthMonitor.getStatus().serviceStatus()); } }