private async Task WaitForInstanceToBecomeHealthyAsync( LoadBalancer loadBalancer, Instance newInstance) { bool IsUnhealthy() { var instanceHealth = loadBalancer .InstanceHealthSummary .SingleOrDefault(x => x.InstanceName == newInstance.Name); return instanceHealth?.InstanceHealth != InstanceHealthState.Healthy; } var stopwatch = this.time.StartStopwatch(); do { await this.time.WaitAsync(5000); if (stopwatch.Elapsed.TotalMinutes > 30) { throw new NewInstanceHealthTimeoutException( $"The newly deployed instance {newInstance.Name} was not healthy after 5 minutes."); } loadBalancer = await mediator.Send(new GetLoadBalancerByNameQuery(loadBalancer.Name)) ?? throw new InvalidOperationException("Could not refresh load balancer status."); } while (IsUnhealthy()); }
private async Task AttachInstanceToLoadBalancerAsync( Instance instance, LoadBalancer loadBalancer) { await mediator.Send(new AttachInstancesToLoadBalancerCommand( loadBalancer.Name, new[] { instance.Name })); }
private async Task DestroyOldInstancesAsync( LoadBalancer loadBalancer, Instance newInstance) { var oldInstanceNames = loadBalancer .InstanceHealthSummary .Where(x => x.InstanceName != newInstance.Name) .Select(x => x.InstanceName); foreach (var oldInstanceName in oldInstanceNames) { logger.Warning("Deleting old instance {InstanceName}.", oldInstanceName); await DestroyInstanceByNameAsync(oldInstanceName); } }
private async Task AssignStaticIpAddressToNewInstanceAsync(Instance newInstance) { await this.mediator.Send(new AssignStaticIpToInstanceCommand( newInstance.Name, ipName)); }