-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
} | ||
}); |
62 changes: 62 additions & 0 deletions
62
Tasks/ServiceFabricDeployV1/Tests/StartApplicationUpgradeShouldRetry.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
60 changes: 60 additions & 0 deletions
60
Tasks/ServiceFabricDeployV1/Tests/StartApplicationUpgradeShouldRetryTillSuccess.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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