All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.hosted.provision.lb.LoadBalancerServiceMock Maven / Gradle / Ivy

There is a newer version: 8.458.13
Show newest version
// Copyright 2018 Yahoo Holdings. 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.ImmutableSet;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.HostName;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
 * @author mpolden
 */
public class LoadBalancerServiceMock implements LoadBalancerService {

    private final Map instances = new HashMap<>();

    public Map instances() {
        return Collections.unmodifiableMap(instances);
    }

    @Override
    public Protocol protocol() {
        return Protocol.ipv4;
    }

    @Override
    public LoadBalancerInstance create(ApplicationId application, ClusterSpec.Id cluster, Set reals, boolean force) {
        var id = new LoadBalancerId(application, cluster);
        var oldInstance = instances.get(id);
        if (!force && oldInstance != null && !oldInstance.reals().isEmpty() && reals.isEmpty()) {
            throw new IllegalArgumentException("Refusing to remove all reals from load balancer " + id);
        }
        var instance = new LoadBalancerInstance(
                HostName.from("lb-" + application.toShortString() + "-" + cluster.value()),
                Optional.of(new DnsZone("zone-id-1")),
                Collections.singleton(4443),
                ImmutableSet.of("10.2.3.0/24", "10.4.5.0/24"),
                reals);
        instances.put(id, instance);
        return instance;
    }

    @Override
    public void remove(ApplicationId application, ClusterSpec.Id cluster) {
        instances.remove(new LoadBalancerId(application, cluster));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy