1
- using Microsoft . Azure . Documents ;
2
- using Microsoft . Azure . Documents . Client ;
1
+ using Microsoft . Azure . Cosmos ;
2
+ using Microsoft . Azure . Cosmos . Linq ;
3
3
using Microsoft . Extensions . Logging ;
4
4
using Microsoft . Extensions . Options ;
5
5
using Orleans . Clustering . CosmosDB . Models ;
@@ -21,7 +21,8 @@ internal class CosmosDBGatewayListProvider : IGatewayListProvider
21
21
private readonly ILoggerFactory _loggerFactory ;
22
22
private readonly TimeSpan _maxStaleness ;
23
23
private readonly string _clusterId ;
24
- private DocumentClient _dbClient ;
24
+ private CosmosClient _cosmos ;
25
+ private Container _container ;
25
26
26
27
public TimeSpan MaxStaleness => this . _maxStaleness ;
27
28
@@ -38,38 +39,40 @@ public CosmosDBGatewayListProvider(ILoggerFactory loggerFactory, IOptions<Cosmos
38
39
39
40
public async Task < IList < Uri > > GetGateways ( )
40
41
{
41
- try
42
- {
43
- var spResponse = await this . _dbClient . ExecuteStoredProcedureAsync < List < SiloEntity > > (
44
- UriFactory . CreateStoredProcedureUri ( this . _options . DB , this . _options . Collection , SPROC ) ,
45
- new RequestOptions { PartitionKey = new PartitionKey ( this . _clusterId ) } ,
46
- this . _clusterId ) ;
42
+ var query = this . _container
43
+ . GetItemLinqQueryable < SiloEntity > ( requestOptions : new QueryRequestOptions { PartitionKey = new PartitionKey ( this . _clusterId ) } )
44
+ . Where ( g => g . EntityType == nameof ( SiloEntity ) &&
45
+ g . Status == SiloStatus . Active &&
46
+ g . ProxyPort . HasValue && g . ProxyPort . Value != 0 ) . ToFeedIterator ( ) ;
47
47
48
- var uris = spResponse . Response . Select ( ConvertToGatewayUri ) . ToList ( ) ;
49
- return uris ;
50
- }
51
- catch ( Exception )
48
+ var entities = new List < SiloEntity > ( ) ;
49
+ do
52
50
{
53
- throw ;
54
- }
51
+ var items = await query . ReadNextAsync ( ) ;
52
+ entities . AddRange ( items ) ;
53
+ } while ( query . HasMoreResults ) ;
54
+
55
+ var uris = entities . Select ( ConvertToGatewayUri ) . ToList ( ) ;
56
+ return uris ;
55
57
}
56
58
57
- public async Task InitializeGatewayListProvider ( )
59
+ public Task InitializeGatewayListProvider ( )
58
60
{
59
61
if ( this . _options . Client != null )
60
62
{
61
- this . _dbClient = this . _options . Client ;
63
+ this . _cosmos = this . _options . Client ;
62
64
}
63
65
else
64
66
{
65
- this . _dbClient = new DocumentClient ( new Uri ( this . _options . AccountEndpoint ) , this . _options . AccountKey ,
66
- new ConnectionPolicy
67
- {
68
- ConnectionMode = this . _options . ConnectionMode ,
69
- ConnectionProtocol = this . _options . ConnectionProtocol
70
- } ) ;
67
+ this . _cosmos = new CosmosClient (
68
+ this . _options . AccountEndpoint ,
69
+ this . _options . AccountKey ,
70
+ new CosmosClientOptions { ConnectionMode = this . _options . ConnectionMode }
71
+ ) ;
71
72
}
72
- await this . _dbClient . OpenAsync ( ) ;
73
+ this . _container = this . _cosmos . GetDatabase ( this . _options . DB ) . GetContainer ( this . _options . Collection ) ;
74
+
75
+ return Task . CompletedTask ;
73
76
}
74
77
75
78
private static Uri ConvertToGatewayUri ( SiloEntity gateway )
0 commit comments