public void SetRoleInstanceCountProcess() { OperationStatusResponse operation; var currentDeployment = this.GetCurrentDeployment(out operation); if (currentDeployment == null) { return; } XNamespace ns = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"; var configuration = XDocument.Parse(currentDeployment.Configuration); var role = configuration.Root.Elements(ns + "Role").SingleOrDefault(p => string.Compare(p.Attribute("name").Value, this.RoleName, true) == 0); if (role != null) { role.Element(ns + "Instances").SetAttributeValue("count", this.Count); } var updatedConfigurationParameter = new DeploymentChangeConfigurationParameters { Configuration = configuration.ToString() }; DeploymentSlot slot; if (!Enum.TryParse(this.Slot, out slot)) { throw new ArgumentOutOfRangeException("Slot"); } ExecuteClientActionNewSM(configuration, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.ChangeConfigurationBySlot(this.ServiceName, slot, updatedConfigurationParameter)); }
public void ExecuteCommand() { string configString = string.Empty; if (!string.IsNullOrEmpty(Configuration)) { configString = GeneralUtilities.GetConfiguration(Configuration); } ExtensionConfiguration extConfig = null; if (ExtensionConfiguration != null) { string errorConfigInput = null; if (!ExtensionManager.Validate(ExtensionConfiguration, out errorConfigInput)) { throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, errorConfigInput)); } foreach (ExtensionConfigurationInput context in ExtensionConfiguration) { if (context != null && context.X509Certificate != null) { ExecuteClientActionNewSM( null, string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, context.X509Certificate.Thumbprint), () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, CertUtilsNewSM.Create(context.X509Certificate))); } } Func <DeploymentSlot, DeploymentGetResponse> func = t => { DeploymentGetResponse d = null; try { d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, t); } catch (CloudException ex) { if (ex.Response.StatusCode != HttpStatusCode.NotFound && IsVerbose() == false) { WriteExceptionError(ex); } } return(d); }; var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true); DeploymentGetResponse currentDeployment = null; InvokeInOperationContext(() => currentDeployment = func(slotType)); var peerSlottype = slotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production; DeploymentGetResponse peerDeployment = null; InvokeInOperationContext(() => peerDeployment = func(peerSlottype)); ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName); extConfig = extensionMgr.Add(currentDeployment, peerDeployment, ExtensionConfiguration, this.Slot); } // Upgrade Parameter Set if (string.Compare(ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) == 0) { bool removePackage = false; var storageName = Profile.Context.Subscription.GetProperty(AzureSubscription.Property.StorageAccount); Uri packageUrl = null; if (Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)) { packageUrl = new Uri(Package); } else { if (string.IsNullOrEmpty(storageName)) { throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet); } var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.UploadingPackage); WriteProgress(progress); removePackage = true; InvokeInOperationContext(() => packageUrl = RetryCall(s => AzureBlob.UploadPackageToBlob(this.StorageClient, storageName, Package, null))); } DeploymentUpgradeMode upgradeMode; if (!Enum.TryParse <DeploymentUpgradeMode>(Mode, out upgradeMode)) { upgradeMode = DeploymentUpgradeMode.Auto; } var upgradeDeploymentInput = new DeploymentUpgradeParameters { Mode = upgradeMode, Configuration = configString, ExtensionConfiguration = extConfig, PackageUri = packageUrl, Label = Label ?? ServiceName, Force = Force.IsPresent }; if (!string.IsNullOrEmpty(RoleName)) { upgradeDeploymentInput.RoleToUpgrade = RoleName; } InvokeInOperationContext(() => { try { ExecuteClientActionNewSM( upgradeDeploymentInput, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.UpgradeBySlot( this.ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true), upgradeDeploymentInput)); if (removePackage == true) { this.RetryCall(s => AzureBlob.DeletePackageFromBlob( this.StorageClient, storageName, packageUrl)); } } catch (CloudException ex) { WriteExceptionError(ex); } }); } else if (string.Compare(this.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) == 0) { // Config parameter set var changeDeploymentStatusParams = new DeploymentChangeConfigurationParameters { Configuration = configString, ExtensionConfiguration = extConfig }; ExecuteClientActionNewSM( changeDeploymentStatusParams, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.ChangeConfigurationBySlot( this.ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true), changeDeploymentStatusParams)); } else { // Status parameter set var updateDeploymentStatusParams = new DeploymentUpdateStatusParameters { Status = (UpdatedDeploymentStatus)Enum.Parse(typeof(UpdatedDeploymentStatus), this.NewStatus, true) }; ExecuteClientActionNewSM( null, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.UpdateStatusByDeploymentSlot( this.ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true), updateDeploymentStatusParams)); } }
protected void ChangeDeployment(ExtensionConfiguration extConfig) { DeploymentChangeConfigurationParameters changeConfigInput = new DeploymentChangeConfigurationParameters { Configuration = Deployment.Configuration, ExtensionConfiguration = Deployment.ExtensionConfiguration = extConfig, Mode = DeploymentChangeConfigurationMode.Auto, TreatWarningsAsError = false }; ExecuteClientActionNewSM( null, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.ChangeConfigurationBySlot( ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), Slot, true), changeConfigInput)); }
public void ExecuteCommand() { string configString = string.Empty; if (!string.IsNullOrEmpty(Configuration)) { configString = GeneralUtilities.GetConfiguration(Configuration); } ExtensionConfiguration extConfig = null; if (ExtensionConfiguration != null) { string errorConfigInput = null; if (!ExtensionManager.Validate(ExtensionConfiguration, out errorConfigInput)) { throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, errorConfigInput)); } foreach (ExtensionConfigurationInput context in ExtensionConfiguration) { if (context != null && context.X509Certificate != null) { ExecuteClientActionNewSM( null, string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, context.X509Certificate.Thumbprint), () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, CertUtilsNewSM.Create(context.X509Certificate))); } } var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true); DeploymentGetResponse d = null; InvokeInOperationContext(() => { try { d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType); } catch (CloudException ex) { if (ex.Response.StatusCode != HttpStatusCode.NotFound && IsVerbose() == false) { this.WriteExceptionDetails(ex); } } }); ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName); extConfig = extensionMgr.Add(d, ExtensionConfiguration, this.Slot); } // Upgrade Parameter Set if (string.Compare(ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) == 0) { bool removePackage = false; var storageName = CurrentSubscription.CurrentStorageAccountName; Uri packageUrl = null; if (Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)) { packageUrl = new Uri(Package); } else { if (string.IsNullOrEmpty(storageName)) { throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet); } var progress = new ProgressRecord(0, Resources.WaitForUploadingPackage, Resources.UploadingPackage); WriteProgress(progress); removePackage = true; InvokeInOperationContext(() => packageUrl = RetryCall(s => AzureBlob.UploadPackageToBlob(this.StorageClient, storageName, Package, null))); } DeploymentUpgradeMode upgradeMode; if (!Enum.TryParse<DeploymentUpgradeMode>(Mode, out upgradeMode)) { upgradeMode = DeploymentUpgradeMode.Auto; } var upgradeDeploymentInput = new DeploymentUpgradeParameters { Mode = upgradeMode, Configuration = configString, ExtensionConfiguration = extConfig, PackageUri = packageUrl, Label = Label ?? ServiceName, Force = Force.IsPresent }; if (!string.IsNullOrEmpty(RoleName)) { upgradeDeploymentInput.RoleToUpgrade = RoleName; } InvokeInOperationContext(() => { try { ExecuteClientActionNewSM( upgradeDeploymentInput, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.UpgradeBySlot( this.ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true), upgradeDeploymentInput)); if (removePackage == true) { this.RetryCall(s => AzureBlob.DeletePackageFromBlob( this.StorageClient, storageName, packageUrl)); } } catch (CloudException ex) { this.WriteExceptionDetails(ex); } }); } else if (string.Compare(this.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) == 0) { // Config parameter set var changeDeploymentStatusParams = new DeploymentChangeConfigurationParameters { Configuration = configString, ExtensionConfiguration = extConfig }; ExecuteClientActionNewSM( changeDeploymentStatusParams, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.ChangeConfigurationBySlot( this.ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true), changeDeploymentStatusParams)); } else { // Status parameter set var updateDeploymentStatusParams = new DeploymentUpdateStatusParameters { Status = (UpdatedDeploymentStatus)Enum.Parse(typeof(UpdatedDeploymentStatus), this.NewStatus, true) }; ExecuteClientActionNewSM( null, CommandRuntime.ToString(), () => this.ComputeClient.Deployments.UpdateStatusByDeploymentSlot( this.ServiceName, (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true), updateDeploymentStatusParams)); } }