Skip to content

Commit f7864d1

Browse files
committed
Fix InstallExtension for Set/New-AzureDeployment cmdlets
1 parent 1073910 commit f7864d1

File tree

9 files changed

+48
-23
lines changed

9 files changed

+48
-23
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/ADDomain/SetAzureServiceADDomainExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void ExecuteCommand()
238238
Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
239239
};
240240

241-
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
241+
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration);
242242
ChangeDeployment(extConfig);
243243
}
244244

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/BaseAzureServiceExtensionCmdlet.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public abstract class BaseAzureServiceExtensionCmdlet : ServiceManagementBaseCmd
5050
protected XDocument PublicConfigurationXml { get; set; }
5151
protected XDocument PrivateConfigurationXml { get; set; }
5252
protected DeploymentGetResponse Deployment { get; set; }
53+
protected DeploymentGetResponse PeerDeployment { get; set; }
5354

5455
public virtual string ServiceName { get; set; }
5556
public virtual string Slot { get; set; }
@@ -109,6 +110,8 @@ protected void ValidateDeployment()
109110
}
110111
Deployment.ExtensionConfiguration = Deployment.ExtensionConfiguration ?? new Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration();
111112
}
113+
114+
PeerDeployment = GetPeerDeployment(Slot);
112115
}
113116

114117
protected void ValidateRoles()
@@ -285,6 +288,15 @@ protected DeploymentGetResponse GetDeployment(string slot)
285288
return d;
286289
}
287290

291+
protected DeploymentGetResponse GetPeerDeployment(string currentSlot)
292+
{
293+
var currentSlotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), currentSlot, true);
294+
var peerSlot = currentSlotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production;
295+
var peerSlotStr = peerSlot.ToString();
296+
297+
return GetDeployment(peerSlotStr);
298+
}
299+
288300
protected SecureString GetSecurePassword(string password)
289301
{
290302
SecureString securePassword = new SecureString();

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private void GetThumbprintAndAlgorithm(IList<HostedServiceListExtensionsResponse
147147

148148
public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot,
149149
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration extConfig,
150-
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration secondSlotExtConfig = null)
150+
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration secondSlotExtConfig)
151151
{
152152
ExtensionConfigurationBuilder builder = GetBuilder(extConfig);
153153
ExtensionConfigurationBuilder secondSlotConfigBuilder = null;
@@ -253,7 +253,7 @@ public void Uninstall(string nameSpace, string type, Microsoft.WindowsAzure.Mana
253253
}
254254
}
255255

256-
public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration Set(DeploymentGetResponse currentDeployment, ExtensionConfigurationInput[] inputs, string slot)
256+
public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration Set(DeploymentGetResponse currentDeployment, DeploymentGetResponse peerDeployment, ExtensionConfigurationInput[] inputs, string slot)
257257
{
258258
string errorConfigInput = null;
259259
if (!Validate(inputs, out errorConfigInput))
@@ -268,7 +268,7 @@ public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration S
268268
{
269269
if (context != null)
270270
{
271-
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration currentConfig = this.InstallExtension(context, slot, oldExtConfig);
271+
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration currentConfig = this.InstallExtension(context, slot, oldExtConfig, peerDeployment.ExtensionConfiguration);
272272
foreach (var r in currentConfig.AllRoles)
273273
{
274274
if (currentDeployment == null || !this.GetBuilder(currentDeployment.ExtensionConfiguration).ExistAny(r.Id))
@@ -294,7 +294,7 @@ public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration S
294294
return extConfig;
295295
}
296296

297-
public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration Add(DeploymentGetResponse deployment, ExtensionConfigurationInput[] inputs, string slot)
297+
public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration Add(DeploymentGetResponse deployment, DeploymentGetResponse peerDeployment, ExtensionConfigurationInput[] inputs, string slot)
298298
{
299299
string errorConfigInput = null;
300300
if (!Validate(inputs, out errorConfigInput))
@@ -309,7 +309,7 @@ public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration A
309309
{
310310
if (context != null)
311311
{
312-
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration currentConfig = this.InstallExtension(context, slot, oldExtConfig);
312+
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration currentConfig = this.InstallExtension(context, slot, oldExtConfig, peerDeployment.ExtensionConfiguration);
313313
foreach (var r in currentConfig.AllRoles)
314314
{
315315
if (!this.GetBuilder(oldExtConfig).ExistAny(r.Id))

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/SetAzureServiceExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void ExecuteCommand()
149149
Version = Version,
150150
Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
151151
};
152-
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
152+
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration);
153153
ChangeDeployment(extConfig);
154154
}
155155

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/RemoveAzureServiceAntimalwareExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void ExecuteCommand()
8181
// process any pending deployment changes
8282
if (extConfigInputs != null)
8383
{
84-
ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, extConfigInputs, Slot);
84+
ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, PeerDeployment, extConfigInputs, Slot);
8585
ChangeDeployment(newExtConfig);
8686
}
8787
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/SetAzureServiceAntimalwareExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public void ExecuteCommand()
444444
// process any pending deployment changes
445445
if (extConfigInputs != null)
446446
{
447-
ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, extConfigInputs, Slot);
447+
ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, PeerDeployment, extConfigInputs, Slot);
448448
ChangeDeployment(newExtConfig);
449449
}
450450
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/RDP/SetAzureServiceRemoteDesktopExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void ExecuteCommand()
132132
Version = Version,
133133
Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
134134
};
135-
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
135+
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration);
136136
ChangeDeployment(extConfig);
137137
}
138138

