-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Service fabric] Retry for remaining commands #7607
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,7 +240,9 @@ function Get-ServiceFabricApplicationUpgradeAction | |
) | ||
|
||
$global:operationId = $SF_Operations.GetApplicationUpgradeStatus | ||
return Get-ServiceFabricApplicationUpgrade -ApplicationName $ApplicationName | ||
$getUpgradeAction = { Get-ServiceFabricApplicationUpgrade -ApplicationName $ApplicationName } | ||
return Invoke-ActionWithDefaultRetries -Action $getUpgradeAction ` | ||
-RetryMessage (Get-VstsLocString -Key SFSDK_RetryingGetApplicationUpgrade) | ||
} | ||
|
||
function Copy-ServiceFabricApplicationPackageAction | ||
|
@@ -518,8 +520,6 @@ function New-ServiceFabricApplicationAction | |
) | ||
|
||
$global:operationId = $SF_Operations.CreateNewApplication | ||
|
||
|
||
$createAction = { New-ServiceFabricApplication -ApplicationName $ApplicationName -ApplicationTypeName $ApplicationTypeName -ApplicationTypeVersion $ApplicationTypeVersion -ApplicationParameter $ApplicationParameter } | ||
$exceptionRetryEvaluator = { | ||
param($ex) | ||
|
@@ -544,11 +544,108 @@ function New-ServiceFabricApplicationAction | |
{ | ||
Write-Host (Get-VstsLocString -Key SFSDK_CreateApplicationFailed) | ||
# print application health status if create did not succeed | ||
Trace-ServiceFabricApplicationHealth | ||
Trace-ServiceFabricApplicationHealth -ApplicationName $ApplicationName | ||
throw | ||
} | ||
} | ||
|
||
function Start-ServiceFabricApplicationUpgradeAction | ||
{ | ||
Param ( | ||
[hashtable] | ||
$UpgradeParameters | ||
) | ||
|
||
$global:operationId = $SF_Operations.StartApplicationUpgrade | ||
$startAction = { Start-ServiceFabricApplicationUpgrade @UpgradeParameters } | ||
$exceptionRetryEvaluator = { | ||
param($ex) | ||
|
||
# If upgrade already started, don't retry | ||
$upgradeStatus = Get-ServiceFabricApplicationUpgradeAction -ApplicationName $($UpgradeParameters["ApplicationName"]) | ||
if ($upgradeStatus -and ($upgradeStatus.UpgradeState -ne "RollingBackCompleted" -and $upgradeStatus.UpgradeState -ne "RollingForwardCompleted")) | ||
{ | ||
return $false | ||
} | ||
|
||
return $true | ||
} | ||
|
||
try | ||
{ | ||
Invoke-ActionWithDefaultRetries -Action $startAction ` | ||
-RetryMessage (Get-VstsLocString -Key SFSDK_RetryingUpgradeApplication) ` | ||
-ExceptionRetryEvaluator $exceptionRetryEvaluator ` | ||
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") | ||
} | ||
catch | ||
{ | ||
# print application health status if starting upgrade did not succeed | ||
Trace-ServiceFabricApplicationHealth -ApplicationName $($UpgradeParameters["ApplicationName"]) | ||
throw | ||
} | ||
} | ||
|
||
function Test-ServiceFabricClusterConnectionAction | ||
{ | ||
try | ||
{ | ||
$global:operationId = $SF_Operations.TestClusterConnection | ||
$testAction = { [void](Test-ServiceFabricClusterConnection) } | ||
Invoke-ActionWithDefaultRetries -Action $testAction ` | ||
-RetryMessage (Get-VstsLocString -Key SFSDK_RetryingTestClusterConnection) ` | ||
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") | ||
} | ||
catch | ||
{ | ||
Write-Warning (Get-VstsLocString -Key SFSDK_UnableToVerifyClusterConnection) | ||
throw | ||
} | ||
} | ||
|
||
function Test-ServiceFabricApplicationPackageAction | ||
{ | ||
Param ( | ||
[string] | ||
$AppPkgPath, | ||
|
||
[string] | ||
$ImageStoreConnectionString | ||
) | ||
|
||
$global:operationId = $SF_Operations.TestApplicationPackage | ||
$testAction = { Test-ServiceFabricApplicationPackage -ApplicationPackagePath $AppPkgPath -ImageStoreConnectionString $ImageStoreConnectionString } | ||
return Invoke-ActionWithDefaultRetries -Action $testAction ` | ||
-RetryMessage (Get-VstsLocString -Key SFSDK_RetryingTestAppPackage) ` | ||
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") | ||
} | ||
|
||
function Get-ServiceFabricClusterManifestAction | ||
{ | ||
$global:operationId = $SF_Operations.GetClusterManifest | ||
$manifestAction = { Get-ServiceFabricClusterManifest } | ||
return Invoke-ActionWithDefaultRetries -Action $manifestAction ` | ||
-RetryMessage (Get-VstsLocString -Key SFSDK_RetryingGetClusterManifest) ` | ||
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") | ||
} | ||
|
||
function Remove-ServiceFabricApplicationPackageAction | ||
{ | ||
Param ( | ||
[string] | ||
$ApplicationPackagePathInImageStore, | ||
|
||
[string] | ||
$ImageStoreConnectionString | ||
) | ||
|
||
$global:operationId = $SF_Operations.RemoveApplicationPackage | ||
$removeAction = { Remove-ServiceFabricApplicationPackage -ApplicationPackagePathInImageStore $applicationPackagePathInImageStore -ImageStoreConnectionString $ImageStoreConnectionString } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the casing in $application starts with lower case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #fixed |
||
Invoke-ActionWithDefaultRetries -Action $removeAction ` | ||
-RetryMessage (Get-VstsLocString -Key SFSDK_RetryingRemoveApplicationPackage) ` | ||
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") | ||
} | ||
|
||
function Trace-ServiceFabricClusterHealth | ||
{ | ||
try | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,5 +63,29 @@ describe('ServiceFabricDeploy Suite', function () { | |
it('Register application type should retry', (done) => { | ||
psr.run(path.join(__dirname, 'RegisterApplicationTypeShouldRetry.ps1'), done); | ||
}) | ||
it('Unregister application type should retry till success', (done) => { | ||
psr.run(path.join(__dirname, 'UnregisterApplicationTypeShouldRetryTillSuccess.ps1'), done); | ||
}) | ||
it('Unregister application type should retry', (done) => { | ||
psr.run(path.join(__dirname, 'UnregisterApplicationTypeShouldRetry.ps1'), done); | ||
}) | ||
it('Create application type should retry till success', (done) => { | ||
psr.run(path.join(__dirname, 'CreateApplicationShouldRetryTillSuccess.ps1'), done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this file already present There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they were part of previous PR. However, during conflict resolution, these changes were reverted in that PR. |
||
}) | ||
it('Create application type should retry', (done) => { | ||
psr.run(path.join(__dirname, 'CreateApplicationShouldRetry.ps1'), done); | ||
}) | ||
it('Remove application type should retry till success', (done) => { | ||
psr.run(path.join(__dirname, 'RemoveApplicationShouldRetryTillSuccess.ps1'), done); | ||
}) | ||
it('Remove application type should retry', (done) => { | ||
psr.run(path.join(__dirname, 'RemoveApplicationShouldRetry.ps1'), done); | ||
}) | ||
it('Start application upgrade should retry till success', (done) => { | ||
psr.run(path.join(__dirname, 'StartApplicationUpgradeShouldRetryTillSuccess.ps1'), done); | ||
}) | ||
it('Start application upgrade should retry', (done) => { | ||
psr.run(path.join(__dirname, 'StartApplicationUpgradeShouldRetry.ps1'), done); | ||
}) | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
Import-Module ServiceFabric | ||
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
|
||
$ApplicationTypeName = "app type name" | ||
$ApplicationTypeVersion = "app type version" | ||
$applicationPackagePathInImageStore = "image path" | ||
|
||
$UpgradeParameters = @{ | ||
'ApplicationTypeName' = $ApplicationTypeName; | ||
'ApplicationTypeVersion' = $ApplicationTypeVersion | ||
'ApplicationParameter' = {} | ||
} | ||
|
||
$upgradeStatus = @{ | ||
'UpgradeState' = 'RollingForwardCompleted' | ||
} | ||
$global:startUpgradeAttempted = 0 | ||
$global:getRetriesAttempted = 0 | ||
$global:appHealthPrinted = $false | ||
|
||
Register-Mock Start-ServiceFabricApplicationUpgrade { | ||
$global:startUpgradeAttempted++ | ||
throw [System.Fabric.FabricTransientException]::new("Could not ping!") | ||
} -- @UpgradeParameters | ||
|
||
Register-Mock Get-ServiceFabricApplicationUpgrade { | ||
$global:getRetriesAttempted++ | ||
|
||
if ($global:getRetriesAttempted -eq 3) | ||
{ | ||
$upgradeStatus.UpgradeState = 'RollingForwardCompleted' | ||
return $upgradeStatus | ||
} | ||
|
||
if ($global:getRetriesAttempted -eq 2) | ||
{ | ||
return $null | ||
} | ||
|
||
throw [System.Fabric.FabricTransientException]::new("Could not ping!") | ||
} -- -ApplicationName $ApplicationName | ||
|
||
Register-Mock Get-ServiceFabricApplicationHealth { | ||
$global:appHealthPrinted = $true | ||
} | ||
|
||
Register-Mock Start-Sleep {} | ||
Register-Mock Write-VstsTaskError | ||
|
||
# Act | ||
. $PSScriptRoot\..\..\..\Tasks\ServiceFabricDeployV1\ps_modules\PowershellHelpers\Helpers.ps1 | ||
. $PSScriptRoot\..\..\..\Tasks\ServiceFabricDeployV1\ServiceFabricSDK\Utilities.ps1 | ||
|
||
# Act/Assert | ||
Assert-Throws { | ||
Start-ServiceFabricApplicationUpgradeAction -UpgradeParameters $UpgradeParameters | ||
} | ||
Assert-AreEqual 3 $global:startUpgradeAttempted "Number of start upgrade retries not correct" | ||
Assert-AreEqual $true $global:appHealthPrinted "cluster health not printed in case of error" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
Import-Module ServiceFabric | ||
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
|
||
$ApplicationTypeName = "app type name" | ||
$ApplicationTypeVersion = "app type version" | ||
$applicationPackagePathInImageStore = "image path" | ||
|
||
$UpgradeParameters = @{ | ||
'ApplicationTypeName' = $ApplicationTypeName; | ||
'ApplicationTypeVersion' = $ApplicationTypeVersion | ||
'ApplicationParameter' = {} | ||
} | ||
|
||
$upgradeStatus = @{ | ||
'UpgradeState' = 'RollingForwardCompleted' | ||
} | ||
$global:startUpgradeAttempted = 0 | ||
$global:getRetriesAttempted = 0 | ||
$global:appHealthPrinted = $false | ||
|
||
Register-Mock Start-ServiceFabricApplicationUpgrade { | ||
$global:startUpgradeAttempted++ | ||
throw [System.Fabric.FabricTransientException]::new("Could not ping!") | ||
} -- @UpgradeParameters | ||
|
||
Register-Mock Get-ServiceFabricApplicationUpgrade { | ||
$global:getRetriesAttempted++ | ||
|
||
if ($global:getRetriesAttempted -eq 6) | ||
{ | ||
$upgradeStatus.UpgradeState = 'RollingForwardInProgress' | ||
return $upgradeStatus | ||
} | ||
|
||
if ($global:getRetriesAttempted -eq 3) | ||
{ | ||
$upgradeStatus.UpgradeState = 'RollingForwardCompleted' | ||
return $upgradeStatus | ||
} | ||
|
||
throw [System.Fabric.FabricTransientException]::new("Could not ping!") | ||
} -- -ApplicationName $ApplicationName | ||
|
||
Register-Mock Get-ServiceFabricApplicationHealth { | ||
$global:appHealthPrinted = $true | ||
} | ||
|
||
Register-Mock Start-Sleep {} | ||
Register-Mock Write-VstsTaskError | ||
|
||
# Act | ||
. $PSScriptRoot\..\..\..\Tasks\ServiceFabricDeployV1\ps_modules\PowershellHelpers\Helpers.ps1 | ||
. $PSScriptRoot\..\..\..\Tasks\ServiceFabricDeployV1\ServiceFabricSDK\Utilities.ps1 | ||
|
||
# Act/Assert | ||
Start-ServiceFabricApplicationUpgradeAction -UpgradeParameters $UpgradeParameters | ||
Assert-AreEqual 2 $global:startUpgradeAttempted "Number of start upgrade retries not correct" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need to put braces for the 2nd expression. However, I m not clear on the logic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is checking if upgrade is already in progress (status should not be RollingBackCompleted or RollingForwardCompleted). if so, it will not retry starting upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you are returning false in those cases, wouldn't that stop the retry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that is intended. The action being tried here is Start-Upgrade.. If upgrade has already started even though the call failed due to timeout, we would not like to try further.
Only in case of upgrade not started, we want to retry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we differentiate between the last upgrade vs the current upgrade
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if current is first upgrade for application, upgrade status will be null, otherwise it will be RollingForwardCompleted or RollingBackCompleted depending upon whether last upgrade was success or rolled back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the same logic which we use while waiting for upgrade to finish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance for us to not even attempt retry if the server didn't even accept our retry request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is nothing like server will not accept request. It will accept and either fail or proceed with upgrade. In either of these cases we don't want to retry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense