-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ClusterOptions.cs
80 lines (70 loc) · 2.77 KB
/
ClusterOptions.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
using Microsoft.Extensions.Options;
using Orleans.Runtime;
namespace Orleans.Configuration
{
/// <summary>
/// Configures the Orleans cluster.
/// </summary>
public class ClusterOptions
{
/// <summary>
/// The default value of <see cref="ClusterId"/>.
/// </summary>
public const string DefaultClusterId = "default";
/// <summary>
/// The default value of <see cref="ServiceId"/>.
/// </summary>
public const string DefaultServiceId = "default";
/// <summary>
/// Default cluster id for development clusters.
/// </summary>
internal const string DevelopmentClusterId = "dev";
/// <summary>
/// Default service id for development clusters.
/// </summary>
internal const string DevelopmentServiceId = "dev";
/// <summary>
/// Gets or sets the cluster identity. This used to be called DeploymentId before Orleans 2.0 name.
/// </summary>
public string ClusterId { get; set; } = DefaultClusterId;
/// <summary>
/// Gets or sets a unique identifier for this service, which should survive deployment and redeployment, where as <see cref="ClusterId"/> might not.
/// </summary>
public string ServiceId { get; set; } = DefaultServiceId;
}
/// <summary>
/// Validator for <see cref="ClusterOptions"/>
/// </summary>
public class ClusterOptionsValidator : IConfigurationValidator
{
private readonly ClusterOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="ClusterOptionsValidator"/> class.
/// </summary>
/// <param name="options">
/// The options.
/// </param>
public ClusterOptionsValidator(IOptions<ClusterOptions> options)
{
this.options = options.Value;
}
/// <inheritdoc />
public void ValidateConfiguration()
{
if (string.IsNullOrWhiteSpace(this.options.ClusterId))
{
throw new OrleansConfigurationException(
$"Configuration for {nameof(ClusterOptions)} is invalid. " +
$"A non-empty value for {nameof(options.ClusterId)} is required. " +
$"See {Constants.TroubleshootingHelpLink} for more information.");
}
if (string.IsNullOrWhiteSpace(this.options.ServiceId))
{
throw new OrleansConfigurationException(
$"Configuration for {nameof(ClusterOptions)} is invalid. " +
$"A non-empty value for {nameof(options.ServiceId)} is required. " +
$"See {Constants.TroubleshootingHelpLink} for more information.");
}
}
}
}