Beispiel #1
0
		public void SetRoleInstanceCountProcess()
		{
			Func<XElement, bool> func = null;
			this.GetCurrentDeployment();
			if (this.currentDeployment != null)
			{
				using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
				{
					try
					{
						XNamespace xNamespace = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration";
						XDocument xDocument = XDocument.Parse(ServiceManagementHelper.DecodeFromBase64String(this.currentDeployment.Configuration));
						IEnumerable<XElement> xElements = xDocument.Root.Elements(xNamespace + "Role");
						if (func == null)
						{
							func = (XElement p) => string.Compare(p.Attribute("name").Value, this.RoleName, true) == 0;
						}
						XElement xElement = xElements.Where<XElement>(func).SingleOrDefault<XElement>();
						if (xElement != null)
						{
							xElement.Element(xNamespace + "Instances").SetAttributeValue("count", this.Count);
						}
						using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
						{
							ChangeConfigurationInput changeConfigurationInput = new ChangeConfigurationInput();
							changeConfigurationInput.Configuration = ServiceManagementHelper.EncodeToBase64String(xDocument.ToString());
							ChangeConfigurationInput changeConfigurationInput1 = changeConfigurationInput;
							CmdletExtensions.WriteVerboseOutputForObject(this, xDocument);
							base.RetryCall((string s) => base.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfigurationInput1));
							Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
							ManagementOperationContext managementOperationContext = new ManagementOperationContext();
							managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
							managementOperationContext.set_OperationId(operation.OperationTrackingId);
							managementOperationContext.set_OperationStatus(operation.Status);
							ManagementOperationContext managementOperationContext1 = managementOperationContext;
							base.WriteObject(managementOperationContext1, true);
						}
					}
					catch (EndpointNotFoundException endpointNotFoundException1)
					{
						EndpointNotFoundException endpointNotFoundException = endpointNotFoundException1;
						this.WriteErrorDetails(endpointNotFoundException);
					}
					catch (CommunicationException communicationException1)
					{
						CommunicationException communicationException = communicationException1;
						this.WriteErrorDetails(communicationException);
					}
				}
				return;
			}
			else
			{
				return;
			}
		}
 public IAsyncResult BeginChangeConfigurationBySlot(string subscriptionId, string serviceName, string deploymentSlot, ChangeConfigurationInput input, AsyncCallback callback, object state)
 {
     SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();
     result.Values["subscriptionId"] = subscriptionId;
     result.Values["serviceName"] = serviceName;
     result.Values["deploymentSlot"] = deploymentSlot;
     result.Values["input"] = input;
     result.Values["callback"] = callback;
     result.Values["state"] = state;
     return result;
 }
        protected override void PerformOperation(IServiceManagement channel)
        {
            var input = new ChangeConfigurationInput();
            input.Configuration = Utility.GetSettings(ConfigFileLocation);

            if (TreatWarningsAsError)
            {
                input.TreatWarningsAsError = TreatWarningsAsError;
            }

            Console.WriteLine("Updating Deployment");
            if (!string.IsNullOrEmpty(DeploymentName))
            {
                channel.ChangeConfiguration(SubscriptionId, HostedServiceName, DeploymentName, input);
            }
            else if (!string.IsNullOrEmpty(DeploymentSlot))
            {
                channel.ChangeConfigurationBySlot(SubscriptionId, HostedServiceName, DeploymentSlot, input);
            }
        }
 public static void ChangeConfigurationBySlot(this IServiceManagement proxy, string subscriptionId, string serviceName, string deploymentSlot, ChangeConfigurationInput input)
 {
     proxy.EndChangeConfigurationBySlot(proxy.BeginChangeConfigurationBySlot(subscriptionId, serviceName, deploymentSlot, input, null, null));
 }
Beispiel #5
0
 public static void ChangeConfigurationBySlot(this IServiceManagement proxy, string subscriptionId, string serviceName, string deploymentSlot, ChangeConfigurationInput input)
 {
     proxy.EndChangeConfigurationBySlot(proxy.BeginChangeConfigurationBySlot(subscriptionId, serviceName, deploymentSlot, input, null, null));
 }
