-
Notifications
You must be signed in to change notification settings - Fork 857
/
Cluster.cs
96 lines (83 loc) · 3.67 KB
/
Cluster.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using Microsoft.ReverseProxy.Utilities;
namespace Microsoft.ReverseProxy.Abstractions
{
/// <summary>
/// A cluster is a group of equivalent endpoints and associated policies.
/// A route maps requests to a cluster, and Reverse Proxy handles that request
/// by proxying to any endpoint within the matching cluster,
/// honoring load balancing and partitioning policies when applicable.
/// </summary>
public sealed class Cluster : IDeepCloneable<Cluster>
{
/// <summary>
/// The Id for this cluster. This needs to be globally unique.
/// </summary>
public string Id { get; set; }
/// <summary>
/// Load balancing options.
/// </summary>
public LoadBalancingOptions LoadBalancing { get; set; }
/// <summary>
/// Session affinity options.
/// </summary>
public SessionAffinityOptions SessionAffinity { get; set; }
/// <summary>
/// Health checking options.
/// </summary>
public HealthCheckOptions HealthCheck { get; set; }
/// <summary>
/// Options of an HTTP client that is used to call this cluster.
/// </summary>
public ProxyHttpClientOptions HttpClient { get; set; }
/// <summary>
/// Options of an outgoing HTTP request.
/// </summary>
public ProxyHttpRequestOptions HttpRequest { get; set; }
/// <summary>
/// The set of destinations associated with this cluster.
/// </summary>
public IDictionary<string, Destination> Destinations { get; private set; } = new Dictionary<string, Destination>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Arbitrary key-value pairs that further describe this cluster.
/// </summary>
public IDictionary<string, string> Metadata { get; set; }
/// <inheritdoc/>
Cluster IDeepCloneable<Cluster>.DeepClone()
{
return new Cluster
{
Id = Id,
LoadBalancing = LoadBalancing?.DeepClone(),
SessionAffinity = SessionAffinity?.DeepClone(),
HealthCheck = HealthCheck?.DeepClone(),
HttpClient = HttpClient?.DeepClone(),
HttpRequest = HttpRequest?.DeepClone(),
Destinations = Destinations.DeepClone(StringComparer.OrdinalIgnoreCase),
Metadata = Metadata?.DeepClone(StringComparer.OrdinalIgnoreCase),
};
}
internal static bool Equals(Cluster cluster1, Cluster cluster2)
{
if (cluster1 == null && cluster2 == null)
{
return true;
}
if (cluster1 == null || cluster2 == null)
{
return false;
}
return string.Equals(cluster1.Id, cluster2.Id, StringComparison.OrdinalIgnoreCase)
&& LoadBalancingOptions.Equals(cluster1.LoadBalancing, cluster2.LoadBalancing)
&& SessionAffinityOptions.Equals(cluster1.SessionAffinity, cluster2.SessionAffinity)
&& HealthCheckOptions.Equals(cluster1.HealthCheck, cluster2.HealthCheck)
&& ProxyHttpClientOptions.Equals(cluster1.HttpClient, cluster2.HttpClient)
&& ProxyHttpRequestOptions.Equals(cluster1.HttpRequest, cluster2.HttpRequest)
&& CaseInsensitiveEqualHelper.Equals(cluster1.Destinations, cluster2.Destinations, Destination.Equals)
&& CaseInsensitiveEqualHelper.Equals(cluster1.Metadata, cluster2.Metadata);
}
}
}