20
20
using Microsoft . Rest . Azure ;
21
21
using System . Threading . Tasks ;
22
22
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
+
23
27
namespace Microsoft . Azure . Commands . ResourceManager . Cmdlets . SdkClient
24
28
{
25
29
public class DeploymentStacksSdkClient
@@ -41,6 +45,33 @@ public DeploymentStacksSdkClient(IDeploymentStacksClient deploymentStacksClient)
41
45
this . DeploymentStacksClient = deploymentStacksClient ;
42
46
}
43
47
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
+
44
75
/// <summary>
45
76
/// Parameter-less constructor for mocking
46
77
/// </summary>
@@ -709,6 +740,7 @@ private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<Dep
709
740
const int counterUnit = 1000 ;
710
741
int step = 5 ;
711
742
int phaseOne = 400 ;
743
+ bool deploymentOperationFlag = true ;
712
744
do
713
745
{
714
746
WriteVerbose ( string . Format ( "Checking stack deployment status" , step ) ) ;
@@ -734,6 +766,12 @@ private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<Dep
734
766
}
735
767
}
736
768
769
+ if ( ! string . IsNullOrEmpty ( stack . DeploymentId ) && deploymentOperationFlag )
770
+ {
771
+ deploymentOperationFlag = false ;
772
+ PollDeployments ( stack ) ;
773
+ }
774
+
737
775
} while ( ! status . Any ( s => s . Equals ( stack . ProvisioningState , StringComparison . OrdinalIgnoreCase ) ) ) ;
738
776
739
777
return stack ;
@@ -757,6 +795,30 @@ Func<Task<AzureOperationResponse<DeploymentStack>>> GetStackAction(string stackN
757
795
}
758
796
}
759
797
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
+
760
822
public PSDeploymentStack UpdateResourceGroupDeploymentStack (
761
823
string deploymentStackName ,
762
824
string resourceGroupName ,
0 commit comments