Beispiel #6
0
        public static bool UpdateConfiguration(string subscriptionId, string serviceName, string roleName, int delta, string certificateThumbprint, int maxInstanceCount, int minInstanceCount)
        {
            if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullException("serviceName");
            if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentNullException("roleName");

            string trackingId = null;
            HttpStatusCode? statusCode = null;
            string statusDescription = null;

            try
            {
                var channel = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", GetCertificate(certificateThumbprint));

                var deployment = channel.GetDeploymentBySlot(subscriptionId, serviceName, DeploymentSlot);

                if (string.IsNullOrEmpty(deployment.Configuration))
                    throw new InvalidOperationException(string.Format("Cannot change Instance Count for Role {0}. Service Configuration is null or empty", roleName));

                string configXML = ServiceManagementHelper.DecodeFromBase64String(deployment.Configuration);

                if (string.IsNullOrEmpty(configXML))
                    throw new InvalidOperationException(string.Format("Cannot change Instance Count for Role {0}. Failed to Decode Service Configuration.", roleName));

                // Traversing to Role Instance
                XElement serviceConfig = XElement.Parse(configXML, LoadOptions.SetBaseUri);
                XNamespace xmlns = NamespaceServiceConfiguration;
                var currentInstanceCount = (from c in serviceConfig.Elements(xmlns + "Role")
                                            where string.Compare(c.Attribute("name").Value, roleName, true) == 0
                                            select c.Element(xmlns + "Instances").Attribute("count").Value).FirstOrDefault();

                if (currentInstanceCount == null)
                {
                    throw new WebException(string.Format("Failed to read Role Information for Role {0} from Service Configuration", serviceName));
                }

                int curInstanceCount = Int32.Parse(currentInstanceCount);
                Trace.WriteLine(string.Format("Current instance count: {0}", currentInstanceCount));

                int instanceCount = Math.Min(Math.Max(curInstanceCount + delta, minInstanceCount), maxInstanceCount);
                if (curInstanceCount == instanceCount)
                {
                    Trace.WriteLine("Instance count not elligible for adjustment, abandoning");
                    return false;
                }

                // Updating instance count
                foreach (XElement p in serviceConfig.Elements(xmlns + "Role"))
                {
                    if (string.Compare((string)p.Attribute("name"), roleName, true) == 0)
                    {
                        p.Element(xmlns + "Instances").Attribute("count").SetValue(instanceCount.ToString());
                    }
                }

                var encodedString = ServiceManagementHelper.EncodeToBase64String(serviceConfig.ToString());

                using (OperationContextScope scope = new OperationContextScope((IContextChannel)channel))
                {
                    try
                    {
                        ChangeConfigurationInput input = new ChangeConfigurationInput { Configuration = encodedString };

                        channel.ChangeConfigurationBySlot(subscriptionId, serviceName, DeploymentSlot, input);

                        if (WebOperationContext.Current.IncomingResponse != null)
                        {
                            trackingId = WebOperationContext.Current.IncomingResponse.Headers[Constants.OperationTrackingIdHeader];
                            statusCode = WebOperationContext.Current.IncomingResponse.StatusCode;
                            statusDescription = WebOperationContext.Current.IncomingResponse.StatusDescription;
                            Trace.WriteLine("Operation ID: {0}", trackingId);
                        }
                    }
                    catch (CommunicationException ce)
                    {
                        ServiceManagementError error = null;
                        HttpStatusCode httpStatusCode = 0;
                        string operationId;
                        ServiceManagementHelper.TryGetExceptionDetails(ce, out error, out httpStatusCode, out operationId);
                        if (error == null)
                        {
                            Trace.WriteLine(ce.Message);
                        }
                        else
                        {
                            Trace.WriteLine(string.Format("HTTP Status Code: {0}", httpStatusCode));
                            Trace.WriteLine(string.Format("Error Message: {0}", error.Message));
                            Trace.WriteLine(string.Format("Operation Id: {0}", operationId));
                        }
                        return false;
                    }
                    finally
                    {
                        if (statusCode != null)
                        {
                            Trace.WriteLine(string.Format("HTTP Status Code: {0}", statusCode));
                            Trace.WriteLine(string.Format("StatusDescription: {0}", statusDescription));
                        }
                    }
                }
            }
            catch (TimeoutException)
            {
                Trace.WriteLine("There was an error processing this command.");
                return false;
            }

            return true;
        }
		public void SetDeploymentTmpProcess()
		{
			SetAzureDeploymentCommand.SetAzureDeploymentCommand variable = null;
			string mode;
			string base64String;
			string empty = string.Empty;
			if (!string.IsNullOrEmpty(this.Configuration))
			{
				empty = Utility.GetConfiguration(this.Configuration);
			}
			if (string.Compare(base.ParameterSetName, "Upgrade", StringComparison.OrdinalIgnoreCase) != 0)
			{
				if (string.Compare(base.ParameterSetName, "Config", StringComparison.OrdinalIgnoreCase) != 0)
				{
					Action<string> action = null;
					UpdateDeploymentStatusInput updateDeploymentStatusInput = new UpdateDeploymentStatusInput();
					updateDeploymentStatusInput.Status = this.NewStatus;
					UpdateDeploymentStatusInput updateDeploymentStatusInput1 = updateDeploymentStatusInput;
					using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
					{
						try
						{
							SetAzureDeploymentCommand setAzureDeploymentCommand = this;
							if (action == null)
							{
								action = (string s) => base.Channel.UpdateDeploymentStatusBySlot(s, this.ServiceName, this.Slot, updateDeploymentStatusInput1);
							}
							((CmdletBase<IServiceManagement>)setAzureDeploymentCommand).RetryCall(action);
							Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
							ManagementOperationContext managementOperationContext = new ManagementOperationContext();
							managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
							managementOperationContext.set_OperationId(operation.OperationTrackingId);
							managementOperationContext.set_OperationStatus(operation.Status);
							ManagementOperationContext managementOperationContext1 = managementOperationContext;
							base.WriteObject(managementOperationContext1, true);
						}
						catch (CommunicationException communicationException1)
						{
							CommunicationException communicationException = communicationException1;
							this.WriteErrorDetails(communicationException);
						}
					}
				}
				else
				{
					Action<string> action1 = null;
					ChangeConfigurationInput changeConfigurationInput = new ChangeConfigurationInput();
					changeConfigurationInput.Configuration = empty;
					ChangeConfigurationInput changeConfigurationInput1 = changeConfigurationInput;
					using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
					{
						try
						{
							CmdletExtensions.WriteVerboseOutputForObject(this, changeConfigurationInput1);
							SetAzureDeploymentCommand setAzureDeploymentCommand1 = this;
							if (action1 == null)
							{
								action1 = (string s) => base.Channel.ChangeConfigurationBySlot(s, this.ServiceName, this.Slot, changeConfigurationInput1);
							}
							((CmdletBase<IServiceManagement>)setAzureDeploymentCommand1).RetryCall(action1);
							Operation operation1 = base.WaitForOperation(base.CommandRuntime.ToString());
							ManagementOperationContext managementOperationContext2 = new ManagementOperationContext();
							managementOperationContext2.set_OperationDescription(base.CommandRuntime.ToString());
							managementOperationContext2.set_OperationId(operation1.OperationTrackingId);
							managementOperationContext2.set_OperationStatus(operation1.Status);
							ManagementOperationContext managementOperationContext3 = managementOperationContext2;
							base.WriteObject(managementOperationContext3, true);
						}
						catch (CommunicationException communicationException3)
						{
							CommunicationException communicationException2 = communicationException3;
							this.WriteErrorDetails(communicationException2);
						}
					}
				}
			}
			else
			{
				Func<string, Uri> func = null;
				Action<string> action2 = null;
				Action<string> action3 = null;
				bool flag = false;
				base.CurrentSubscription = CmdletSubscriptionExtensions.GetCurrentSubscription(this);
				string currentStorageAccount = base.CurrentSubscription.CurrentStorageAccount;
				if (this.Package.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) || this.Package.StartsWith(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
				{
					Uri uri = new Uri(this.Package);
				}
				else
				{
					if (!string.IsNullOrEmpty(currentStorageAccount))
					{
						ProgressRecord progressRecord = new ProgressRecord(0, "Please wait...", "Uploading package to blob storage");
						base.WriteProgress(progressRecord);
						flag = true;
						SetAzureDeploymentCommand variable1 = variable;
						SetAzureDeploymentCommand setAzureDeploymentCommand2 = this;
						if (func == null)
						{
							func = (string s) => AzureBlob.UploadPackageToBlob(this.CreateChannel(), currentStorageAccount, s, this.Package);
						}
						packageUrl = ((CmdletBase<IServiceManagement>)setAzureDeploymentCommand2).RetryCall<Uri>(func);
					}
					else
					{
						throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
					}
				}
				SetAzureDeploymentCommand variable2 = variable;
				UpgradeDeploymentInput upgradeDeploymentInput = new UpgradeDeploymentInput();
				UpgradeDeploymentInput upgradeDeploymentInput1 = upgradeDeploymentInput;
				if (this.Mode == null)
				{
					mode = "Auto";
				}
				else
				{
					mode = this.Mode;
				}
				upgradeDeploymentInput1.Mode = mode;
				upgradeDeploymentInput.Configuration = empty;
				upgradeDeploymentInput.PackageUrl = uri;
				UpgradeDeploymentInput upgradeDeploymentInput2 = upgradeDeploymentInput;
				if (this.Label != null)
				{
					base64String = ServiceManagementHelper.EncodeToBase64String(this.Label);
				}
				else
				{
					base64String = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
				}
				upgradeDeploymentInput2.Label = base64String;
				SwitchParameter force = this.Force;
				upgradeDeploymentInput.Force = new bool?(force.IsPresent);
				variable2.upgradeDeploymentInput = upgradeDeploymentInput;
				if (!string.IsNullOrEmpty(this.RoleName))
				{
					UpgradeDeploymentInput roleName = this.RoleName;
				}
				using (OperationContextScope operationContextScope2 = new OperationContextScope((IContextChannel)base.Channel))
				{
					try
					{
						CmdletExtensions.WriteVerboseOutputForObject(this, roleName);
						SetAzureDeploymentCommand setAzureDeploymentCommand3 = this;
						if (action2 == null)
						{
							action2 = (string s) => this.Channel.UpgradeDeploymentBySlot(s, this.ServiceName, this.Slot, this.upgradeDeploymentInput);
						}
						((CmdletBase<IServiceManagement>)setAzureDeploymentCommand3).RetryCall(action2);
						Operation operation2 = base.WaitForOperation(base.CommandRuntime.ToString());
						ManagementOperationContext managementOperationContext4 = new ManagementOperationContext();
						managementOperationContext4.OperationDescription = base.CommandRuntime.ToString();
						managementOperationContext4.OperationId = operation2.OperationTrackingId;
						managementOperationContext4.OperationStatus = operation2.Status;
						ManagementOperationContext managementOperationContext5 = managementOperationContext4;
						base.WriteObject(managementOperationContext5, true);
						if (flag)
						{
							SetAzureDeploymentCommand setAzureDeploymentCommand4 = this;
							if (action3 == null)
							{
								action3 = (string s) => AzureBlob.DeletePackageFromBlob(base.Channel, currentStorageAccount, s, uri);
							}
							((CmdletBase<IServiceManagement>)setAzureDeploymentCommand4).RetryCall(action3);
						}
					}
					catch (CommunicationException communicationException5)
					{
						CommunicationException communicationException4 = communicationException5;
						this.WriteErrorDetails(communicationException4);
					}
				}
			}
		}