Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,34 @@ function Get-SfStabilitySnapshot {
}
}
}
$notDeployedOn = @()
foreach ($node in @($nodes.Keys)) {
foreach ($package in @(Get-ServiceFabricDeployedCodePackage -NodeName $node -ApplicationName $Application -ErrorAction Stop)) {
# Right after the application is created or recreated, a node can already hold a replica while the application is
# not yet activated there, and the query answers "Application not found". That is a transient state of a deployment
# in progress, so report it as a non-Ok snapshot (the check keeps waiting) instead of aborting the check.
try {
$packages = @(Get-ServiceFabricDeployedCodePackage -NodeName $node -ApplicationName $Application -ErrorAction Stop)
} catch {
if ($_.Exception.GetType().Name -ne 'FabricElementNotFoundException') { throw }
$notDeployedOn += $node
continue
}
foreach ($package in $packages) {
$entryPoint = $package.EntryPoint
if ($null -eq $entryPoint) { continue }
$activation = if ($package.PSObject.Properties['ServicePackageActivationId']) { $package.ServicePackageActivationId } else { '' }
$identities["process $node $($package.ServiceManifestName) $($package.CodePackageName) $activation"] = "$($entryPoint.InstanceId)/$($entryPoint.ProcessId)"
}
}
$state = [string]$health.AggregatedHealthState
$details = Get-SfHealthDetails $health
if ($notDeployedOn.Count -gt 0) {
$state = 'NotDeployed'
Comment on lines +72 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Error health when a node has not deployed the application

If application health is Error while a node returns FabricElementNotFoundException, this assignment replaces the actual health with NotDeployed. If that condition persists until the readiness timeout, Wait-SfApplicationStable returns NeverOk with Health = 'NotDeployed', so Test-SfRollbackWarranted returns false and a configured rollback is skipped despite the application's Error health. Preserve Error when marking incomplete deployment, or track deployment readiness separately so it does not suppress the rollback decision.

Useful? React with 👍 / 👎.

$details = @("application not yet deployed on node(s): $($notDeployedOn -join ', ')") + $details
}
return [pscustomobject]@{
Health = [string]$health.AggregatedHealthState
Details = Get-SfHealthDetails $health
Health = $state
Details = $details
Identities = $identities
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ Assert-Result (Invoke-Scenario @((New-Snapshot Ok), (New-Snapshot Ok '200'))) $f
Assert-Result (Invoke-Scenario @((New-Snapshot Ok), (New-Snapshot Ok), (New-Snapshot Error))) $false 'HealthError' $true 'ErrorInWindowFailsAndRollsBack'
Assert-Result (Invoke-Scenario @((New-Snapshot Ok), (New-Snapshot Warning))) $false 'HealthWarning' $false 'WarningInWindowFailsWithoutRollback'
Assert-Result (Invoke-Scenario @((New-Snapshot Warning)) -ReadyTimeoutSeconds 20) $false 'NeverOk' $false 'PersistentWarningFailsWithoutRollback'
Assert-Result (Invoke-Scenario @((New-Snapshot NotDeployed), (New-Snapshot NotDeployed), (New-Snapshot Ok))) $true 'Stable' $false 'RecreatedApplicationNotYetDeployedIsTolerated'
Assert-Result (Invoke-Scenario @((New-Snapshot NotDeployed)) -ReadyTimeoutSeconds 30) $false 'NeverOk' $false 'NeverDeployedStillFails'

# Get-SfStabilitySnapshot must turn "Application not found" on a node into a NotDeployed snapshot and rethrow anything else.
function Get-ServiceFabricApplicationHealth { [pscustomobject]@{ AggregatedHealthState = 'Ok'; UnhealthyEvaluations = @() } }
function Get-ServiceFabricService { [pscustomobject]@{ ServiceName = 'fabric:/Fixture/svc' } }
function Get-ServiceFabricPartition { [pscustomobject]@{ PartitionId = [guid]::Empty } }
function Get-ServiceFabricReplica { [pscustomobject]@{ NodeName = 'vm1'; ReplicaId = 7 } }
Add-Type -TypeDefinition 'public class FabricElementNotFoundException : System.Exception { public FabricElementNotFoundException(string m) : base(m) {} }'
function Get-ServiceFabricDeployedCodePackage { throw [FabricElementNotFoundException]::new('Application not found') }
$snapshot = Get-SfStabilitySnapshot -Application 'fabric:/Fixture'
if ($snapshot.Health -ne 'NotDeployed') { throw "Snapshot of a not yet deployed application must be NotDeployed, got $($snapshot.Health)." }
Write-Host 'PASS SnapshotReportsNotDeployed'
function Get-ServiceFabricDeployedCodePackage { throw 'boom' }
$threw = $false
try { Get-SfStabilitySnapshot -Application 'fabric:/Fixture' | Out-Null } catch { $threw = $true }
if (-not $threw) { throw 'Other errors must still abort the snapshot.' }
Write-Host 'PASS OtherSnapshotErrorsStillThrow'

$changes = Compare-SfIdentities -Baseline @{ a = '1'; b = '2' } -Current @{ a = '1'; c = '3' }
if ($changes.Count -ne 2) { throw 'Identity comparison must report removed and added replicas.' }
Expand Down
Loading