public void ExecuteCommand() { var prodDeployment = GetDeploymentBySlot(DeploymentSlotType.Production); var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging); if (stagingDeployment == null && prodDeployment == null) { throw new ArgumentOutOfRangeException(String.Format("No deployment found in Staging or Production: {0}", ServiceName)); } if (stagingDeployment == null && prodDeployment != null) { throw new ArgumentOutOfRangeException(String.Format("No deployment found in Staging: {0}", ServiceName)); } if (prodDeployment == null) { this.WriteVerbose(string.Format("Moving deployment from Staging to Production:{0}", ServiceName)); } else { this.WriteVerbose(string.Format("VIP Swap is taking place between Staging and Production deployments.:{0}", ServiceName)); } var swapDeploymentInput = new SwapDeploymentInput { SourceDeployment = stagingDeployment.Name, Production = prodDeployment == null ? null : prodDeployment.Name }; ExecuteClientActionInOCS(swapDeploymentInput, CommandRuntime.ToString(), s => this.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput)); }
public void ExecuteCommand() { var prodDeployment = GetDeploymentBySlot(DeploymentSlotType.Production); var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging); if(stagingDeployment == null && prodDeployment == null) { throw new ArgumentOutOfRangeException(String.Format("No deployment found in Staging or Production: {0}", ServiceName)); } if(stagingDeployment == null && prodDeployment != null) { throw new ArgumentOutOfRangeException(String.Format("No deployment found in Staging: {0}", ServiceName)); } if(prodDeployment == null) { this.WriteVerbose(string.Format("Moving deployment from Staging to Production:{0}", ServiceName)); } else { this.WriteVerbose(string.Format("VIP Swap is taking place between Staging and Production deployments.:{0}", ServiceName)); } var swapDeploymentInput = new SwapDeploymentInput { SourceDeployment = stagingDeployment.Name, Production = prodDeployment == null ? null : prodDeployment.Name }; ExecuteClientActionInOCS(swapDeploymentInput, CommandRuntime.ToString(), s => this.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput)); }
public string SwapDeployment(string serviceName) { var production = this.GetDeployment(serviceName, DeploymentSlotType.Production); var staging = this.GetDeployment(serviceName, DeploymentSlotType.Staging); if (staging == null || string.IsNullOrWhiteSpace(staging.Name)) { return(null); } var swapDeploymentInput = new SwapDeploymentInput { Production = (production == null || string.IsNullOrWhiteSpace(production.Name)) ? null : production.Name, SourceDeployment = staging.Name }; var formatter = new XmlMediaTypeFormatter(); formatter.SetSerializer <SwapDeploymentInput>(new DataContractSerializer(typeof(SwapDeploymentInput))); using (var content = new ObjectContent <SwapDeploymentInput>(swapDeploymentInput, "application/xml", new[] { formatter })) { var requestUri = string.Format("services/hostedservices/{0}", serviceName); var response = this.client.Post(requestUri, content); if (!response.IsSuccessStatusCode) { var errorDetails = GetErrorDetails(response); throw new InvalidOperationException(errorDetails.Message); } return(response.Headers.GetValues(Constants.OperationTrackingIdHeader).FirstOrDefault()); } }
public void ExecuteCommand() { var prodDeployment = GetDeploymentBySlot(DeploymentSlotType.Production); var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging); if (stagingDeployment == null && prodDeployment == null) { throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStagingOrProduction, ServiceName)); } if (stagingDeployment == null && prodDeployment != null) { throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStaging, ServiceName)); } if (prodDeployment == null) { this.WriteVerbose(string.Format(Resources.MovingDeploymentFromStagingToProduction, ServiceName)); } else { this.WriteVerbose(string.Format(Resources.VIPSwapBetweenStagingAndProduction, ServiceName)); } var swapDeploymentInput = new SwapDeploymentInput { SourceDeployment = stagingDeployment.Name, Production = prodDeployment == null ? null : prodDeployment.Name }; ExecuteClientActionInOCS(swapDeploymentInput, CommandRuntime.ToString(), s => this.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput)); }
protected override void PerformOperation(IServiceManagement channel) { SwapDeploymentInput input = new SwapDeploymentInput { Production = DeploymentNameInProduction, SourceDeployment = SourceDeploymentName }; Console.WriteLine("Swapping Deployment"); channel.SwapDeployment(SubscriptionId, HostedServiceName, input); }
/// <summary> /// Connect to an Azure subscription and execute a VIP swap. /// </summary> /// <returns>The asynchronous operation identifier.</returns> protected override string AzureExecute() { var swapDeploymentInput = new SwapDeploymentInput() { SourceDeployment = this.StagingDeploymentName.Get(this.ActivityContext), Production = this.ProductionDeploymentName.Get(this.ActivityContext) }; using (new OperationContextScope((IContextChannel)Channel)) { try { this.RetryCall(s => this.Channel.SwapDeployment(s, this.ServiceName.Get(this.ActivityContext), swapDeploymentInput)); return(RetrieveOperationId()); } catch (EndpointNotFoundException ex) { LogBuildMessage(ex.Message); return(null); } } }
public static void SwapDeployment(this IServiceManagement proxy, string subscriptionId, string serviceName, SwapDeploymentInput input) { proxy.EndSwapDeployment(proxy.BeginSwapDeployment(subscriptionId, serviceName, input, null, null)); }
public IAsyncResult BeginSwapDeployment(string subscriptionId, string serviceName, SwapDeploymentInput input, AsyncCallback callback, object state) { SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult(); result.Values["subscriptionId"] = subscriptionId; result.Values["serviceName"] = serviceName; result.Values["input"] = input; result.Values["callback"] = callback; result.Values["state"] = state; return result; }
public void MoveDeploymentProcess() { Func <string, Deployment> func = null; Action <string> action = null; using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel)) { try { new List <PersistentVMRoleContext>(); MoveAzureDeploymentCommand moveAzureDeploymentCommand = this; if (func == null) { func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, "Production"); } Deployment deployment = ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand).RetryCall <Deployment>(func); if (deployment.RoleList != null && string.Compare(deployment.RoleList[0].RoleType, "PersistentVMRole", StringComparison.OrdinalIgnoreCase) == 0) { throw new ArgumentException("Cannot Move Deployments with Virtual Machines Present"); } } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; if (communicationException as EndpointNotFoundException == null || base.IsVerbose()) { this.WriteErrorDetails(communicationException); } } } string deploymentName = this.GetDeploymentName("Production"); string str = this.GetDeploymentName("Staging"); if (str != null) { SwapDeploymentInput swapDeploymentInput = new SwapDeploymentInput(); swapDeploymentInput.SourceDeployment = str; swapDeploymentInput.Production = deploymentName; using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel)) { try { CmdletExtensions.WriteVerboseOutputForObject(this, swapDeploymentInput); MoveAzureDeploymentCommand moveAzureDeploymentCommand1 = this; if (action == null) { action = (string s) => base.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput); } ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand1).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 communicationException3) { CommunicationException communicationException2 = communicationException3; this.WriteErrorDetails(communicationException2); } } return; } else { throw new ArgumentException("The Staging deployment slot is empty."); } }
public void ExecuteCommand() { var prodDeployment = GetDeploymentBySlot(DeploymentSlotType.Production); var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging); if(stagingDeployment == null && prodDeployment == null) { throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStagingOrProduction, ServiceName)); } if(stagingDeployment == null && prodDeployment != null) { throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStaging, ServiceName)); } if(prodDeployment == null) { this.WriteVerbose(string.Format(Resources.MovingDeploymentFromStagingToProduction, ServiceName)); } else { this.WriteVerbose(string.Format(Resources.VIPSwapBetweenStagingAndProduction, ServiceName)); } var swapDeploymentInput = new SwapDeploymentInput { SourceDeployment = stagingDeployment.Name, Production = prodDeployment == null ? null : prodDeployment.Name }; ExecuteClientActionInOCS(swapDeploymentInput, CommandRuntime.ToString(), s => this.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput)); }