aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-core/src/main/java/com/yahoo/vespaclient/ClusterList.java
blob: 452ab175862d6413b402bad88a8690cb6c334622 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespaclient;

import com.yahoo.cloud.config.ClusterListConfig;
import com.yahoo.config.subscription.ConfigGetter;

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

/** A list of content clusters, either obtained from a list, a given config or by self-subscribing */
public class ClusterList {

    private final List<ClusterDef> contentClusters;

    public ClusterList() {
        this(List.of());
    }
    
    public ClusterList(List<ClusterDef> contentClusters) {
        this.contentClusters = List.copyOf(contentClusters);
    }

    @SuppressWarnings("deprecation")
    public ClusterList(String configId) {
        this(new ConfigGetter<>(ClusterListConfig.class).getConfig(configId));
    }
    
    public ClusterList(ClusterListConfig config) {
        this(parse(config));
    }

    public List<ClusterDef> getStorageClusters() {
        return contentClusters;
    }

    private static List<ClusterDef> parse(ClusterListConfig config) {
        return config.storage().stream()
                     .map(storage -> new ClusterDef(storage.name()))
                     .toList();
    }

}