/// <summary> /// Serializes the object to JSON. /// </summary> /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="obj">The object to serialize to JSON.</param> internal static void Serialize(JsonWriter writer, ComposeDeploymentUpgradeDescription obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.UpgradeKind, "UpgradeKind", UpgradeKindConverter.Serialize); writer.WriteProperty(obj.DeploymentName, "DeploymentName", JsonWriterExtensions.WriteStringValue); writer.WriteProperty(obj.ComposeFileContent, "ComposeFileContent", JsonWriterExtensions.WriteStringValue); writer.WriteProperty(obj.RollingUpgradeMode, "RollingUpgradeMode", UpgradeModeConverter.Serialize); if (obj.RegistryCredential != null) { writer.WriteProperty(obj.RegistryCredential, "RegistryCredential", RegistryCredentialConverter.Serialize); } if (obj.UpgradeReplicaSetCheckTimeoutInSeconds != null) { writer.WriteProperty(obj.UpgradeReplicaSetCheckTimeoutInSeconds, "UpgradeReplicaSetCheckTimeoutInSeconds", JsonWriterExtensions.WriteLongValue); } if (obj.ForceRestart != null) { writer.WriteProperty(obj.ForceRestart, "ForceRestart", JsonWriterExtensions.WriteBoolValue); } if (obj.MonitoringPolicy != null) { writer.WriteProperty(obj.MonitoringPolicy, "MonitoringPolicy", MonitoringPolicyDescriptionConverter.Serialize); } if (obj.ApplicationHealthPolicy != null) { writer.WriteProperty(obj.ApplicationHealthPolicy, "ApplicationHealthPolicy", ApplicationHealthPolicyConverter.Serialize); } writer.WriteEndObject(); }
protected PSObject ToPSObject(ComposeDeploymentUpgradeDescription upgradeDescription) { var itemPSObj = new PSObject(upgradeDescription); var composeFilePathsPSObj = new PSObject(upgradeDescription.ComposeFilePaths); composeFilePathsPSObj.Members.Add( new PSCodeMethod( Constants.ToStringMethodName, typeof(OutputFormatter).GetMethod(Constants.FormatObjectMethodName))); itemPSObj.Properties.Add( new PSNoteProperty( Constants.ComposeFilePathsPropertyName, composeFilePathsPSObj)); if (upgradeDescription.UpgradePolicyDescription == null) { return(itemPSObj); } var monitoredPolicy = upgradeDescription.UpgradePolicyDescription as MonitoredRollingApplicationUpgradePolicyDescription; if (monitoredPolicy != null) { itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeKindPropertyName, monitoredPolicy.Kind)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.ForceRestartPropertyName, monitoredPolicy.ForceRestart)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeModePropertyName, monitoredPolicy.UpgradeMode)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeReplicaSetCheckTimeoutPropertyName, monitoredPolicy.UpgradeReplicaSetCheckTimeout)); if (monitoredPolicy.MonitoringPolicy != null) { itemPSObj.Properties.Add(new PSNoteProperty(Constants.FailureActionPropertyName, monitoredPolicy.MonitoringPolicy.FailureAction)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.HealthCheckWaitDurationPropertyName, monitoredPolicy.MonitoringPolicy.HealthCheckWaitDuration)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.HealthCheckStableDurationPropertyName, monitoredPolicy.MonitoringPolicy.HealthCheckStableDuration)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.HealthCheckRetryTimeoutPropertyName, monitoredPolicy.MonitoringPolicy.HealthCheckRetryTimeout)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeDomainTimeoutPropertyName, monitoredPolicy.MonitoringPolicy.UpgradeDomainTimeout)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeTimeoutPropertyName, monitoredPolicy.MonitoringPolicy.UpgradeTimeout)); } if (monitoredPolicy.HealthPolicy != null) { this.AddToPSObject(itemPSObj, monitoredPolicy.HealthPolicy); } } else { var policy = upgradeDescription.UpgradePolicyDescription as RollingUpgradePolicyDescription; if (policy != null) { itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeKindPropertyName, policy.Kind)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.ForceRestartPropertyName, policy.ForceRestart)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeModePropertyName, policy.UpgradeMode)); itemPSObj.Properties.Add(new PSNoteProperty(Constants.UpgradeReplicaSetCheckTimeoutPropertyName, policy.UpgradeReplicaSetCheckTimeout)); } } return(itemPSObj); }
/// <summary> /// <para>Starts the upgrade for the compose deployment identified by the deployment name, in the cluster.</para> /// </summary> public static Task UpgradeComposeDeploymentAsync( this FabricClient.ComposeDeploymentClient client, ComposeDeploymentUpgradeDescription upgradeDescription, TimeSpan timeout, CancellationToken cancellationToken) { return(client.UpgradeComposeDeploymentAsync(upgradeDescription.ToWrapper(), timeout, cancellationToken)); }
/// <inheritdoc/> protected override void ProcessRecordInternal() { var registryCredential = new RegistryCredential( registryUserName: this.RegistryUserName, registryPassword: this.RegistryPassword, passwordEncrypted: this.PasswordEncrypted); var monitoringPolicyDescription = new MonitoringPolicyDescription( failureAction: this.FailureAction, healthCheckWaitDurationInMilliseconds: this.HealthCheckWaitDurationInMilliseconds, healthCheckStableDurationInMilliseconds: this.HealthCheckStableDurationInMilliseconds, healthCheckRetryTimeoutInMilliseconds: this.HealthCheckRetryTimeoutInMilliseconds, upgradeTimeoutInMilliseconds: this.UpgradeTimeoutInMilliseconds, upgradeDomainTimeoutInMilliseconds: this.UpgradeDomainTimeoutInMilliseconds); var serviceTypeHealthPolicy = new ServiceTypeHealthPolicy( maxPercentUnhealthyPartitionsPerService: this.MaxPercentUnhealthyPartitionsPerService, maxPercentUnhealthyReplicasPerPartition: this.MaxPercentUnhealthyReplicasPerPartition, maxPercentUnhealthyServices: this.MaxPercentUnhealthyServices); var applicationHealthPolicy = new ApplicationHealthPolicy( considerWarningAsError: this.ConsiderWarningAsError, maxPercentUnhealthyDeployedApplications: this.MaxPercentUnhealthyDeployedApplications, defaultServiceTypeHealthPolicy: serviceTypeHealthPolicy, serviceTypeHealthPolicyMap: this.ServiceTypeHealthPolicyMap); var composeDeploymentUpgradeDescription = new ComposeDeploymentUpgradeDescription( deploymentName: this.DeploymentName, composeFileContent: this.ComposeFileContent, upgradeKind: this.UpgradeKind, registryCredential: registryCredential, rollingUpgradeMode: this.RollingUpgradeMode, upgradeReplicaSetCheckTimeoutInSeconds: this.UpgradeReplicaSetCheckTimeoutInSeconds, forceRestart: this.ForceRestart, monitoringPolicy: monitoringPolicyDescription, applicationHealthPolicy: applicationHealthPolicy); this.ServiceFabricClient.ComposeDeployments.StartComposeDeploymentUpgradeAsync( deploymentName: this.DeploymentName, composeDeploymentUpgradeDescription: composeDeploymentUpgradeDescription, serverTimeout: this.ServerTimeout, cancellationToken: this.CancellationToken).GetAwaiter().GetResult(); Console.WriteLine("Success!"); }
/// <inheritdoc /> public Task StartComposeDeploymentUpgradeAsync( string deploymentName, ComposeDeploymentUpgradeDescription composeDeploymentUpgradeDescription, long?serverTimeout = 60, CancellationToken cancellationToken = default(CancellationToken)) { deploymentName.ThrowIfNull(nameof(deploymentName)); composeDeploymentUpgradeDescription.ThrowIfNull(nameof(composeDeploymentUpgradeDescription)); serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295); var requestId = Guid.NewGuid().ToString(); var url = "ComposeDeployments/{deploymentName}/$/Upgrade"; url = url.Replace("{deploymentName}", deploymentName); var queryParams = new List <string>(); // Append to queryParams if not null. serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}"); queryParams.Add("api-version=6.0-preview"); url += "?" + string.Join("&", queryParams); string content; using (var sw = new StringWriter()) { ComposeDeploymentUpgradeDescriptionConverter.Serialize(new JsonTextWriter(sw), composeDeploymentUpgradeDescription); content = sw.ToString(); } HttpRequestMessage RequestFunc() { var request = new HttpRequestMessage() { Method = HttpMethod.Post, Content = new StringContent(content, Encoding.UTF8), }; request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); return(request); } return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken)); }
protected void UpgradeComposeDeployment(ComposeDeploymentUpgradeDescription upgradeDescription) { var clusterConnection = this.GetClusterConnection(); try { clusterConnection.UpgradeComposeDeploymentAsync( upgradeDescription, this.GetTimeout(), this.GetCancellationToken()).Wait(); this.WriteObject(this.FormatOutput(upgradeDescription), true); } catch (AggregateException aggregateException) { aggregateException.Handle((ae) => { this.ThrowTerminatingError( ae, Constants.UpgradeComposeDeploymentErrorId, clusterConnection); return(true); }); } }
/// <summary> /// <para>Starts the upgrade for the compose deployment identified by the deployment name, in the cluster.</para> /// </summary> public static Task UpgradeComposeDeploymentAsync( this FabricClient.ComposeDeploymentClient client, ComposeDeploymentUpgradeDescription upgradeDescription) { return(client.UpgradeComposeDeploymentAsync(upgradeDescription.ToWrapper())); }
protected override void ProcessRecord() { try { RollingUpgradePolicyDescription policyDescription; if (this.Monitored) { var monitoringPolicy = new RollingUpgradeMonitoringPolicy(); if (this.FailureAction == UpgradeFailureAction.Invalid) { this.FailureAction = Constants.DefaultUpgradeFailureAction; } monitoringPolicy.FailureAction = this.FailureAction; if (this.HealthCheckRetryTimeoutSec.HasValue) { monitoringPolicy.HealthCheckRetryTimeout = TimeSpan.FromSeconds(this.HealthCheckRetryTimeoutSec.Value); } if (this.HealthCheckWaitDurationSec.HasValue) { monitoringPolicy.HealthCheckWaitDuration = TimeSpan.FromSeconds(this.HealthCheckWaitDurationSec.Value); } if (this.HealthCheckStableDurationSec.HasValue) { monitoringPolicy.HealthCheckStableDuration = TimeSpan.FromSeconds(this.HealthCheckStableDurationSec.Value); } if (this.UpgradeDomainTimeoutSec.HasValue) { monitoringPolicy.UpgradeDomainTimeout = TimeSpan.FromSeconds(this.UpgradeDomainTimeoutSec.Value); } if (this.UpgradeTimeoutSec.HasValue) { monitoringPolicy.UpgradeTimeout = TimeSpan.FromSeconds(this.UpgradeTimeoutSec.Value); } var monitoredPolicyDescription = new MonitoredRollingApplicationUpgradePolicyDescription { UpgradeMode = RollingUpgradeMode.Monitored, ForceRestart = this.ForceRestart, MonitoringPolicy = monitoringPolicy }; policyDescription = monitoredPolicyDescription; if (this.IsUpdatingHealthPolicy()) { if (!this.Force && !this.IsHealthPolicyComplete() && !this.ShouldProcess( //// description shows up for "-WhatIf" string.Format( CultureInfo.InvariantCulture, "{0} {1}", StringResources.PowerShell_HealthPolicyUpgradeCaption, StringResources.PowerShell_ApplicationHealthPolicyUpdateWarning), //// warning and caption show up when prompting for confirmation StringResources.PowerShell_ApplicationHealthPolicyUpdateWarning, StringResources.PowerShell_HealthPolicyUpgradeCaption)) { return; } var healthPolicy = new ApplicationHealthPolicy(); if (this.ConsiderWarningAsError.HasValue) { healthPolicy.ConsiderWarningAsError = this.ConsiderWarningAsError.Value; } if (this.DefaultServiceTypeHealthPolicy != null) { healthPolicy.DefaultServiceTypeHealthPolicy = this.ParseServiceTypeHealthPolicy(this.DefaultServiceTypeHealthPolicy); } if (this.MaxPercentUnhealthyDeployedApplications.HasValue) { healthPolicy.MaxPercentUnhealthyDeployedApplications = this.MaxPercentUnhealthyDeployedApplications.Value; } if (this.ServiceTypeHealthPolicyMap != null) { foreach (DictionaryEntry entry in this.ServiceTypeHealthPolicyMap) { healthPolicy.ServiceTypeHealthPolicyMap.Add(entry.Key as string, this.ParseServiceTypeHealthPolicy(entry.Value as string)); } } monitoredPolicyDescription.HealthPolicy = healthPolicy; } } else if (this.UnmonitoredManual) { policyDescription = new RollingUpgradePolicyDescription { UpgradeMode = RollingUpgradeMode.UnmonitoredManual, ForceRestart = this.ForceRestart, }; } else { policyDescription = new RollingUpgradePolicyDescription { UpgradeMode = RollingUpgradeMode.UnmonitoredAuto, ForceRestart = this.ForceRestart, }; } if (this.UpgradeReplicaSetCheckTimeoutSec.HasValue) { policyDescription.UpgradeReplicaSetCheckTimeout = TimeSpan.FromSeconds(this.UpgradeReplicaSetCheckTimeoutSec.Value); } var composeFiles = new string[] { this.GetAbsolutePath(this.Compose) }; var upgradeDescription = new ComposeDeploymentUpgradeDescription( this.DeploymentName, composeFiles) { UpgradePolicyDescription = policyDescription, ContainerRegistryUserName = this.RegistryUserName, ContainerRegistryPassword = this.RegistryPassword, IsRegistryPasswordEncrypted = this.PasswordEncrypted }; this.UpgradeComposeDeployment(upgradeDescription); } catch (Exception exception) { this.ThrowTerminatingError( exception, Constants.UpgradeComposeDeploymentErrorId, null); } }