Skip to content

Commit fd7ac47

Browse files
committed
Merge remote-tracking branch 'origin-public/athipp-public' into athipp-pr
2 parents c7e938f + 14e8c11 commit fd7ac47

File tree

3 files changed

+76
-30
lines changed

3 files changed

+76
-30
lines changed

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Dataplane/Commands/Synchronize-AzureASInstance.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected override void BeginProcessing()
208208
{
209209
var currentContext = AsAzureClientSession.Instance.Profile.Context;
210210
if (currentContext != null
211-
&& !AsAzureClientSession.AsAzureRolloutEnvironmentMapping.ContainsKey(currentContext.Environment.Name))
211+
&& AsAzureClientSession.AsAzureRolloutEnvironmentMapping.ContainsKey(currentContext.Environment.Name))
212212
{
213213
throw new PSInvalidOperationException(string.Format(Resources.InvalidServerName, serverName));
214214
}
@@ -338,7 +338,6 @@ private async Task<Tuple<Uri, RetryConditionHeaderValue>> PostSyncRequestAsync(
338338
string accessToken)
339339
{
340340
var synchronize = string.Format((string)context.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.SyncEndpoint], this.clusterResolveResult.CoreServerName, databaseName);
341-
WriteInformation(new InformationRecord(string.Format("Synchronize database {0}", databaseName) + string.Format("Submitting sync request to server", serverName), string.Empty));
342341

