Skip to content

Commit

Permalink
Merge pull request vespa-engine#9887 from vespa-engine/mpolden/never-…
Browse files Browse the repository at this point in the history
…provision-new-lb-on-activate

Never provision a new LB in activate MERGEOK
  • Loading branch information
mpolden authored Jun 25, 2019
2 parents a512024 + 5b32cbd commit 37bfd5b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public NodeRepositoryMaintenance(NodeRepository nodeRepository, Deployer deploye
metricsReporter = new MetricsReporter(nodeRepository, metric, orchestrator, serviceMonitor, periodicApplicationMaintainer::pendingDeployments, durationFromEnv("metrics_interval").orElse(defaults.metricsInterval));
infrastructureProvisioner = new InfrastructureProvisioner(nodeRepository, infraDeployer, durationFromEnv("infrastructure_provision_interval").orElse(defaults.infrastructureProvisionInterval));
loadBalancerExpirer = provisionServiceProvider.getLoadBalancerService().map(lbService ->
new LoadBalancerExpirer(nodeRepository, durationFromEnv("load_balancer_expiry").orElse(defaults.loadBalancerExpiry), lbService));
new LoadBalancerExpirer(nodeRepository, durationFromEnv("load_balancer_expirer_interval").orElse(defaults.loadBalancerExpirerInterval), lbService));
hostProvisionMaintainer = provisionServiceProvider.getHostProvisioner().map(hostProvisioner ->
new HostProvisionMaintainer(nodeRepository, durationFromEnv("host_provisioner_interval").orElse(defaults.hostProvisionerInterval), hostProvisioner, flagSource));
hostDeprovisionMaintainer = provisionServiceProvider.getHostProvisioner().map(hostProvisioner ->
Expand Down Expand Up @@ -143,7 +143,7 @@ private static class DefaultTimes {
private final Duration metricsInterval;
private final Duration retiredInterval;
private final Duration infrastructureProvisionInterval;
private final Duration loadBalancerExpiry;
private final Duration loadBalancerExpirerInterval;
private final Duration hostProvisionerInterval;
private final Duration hostDeprovisionerInterval;

Expand All @@ -161,7 +161,7 @@ private static class DefaultTimes {
metricsInterval = Duration.ofMinutes(1);
infrastructureProvisionInterval = Duration.ofMinutes(1);
throttlePolicy = NodeFailer.ThrottlePolicy.hosted;
loadBalancerExpiry = Duration.ofMinutes(10);
loadBalancerExpirerInterval = Duration.ofMinutes(10);
reservationExpiry = Duration.ofMinutes(20); // Need to be long enough for deployment to be finished for all config model versions
hostProvisionerInterval = Duration.ofMinutes(5);
hostDeprovisionerInterval = Duration.ofMinutes(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ private void provision(ApplicationId application, ClusterSpec.Id clusterId, bool
try (var loadBalancersLock = db.lockLoadBalancers()) {
var id = new LoadBalancerId(application, clusterId);
var now = nodeRepository.clock().instant();
var instance = create(application, clusterId, allocatedContainers(application, clusterId));
var loadBalancer = db.readLoadBalancers().get(id);
if (loadBalancer == null && activate) return; // Nothing to activate as this load balancer was never prepared

var instance = create(application, clusterId, allocatedContainers(application, clusterId));
if (loadBalancer == null) {
if (activate) return; // Nothing to activate as this load balancer was never prepared
loadBalancer = new LoadBalancer(id, instance, LoadBalancer.State.reserved, now);
} else {
var newState = activate ? LoadBalancer.State.active : loadBalancer.state();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.HostSpec;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.transaction.NestedTransaction;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.lb.LoadBalancer;
Expand Down Expand Up @@ -37,6 +38,8 @@ public class LoadBalancerProvisionerTest {
private final ApplicationId app1 = ApplicationId.from("tenant1", "application1", "default");
private final ApplicationId app2 = ApplicationId.from("tenant2", "application2", "default");

private final ApplicationId infraApp1 = ApplicationId.from("vespa", "tenant-host", "default");

private ProvisioningTester tester = new ProvisioningTester.Builder().build();

@Test
Expand Down Expand Up @@ -131,15 +134,36 @@ public void provision_load_balancer() {
.orElseThrow());
}

@Test
public void does_not_provision_load_balancers_for_non_tenant_node_type() {
tester.activate(infraApp1, prepare(infraApp1, Capacity.fromRequiredNodeType(NodeType.host),
clusterRequest(ClusterSpec.Type.container,
ClusterSpec.Id.from("tenant-host"))));
assertTrue("No load balancer provisioned", tester.loadBalancerService().instances().isEmpty());
assertEquals(List.of(), tester.nodeRepository().loadBalancers().owner(infraApp1).asList());
}

@Test
public void does_not_provision_load_balancers_for_non_container_cluster() {
tester.activate(app1, prepare(app1, clusterRequest(ClusterSpec.Type.content,
ClusterSpec.Id.from("tenant-host"))));
assertTrue("No load balancer provisioned", tester.loadBalancerService().instances().isEmpty());
assertEquals(List.of(), tester.nodeRepository().loadBalancers().owner(app1).asList());
}

private void dirtyNodesOf(ApplicationId application) {
tester.nodeRepository().setDirty(tester.nodeRepository().getNodes(application), Agent.system, this.getClass().getSimpleName());
}

private Set<HostSpec> prepare(ApplicationId application, ClusterSpec... specs) {
tester.makeReadyNodes(specs.length * 2, "d-1-1-1");
return prepare(application, Capacity.fromCount(2, new NodeResources(1, 1, 1), false, true), specs);
}

private Set<HostSpec> prepare(ApplicationId application, Capacity capacity, ClusterSpec... specs) {
tester.makeReadyNodes(specs.length * 2, "d-1-1-1", capacity.type());
Set<HostSpec> allNodes = new LinkedHashSet<>();
for (ClusterSpec spec : specs) {
allNodes.addAll(tester.prepare(application, spec, Capacity.fromCount(2, new NodeResources(1, 1, 1), false, true), 1, false));
allNodes.addAll(tester.prepare(application, spec, capacity, 1, false));
}
return allNodes;
}
Expand Down

0 comments on commit 37bfd5b

Please sign in to comment.