protected override void ProcessRecord() { try { if (this.ReplicaQuorumTimeoutSec.HasValue) { this.WriteWarning(StringResources.PowerShell_ReplicaQuorumTimeoutSec_Deprecated); if (!this.UpgradeReplicaSetCheckTimeoutSec.HasValue) { this.UpgradeReplicaSetCheckTimeoutSec = this.ReplicaQuorumTimeoutSec.Value; } } if (this.RestartProcess) { this.WriteWarning(StringResources.PowerShell_RestartProcess_Deprecated); if (!this.ForceRestart) { this.ForceRestart = this.RestartProcess; } } 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 upgradeDescription = new ApplicationUpgradeDescription { ApplicationName = this.ApplicationName, TargetApplicationTypeVersion = this.ApplicationTypeVersion, UpgradePolicyDescription = policyDescription }; upgradeDescription.ApplicationParameters.Add(this.GetNameValueCollection(this.ApplicationParameter)); this.UpgradeApplication(upgradeDescription); } catch (Exception exception) { this.ThrowTerminatingError( exception, Constants.UpgradeApplicationErrorId, null); } }
/// <summary> /// start an application upgrade /// </summary> /// <param name="fromPackage">from package</param> /// <param name="toPackage">to package</param> /// <param name="isRolling">specify if rolling</param> /// <param name="mode">monitor mode</param> /// <param name="timeout">timeout for upgrade start</param> /// <returns>true if upgrade started</returns> public bool TryApplicationUpgrade(PackageSettings fromPackage, PackageSettings toPackage, bool isRolling, UpgradeMonitor mode, TimeSpan timeout) { this.LastException = null; try { ApplicationUpgradeDescription upgradeDescription = new ApplicationUpgradeDescription(); // we use the "from" package's address upgradeDescription.ApplicationName = new Uri(fromPackage.ApplicationAddress); // we use the "to" package's version upgradeDescription.TargetApplicationTypeVersion = toPackage.ApplicationVersion; // split parameters if any are specified NameValueCollection upgradeParams = Control64.GetApplicationParameters(toPackage); if (upgradeParams != null && upgradeParams.Count > 0) { upgradeDescription.ApplicationParameters.Add(upgradeParams); } RollingUpgradePolicyDescription policy = new RollingUpgradePolicyDescription(); policy.ForceRestart = true; policy.UpgradeMode = RollingUpgradeMode.UnmonitoredManual; if (isRolling) { switch (mode) { case UpgradeMonitor.Auto: policy.UpgradeMode = RollingUpgradeMode.UnmonitoredAuto; break; case UpgradeMonitor.Manual: policy.UpgradeMode = RollingUpgradeMode.UnmonitoredManual; break; } policy.UpgradeReplicaSetCheckTimeout = timeout; } upgradeDescription.UpgradePolicyDescription = policy; this.fc.ApplicationManager.UpgradeApplicationAsync(upgradeDescription, Defaults.UpgradeTimeout, CancellationToken.None).Wait(); return true; } catch (Exception e) { this.LastException = e; if (e is AggregateException) { if (e is FabricException) { log.Error("Upgrade failed: " + e.InnerException.Message); return false; } log.Error("UpgradeApplication Aggregate failure, err={0}", e.InnerException.Message); } else { log.Error("UpgradeApplication failed, err={0}", e.Message); } } return false; }
internal static unsafe ComposeDeploymentUpgradeProgress CreateFromNative( NativeClient.IFabricComposeDeploymentUpgradeProgressResult nativeResult) { ComposeDeploymentUpgradeProgress result = new ComposeDeploymentUpgradeProgress(); IntPtr upgradeProgressPtr = nativeResult.get_UpgradeProgress(); if (upgradeProgressPtr != IntPtr.Zero) { var castedUpgradeProgressPtr = (NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_PROGRESS *)upgradeProgressPtr; result.ApplicationName = NativeTypes.FromNativeUri(castedUpgradeProgressPtr->ApplicationName); result.DeploymentName = NativeTypes.FromNativeString(castedUpgradeProgressPtr->DeploymentName); // Upgrade policy if (castedUpgradeProgressPtr->UpgradePolicyDescription != IntPtr.Zero) { RollingUpgradePolicyDescription policy = null; var castedPolicyPtr = (NativeTypes.FABRIC_ROLLING_UPGRADE_POLICY_DESCRIPTION *)castedUpgradeProgressPtr->UpgradePolicyDescription; if (castedPolicyPtr->RollingUpgradeMode == NativeTypes.FABRIC_ROLLING_UPGRADE_MODE.FABRIC_ROLLING_UPGRADE_MODE_MONITORED) { policy = MonitoredRollingApplicationUpgradePolicyDescription.FromNative(castedUpgradeProgressPtr->UpgradePolicyDescription); } else { policy = RollingUpgradePolicyDescription.FromNative(castedUpgradeProgressPtr->UpgradePolicyDescription); } result.UpgradePolicyDescription = policy; } result.TargetApplicationTypeVersion = NativeTypes.FromNativeString(castedUpgradeProgressPtr->TargetApplicationTypeVersion); switch (castedUpgradeProgressPtr->UpgradeState) { case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_PROVISIONING_TARGET: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_ROLLING_FORWARD_IN_PROGRESS: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_ROLLING_FORWARD_PENDING: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_UNPROVISIONING_CURRENT: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_ROLLING_FORWARD_COMPLETED: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_ROLLING_BACK_IN_PROGRESS: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_UNPROVISIONING_TARGET: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_ROLLING_BACK_COMPLETED: case NativeTypes.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE.FABRIC_COMPOSE_DEPLOYMENT_UPGRADE_STATE_FAILED: result.UpgradeState = (ComposeDeploymentUpgradeState)castedUpgradeProgressPtr->UpgradeState; break; default: result.UpgradeState = ComposeDeploymentUpgradeState.Invalid; break; } result.NextUpgradeDomain = NativeTypes.FromNativeString(castedUpgradeProgressPtr->NextUpgradeDomain); if (castedUpgradeProgressPtr->UpgradeDomains != IntPtr.Zero) { var upgradeDomainsPtr = (NativeTypes.FABRIC_UPGRADE_DOMAIN_STATUS_DESCRIPTION_LIST *)castedUpgradeProgressPtr->UpgradeDomains; uint count = upgradeDomainsPtr->Count; result.UpgradeDomains = Interop.InteropHelpers.UpgradeDomainHelper.CreateUpgradeDomainsFromNative(count, upgradeDomainsPtr->Items); } result.UpgradeDuration = TimeSpan.FromSeconds(castedUpgradeProgressPtr->UpgradeDurationInSeconds); result.CurrentUpgradeDomainDuration = TimeSpan.FromSeconds(castedUpgradeProgressPtr->CurrentUpgradeDomainDurationInSeconds); result.ApplicationUnhealthyEvaluations = HealthEvaluation.FromNativeList(castedUpgradeProgressPtr->ApplicationUnhealthyEvaluations); result.CurrentUpgradeDomainProgress = UpgradeDomainProgress.FromNative(castedUpgradeProgressPtr->CurrentUpgradeDomainProgress); result.StartTimestampUtc = NativeTypes.FromNullableNativeFILETIME(castedUpgradeProgressPtr->StartTimestampUtc); result.FailureTimestampUtc = NativeTypes.FromNullableNativeFILETIME(castedUpgradeProgressPtr->FailureTimestampUtc); if (result.FailureTimestampUtc.HasValue) { switch (castedUpgradeProgressPtr->FailureReason) { case NativeTypes.FABRIC_UPGRADE_FAILURE_REASON.FABRIC_UPGRADE_FAILURE_REASON_INTERRUPTED: case NativeTypes.FABRIC_UPGRADE_FAILURE_REASON.FABRIC_UPGRADE_FAILURE_REASON_HEALTH_CHECK: case NativeTypes.FABRIC_UPGRADE_FAILURE_REASON.FABRIC_UPGRADE_FAILURE_REASON_UPGRADE_DOMAIN_TIMEOUT: case NativeTypes.FABRIC_UPGRADE_FAILURE_REASON.FABRIC_UPGRADE_FAILURE_REASON_OVERALL_UPGRADE_TIMEOUT: case NativeTypes.FABRIC_UPGRADE_FAILURE_REASON.FABRIC_UPGRADE_FAILURE_REASON_PROCESSING_FAILURE: result.FailureReason = (UpgradeFailureReason)castedUpgradeProgressPtr->FailureReason; break; default: result.FailureReason = UpgradeFailureReason.None; break; } result.UpgradeDomainProgressAtFailure = UpgradeDomainProgress.FromNative(castedUpgradeProgressPtr->UpgradeDomainProgressAtFailure); } result.ApplicationUpgradeStatusDetails = NativeTypes.FromNativeString(castedUpgradeProgressPtr->ApplicationUpgradeStatusDetails); result.UpgradeStatusDetails = NativeTypes.FromNativeString(castedUpgradeProgressPtr->UpgradeStatusDetails); } return(result); }
/// <summary> /// start an application upgrade /// </summary> /// <param name="fromPackage">from package</param> /// <param name="toPackage">to package</param> /// <param name="isRolling">specify if rolling</param> /// <param name="mode">monitor mode</param> /// <param name="timeout">timeout for upgrade start</param> /// <returns>true if upgrade started</returns> public bool TryApplicationUpgrade(PackageSettings fromPackage, PackageSettings toPackage, bool isRolling, UpgradeMonitor mode, TimeSpan timeout) { this.LastException = null; try { ApplicationUpgradeDescription upgradeDescription = new ApplicationUpgradeDescription(); // we use the "from" package's address upgradeDescription.ApplicationName = new Uri(fromPackage.ApplicationAddress); // we use the "to" package's version upgradeDescription.TargetApplicationTypeVersion = toPackage.ApplicationVersion; // split parameters if any are specified NameValueCollection upgradeParams = Control64.GetApplicationParameters(toPackage); if (upgradeParams != null && upgradeParams.Count > 0) { upgradeDescription.ApplicationParameters.Add(upgradeParams); } RollingUpgradePolicyDescription policy = new RollingUpgradePolicyDescription(); policy.ForceRestart = true; policy.UpgradeMode = RollingUpgradeMode.UnmonitoredManual; if (isRolling) { switch (mode) { case UpgradeMonitor.Auto: policy.UpgradeMode = RollingUpgradeMode.UnmonitoredAuto; break; case UpgradeMonitor.Manual: policy.UpgradeMode = RollingUpgradeMode.UnmonitoredManual; break; } policy.UpgradeReplicaSetCheckTimeout = timeout; } upgradeDescription.UpgradePolicyDescription = policy; this.fc.ApplicationManager.UpgradeApplicationAsync(upgradeDescription, Defaults.UpgradeTimeout, CancellationToken.None).Wait(); return(true); } catch (Exception e) { this.LastException = e; if (e is AggregateException) { if (e is FabricException) { log.Error("Upgrade failed: " + e.InnerException.Message); return(false); } log.Error("UpgradeApplication Aggregate failure, err={0}", e.InnerException.Message); } else { log.Error("UpgradeApplication failed, err={0}", e.Message); } } return(false); }
protected override void ProcessRecord() { try { if (this.ReplicaQuorumTimeoutSec.HasValue) { this.WriteWarning(StringResources.PowerShell_ReplicaQuorumTimeoutSec_Deprecated); if (!this.UpgradeReplicaSetCheckTimeoutSec.HasValue) { this.UpgradeReplicaSetCheckTimeoutSec = this.ReplicaQuorumTimeoutSec.Value; } } if (this.RestartProcess) { this.WriteWarning(StringResources.PowerShell_RestartProcess_Deprecated); if (!this.ForceRestart) { this.ForceRestart = this.RestartProcess; } } RollingUpgradePolicyDescription upgradePolicyDescription; if (this.Monitored) { var monitoringPolicy = new RollingUpgradeMonitoringPolicy(); if (this.FailureAction != UpgradeFailureAction.Invalid) { 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 MonitoredRollingFabricUpgradePolicyDescription { UpgradeMode = RollingUpgradeMode.Monitored, ForceRestart = this.ForceRestart, MonitoringPolicy = monitoringPolicy }; upgradePolicyDescription = 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_ClusterHealthPolicyUpdateWarning), //// warning and caption show up when prompting for confirmation StringResources.PowerShell_ClusterHealthPolicyUpdateWarning, StringResources.PowerShell_HealthPolicyUpgradeCaption)) { return; } var healthPolicy = new ClusterHealthPolicy(); if (this.ConsiderWarningAsError.HasValue) { healthPolicy.ConsiderWarningAsError = this.ConsiderWarningAsError.Value; } if (this.MaxPercentUnhealthyApplications.HasValue) { healthPolicy.MaxPercentUnhealthyApplications = this.MaxPercentUnhealthyApplications.Value; } if (this.MaxPercentUnhealthyNodes.HasValue) { healthPolicy.MaxPercentUnhealthyNodes = this.MaxPercentUnhealthyNodes.Value; } if (this.ApplicationTypeHealthPolicyMap != null) { foreach (var entry in this.ApplicationTypeHealthPolicyMap) { healthPolicy.ApplicationTypeHealthPolicyMap.Add(entry.Key, entry.Value); } } monitoredPolicyDescription.HealthPolicy = healthPolicy; } monitoredPolicyDescription.EnableDeltaHealthEvaluation = this.EnableDeltaHealthEvaluation; if (this.IsUpdatingUpgradeHealthPolicy()) { if (!this.Force && !this.IsUpgradeHealthPolicyComplete() && !this.ShouldProcess( //// description shows up for "-WhatIf" string.Format( CultureInfo.InvariantCulture, "{0} {1}", StringResources.PowerShell_HealthPolicyUpgradeCaption, StringResources.PowerShell_ClusterUpgradeHealthPolicyUpdateWarning), //// warning and caption show up when prompting for confirmation StringResources.PowerShell_ClusterUpgradeHealthPolicyUpdateWarning, StringResources.PowerShell_HealthPolicyUpgradeCaption)) { return; } var upgradeHealthPolicy = new ClusterUpgradeHealthPolicy(); if (this.MaxPercentDeltaUnhealthyNodes.HasValue) { upgradeHealthPolicy.MaxPercentDeltaUnhealthyNodes = this.MaxPercentDeltaUnhealthyNodes.Value; } if (this.MaxPercentUpgradeDomainDeltaUnhealthyNodes.HasValue) { upgradeHealthPolicy.MaxPercentUpgradeDomainDeltaUnhealthyNodes = this.MaxPercentUpgradeDomainDeltaUnhealthyNodes.Value; } monitoredPolicyDescription.UpgradeHealthPolicy = upgradeHealthPolicy; } if (this.ApplicationHealthPolicyMap != null) { foreach (var entry in this.ApplicationHealthPolicyMap) { monitoredPolicyDescription.ApplicationHealthPolicyMap.Add(entry.Key, entry.Value); } } } else if (this.UnmonitoredManual) { upgradePolicyDescription = new RollingUpgradePolicyDescription { UpgradeMode = RollingUpgradeMode.UnmonitoredManual, ForceRestart = this.ForceRestart, }; } else { upgradePolicyDescription = new RollingUpgradePolicyDescription { UpgradeMode = RollingUpgradeMode.UnmonitoredAuto, ForceRestart = this.ForceRestart, }; } if (this.UpgradeReplicaSetCheckTimeoutSec.HasValue) { upgradePolicyDescription.UpgradeReplicaSetCheckTimeout = TimeSpan.FromSeconds(this.UpgradeReplicaSetCheckTimeoutSec.Value); } var upgradeDescription = new FabricUpgradeDescription { UpgradePolicyDescription = upgradePolicyDescription, TargetCodeVersion = this.CodePackageVersion, TargetConfigVersion = this.ClusterManifestVersion }; this.UpgradeCluster(upgradeDescription); } catch (Exception exception) { this.ThrowTerminatingError( exception, Constants.UpgradeClusterErrorId, null); } }