void UpdateConfigurationWithCurrentInstanceCount(XContainer localConfigurationFile, string configurationFileName, VariableDictionary variables) { if (!variables.GetFlag(SpecialVariables.Action.Azure.UseCurrentInstanceCount)) { return; } var serviceName = variables.Get(SpecialVariables.Action.Azure.CloudServiceName); var slot = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), variables.Get(SpecialVariables.Action.Azure.Slot)); var remoteConfigurationFile = configurationRetriever.GetConfiguration( credentialsFactory.GetCredentials(variables.Get(SpecialVariables.Action.Azure.SubscriptionId), variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint), variables.Get(SpecialVariables.Action.Azure.CertificateBytes)), serviceName, slot); if (remoteConfigurationFile == null) { Log.Info("There is no current deployment of service '{0}' in slot '{1}', so existing instance counts will not be imported.", serviceName, slot); return; } var rolesByCount = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); Log.Verbose("Local instance counts (from " + Path.GetFileName(configurationFileName) + "): "); WithInstanceCounts(localConfigurationFile, (roleName, attribute) => { Log.Verbose(" - " + roleName + " = " + attribute.Value); string value; if (rolesByCount.TryGetValue(roleName, out value)) { attribute.SetValue(value); } }); Log.Verbose("Remote instance counts: "); WithInstanceCounts(remoteConfigurationFile, (roleName, attribute) => { rolesByCount[roleName] = attribute.Value; Log.Verbose(" - " + roleName + " = " + attribute.Value); }); Log.Verbose("Replacing local instance count settings with remote settings: "); WithInstanceCounts(localConfigurationFile, (roleName, attribute) => { string value; if (!rolesByCount.TryGetValue(roleName, out value)) { return; } attribute.SetValue(value); Log.Verbose(" - " + roleName + " = " + attribute.Value); }); }
public void ShouldUseExistingInstanceCountIfSpecified() { ArrangeOriginalConfigurationFileForSuccess(Path.Combine(StagingDirectory, DefaultConfigurationFileName), SimpleConfigSample, x => result = x); variables.Set(SpecialVariables.Action.Azure.UseCurrentInstanceCount, true.ToString()); configurationRetriever.GetConfiguration( Arg.Is <SubscriptionCloudCredentials>(x => x.SubscriptionId == AzureSubscriptionId), CloudServiceName, DeploymentSlot) .Returns(XDocument.Parse(RemoteConfigWithInstanceCount4)); convention.Install(deployment); AssertIsValidConfigurationFile(result); AssertRoleHasInstanceCount(result, "Humpty.Web", 4); AssertRoleHasInstanceCount(result, "Humpty.Worker", 6); }