-
Notifications
You must be signed in to change notification settings - Fork 869
/
Copy pathLoadBalancer.cs
40 lines (37 loc) · 1.53 KB
/
LoadBalancer.cs
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
38
39
40
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Microsoft.ReverseProxy.Core.Abstractions;
using Microsoft.ReverseProxy.Core.RuntimeModel;
namespace Microsoft.ReverseProxy.Core.Service.Proxy
{
/// <summary>
/// Default implementation of <see cref="ILoadBalancer"/>.
/// </summary>
internal class LoadBalancer : ILoadBalancer
{
public EndpointInfo PickEndpoint(
IReadOnlyList<EndpointInfo> healthyEndpoints,
IReadOnlyList<EndpointInfo> allEndpoints,
in BackendConfig.BackendLoadBalancingOptions loadBalancingOptions)
{
switch (loadBalancingOptions.Mode)
{
case BackendConfig.BackendLoadBalancingOptions.LoadBalancingMode.First:
// TODO: Remove, this is a silly load balancing mode
if (healthyEndpoints.Count == 0)
{
return null;
}
return healthyEndpoints[0];
case BackendConfig.BackendLoadBalancingOptions.LoadBalancingMode.Random:
throw new NotImplementedException();
case BackendConfig.BackendLoadBalancingOptions.LoadBalancingMode.PowerOfTwoChoices:
throw new NotImplementedException();
default:
throw new ReverseProxyException($"Load balancing mode '{loadBalancingOptions.Mode}' is not supported.");
}
}
}
}