|
18 | 18 | using Microsoft.Azure.Commands.ResourceManager.Common;
|
19 | 19 | using Microsoft.Azure.Management.Authorization.Version2015_07_01;
|
20 | 20 | using Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01;
|
21 |
| -using Microsoft.Azure.PowerShell.Cmdlets.Blueprint.Properties; |
22 | 21 | using Microsoft.Rest;
|
23 | 22 | using System;
|
24 |
| -using System.Collections.Generic; |
25 | 23 | 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; |
26 | 27 |
|
27 | 28 | namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
|
28 | 29 | {
|
@@ -121,15 +122,41 @@ protected override void WriteExceptionError(Exception ex)
|
121 | 122 | /// <param name="subscriptionId"> SubscriptionId passed from the cmdlet</param>
|
122 | 123 | protected void RegisterBlueprintRp(string subscriptionId)
|
123 | 124 | {
|
| 125 | + // To save time, we'll check the registration state first before making the register call. |
124 | 126 | ResourceManagerClient.SubscriptionId = subscriptionId;
|
125 |
| - var response = ResourceManagerClient.Providers.Register(BlueprintConstants.BlueprintProviderNamespace); |
| 127 | + Provider provider = ResourceManagerClient.Providers.Get(BlueprintConstants.BlueprintProviderNamespace); |
126 | 128 |
|
127 |
| - if (response == null) |
| 129 | + if (provider.RegistrationState == RegistrationState.Registered) |
128 | 130 | {
|
129 |
| - throw new KeyNotFoundException(string.Format(Resources.ResourceProviderRegistrationFailed, BlueprintConstants.BlueprintProviderNamespace)); |
| 131 | + return; |
130 | 132 | }
|
131 |
| - } |
132 | 133 |
|
| 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 | + } |
133 | 160 |
|
134 | 161 | /// <summary>
|
135 | 162 | /// Expects a string that consist of full file path with file extension and check if it exists.
|
|
0 commit comments