343342
return await Task.Run(async () =>
344343
{
@@ -347,7 +346,8 @@ private async Task<Tuple<Uri, RetryConditionHeaderValue>> PostSyncRequestAsync(
347346
syncBaseUri,
348347
synchronize,
349348
accessToken,
350-
correlationId))
349+
correlationId,
350+
null))
351351
{
352352
this.syncRequestRootActivityId = message.Headers.Contains(RootActivityIdHeaderName) ? message.Headers.GetValues(RootActivityIdHeaderName).FirstOrDefault() : string.Empty;
353353
this.syncRequestTimeStamp = message.Headers.Contains(CurrentUtcDateHeaderName) ? message.Headers.GetValues(CurrentUtcDateHeaderName).FirstOrDefault() : string.Empty;
@@ -357,7 +357,6 @@ private async Task<Tuple<Uri, RetryConditionHeaderValue>> PostSyncRequestAsync(
357357
var pollingUrl = message.Headers.Location;
358358
var retryAfter = message.Headers.RetryAfter;
359359

360-
WriteInformation(new InformationRecord(string.Format("Synchronize database {0}. Successfully submitted sync request. StatusCode: {1}", databaseName, message.StatusCode.ToString()), string.Empty));
361360
return new Tuple<Uri, RetryConditionHeaderValue>(pollingUrl, retryAfter);
362361
}
363362
});
@@ -372,7 +371,7 @@ private async Task<Tuple<Uri, RetryConditionHeaderValue>> PostSyncRequestAsync(
372371
/// <param name="pollingInterval">Polling interval set by the post response</param>
373372
/// <param name="maxNumberOfAttempts">Max number of attempts for each poll before the attempt is declared a failure</param>
374373
/// <returns></returns>
375-
private async Task<ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsync(string databaseName, string accessToken, Uri pollingUrl, TimeSpan pollingInterval, int maxNumberOfAttempts = 2000)
374+
private async Task<ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsync(string databaseName, string accessToken, Uri pollingUrl, TimeSpan pollingInterval, int maxNumberOfAttempts = 3)
376375
{
377376
return await Task.Run(async () =>
378377
{
@@ -386,7 +385,7 @@ private async Task<ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsyn
386385
// Wait for specified polling interval other than retries.
387386
if (retryCount == 0)
388387
{
389-
WriteInformation(new InformationRecord(string.Format("Synchronize database {0}. Attempt #{1}. Waiting for {2} seconds to get sync results...", databaseName, retryCount, pollingInterval.TotalSeconds), string.Empty));
388+
// WriteInformation(new InformationRecord(string.Format("Synchronize database {0}. Attempt #{1}. Waiting for {2} seconds to get sync results...", databaseName, retryCount, pollingInterval.TotalSeconds), string.Empty));
390389
await Task.Delay(pollingInterval);
391390
}
392391
else
@@ -404,7 +403,6 @@ private async Task<ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsyn
404403
syncCompleted = !message.StatusCode.Equals(HttpStatusCode.SeeOther);
405404
if (syncCompleted)
406405
{
407-
string errorResponse = string.Empty;
408406
if (message.IsSuccessStatusCode)
409407
{
410408
var responseString = await message.Content.ReadAsStringAsync();
@@ -413,23 +411,24 @@ private async Task<ScaleOutServerDatabaseSyncResult> PollSyncStatusWithRetryAsyn
413411
}
414412
else
415413
{
416-
errorResponse = await message.Content.ReadAsStringAsync();
417414
retryCount++;
418-
if (retryCount >= maxNumberOfAttempts)
415+
if (response == null)
419416
{
420-
if (response == null)
417+
response = new ScaleOutServerDatabaseSyncResult()
421418
{
422-
response = new ScaleOutServerDatabaseSyncResult()
423-
{
424-
Database = databaseName,
425-
SyncState = DatabaseSyncState.Invalid,
426-
Details = errorResponse
427-
};
428-
}
419+
Database = databaseName,
420+
SyncState = DatabaseSyncState.Invalid
421+
};
422+
423+
response.Details = string.Format(
424+
"Http Error code: {0}. {1}",
425+
message.StatusCode.ToString(),
426+
message.Content != null ? await message.Content.ReadAsStringAsync() : string.Empty);
429427
}
430-
else
428+
429+
if (message.StatusCode >= (HttpStatusCode)400 && message.StatusCode <= (HttpStatusCode)499)
431430
{
432-
//WriteWarning(string.Format("Synchronize database {0}.", databaseName) + string.Format("Attempt #{0}, failed to get sync status. StatusCode: {1}. Retrying...", retryCount, pollingInterval.TotalSeconds));
431+
break;
433432
}
434433
}
435434
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Dataplane/Models/ClusterResolutionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane.Models
2020
{
2121
[DataContract]
22-
sealed class ClusterResolutionResult
22+
public sealed class ClusterResolutionResult
2323
{
2424
[DataMember(Name = "clusterFQDN")]
2525
public string ClusterFQDN { get; set; }

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Test/InMemoryTests/DataPlaneCommandTests.cs

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using Xunit.Abstractions;
3434
using System.Collections.Generic;
3535
using System.Net.Http.Headers;
36+
using Newtonsoft.Json;
3637

3738
namespace Microsoft.Azure.Commands.AnalysisServices.Test.InMemoryTests
3839
{
@@ -368,25 +369,50 @@ public void SynchronizeAzureASInstance_SingleDB_Succeeds()
368369
// Set up AsAzureHttpClient mock
369370
var mockAsAzureHttpClient = new Mock<IAsAzureHttpClient>();
370371

372+
// set up cluster resolve respnose
373+
ClusterResolutionResult resolveResult = new ClusterResolutionResult()
374+
{
375+
ClusterFQDN = "resolved.westcentralus.asazure.windows.net",
376+
CoreServerName = testServer + ":rw",
377+
TenantId = Guid.NewGuid().ToString()
378+
};
379+
mockAsAzureHttpClient
380+
.Setup(obj => obj.CallPostAsync(
381+
It.IsAny<Uri>(),
382+
It.Is<string>(s => s.Contains("clusterResolve")),
383+
It.IsAny<string>(),
384+
It.IsAny<HttpContent>()))
385+
.Returns(Task<HttpResponseMessage>.FromResult(
386+
new HttpResponseMessage(HttpStatusCode.OK)
387+
{
388+
Content = new StringContent(JsonConvert.SerializeObject(resolveResult))
389+
}));
390+
391+
// set up sync respnose
371392
var postResponse = new HttpResponseMessage(HttpStatusCode.Accepted);
372393
postResponse.Headers.Location = new Uri("https://1");
373394
postResponse.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromMilliseconds(500));
395+
postResponse.Headers.Add("x-ms-root-activity-id", Guid.NewGuid().ToString());
396+
postResponse.Headers.Add("x-ms-current-utc-date", Guid.NewGuid().ToString());
374397
mockAsAzureHttpClient
375398
.Setup(obj => obj.CallPostAsync(
376399
It.IsAny<Uri>(),
377-
It.IsAny<string>(),
378-
It.IsAny<string>(),
379-
It.IsAny<HttpContent>()))
400+
It.Is<string>(s => s.Contains("sync")),
401+
It.IsAny<string>(),
402+
It.IsAny<Guid>(),
403+
null))
380404
.Returns(Task<Mock<HttpResponseMessage>>.FromResult(postResponse));
381405

406+
382407
var getResponse1 = new HttpResponseMessage(HttpStatusCode.SeeOther);
383408
getResponse1.Headers.Location = new Uri("https://done");
384409
getResponse1.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromMilliseconds(500));
385410
mockAsAzureHttpClient
386411
.Setup(obj => obj.CallGetAsync(
387412
It.Is<Uri>(u => u.OriginalString.Contains("1")),
413+
string.Empty,
388414
It.IsAny<string>(),
389-
It.IsAny<string>()))
415+
It.IsAny<Guid>()))
390416
.Returns(Task<HttpResponseMessage>.FromResult(getResponse1));
391417

392418
var getResponseSucceed = new HttpResponseMessage
@@ -402,8 +428,9 @@ public void SynchronizeAzureASInstance_SingleDB_Succeeds()
402428
mockAsAzureHttpClient
403429
.Setup(obj => obj.CallGetAsync(
404430
It.Is<Uri>(u => u.OriginalString.Contains("done")),
431+
string.Empty,
405432
It.IsAny<string>(),
406-
It.IsAny<string>()))
433+
It.IsAny<Guid>()))
407434
.Returns(() => Task.FromResult(finalResponses.Dequeue()));
408435

