com.yahoo.vespa.hosted.provision.lb.LoadBalancerInstance Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of node-repository Show documentation
Show all versions of node-repository Show documentation
Keeps track of node assignment in a multi-application setup.
// Copyright 2019 Oath Inc. 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.google.common.collect.ImmutableSortedSet;
import com.yahoo.config.provision.HostName;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
/**
* Represents a load balancer instance. This contains the fields that are owned by a {@link LoadBalancerService} and is
* immutable.
*
* @author mpolden
*/
public class LoadBalancerInstance {
private final HostName hostname;
private final Optional dnsZone;
private final Set ports;
private final Set networks;
private final Set reals;
public LoadBalancerInstance(HostName hostname, Optional dnsZone, Set ports, Set networks,
Set reals) {
this.hostname = Objects.requireNonNull(hostname, "hostname must be non-null");
this.dnsZone = Objects.requireNonNull(dnsZone, "dnsZone must be non-null");
this.ports = ImmutableSortedSet.copyOf(requirePorts(ports));
this.networks = ImmutableSortedSet.copyOf(Objects.requireNonNull(networks, "networks must be non-null"));
this.reals = ImmutableSortedSet.copyOf(Objects.requireNonNull(reals, "targets must be non-null"));
}
/** Fully-qualified domain name of this load balancer. This hostname can be used for query and feed */
public HostName hostname() {
return hostname;
}
/** ID of the DNS zone associated with this */
public Optional dnsZone() {
return dnsZone;
}
/** Listening port(s) of this load balancer */
public Set ports() {
return ports;
}
/** Networks (CIDR blocks) of this load balancer */
public Set networks() {
return networks;
}
/** Real servers behind this load balancer */
public Set reals() {
return reals;
}
/** Returns a copy of this with reals set to given reals */
public LoadBalancerInstance withReals(Set reals) {
return new LoadBalancerInstance(hostname, dnsZone, ports, networks, reals);
}
private static Set requirePorts(Set ports) {
Objects.requireNonNull(ports, "ports must be non-null");
if (ports.isEmpty()) {
throw new IllegalArgumentException("ports must be non-empty");
}
if (!ports.stream().allMatch(port -> port >= 1 && port <= 65535)) {
throw new IllegalArgumentException("all ports must be >= 1 and <= 65535");
}
return ports;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy