@@ -142,7 +142,8 @@ public override void ExecuteCmdlet()
142
142
AsAzureClientSession . Instance . Login ( context ) ;
143
143
WriteProgress ( new ProgressRecord ( 0 , "Sync-AzureAnalysisServicesInstance." , string . Format ( "Authenticating user for '{0}' environment." , context . Environment . Name ) ) ) ;
144
144
var clusterResolveResult = ClusterResolve ( context , serverName ) ;
145
- if ( ! clusterResolveResult . CoreServerName . Equals ( serverName ) || ! clusterResolveResult . CoreServerName . EndsWith ( ":rw" ) )
145
+ var virtualServerName = clusterResolveResult . CoreServerName . Split ( ":" . ToCharArray ( ) ) [ 0 ] ;
146
+ if ( ! serverName . Equals ( virtualServerName ) && ! clusterResolveResult . CoreServerName . EndsWith ( ":rw" ) )
146
147
{
147
148
throw new SynchronizationFailedException ( "Sync request can only be sent to the management endpoint" ) ;
148
149
}
@@ -245,6 +246,7 @@ protected override void InitializeQosEvent()
245
246
{
246
247
// No data collection for this commandlet
247
248
}
249
+
248
250
protected override string DataCollectionWarning
249
251
{
250
252
get
@@ -275,8 +277,7 @@ private async Task<ScaleOutServerDatabaseSyncDetails> SynchronizeDatabaseAsync(
275
277
{
276
278
try
277
279
{
278
- // pollingUrlAndRetryAfter = await PostSyncRequestAsync(context, syncBaseUri, databaseName, accessToken);
279
- var synchronize = string . Format ( ( string ) context . Environment . Endpoints [ AsAzureEnvironment . AsRolloutEndpoints . SyncEndpoint ] , this . clusterResolveResult . CoreServerName , databaseName ) ;
280
+ var synchronize = string . Format ( ( string ) context . Environment . Endpoints [ AsAzureEnvironment . AsRolloutEndpoints . SyncEndpoint ] , this . serverName , databaseName ) ;
280
281
this . AsAzureHttpClient . resetHttpClient ( ) ;
281
282
using ( var message = await AsAzureHttpClient . CallPostAsync (
282
283
syncBaseUri ,
@@ -381,70 +382,81 @@ private async Task<ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsyn
381
382
{
382
383
ScaleOutServerDatabaseSyncResult response = null ;
383
384
var syncCompleted = false ;
384
- do
385
+ var retryCount = 0 ;
386
+
387
+ while ( ! syncCompleted && retryCount < maxNumberOfAttempts )
385
388
{
386
- var retryCount = 0 ;
387
- while ( retryCount < maxNumberOfAttempts )
389
+ // Wait for specified polling interval other than retries.
390
+ if ( retryCount == 0 )
388
391
{
389
- // Wait for specified polling interval other than retries.
390
- if ( retryCount == 0 )
391
- {
392
- // WriteInformation(new InformationRecord(string.Format("Synchronize database {0}. Attempt #{1}. Waiting for {2} seconds to get sync results...", databaseName, retryCount, pollingInterval.TotalSeconds), string.Empty));
393
- await Task . Delay ( pollingInterval ) ;
394
- }
395
- else
396
- {
397
- await Task . Delay ( DefaultRetryIntervalForPolling ) ;
398
- }
392
+ await Task . Delay ( pollingInterval ) ;
393
+ }
394
+ else
395
+ {
396
+ await Task . Delay ( DefaultRetryIntervalForPolling ) ;
397
+ }
399
398
400
- this . AsAzureHttpClient . resetHttpClient ( ) ;
401
- using ( HttpResponseMessage message = await AsAzureHttpClient . CallGetAsync (
402
- pollingUrl ,
403
- string . Empty ,
404
- accessToken ,
405
- correlationId ) )
399
+ this . AsAzureHttpClient . resetHttpClient ( ) ;
400
+ using ( HttpResponseMessage message = await AsAzureHttpClient . CallGetAsync (
401
+ pollingUrl ,
402
+ string . Empty ,
403
+ accessToken ,
404
+ correlationId ) )
405
+ {
406
+ bool shouldRetry = false ;
407
+ if ( message . IsSuccessStatusCode && message . Content != null )
406
408
{
407
- syncCompleted = ! message . StatusCode . Equals ( HttpStatusCode . SeeOther ) ;
408
- if ( syncCompleted )
409
+ var responseString = await message . Content . ReadAsStringAsync ( ) ;
410
+ response = JsonConvert . DeserializeObject < ScaleOutServerDatabaseSyncResult > ( responseString ) ;
411
+
412
+ if ( response != null )
409
413
{
410
- if ( message . IsSuccessStatusCode )
414
+ var state = response . SyncState ;
415
+ if ( state == DatabaseSyncState . Completed || state == DatabaseSyncState . Failed )
411
416
{
412
- var responseString = await message . Content . ReadAsStringAsync ( ) ;
413
- response = JsonConvert . DeserializeObject < ScaleOutServerDatabaseSyncResult > ( responseString ) ;
414
- break ;
417
+ syncCompleted = true ;
415
418
}
416
419
else
417
420
{
418
- retryCount ++ ;
419
- if ( response == null )
420
- {
421
- response = new ScaleOutServerDatabaseSyncResult ( )
422
- {
423
- Database = databaseName ,
424
- SyncState = DatabaseSyncState . Invalid
425
- } ;
426
-
427
- response . Details = string . Format (
428
- "Http Error code: {0}. {1}" ,
429
- message . StatusCode . ToString ( ) ,
430
- message . Content != null ? await message . Content . ReadAsStringAsync ( ) : string . Empty ) ;
431
- }
432
-
433
- if ( message . StatusCode >= ( HttpStatusCode ) 400 && message . StatusCode <= ( HttpStatusCode ) 499 )
434
- {
435
- break ;
436
- }
421
+ pollingUrl = message . Headers . Location ?? pollingUrl ;
422
+ pollingInterval = message . Headers . RetryAfter . Delta ?? pollingInterval ;
437
423
}
438
424
}
439
425
else
440
426
{
441
- pollingUrl = message . Headers . Location ;
442
- pollingInterval = message . Headers . RetryAfter . Delta ?? pollingInterval ;
427
+ shouldRetry = true ;
443
428
}
444
429
}
430
+ else
431
+ {
432
+ shouldRetry = true ;
433
+ }
434
+
435
+ if ( shouldRetry )
436
+ {
437
+ retryCount ++ ;
438
+ response = new ScaleOutServerDatabaseSyncResult ( )
439
+ {
440
+ Database = databaseName ,
441
+ SyncState = DatabaseSyncState . Invalid
442
+ } ;
443
+
444
+ response . Details = string . Format (
445
+ "Http Error code: {0}. Message: {1}" ,
446
+ message . StatusCode . ToString ( ) ,
447
+ message . Content != null ? await message . Content . ReadAsStringAsync ( ) : string . Empty ) ;
448
+
449
+ if ( message . StatusCode >= ( HttpStatusCode ) 400 && message . StatusCode <= ( HttpStatusCode ) 499 )
450
+ {
451
+ break ;
452
+ }
453
+ }
454
+ else
455
+ {
456
+ retryCount = 0 ;
457
+ }
445
458
}
446
459
}
447
- while ( ! syncCompleted ) ;
448
460
449
461
return response ;
450
462
} ) ;
0 commit comments