Skip to content

Commit dc79350

Browse files
authored
Merge pull request Azure#9878 from filizt/RegisterRPRequestReply
[Blueprint] Make RP registration call request reply
2 parents 4fd93d5 + fe47c9a commit dc79350

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/Blueprint/Blueprint/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Add functionality to make sure Blueprint RP is registered before any service calls
2122

2223
## Version 0.2.4
2324
* Fixed miscellaneous typos across module

src/Blueprint/Blueprint/Cmdlets/BlueprintCmdletBase.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
using Microsoft.Azure.Commands.ResourceManager.Common;
1919
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
2020
using Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01;
21-
using Microsoft.Azure.PowerShell.Cmdlets.Blueprint.Properties;
2221
using Microsoft.Rest;
2322
using System;
24-
using System.Collections.Generic;
2523
using System.IO;
24+
using Microsoft.Azure.Management.Internal.Resources.Models;
25+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
26+
using Provider = Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01.Models.Provider;
2627

2728
namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
2829
{
@@ -121,15 +122,41 @@ protected override void WriteExceptionError(Exception ex)
121122
/// <param name="subscriptionId"> SubscriptionId passed from the cmdlet</param>
122123
protected void RegisterBlueprintRp(string subscriptionId)
123124
{
125+
// To save time, we'll check the registration state first before making the register call.
124126
ResourceManagerClient.SubscriptionId = subscriptionId;
125-
var response = ResourceManagerClient.Providers.Register(BlueprintConstants.BlueprintProviderNamespace);
127+
Provider provider = ResourceManagerClient.Providers.Get(BlueprintConstants.BlueprintProviderNamespace);
126128

127-
if (response == null)
129+
if (provider.RegistrationState == RegistrationState.Registered)
128130
{
129-
throw new KeyNotFoundException(string.Format(Resources.ResourceProviderRegistrationFailed, BlueprintConstants.BlueprintProviderNamespace));
131+
return;
130132
}
131-
}
132133

134+
// The reason we poll for the registrationState for RP registration is because we'd like to make sure the RP registering
135+
// happens before the blueprint creation/assignment request is submitted. This should help alleviate the spike in
136+
// blueprint creation/assignment failures due to RP not being registered.
137+
const int MaxPoll = 20;
138+
int pollCount = 0;
139+
140+
do
141+
{
142+
if (pollCount > MaxPoll)
143+
{
144+
// We should ideally throw a timeout exception here but we're collecting logs on service side about RP registration failures
145+
// and would like to continue with blueprint/assignment creation flow.
146+
//
147+
// To-Do: Add TimeoutException
148+
break;
149+
}
150+
151+
provider = ResourceManagerClient.Providers.Register(BlueprintConstants
152+
.BlueprintProviderNamespace); // Instead of Get, do Register call again since GET takes its sweet time to return the status.
153+
154+
TestMockSupport.Delay(TimeSpan.FromSeconds(1));
155+
156+
pollCount++;
157+
158+
} while (provider.RegistrationState != RegistrationState.Registered);
159+
}
133160

134161
/// <summary>
135162
/// Expects a string that consist of full file path with file extension and check if it exists.

0 commit comments

Comments
 (0)