-
Notifications
You must be signed in to change notification settings - Fork 2k
/
DynamoDBStorageOptions.cs
executable file
·102 lines (87 loc) · 3.89 KB
/
DynamoDBStorageOptions.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
using System;
using Orleans.Persistence.DynamoDB;
using Orleans.Runtime;
using Orleans.Storage;
namespace Orleans.Configuration
{
public class DynamoDBStorageOptions : DynamoDBClientOptions, IStorageProviderSerializerOptions
{
/// <summary>
/// Gets or sets a unique identifier for this service, which should survive deployment and redeployment.
/// </summary>
public string ServiceId { get; set; } = string.Empty;
/// <summary>
/// Use Provisioned Throughput for tables
/// </summary>
public bool UseProvisionedThroughput { get; set; } = true;
/// <summary>
/// Create the table if it doesn't exist
/// </summary>
public bool CreateIfNotExists { get; set; } = true;
/// <summary>
/// Update the table if it exists
/// </summary>
public bool UpdateIfExists { get; set; } = true;
/// <summary>
/// Read capacity unit for DynamoDB storage
/// </summary>
public int ReadCapacityUnits { get; set; } = DynamoDBStorage.DefaultReadCapacityUnits;
/// <summary>
/// Write capacity unit for DynamoDB storage
/// </summary>
public int WriteCapacityUnits { get; set; } = DynamoDBStorage.DefaultWriteCapacityUnits;
/// <summary>
/// DynamoDB table name.
/// Defaults to 'OrleansGrainState'.
/// </summary>
public string TableName { get; set; } = "OrleansGrainState";
/// <summary>
/// Indicates if grain data should be deleted or reset to defaults when a grain clears it's state.
/// </summary>
public bool DeleteStateOnClear { get; set; } = false;
/// <summary>
/// Stage of silo lifecycle where storage should be initialized. Storage must be initialized prior to use.
/// </summary>
public int InitStage { get; set; } = DEFAULT_INIT_STAGE;
public const int DEFAULT_INIT_STAGE = ServiceLifecycleStage.ApplicationServices;
/// <summary>
/// Specifies a time span in which the item would be expired in the future
/// every StateWrite will increase the TTL of the grain
/// </summary>
public TimeSpan? TimeToLive { get; set; }
public IGrainStorageSerializer GrainStorageSerializer { get; set; }
}
/// <summary>
/// Configuration validator for DynamoDBStorageOptions
/// </summary>
public class DynamoDBGrainStorageOptionsValidator : IConfigurationValidator
{
private readonly DynamoDBStorageOptions options;
private readonly string name;
/// <summary>
/// Constructor
/// </summary>
/// <param name="options">The option to be validated.</param>
/// <param name="name">The option name to be validated.</param>
public DynamoDBGrainStorageOptionsValidator(DynamoDBStorageOptions options, string name)
{
this.options = options;
this.name = name;
}
public void ValidateConfiguration()
{
if (string.IsNullOrWhiteSpace(this.options.TableName))
throw new OrleansConfigurationException(
$"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.TableName)} is not valid.");
if (this.options.UseProvisionedThroughput)
{
if (this.options.ReadCapacityUnits == 0)
throw new OrleansConfigurationException(
$"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.ReadCapacityUnits)} is not valid.");
if (this.options.WriteCapacityUnits == 0)
throw new OrleansConfigurationException(
$"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.WriteCapacityUnits)} is not valid.");
}
}
}
}