Skip to content
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

[ServiceFabricDeploy] Test application package only if copy and register is going to happen #7524

Merged
merged 5 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -140,16 +140,7 @@
throw $errMsg
}

if (!$SkipPackageValidation)
{
$global:operationId = $SF_Operations.TestApplicationPackage
$packageValidationSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse)
if (!$packageValidationSuccess)
{
$errMsg = (Get-VstsLocString -Key SFSDK_PackageValidationFailed -ArgumentList $ApplicationPackagePath)
throw $errMsg
}
}


$ApplicationManifestPath = "$AppPkgPathToUse\ApplicationManifest.xml"

Expand Down Expand Up @@ -271,6 +262,17 @@
}
if (!$reg -or !$ApplicationTypeAlreadyRegistered)
{
if (!$SkipPackageValidation)
{
$global:operationId = $SF_Operations.TestApplicationPackage
$packageValidationSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse)
if (!$packageValidationSuccess)
{
$errMsg = (Get-VstsLocString -Key SFSDK_PackageValidationFailed -ArgumentList $ApplicationPackagePath)
throw $errMsg
}
}

Write-Host (Get-VstsLocString -Key SFSDK_CopyingAppToImageStore)
# Get image store connection string
$global:operationId = $SF_Operations.GetClusterManifest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,6 @@ function Publish-UpgradedServiceFabricApplication
return
}

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

if (!$SkipPackageValidation)
{
$global:operationId = $SF_Operations.TestApplicationPackage
$packageValidationSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse -ImageStoreConnectionString $imageStoreConnectionString)
if (!$packageValidationSuccess)
{
$errMsg = (Get-VstsLocString -Key SFSDK_PackageValidationFailed -ArgumentList $ApplicationPackagePath)
throw $errMsg
}
}

try
{
Expand Down Expand Up @@ -250,6 +235,22 @@ function Publish-UpgradedServiceFabricApplication

if (!$reg -or !$ApplicationTypeAlreadyRegistered)
{
# Get image store connection string
$global:operationId = $SF_Operations.GetClusterManifest
$clusterManifestText = Get-ServiceFabricClusterManifest
$imageStoreConnectionString = Get-ImageStoreConnectionStringFromClusterManifest ([xml] $clusterManifestText)

if (!$SkipPackageValidation)
{
$global:operationId = $SF_Operations.TestApplicationPackage
$packageValidationSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse -ImageStoreConnectionString $imageStoreConnectionString)
if (!$packageValidationSuccess)
{
$errMsg = (Get-VstsLocString -Key SFSDK_PackageValidationFailed -ArgumentList $ApplicationPackagePath)
throw $errMsg
}
}

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

Expand Down Expand Up @@ -383,16 +384,16 @@ function Publish-UpgradedServiceFabricApplication
if ($UnregisterUnusedVersions)
{
Write-Host (Get-VstsLocString -Key SFSDK_UnregisterUnusedVersions)
foreach ($registeredAppTypes in Get-ServiceFabricApplicationTypeAction -ApplicationTypeName $names.ApplicationTypeName | Where-Object { $_.ApplicationTypeVersion -ne $names.ApplicationTypeVersion })
foreach ($registeredAppType in Get-ServiceFabricApplicationTypeAction -ApplicationTypeName $names.ApplicationTypeName)
{
try
{

Choose a reason for hiding this comment

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

If business use case is to consume the error in case of AppType and Version in use then its better to check for error code "ApplicationTypeInUse" instead of consuming System.Fabric.FabricException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO use case is to suppress any kind of exception. We don't want task to fail due to failure here. Infact I will remove [System.Fabric.FabricException] from here as well

Choose a reason for hiding this comment

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

Lets communicate to the users by surfacing a warning message in case of failures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

$global:operationId = $SF_Operations.UnregisterApplicationType
$registeredAppTypes | Unregister-ServiceFabricApplicationType -Force -TimeoutSec $UnregisterPackageTimeoutSec
$registeredAppType | Unregister-ServiceFabricApplicationType -Force -TimeoutSec $UnregisterPackageTimeoutSec
}
catch [System.Fabric.FabricException]
catch
{
# AppType and Version in use.
Write-Warning (Get-VstsLocString -Key SFSDK_UnregisterAppTypeFailure -ArgumentList @($names.ApplicationTypeName, $registeredAppType.ApplicationTypeVersion, $_.Exception.ToString()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@
"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.",
"loc.messages.SFSDK_UnregisterAppTypeFailed": "Failed to unregister application type. Error: {0}.",
"loc.messages.SFSDK_PerformingForceRemoveOnTimeout": "Removal of application '{0}' is timing out, this means that the service is stuck in ChangeRole/Close and the shutdown sequence cannot complete. Performing ForceRemove of the application."
"loc.messages.SFSDK_PerformingForceRemoveOnTimeout": "Removal of application '{0}' is timing out, this means that the service is stuck in ChangeRole/Close and the shutdown sequence cannot complete. Performing ForceRemove of the application.",
"loc.messages.SFSDK_UnregisterAppTypeFailure": "Failed to unregister application type '{0}' and version '{1}'. Error: {2}."
}
3 changes: 2 additions & 1 deletion Tasks/ServiceFabricDeployV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
"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.",
"SFSDK_UnregisterAppTypeFailed": "Failed to unregister application type. Error: {0}.",
"SFSDK_PerformingForceRemoveOnTimeout": "Removal of application '{0}' is timing out, this means that the service is stuck in ChangeRole/Close and the shutdown sequence cannot complete. Performing ForceRemove of the application."
"SFSDK_PerformingForceRemoveOnTimeout": "Removal of application '{0}' is timing out, this means that the service is stuck in ChangeRole/Close and the shutdown sequence cannot complete. Performing ForceRemove of the application.",
"SFSDK_UnregisterAppTypeFailure": "Failed to unregister application type '{0}' and version '{1}'. Error: {2}."
}
}
3 changes: 2 additions & 1 deletion Tasks/ServiceFabricDeployV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
"SFSDK_CompressPackageWarning": "ms-resource:loc.messages.SFSDK_CompressPackageWarning",
"SFSDK_SkipUpgradeWarning": "ms-resource:loc.messages.SFSDK_SkipUpgradeWarning",
"SFSDK_UnregisterAppTypeFailed": "ms-resource:loc.messages.SFSDK_UnregisterAppTypeFailed",
"SFSDK_PerformingForceRemoveOnTimeout": "ms-resource:loc.messages.SFSDK_PerformingForceRemoveOnTimeout"
"SFSDK_PerformingForceRemoveOnTimeout": "ms-resource:loc.messages.SFSDK_PerformingForceRemoveOnTimeout",
"SFSDK_UnregisterAppTypeFailure": "ms-resource:loc.messages.SFSDK_UnregisterAppTypeFailure"
}
}