409436
var mockTokenCacheItemProvider = new Mock<ITokenCacheItemProvider>();
@@ -421,7 +448,7 @@ public void SynchronizeAzureASInstance_SingleDB_Succeeds()
421448
};
422449

423450
DoLogin(addAmdlet);
424-
syncCmdlet.Instance = testServer;
451+
syncCmdlet.Instance = testServer + ":rw";
425452
syncCmdlet.Database = "db0";
426453

427454
// Act
@@ -454,6 +481,26 @@ public void SynchronizeAzureASInstance_FailsAfterTooManyRetries()
454481
// Set up AsAzureHttpClient mock
455482
var mockAsAzureHttpClient = new Mock<IAsAzureHttpClient>();
456483

484+
// set up cluster resolve respnose
485+
ClusterResolutionResult resolveResult = new ClusterResolutionResult()
486+
{
487+
ClusterFQDN = "resolved.westcentralus.asazure.windows.net",
488+
CoreServerName = testServer + ":rw",
489+
TenantId = Guid.NewGuid().ToString()
490+
};
491+
mockAsAzureHttpClient
492+
.Setup(obj => obj.CallPostAsync(
493+
It.IsAny<Uri>(),
494+
It.Is<string>(s => s.Contains("clusterResolve")),
495+
It.IsAny<string>(),
496+
It.IsAny<HttpContent>()))
497+
.Returns(Task<HttpResponseMessage>.FromResult(
498+
new HttpResponseMessage(HttpStatusCode.OK)
499+
{
500+
Content = new StringContent(JsonConvert.SerializeObject(resolveResult))
501+
}));
502+
503+
// set up sync respnose
457504
var postResponse = new HttpResponseMessage(HttpStatusCode.Accepted);
458505
postResponse.Headers.Location = new Uri("https://1");
459506
postResponse.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromMilliseconds(500));
@@ -462,10 +509,10 @@ public void SynchronizeAzureASInstance_FailsAfterTooManyRetries()
462509
mockAsAzureHttpClient
463510
.Setup(obj => obj.CallPostAsync(
464511
It.IsAny<Uri>(),
465-
It.IsAny<string>(),
512+
It.Is<string>(s => s.Contains("sync")),
466513
It.IsAny<string>(),
467514
It.IsAny<Guid>(),
468-
It.IsAny<HttpContent>()))
515+
null))
469516
.Returns(Task<Mock<HttpResponseMessage>>.FromResult(postResponse));
470517

471518
var getResponse1 = new HttpResponseMessage(HttpStatusCode.SeeOther);
@@ -518,15 +565,15 @@ public void SynchronizeAzureASInstance_FailsAfterTooManyRetries()
518565
};
519566

520567
DoLogin(addAmdlet);
521-
syncCmdlet.Instance = testServer;
568+
syncCmdlet.Instance = testServer + ":rw";
522569
syncCmdlet.Database = "db0";
523570

524571
// Act
525572
syncCmdlet.InvokeBeginProcessing();
526573
Assert.Throws<SynchronizationFailedException>(() => syncCmdlet.ExecuteCmdlet());
527574
syncCmdlet.InvokeEndProcessing();
528575
}
529-
576+
530577
private void DoLogin(AddAzureASAccountCommand addCmdlet)
531578
{
532579
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();

0 commit comments

Comments
 (0)