Skip to content

Commit

Permalink
Merge pull request #3529 from mikanyg/master
Browse files Browse the repository at this point in the history
Added option to SkipUpgradeSameTypeAndVersion
  • Loading branch information
NCarlsonMSFT authored Mar 10, 2017
2 parents 5b86491 + 2a968c3 commit 80bc9ec
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function Publish-UpgradedServiceFabricApplication
{
<#
.SYNOPSIS
.SYNOPSIS
Publishes and starts an upgrade for an existing Service Fabric application in Service Fabric cluster.
.DESCRIPTION
Expand All @@ -14,7 +14,7 @@ function Publish-UpgradedServiceFabricApplication
Path to the folder containing the Service Fabric application package OR path to the zipped service fabric applciation package.
.PARAMETER ApplicationParameterFilePath
Path to the application parameter file which contains Application Name and application parameters to be used for the application.
Path to the application parameter file which contains Application Name and application parameters to be used for the application.
.PARAMETER ApplicationName
Name of Service Fabric application to be created. If value for this parameter is provided alongwith ApplicationParameterFilePath it will override the Application name specified in ApplicationParameter file.
Expand Down Expand Up @@ -44,6 +44,9 @@ function Publish-UpgradedServiceFabricApplication
.PARAMETER CompressPackage
Indicates whether the application package should be compressed before copying to the image store.
.PARAMETER SkipUpgradeSameTypeAndVersion
Indicates whether an upgrade will be skipped if the same application type and version already exists in the cluster, otherwise the upgrade fails during validation.
.EXAMPLE
Publish-UpgradeServiceFabricApplication -ApplicationPackagePath 'pkg\Debug' -ApplicationParameterFilePath 'AppParameters.Local.xml'
Expand All @@ -55,7 +58,7 @@ function Publish-UpgradedServiceFabricApplication
#>

[CmdletBinding(DefaultParameterSetName="ApplicationName")]
[CmdletBinding(DefaultParameterSetName="ApplicationName")]
Param
(
[Parameter(Mandatory=$true,ParameterSetName="ApplicationParameterFilePath")]
Expand Down Expand Up @@ -99,9 +102,12 @@ function Publish-UpgradedServiceFabricApplication

[Parameter(ParameterSetName="ApplicationParameterFilePath")]
[Parameter(ParameterSetName="ApplicationName")]
[Switch]$CompressPackage
)
[Switch]$CompressPackage,

[Parameter(ParameterSetName="ApplicationParameterFilePath")]
[Parameter(ParameterSetName="ApplicationName")]
[Switch]$SkipUpgradeSameTypeAndVersion
)

if (!(Test-Path $ApplicationPackagePath))
{
Expand Down Expand Up @@ -147,7 +153,7 @@ function Publish-UpgradedServiceFabricApplication
}
}

$ApplicationManifestPath = "$AppPkgPathToUse\ApplicationManifest.xml"
$ApplicationManifestPath = "$AppPkgPathToUse\ApplicationManifest.xml"

try
{
Expand All @@ -172,10 +178,10 @@ function Publish-UpgradedServiceFabricApplication
}

if ($Action.Equals('RegisterAndUpgrade') -or $Action.Equals('Register'))
{
{
## Check existence of the application
$oldApplication = Get-ServiceFabricApplication -ApplicationName $ApplicationName

if (!$oldApplication)
{
$errMsg = (Get-VstsLocString -Key SFSDK_AppDoesNotExist -ArgumentList $ApplicationName)
Expand All @@ -184,12 +190,18 @@ function Publish-UpgradedServiceFabricApplication
else
{
if($oldApplication.ApplicationTypeName -ne $names.ApplicationTypeName)
{
{
$errMsg = (Get-VstsLocString -Key SFSDK_AppTypeMismatch -ArgumentList $ApplicationName)
throw $errMsg
}
}


if($SkipUpgradeSameTypeAndVersion -And $oldApplication.ApplicationTypeVersion -eq $names.ApplicationTypeVersion)
{
Write-Warning (Get-VstsLocString -Key SFSDK_SkipUpgradeWarning -ArgumentList @($names.ApplicationTypeName, $names.ApplicationTypeVersion))
return
}
}

## Check upgrade status
$upgradeStatus = Get-ServiceFabricApplicationUpgrade -ApplicationName $ApplicationName
if ($upgradeStatus.UpgradeState -ne "RollingBackCompleted" -and $upgradeStatus.UpgradeState -ne "RollingForwardCompleted")
Expand All @@ -204,7 +216,7 @@ function Publish-UpgradedServiceFabricApplication
Write-Host (Get-VstsLocString -Key SFSDK_UnregisteringExistingAppType -ArgumentList @($names.ApplicationTypeName, $names.ApplicationTypeVersion))
$reg | Unregister-ServiceFabricApplicationType -Force
}

$applicationPackagePathInImageStore = $names.ApplicationTypeName
Write-Host (Get-VstsLocString -Key SFSDK_CopyingAppToImageStore)

Expand Down Expand Up @@ -245,11 +257,11 @@ function Publish-UpgradedServiceFabricApplication
{
throw (Get-VstsLocString -Key SFSDK_CopyingAppToImageStoreFailed)
}

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

if ($RegisterPackageTimeoutSec)
{
$registerParameters['TimeOutSec'] = $RegisterPackageTimeoutSec
Expand All @@ -262,37 +274,37 @@ function Publish-UpgradedServiceFabricApplication
throw Write-Host (Get-VstsLocString -Key SFSDK_RegisterAppTypeFailed)
}
}

if ($Action.Equals('Upgrade') -or $Action.Equals('RegisterAndUpgrade'))
{
try
{
$UpgradeParameters["ApplicationName"] = $ApplicationName
$UpgradeParameters["ApplicationTypeVersion"] = $names.ApplicationTypeVersion

# If application parameters file is specified read values from and merge it with parameters passed on Commandline
if ($PSBoundParameters.ContainsKey('ApplicationParameterFilePath'))
{
$appParamsFromFile = Get-ApplicationParametersFromApplicationParameterFile $ApplicationParameterFilePath
$appParamsFromFile = Get-ApplicationParametersFromApplicationParameterFile $ApplicationParameterFilePath
if(!$ApplicationParameter)
{
$ApplicationParameter = $appParamsFromFile
}
else
{
$ApplicationParameter = Merge-Hashtables -HashTableOld $appParamsFromFile -HashTableNew $ApplicationParameter
}
}
}

$UpgradeParameters["ApplicationParameter"] = $ApplicationParameter

$serviceTypeHealthPolicyMap = $upgradeParameters["ServiceTypeHealthPolicyMap"]
if ($serviceTypeHealthPolicyMap -and $serviceTypeHealthPolicyMap -is [string])
{
$upgradeParameters["ServiceTypeHealthPolicyMap"] = Invoke-Expression $serviceTypeHealthPolicyMap
}
Write-Host (Get-VstsLocString -Key SFSDK_StartAppUpgrade)

Write-Host (Get-VstsLocString -Key SFSDK_StartAppUpgrade)
Start-ServiceFabricApplicationUpgrade @UpgradeParameters
}
catch
Expand All @@ -306,14 +318,14 @@ function Publish-UpgradedServiceFabricApplication
{
return
}

do
{
Write-Host (Get-VstsLocString -Key SFSDK_WaitingForUpgrade)
Start-Sleep -Seconds 3
$upgradeStatus = Get-ServiceFabricApplicationUpgrade -ApplicationName $ApplicationName
} while ($upgradeStatus.UpgradeState -ne "RollingBackCompleted" -and $upgradeStatus.UpgradeState -ne "RollingForwardCompleted")

if($UnregisterUnusedVersions)
{
Write-Host (Get-VstsLocString -Key SFSDK_UnregisterUnusedVersions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"loc.input.help.registerPackageTimeoutSec": "Timeout in seconds for registering application package.",
"loc.input.label.overwriteBehavior": "Overwrite Behavior",
"loc.input.help.overwriteBehavior": "Overwrite Behavior if an application exists in the cluster with the same name, and upgrades have not been configured.",
"loc.input.label.skipUpgradeSameTypeAndVersion": "Skip upgrade for same Type and Version",
"loc.input.help.skipUpgradeSameTypeAndVersion": "Indicates whether an upgrade will be skipped if the same application type and version already exists in the cluster, otherwise the upgrade fails during validation. If enabled, re-deployments are idempotent.",
"loc.input.label.overridePublishProfileSettings": "Override All Publish Profile Upgrade Settings",
"loc.input.help.overridePublishProfileSettings": "This will override all upgrade settings with either the values specified below or the default value if not specified.",
"loc.input.label.isUpgrade": "Upgrade the Application",
Expand Down Expand Up @@ -78,5 +80,6 @@
"loc.messages.SFSDK_UnzipPackage": "Attempting to unzip '{0}' to location '{1}'.",
"loc.messages.SFSDK_UnexpectedError": "Unexpected Error. Error details: $_.Exception.Message",
"loc.messages.SFSDK_CopyPackageTimeoutSecWarning": "The CopyPackageTimeoutSec parameter requires version '2.3' of the Service Fabric SDK, but the installed version is '{0}'. This parameter will be ignored.",
"loc.messages.SFSDK_CompressPackageWarning": "The CompressPackage parameter requires version '2.5' of the Service Fabric SDK, but the installed version is '{0}'. This parameter will be ignored."
"loc.messages.SFSDK_CompressPackageWarning": "The CompressPackage parameter requires version '2.5' of the Service Fabric SDK, but the installed version is '{0}'. This parameter will be ignored.",
"loc.messages.SFSDK_SkipUpgradeWarning": "Skipping upgrade, since application type '{0}' with version '{1}' already exists in cluster."
}
1 change: 1 addition & 0 deletions Tasks/ServiceFabricDeploy/Tests/AadDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Register-Mock Get-VstsInput { $applicationPackagePath } -- -Name applicationPack
Register-Mock Get-VstsInput { $serviceConnectionName } -- -Name serviceConnectionName -Require
Register-Mock Get-VstsInput { "false" } -- -Name compressPackage
Register-Mock Get-VstsInput { $overwriteBehavior } -- -Name overwriteBehavior
Register-Mock Get-VstsInput { "false" } -- -Name skipUpgradeSameTypeAndVersion

# Setup file resolution
Register-Mock Find-VstsFiles { $publishProfilePath } -- -LegacyPattern $publishProfilePath
Expand Down
1 change: 1 addition & 0 deletions Tasks/ServiceFabricDeploy/Tests/CertDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Register-Mock Get-VstsInput { $applicationPackagePath } -- -Name applicationPack
Register-Mock Get-VstsInput { $serviceConnectionName } -- -Name serviceConnectionName -Require
Register-Mock Get-VstsInput { "false" } -- -Name compressPackage
Register-Mock Get-VstsInput { $overwriteBehavior } -- -Name overwriteBehavior
Register-Mock Get-VstsInput { "false" } -- -Name skipUpgradeSameTypeAndVersion

# Setup file resolution
Register-Mock Find-VstsFiles { $publishProfilePath } -- -LegacyPattern $publishProfilePath
Expand Down
1 change: 1 addition & 0 deletions Tasks/ServiceFabricDeploy/Tests/NoAuthDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Register-Mock Get-VstsInput { $applicationPackagePath } -- -Name applicationPack
Register-Mock Get-VstsInput { $serviceConnectionName } -- -Name serviceConnectionName -Require
Register-Mock Get-VstsInput { "false" } -- -Name compressPackage
Register-Mock Get-VstsInput { $overwriteBehavior } -- -Name overwriteBehavior
Register-Mock Get-VstsInput { "false" } -- -Name skipUpgradeSameTypeAndVersion

# Setup file resolution
Register-Mock Find-VstsFiles { $publishProfilePath } -- -LegacyPattern $publishProfilePath
Expand Down
2 changes: 2 additions & 0 deletions Tasks/ServiceFabricDeploy/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ try {
$copyPackageTimeoutSec = Get-VstsInput -Name copyPackageTimeoutSec
$registerPackageTimeoutSec = Get-VstsInput -Name registerPackageTimeoutSec
$compressPackage = [System.Boolean]::Parse((Get-VstsInput -Name compressPackage))
$skipUpgrade = [System.Boolean]::Parse((Get-VstsInput -Name skipUpgradeSameTypeAndVersion))

$clusterConnectionParameters = @{}

Expand Down Expand Up @@ -131,6 +132,7 @@ try {
$publishParameters['Action'] = "RegisterAndUpgrade"
$publishParameters['UpgradeParameters'] = $upgradeParameters
$publishParameters['UnregisterUnusedVersions'] = $true
$publishParameters['SkipUpgradeSameTypeAndVersion'] = $skipUpgrade

Publish-UpgradedServiceFabricApplication @publishParameters
}
Expand Down
14 changes: 12 additions & 2 deletions Tasks/ServiceFabricDeploy/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 1,
"Minor": 3,
"Patch": 6
"Patch": 7
},
"demands": [
"Cmd"
Expand Down Expand Up @@ -109,6 +109,15 @@
"groupname": "advanced",
"helpMarkDown": "Overwrite Behavior if an application exists in the cluster with the same name, and upgrades have not been configured."
},
{
"name": "skipUpgradeSameTypeAndVersion",
"type": "boolean",
"label": "Skip upgrade for same Type and Version",
"defaultValue": "false",
"required": false,
"groupname": "advanced",
"helpMarkDown": "Indicates whether an upgrade will be skipped if the same application type and version already exists in the cluster, otherwise the upgrade fails during validation. If enabled, re-deployments are idempotent."
},
{
"name": "overridePublishProfileSettings",
"type": "boolean",
Expand Down Expand Up @@ -317,6 +326,7 @@
"SFSDK_UnzipPackage": "Attempting to unzip '{0}' to location '{1}'.",
"SFSDK_UnexpectedError": "Unexpected Error. Error details: $_.Exception.Message",
"SFSDK_CopyPackageTimeoutSecWarning": "The CopyPackageTimeoutSec parameter requires version '2.3' of the Service Fabric SDK, but the installed version is '{0}'. This parameter will be ignored.",
"SFSDK_CompressPackageWarning": "The CompressPackage parameter requires version '2.5' of the Service Fabric SDK, but the installed version is '{0}'. This parameter will be ignored."
"SFSDK_CompressPackageWarning": "The CompressPackage parameter requires version '2.5' of the Service Fabric SDK, but the installed version is '{0}'. This parameter will be ignored.",
"SFSDK_SkipUpgradeWarning": "Skipping upgrade, since application type '{0}' with version '{1}' already exists in cluster."
}
}
14 changes: 12 additions & 2 deletions Tasks/ServiceFabricDeploy/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 1,
"Minor": 3,
"Patch": 6
"Patch": 7
},
"demands": [
"Cmd"
Expand Down Expand Up @@ -109,6 +109,15 @@
"groupname": "advanced",
"helpMarkDown": "ms-resource:loc.input.help.overwriteBehavior"
},
{
"name": "skipUpgradeSameTypeAndVersion",
"type": "boolean",
"label": "ms-resource:loc.input.label.skipUpgradeSameTypeAndVersion",
"defaultValue": "false",
"required": false,
"groupname": "advanced",
"helpMarkDown": "ms-resource:loc.input.help.skipUpgradeSameTypeAndVersion"
},
{
"name": "overridePublishProfileSettings",
"type": "boolean",
Expand Down Expand Up @@ -317,6 +326,7 @@
"SFSDK_UnzipPackage": "ms-resource:loc.messages.SFSDK_UnzipPackage",
"SFSDK_UnexpectedError": "ms-resource:loc.messages.SFSDK_UnexpectedError",
"SFSDK_CopyPackageTimeoutSecWarning": "ms-resource:loc.messages.SFSDK_CopyPackageTimeoutSecWarning",
"SFSDK_CompressPackageWarning": "ms-resource:loc.messages.SFSDK_CompressPackageWarning"
"SFSDK_CompressPackageWarning": "ms-resource:loc.messages.SFSDK_CompressPackageWarning",
"SFSDK_SkipUpgradeWarning": "ms-resource:loc.messages.SFSDK_SkipUpgradeWarning"
}
}

0 comments on commit 80bc9ec

Please sign in to comment.