aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/lb/LoadBalancers.java
blob: 1d218e6c97321246e61a6906cb78081e533e64b1 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.lb;

import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.hosted.provision.persistence.CuratorDb;

import java.util.function.Predicate;

/**
 * The load balancers of this node repo.
 *
 * @author bratseth
 * @author mpolden
 */
public class LoadBalancers {

    private final CuratorDb db;

    public LoadBalancers(CuratorDb db) {
        this.db = db;
    }

    /** Returns a filterable list of all load balancers in this repository */
    public LoadBalancerList list() {
        return list((ignored) -> true);
    }

    /** Returns a filterable list of load balancers belonging to given application */
    public LoadBalancerList list(ApplicationId application) {
        return list((id) -> id.application().equals(application));
    }

    private LoadBalancerList list(Predicate<LoadBalancerId> predicate) {
        return LoadBalancerList.copyOf(db.readLoadBalancers(predicate).values());
    }

}