aboutsummaryrefslogtreecommitdiffstats
path: root/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/ConfigServerApplication.java
blob: 7a76c072076185a340d94c2c489c199f45b78432 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.service.monitor;

import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceId;
import com.yahoo.vespa.applicationmodel.ClusterId;
import com.yahoo.vespa.applicationmodel.ConfigId;
import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.applicationmodel.ServiceCluster;
import com.yahoo.vespa.applicationmodel.ServiceInstance;
import com.yahoo.vespa.applicationmodel.ServiceStatus;
import com.yahoo.vespa.applicationmodel.ServiceType;
import com.yahoo.vespa.applicationmodel.TenantId;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * A service/application model of the config server with health status.
 */
public class ConfigServerApplication {
    public static final ClusterId CLUSTER_ID = new ClusterId("zone-config-servers");
    public static final ServiceType SERVICE_TYPE = new ServiceType("configserver");
    public static final TenantId TENANT_ID = new TenantId("hosted-vespa");
    public static final ApplicationInstanceId APPLICATION_INSTANCE_ID = new ApplicationInstanceId("zone-config-servers");
    public static final String CONFIG_ID_PREFIX = "configid.";

    ApplicationInstance toApplicationInstance(List<String> hostnames) {
        Set<ServiceInstance> serviceInstances = hostnames.stream()
                .map(hostname -> new ServiceInstance(
                        new ConfigId(CONFIG_ID_PREFIX + hostname),
                        new HostName(hostname),
                        ServiceStatus.NOT_CHECKED))
                .collect(Collectors.toSet());

        ServiceCluster serviceCluster = new ServiceCluster(
                CLUSTER_ID,
                SERVICE_TYPE,
                serviceInstances);

        Set<ServiceCluster> serviceClusters =
                Stream.of(serviceCluster).collect(Collectors.toSet());

        ApplicationInstance applicationInstance = new ApplicationInstance(
                TENANT_ID,
                APPLICATION_INSTANCE_ID,
                serviceClusters);

        // Fill back-references
        serviceCluster.setApplicationInstance(applicationInstance);
        for (ServiceInstance serviceInstance : serviceCluster.serviceInstances()) {
            serviceInstance.setServiceCluster(serviceCluster);
        }

        return applicationInstance;
    }
}