-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAzureDiscoverySetup.cs
259 lines (227 loc) · 10.3 KB
/
AzureDiscoverySetup.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// -----------------------------------------------------------------------
// <copyright file="AzureDiscoverySettings.cs" company="Akka.NET Project">
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Akka.Actor.Setup;
using Azure.Core;
using Azure.Data.Tables;
using Azure.Identity;
namespace Akka.Discovery.Azure
{
public sealed class AzureDiscoverySetup: Setup
{
/// <summary>
/// If set to true, the extension will not participate in updating the Azure table.
/// Only need to be set to true if the extension is being used by a read only extension
/// such as ClusterClient contact discovery.
/// Default value: false
/// </summary>
public bool? ReadOnly { get; set; }
/// <summary>
/// The service name assigned to the cluster.
/// Default value: "default"
/// </summary>
public string? ServiceName { get; set; }
/// <summary>
/// The public facing IP/host of this node
/// akka.remote.dot-netty.tcp.public-hostname is used if not overriden or empty.
/// if akka.remote.dot-netty.tcp.public-hostname is empty, Dns.GetHostName is used.
/// </summary>
public string? HostName { get; set; }
/// <summary>
/// The public open akka management port of this node
/// The value will need to be from 1 to 65535, auto-assign port (0) is not supported.
/// Default value: 8558
/// </summary>
public int? Port { get; set; }
/// <summary>
/// The connection string used to connect to Azure Table hosting the cluster membership table.
/// </summary>
public string? ConnectionString { get; set; }
/// <summary>
/// The azure table name used to store cluster membership entries.
/// Default value: "akkaclustermembers"
/// </summary>
public string? TableName { get; set; }
/// <summary>
/// The time-to-live heartbeat update interval.
/// Default value: 1 minute
/// </summary>
public TimeSpan? TtlHeartbeatInterval { get; set; }
/// <summary>
/// The threshold for a cluster member entry to be considered stale.
/// Override this value by providing a value greater than TtlHeartbeatInterval.
/// * If set to 0, this will use the value (TtlHeartbeatInterval * 5).
/// * If set to a value less than TtlHeartbeatInterval, discovery WILL throw an exception.
/// </summary>
public TimeSpan? StaleTtlThreshold { get; set; }
/// <summary>
/// The stale data pruning interval.
/// Default value: 1 hour
/// </summary>
public TimeSpan? PruneInterval { get; set; }
/// <summary>
/// The timeout period for all Azure Tables API HTTP operation. If set, must be greater than zero.
/// Default value: 10 seconds
/// </summary>
public TimeSpan? OperationTimeout { get; set; }
/// <summary>
/// The retry backoff for all HTTP operation. If set, must be greater than zero.
/// Default value: 500 milliseconds
/// </summary>
public TimeSpan? RetryBackoff { get; set; }
/// <summary>
/// The maximum retry backoff for all HTTP operations. If set, must be greater than retry-backoff.
/// Default value: 5 seconds
/// </summary>
public TimeSpan? MaximumRetryBackoff { get; set; }
/// <summary>
/// A <see cref="Uri"/> referencing the table service account.
/// This is likely to be similar to "https:// {account_name}.table.core.windows.net"
/// or "https:// {account_name}.table.cosmos.azure.com".
/// If you set the <see cref="AzureCredential"/> property, This property MUST NOT be null.
/// </summary>
public Uri? AzureTableEndpoint { get; set; }
/// <summary>
/// The <see cref="TokenCredential"/> used to authorize requests.
/// </summary>
public TokenCredential? AzureCredential { get; set; }
/// <summary>
/// Optional client options that define the transport pipeline policies for authentication,
/// retries, etc., that are applied to every request.
/// </summary>
public TableClientOptions? TableClientOptions { get; set; }
public AzureDiscoverySetup WithReadOnlyMode(bool readOnly)
{
ReadOnly = readOnly;
return this;
}
public AzureDiscoverySetup WithServiceName(string serviceName)
{
ServiceName = serviceName;
return this;
}
public AzureDiscoverySetup WithPublicHostName(string hostName)
{
HostName = hostName;
return this;
}
public AzureDiscoverySetup WithPublicPort(int port)
{
Port = port;
return this;
}
public AzureDiscoverySetup WithConnectionString(string connectionString)
{
ConnectionString = connectionString;
return this;
}
public AzureDiscoverySetup WithTableName(string tableName)
{
TableName = tableName;
return this;
}
public AzureDiscoverySetup WithTtlHeartbeatInterval(TimeSpan ttlHeartbeatInterval)
{
TtlHeartbeatInterval = ttlHeartbeatInterval;
return this;
}
public AzureDiscoverySetup WithStaleTtlThreshold(TimeSpan staleTtlThreshold)
{
StaleTtlThreshold = staleTtlThreshold;
return this;
}
public AzureDiscoverySetup WithPruneInterval(TimeSpan pruneInterval)
{
PruneInterval = pruneInterval;
return this;
}
public AzureDiscoverySetup WithOperationTimeout(TimeSpan operationTimeout)
{
OperationTimeout = operationTimeout;
return this;
}
public AzureDiscoverySetup WithRetryBackoff(TimeSpan retryBackoff, TimeSpan maximumRetryBackoff)
{
RetryBackoff = retryBackoff;
MaximumRetryBackoff = maximumRetryBackoff;
return this;
}
public AzureDiscoverySetup WithAzureCredential(
Uri azureTableEndpoint,
TokenCredential credential,
TableClientOptions? tableClientOptions = null)
{
AzureTableEndpoint = azureTableEndpoint;
AzureCredential = credential;
TableClientOptions = tableClientOptions;
return this;
}
public override string ToString()
{
var props = new List<string>();
if(ReadOnly != null)
props.Add($"{nameof(ReadOnly)}:{ReadOnly}");
if(ServiceName != null)
props.Add($"{nameof(ServiceName)}:{ServiceName}");
if(HostName != null)
props.Add($"{nameof(HostName)}:{HostName}");
if(Port != null)
props.Add($"{nameof(Port)}:{Port}");
if(ConnectionString != null)
props.Add($"{nameof(ConnectionString)}:{ConnectionString}");
if(TableName != null)
props.Add($"{nameof(TableName)}:{TableName}");
if(TtlHeartbeatInterval != null)
props.Add($"{nameof(TtlHeartbeatInterval)}:{TtlHeartbeatInterval}");
if(StaleTtlThreshold != null)
props.Add($"{nameof(StaleTtlThreshold)}:{StaleTtlThreshold}");
if(PruneInterval != null)
props.Add($"{nameof(PruneInterval)}:{PruneInterval}");
if(OperationTimeout != null)
props.Add($"{nameof(OperationTimeout)}:{OperationTimeout}");
if(RetryBackoff != null)
props.Add($"{nameof(RetryBackoff)}:{RetryBackoff}");
if(MaximumRetryBackoff != null)
props.Add($"{nameof(MaximumRetryBackoff)}:{MaximumRetryBackoff}");
if(AzureTableEndpoint != null)
props.Add($"{nameof(AzureTableEndpoint)}:{AzureTableEndpoint}");
if(AzureCredential != null)
props.Add($"{nameof(AzureCredential)}:{AzureCredential}");
if(TableClientOptions != null)
props.Add($"{nameof(TableClientOptions)}:{TableClientOptions}");
return $"[AzureDiscoverySetup]({string.Join(", ", props)})";
}
public AzureDiscoverySettings Apply(AzureDiscoverySettings setting)
{
if (ReadOnly != null)
setting = setting.WithReadOnlyMode(ReadOnly.Value);
if (ServiceName != null)
setting = setting.WithServiceName(ServiceName);
if (HostName != null)
setting = setting.WithPublicHostName(HostName);
if (Port != null)
setting = setting.WithPublicPort(Port.Value);
if (ConnectionString != null)
setting = setting.WithConnectionString(ConnectionString);
if (TableName != null)
setting = setting.WithTableName(TableName);
if (TtlHeartbeatInterval != null)
setting = setting.WithTtlHeartbeatInterval(TtlHeartbeatInterval.Value);
if (StaleTtlThreshold != null)
setting = setting.WithStaleTtlThreshold(StaleTtlThreshold.Value);
if (PruneInterval != null)
setting = setting.WithPruneInterval(PruneInterval.Value);
if (OperationTimeout != null)
setting = setting.WithOperationTimeout(OperationTimeout.Value);
if (RetryBackoff != null && MaximumRetryBackoff != null)
setting = setting.WithRetryBackoff(RetryBackoff.Value, MaximumRetryBackoff.Value);
if (AzureTableEndpoint != null && AzureCredential != null)
setting = setting.WithAzureCredential(AzureTableEndpoint, AzureCredential, TableClientOptions);
return setting;
}
}
}