src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/NewAzureDeployment.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,12 @@ public virtual void NewPaaSDeploymentProcess()
159159
}
160160
}
161161

162-
163-
var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
164-
DeploymentGetResponse d = null;
165-
InvokeInOperationContext(() =>
162+
Action<DeploymentSlot, DeploymentGetResponse> func = (t, d) =>
166163
{
164+
d = null;
167165
try
168166
{
169-
d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType);
167+
d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, t);
170168
}
171169
catch (CloudException ex)
172170
{
@@ -175,10 +173,18 @@ public virtual void NewPaaSDeploymentProcess()
175173
this.WriteExceptionDetails(ex);
176174
}
177175
}
178-
});
176+
};
177+
178+
var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
179+
DeploymentGetResponse currentDeployment = null;
180+
InvokeInOperationContext(() => func(slotType, currentDeployment));
181+
182+
var peerSlottype = slotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production;
183+
DeploymentGetResponse peerDeployment = null;
184+
InvokeInOperationContext(() => func(slotType, peerDeployment));
179185

180186
ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName);
181-
extConfig = extensionMgr.Set(d, ExtensionConfiguration, this.Slot);
187+
extConfig = extensionMgr.Set(currentDeployment, peerDeployment, ExtensionConfiguration, this.Slot);
182188
}
183189

184190
var deploymentInput = new DeploymentCreateParameters

src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/SetAzureDeployment.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,12 @@ public void ExecuteCommand()
164164
}
165165
}
166166

167-
var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
168-
DeploymentGetResponse d = null;
169-
InvokeInOperationContext(() =>
167+
Action<DeploymentSlot, DeploymentGetResponse> func = (t, d) =>
170168
{
169+
d = null;
171170
try
172171
{
173-
d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType);
172+
d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, t);
174173
}
175174
catch (CloudException ex)
176175
{
@@ -179,10 +178,18 @@ public void ExecuteCommand()
179178
this.WriteExceptionDetails(ex);
180179
}
181180
}
182-
});
181+
};
182+
183+
var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);
184+
DeploymentGetResponse currentDeployment = null;
185+
InvokeInOperationContext(() => func(slotType, currentDeployment));
186+
187+
var peerSlottype = slotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production;
188+
DeploymentGetResponse peerDeployment = null;
189+
InvokeInOperationContext(() => func(slotType, peerDeployment));
183190

184191
ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName);
185-
extConfig = extensionMgr.Add(d, ExtensionConfiguration, this.Slot);
192+
extConfig = extensionMgr.Add(currentDeployment, peerDeployment, ExtensionConfiguration, this.Slot);
186193
}
187194

188195
// Upgrade Parameter Set

0 commit comments

Comments
 (0)