Skip to content

Commit 0380907

Browse files
committed
Poll deployment operations to ensure -Verbose parity with deployments cmdlets
1 parent 4e079f4 commit 0380907

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
using Microsoft.Rest.Azure;
2121
using System.Threading.Tasks;
2222
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
23+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
24+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
25+
using System.Net;
26+
2327
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
2428
{
2529
public class DeploymentStacksSdkClient
@@ -41,6 +45,33 @@ public DeploymentStacksSdkClient(IDeploymentStacksClient deploymentStacksClient)
4145
this.DeploymentStacksClient = deploymentStacksClient;
4246
}
4347

48+
/// <summary>
49+
/// Field that holds the resource client instance
50+
/// </summary>
51+
private ResourceManagerSdkClient resourceManagerSdkClient;
52+
53+
/// <summary>
54+
/// Gets or sets the resource manager sdk client
55+
/// </summary>
56+
public ResourceManagerSdkClient ResourceManagerSdkClient
57+
{
58+
get
59+
{
60+
if (this.resourceManagerSdkClient == null)
61+
{
62+
this.resourceManagerSdkClient = new ResourceManagerSdkClient(azureContext);
63+
}
64+
65+
this.resourceManagerSdkClient.VerboseLogger = WriteVerbose;
66+
this.resourceManagerSdkClient.ErrorLogger = WriteError;
67+
this.resourceManagerSdkClient.WarningLogger = WriteWarning;
68+
69+
return this.resourceManagerSdkClient;
70+
}
71+
72+
set { this.resourceManagerSdkClient = value; }
73+
}
74+
4475
/// <summary>
4576
/// Parameter-less constructor for mocking
4677
/// </summary>
@@ -709,6 +740,7 @@ private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<Dep
709740
const int counterUnit = 1000;
710741
int step = 5;
711742
int phaseOne = 400;
743+
bool deploymentOperationFlag = true;
712744
do
713745
{
714746
WriteVerbose(string.Format("Checking stack deployment status", step));
@@ -734,6 +766,12 @@ private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<Dep
734766
}
735767
}
736768

769+
if(!string.IsNullOrEmpty(stack.DeploymentId) && deploymentOperationFlag)
770+
{
771+
deploymentOperationFlag = false;
772+
PollDeployments(stack);
773+
}
774+
737775
} while (!status.Any(s => s.Equals(stack.ProvisioningState, StringComparison.OrdinalIgnoreCase)));
738776

739777
return stack;
@@ -757,6 +795,30 @@ Func<Task<AzureOperationResponse<DeploymentStack>>> GetStackAction(string stackN
757795
}
758796
}
759797

798+
//verboseLoggingStuff - subject to change
799+
800+
private DeploymentStack PollDeployments(DeploymentStack stack)
801+
{
802+
string deploymentId = stack.DeploymentId;
803+
PSDeploymentCmdletParameters parameters = new PSDeploymentCmdletParameters();
804+
parameters.DeploymentName = ResourceIdUtility.GetDeploymentName(deploymentId);
805+
parameters.ResourceGroupName = ResourceIdUtility.GetResourceGroupName(deploymentId);
806+
parameters.ManagementGroupId = ResourceIdUtility.GetManagementGroupId(deploymentId);
807+
if (parameters.ResourceGroupName != null)
808+
{
809+
parameters.ScopeType = DeploymentScopeType.ResourceGroup;
810+
ResourceManagerSdkClient.ProvisionDeploymentStatus(parameters, new Deployment()); //Only called for RG at this time to avoid replication issues
811+
}
812+
else if (parameters.ManagementGroupId != null)
813+
parameters.ScopeType = DeploymentScopeType.ManagementGroup;
814+
else
815+
parameters.ScopeType = DeploymentScopeType.Subscription;
816+
//Enable when deploymentOperations can be fetched for all scopes and not just RG
817+
//resourceManagerSdkClient.ProvisionDeploymentStatus(parameters, new Deployment());
818+
return stack;
819+
}
820+
821+
760822
public PSDeploymentStack UpdateResourceGroupDeploymentStack(
761823
string deploymentStackName,
762824
string resourceGroupName,

0 commit comments

Comments
 (0)