Skip to content

Commit

Permalink
Merge ServiceFabricDeploy task related changes (#7751)
Browse files Browse the repository at this point in the history
* [ServiceFabric] Re-tries for Unregister, connect, create and remove commands (#7588)

* Re-tries for copy and register commands

* PR comments

* PR comments and few suggestion as per Oana

* connect, unregister, create, remove re-tries

* L0 for unregister retry

* L0 for create and remove application

* Utilities changes which were not picked in merge

* PR comments

* Moving retry logic for UpgradeApplication to corresponding helper fun… (#7593)

* Moving retry logic for UpgradeApplication to corresponding helper function

* Updated function name

* Added new operation

* Indentation

* Adding timeout exception

* [Service fabric] Retry for remaining commands (#7607)

* Retry for remaining commands

* PR comment

* Adding logs for upgrade service fabric application. (#7217)

* Adding logs for upgrade service fabric application.

* resolving comments

* Forming upgrade errors message.

* Formatting unhealthy evaluation and upgrade status.

* fixed merge changes

* Formatting UnhealthyEvaluation and DomainUpgradeStatus while printing only conditionally.

* Moved waiting for upgrade to complete and printing logic to function in Utilities file.

* Keeping other exception as well.

* Implemented async operations (#7631)

* Implemented Async operations

* Added null checks

* Modified code as per review comments

* typo

* Revert "typo"

This reverts commit f04d14e.

* Revert "Modified code as per review comments"

This reverts commit e24bc53.

* Modified code as per review comments

* Modified code as per review comments

* Addressed review comments

* Added retry logic to Wait-ServiceFabricApplicationTypeRegistrationStatus

* Added comments

* Addressed review comments

* typo

* Added comments

* typo

* Addressed review comments

* Updated test cases

* Modified code as per review comments

* Users/hiyada/s ftask log bug fixes (#7722)

* Corrected typo.

* Corrected retry message null check

* Addressed bugs raised as a part of bugbash (#7739)

* Added powershell helper module

* Replacing Trace-VstsEnteringInvocation with print statement

* Removing Trace-VstsLeavingInvocation $MyInvocation

* Addressed review comments

* Updated patch version (#7748)
  • Loading branch information
vinodkumar3 authored Jul 17, 2018
1 parent 8896c8e commit 1f39d6b
Show file tree
Hide file tree
Showing 28 changed files with 1,065 additions and 252 deletions.
27 changes: 12 additions & 15 deletions Tasks/Common/PowershellHelpers/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ function Invoke-ActionWithRetries
$RetryMessage
)

Trace-VstsEnteringInvocation $MyInvocation

if (!$RetryMessage)
{
$RetryMessage = Get-VstsLocString -Key RetryAfterMessage $RetryIntervalInSeconds
}

$lastResult = $null;
$retryIteration = 1
do
{
Expand All @@ -42,11 +36,12 @@ function Invoke-ActionWithRetries

try
{
$result = & $Action
$result = & $Action $lastResult
$lastResult = $result
}
catch
{
if (($null -eq $RetryableExceptions) -or (Test-RetryableException -Exception $_.Exception -AllowedExceptions $RetryableExceptions))
if (($null -eq $RetryableExceptions) -or (Test-RetryableException -Exception $_.Exception -RetryableExceptions $RetryableExceptions))
{
$shouldRetry = $ExceptionRetryEvaluator.Invoke($_.Exception)
if (!$shouldRetry)
Expand Down Expand Up @@ -80,12 +75,14 @@ function Invoke-ActionWithRetries
}
}

Write-Host $RetryMessage
if ($RetryMessage)
{
Write-Host $RetryMessage
}

$retryIteration++
Start-Sleep $RetryIntervalInSeconds
} while ($true)

Trace-VstsLeavingInvocation $MyInvocation
}

function Get-TempDirectoryPath
Expand Down Expand Up @@ -115,15 +112,15 @@ function Test-RetryableException
$Exception,

[string[]]
$AllowedExceptions
$RetryableExceptions
)

$AllowedExceptions | ForEach-Object {
$RetryableExceptions | ForEach-Object {
if ($_ -and ($Exception -is ([type]$_)))
{
return $true;
}
}

return $false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Get-AadSecurityToken

# Query cluster metadata
$global:operationId = $SF_Operations.ConnectClusterMetadata
$connectResult = Connect-ServiceFabricCluster @connectionParametersWithGetMetadata
$connectResult = Connect-ServiceFabricClusterAction -ClusterConnectionParameters $connectionParametersWithGetMetadata
$authority = $connectResult.AzureActiveDirectoryMetadata.Authority
Write-Host (Get-VstsLocString -Key AadAuthority -ArgumentList $authority)
$clusterApplicationId = $connectResult.AzureActiveDirectoryMetadata.ClusterApplication
Expand Down Expand Up @@ -123,6 +123,7 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
Trace-VstsEnteringInvocation $MyInvocation

Import-Module $PSScriptRoot/../TlsHelper_
Import-Module $PSScriptRoot/../PowershellHelpers
Add-Tls12InSession

try
Expand Down Expand Up @@ -183,7 +184,7 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
$global:operationId = $SF_Operations.ConnectCluster
try
{
[void](Connect-ServiceFabricCluster @clusterConnectionParameters)
[void](Connect-ServiceFabricClusterAction -ClusterConnectionParameters $clusterConnectionParameters)
}
catch
{
Expand All @@ -195,11 +196,6 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
throw $_
}

Write-Host (Get-VstsLocString -Key ConnectedToCluster)

# Reset the scope of the ClusterConnection variable that gets set by the call to Connect-ServiceFabricCluster so that it is available outside the scope of this module
Set-Variable -Name ClusterConnection -Value $Private:ClusterConnection -Scope Global

}
catch
{
Expand All @@ -210,4 +206,35 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
{
Trace-VstsLeavingInvocation $MyInvocation
}
}

function Connect-ServiceFabricClusterAction
{
param(
[Hashtable]
$ClusterConnectionParameters
)

$connectResult = $null

try
{
# Call a trial Connect-ServiceFabricCluster first so that ServiceFabric PS module gets loaded. Retry only if this connect fails.
$connectResult = Connect-ServiceFabricCluster @clusterConnectionParameters
}
catch [System.Fabric.FabricTransientException], [System.TimeoutException]
{
$connectAction = { Connect-ServiceFabricCluster @clusterConnectionParameters }
$connectResult = Invoke-ActionWithRetries -Action $connectAction `
-MaxTries 3 `
-RetryIntervalInSeconds 10 `
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") `
-RetryMessage (Get-VstsLocString -Key RetryingClusterConnection)
}

Write-Host (Get-VstsLocString -Key ConnectedToCluster)

# Reset the scope of the ClusterConnection variable that gets set by the call to Connect-ServiceFabricCluster so that it is available outside the scope of this module
Set-Variable -Name ClusterConnection -Value $Private:ClusterConnection -Scope Global
return $connectResult
}
1 change: 1 addition & 0 deletions Tasks/Common/ServiceFabricHelpers/SFOperations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $SF_Operations = @{
CreateNewApplication = 'CreateNewApplication'
StartApplicationUpgrade = 'StartApplicationUpgrade';
GetApplicationUpgradeStatus = 'GetApplicationUpgradeStatus';
WaitApplicationUpgradeStatus = 'WaitApplicationUpgradeStatus';
EncryptServiceFabricText = 'EncryptServiceFabricText';
CreateDiffPackage = 'CreateDiffPackage';
GetComposeDeploymentStatus = 'GetComposeDeploymentStatus';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"loc.messages.ImportedCertificate": "Imported cluster client certificate with thumbprint '{0}'.",
"loc.messages.ServiceFabricSDKNotInstalled": "Service Fabric SDK is not installed on the build agent. Go to https://aka.ms/servicefabric to download and install it.",
"loc.messages.UseWindowsSecurity": "Windows security is specified. -WindowsCredential switch will be used while connecting.",
"loc.messages.ServerCertificateNotFoundForTextEncrypt": "The cluster's server certificate with thumbprint '{0}' is required in order to encrypt text but the certificate could not be found on the agent machine in the 'CurrentUser\\My' certificate store location."
"loc.messages.ServerCertificateNotFoundForTextEncrypt": "The cluster's server certificate with thumbprint '{0}' is required in order to encrypt text but the certificate could not be found on the agent machine in the 'CurrentUser\\My' certificate store location.",
"loc.messages.RetryingClusterConnection": "Retrying to connect to cluster.."
}
3 changes: 2 additions & 1 deletion Tasks/Common/ServiceFabricHelpers/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"ImportedCertificate": "Imported cluster client certificate with thumbprint '{0}'.",
"ServiceFabricSDKNotInstalled": "Service Fabric SDK is not installed on the build agent. Go to https://aka.ms/servicefabric to download and install it.",
"UseWindowsSecurity": "Windows security is specified. -WindowsCredential switch will be used while connecting.",
"ServerCertificateNotFoundForTextEncrypt": "The cluster's server certificate with thumbprint '{0}' is required in order to encrypt text but the certificate could not be found on the agent machine in the 'CurrentUser\\My' certificate store location."
"ServerCertificateNotFoundForTextEncrypt": "The cluster's server certificate with thumbprint '{0}' is required in order to encrypt text but the certificate could not be found on the agent machine in the 'CurrentUser\\My' certificate store location.",
"RetryingClusterConnection": "Retrying to connect to cluster.."
}
}
4 changes: 4 additions & 0 deletions Tasks/ServiceFabricComposeDeployV0/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"module": "../Common/Deployment/TelemetryHelper",
"type": "ps"
},
{
"module": "../Common/PowershellHelpers",
"type": "ps"
}
],
"externals": {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/ServiceFabricComposeDeployV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 3,
"Patch": 3
"Patch": 4
},
"demands": [
"Cmd"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/ServiceFabricComposeDeployV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 3,
"Patch": 3
"Patch": 4
},
"demands": [
"Cmd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,7 @@

$ApplicationManifestPath = "$AppPkgPathToUse\ApplicationManifest.xml"

try
{
$global:operationId = $SF_Operations.TestClusterConnection
[void](Test-ServiceFabricClusterConnection)
}
catch
{
Write-Warning (Get-VstsLocString -Key SFSDK_UnableToVerifyClusterConnection)
throw
}
Test-ServiceFabricClusterConnectionAction

# If ApplicationName is not specified on command line get application name from Application Parameter file.
if (!$ApplicationName)
Expand Down Expand Up @@ -207,26 +198,15 @@
if ($removeApp)
{
Write-Host (Get-VstsLocString -Key SFSDK_AppAlreadyExistsInfo -ArgumentList @($ApplicationName, $app.ApplicationTypeName, $app.ApplicationTypeVersion))

try
{
$global:operationId = $SF_Operations.RemoveApplication
$app | Remove-ServiceFabricApplication -Force
}
catch [System.TimeoutException]
{
Write-Host (Get-VstsLocString -Key SFSDK_PerformingForceRemoveOnTimeout -ArgumentList $ApplicationName)
$app | Remove-ServiceFabricApplication -Force -ForceRemove
}
Remove-ServiceFabricApplicationAction -ApplicationName $($app.ApplicationName)

if ($OverwriteBehavior.Equals("Always"))
{
# Unregsiter AppType and Version if there are no other applciations for the Type and Version.
# It will unregister the existing application's type and version even if its different from the application being created,
if ((Get-ServiceFabricApplicationAction | Where-Object {$_.ApplicationTypeVersion -eq $($app.ApplicationTypeVersion) -and $_.ApplicationTypeName -eq $($app.ApplicationTypeName)}).Count -eq 0)
{
$global:operationId = $SF_Operations.UnregisterApplicationType
Unregister-ServiceFabricApplicationType -ApplicationTypeName $($app.ApplicationTypeName) -ApplicationTypeVersion $($app.ApplicationTypeVersion) -Force -TimeoutSec $UnregisterPackageTimeoutSec
Unregister-ServiceFabricApplicationTypeAction -ApplicationTypeName $($app.ApplicationTypeName) -ApplicationTypeVersion $($app.ApplicationTypeVersion) -TimeoutSec $UnregisterPackageTimeoutSec
}
}
}
Expand All @@ -246,13 +226,8 @@
}
if (!$typeIsInUse)
{
$global:operationId = $SF_Operations.UnregisterApplicationType
Write-Host (Get-VstsLocString -Key SFSDK_UnregisteringExistingAppType -ArgumentList @($names.ApplicationTypeName, $names.ApplicationTypeVersion))
$reg | Unregister-ServiceFabricApplicationType -Force -TimeoutSec $UnregisterPackageTimeoutSec
if (!$?)
{
throw (Get-VstsLocString -Key SFSDK_UnableToUnregisterAppType)
}
Unregister-ServiceFabricApplicationTypeAction -ApplicationTypeName $($reg.ApplicationTypeName) -ApplicationTypeVersion $($reg.ApplicationTypeVersion) -TimeoutSec $UnregisterPackageTimeoutSec
$ApplicationTypeAlreadyRegistered = $false
}
else
Expand All @@ -275,8 +250,7 @@

Write-Host (Get-VstsLocString -Key SFSDK_CopyingAppToImageStore)
# Get image store connection string
$global:operationId = $SF_Operations.GetClusterManifest
$clusterManifestText = Get-ServiceFabricClusterManifest
$clusterManifestText = Get-ServiceFabricClusterManifestAction
$imageStoreConnectionString = Get-ImageStoreConnectionStringFromClusterManifest ([xml] $clusterManifestText)

$applicationPackagePathInImageStore = $names.ApplicationTypeName
Expand Down Expand Up @@ -313,29 +287,15 @@
}

Copy-ServiceFabricApplicationPackageAction -CopyParameters $copyParameters
if (!$?)
{
throw (Get-VstsLocString -Key SFSDK_CopyingAppToImageStoreFailed)
}

$registerParameters = @{
'ApplicationPathInImageStore' = $applicationPackagePathInImageStore
}

if ($RegisterPackageTimeoutSec)
{
$registerParameters['TimeOutSec'] = $RegisterPackageTimeoutSec
}

Write-Host (Get-VstsLocString -Key SFSDK_RegisterAppType)
Register-ServiceFabricApplicationTypeAction -RegisterParameters $registerParameters -ApplicationTypeName $names.ApplicationTypeName -ApplicationTypeVersion $names.ApplicationTypeVersion
if (!$?)
{
throw (Get-VstsLocString -Key SFSDK_RegisterAppTypeFailed)
}
$global:operationId = $SF_Operations.RemoveApplicationPackage
Register-ServiceFabricApplicationTypeAction -RegisterParameters $registerParameters -ApplicationTypeName $names.ApplicationTypeName -ApplicationTypeVersion $names.ApplicationTypeVersion -TimeoutSec $RegisterPackageTimeoutSec
Write-Host (Get-VstsLocString -Key SFSDK_RemoveAppPackage)
Remove-ServiceFabricApplicationPackage -ApplicationPackagePathInImageStore $applicationPackagePathInImageStore -ImageStoreConnectionString $imageStoreConnectionString
Remove-ServiceFabricApplicationPackageAction -ApplicationPackagePathInImageStore $applicationPackagePathInImageStore -ImageStoreConnectionString $imageStoreConnectionString
}
}

Expand All @@ -356,13 +316,8 @@
$ApplicationParameter = Merge-Hashtables -HashTableOld $appParamsFromFile -HashTableNew $ApplicationParameter
}
}
$global:operationId = $SF_Operations.CreateNewApplication
New-ServiceFabricApplication -ApplicationName $ApplicationName -ApplicationTypeName $names.ApplicationTypeName -ApplicationTypeVersion $names.ApplicationTypeVersion -ApplicationParameter $ApplicationParameter
if (!$?)
{
throw (Get-VstsLocString -Key SFSDK_CreateApplicationFailed)
}

New-ServiceFabricApplicationAction -ApplicationName $ApplicationName -ApplicationTypeName $names.ApplicationTypeName -ApplicationTypeVersion $names.ApplicationTypeVersion -ApplicationParameter $ApplicationParameter
Write-Host (Get-VstsLocString -Key SFSDK_CreateApplicationSuccess)
}
}
Loading

0 comments on commit 1f39d6b

Please sign in to comment.