Skip to content

Commit 8dc288d

Browse files
authored
Update for changes to compose APIs in 5.7 (#4806)
* Update for changes to compose APIs in 5.7 * Updates per PR comments
1 parent 2d39dc6 commit 8dc288d

File tree

10 files changed

+269
-23
lines changed

10 files changed

+269
-23
lines changed

Tasks/ServiceFabricComposeDeploy/ServiceFabricComposeDeploy.ps1

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ try {
3333
'ApplicationName' = $applicationName
3434
}
3535

36+
$usePreviewApi = $false
37+
$regKey = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Service Fabric\' -ErrorAction SilentlyContinue
38+
if ($regKey)
39+
{
40+
if ($regKey.FabricVersion.StartsWith('255.255'))
41+
{
42+
$usePreviewApi = $true
43+
Write-Verbose (Get-VstsLocString -Key UsingPreviewAPI)
44+
}
45+
}
46+
3647
# Test the compose file
3748
Write-Host (Get-VstsLocString -Key CheckingComposeFile)
3849
$valid = Test-ServiceFabricApplicationPackage -ComposeFilePath $composeFilePath -ErrorAction Stop
@@ -88,8 +99,17 @@ try {
8899
}
89100
}
90101

91-
$deployParameters['RepositoryUserName'] = $username
92-
$deployParameters['RepositoryPassword'] = $password
102+
if ($usePreviewApi)
103+
{
104+
$deployParameters['RepositoryUserName'] = $username
105+
$deployParameters['RepositoryPassword'] = $password
106+
}
107+
else
108+
{
109+
$deployParameters['RegistryUserName'] = $username
110+
$deployParameters['RegistryPassword'] = $password
111+
}
112+
93113
$deployParameters['PasswordEncrypted'] = $isEncrypted
94114
}
95115

@@ -106,7 +126,7 @@ try {
106126
$getStatusParameters['TimeoutSec'] = $getStatusTimeoutSec
107127
}
108128

109-
$existingApplication = Get-ServiceFabricComposeApplicationStatusPaged @getStatusParameters
129+
$existingApplication = Get-ServiceFabricComposeApplicationStatusHelper -UsePreviewAPI $usePreviewAPI -GetStatusParameters $getStatusParameters
110130
if ($existingApplication -ne $null)
111131
{
112132
Write-Host (Get-VstsLocString -Key RemovingApplication -ArgumentList $applicationName)
@@ -117,7 +137,8 @@ try {
117137
{
118138
Write-Host (Get-VstsLocString -Key CurrentStatus -ArgumentList $existingApplication.ComposeApplicationStatus)
119139
Start-Sleep -Seconds 3
120-
$existingApplication = Get-ServiceFabricComposeApplicationStatusPaged @getStatusParameters
140+
$existingApplication = Get-ServiceFabricComposeApplicationStatusHelper -UsePreviewAPI $usePreviewAPI -GetStatusParameters $getStatusParameters
141+
121142
}
122143
while ($existingApplication -ne $null)
123144
Write-Host (Get-VstsLocString -Key ApplicationRemoved)
@@ -127,7 +148,7 @@ try {
127148
New-ServiceFabricComposeApplication @deployParameters
128149

129150
Write-Host (Get-VstsLocString -Key WaitingForDeploy)
130-
$newApplication = Get-ServiceFabricComposeApplicationStatusPaged @getStatusParameters
151+
$newApplication = Get-ServiceFabricComposeApplicationStatusHelper -UsePreviewAPI $usePreviewAPI -GetStatusParameters $getStatusParameters
131152
while (($newApplication -eq $null) -or `
132153
($newApplication.ComposeApplicationStatus -eq 'Provisioning') -or `
133154
($newApplication.ComposeApplicationStatus -eq 'Creating'))
@@ -141,7 +162,7 @@ try {
141162
Write-Host (Get-VstsLocString -Key CurrentStatus -ArgumentList $newApplication.ComposeApplicationStatus)
142163
}
143164
Start-Sleep -Seconds 3
144-
$newApplication = Get-ServiceFabricComposeApplicationStatusPaged @getStatusParameters
165+
$newApplication = Get-ServiceFabricComposeApplicationStatusHelper -UsePreviewAPI $usePreviewAPI -GetStatusParameters $getStatusParameters
145166
}
146167
Write-Host (Get-VstsLocString -Key CurrentStatus -ArgumentList $newApplication.ComposeApplicationStatus)
147168

Tasks/ServiceFabricComposeDeploy/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"loc.input.label.composeFilePath": "Compose File Path",
1111
"loc.input.help.composeFilePath": "Path to the compose file that is to be deployed. [Variables](https://go.microsoft.com/fwlink/?LinkID=550988) and wildcards can be used in the path.",
1212
"loc.input.label.applicationName": "Application Name",
13-
"loc.input.help.applicationName": "The Service Fabric Application Name of the application being deployed. Use fabric:/ as a prefix.",
13+
"loc.input.help.applicationName": "Name of the application being deployed.",
1414
"loc.input.label.registryCredentials": "Registry Credentials Source",
1515
"loc.input.help.registryCredentials": "Choose if/how credentials for the docker registry will be provided.",
1616
"loc.input.label.dockerRegistryEndpointName": "Docker Registry Connection",
@@ -43,5 +43,6 @@
4343
"loc.messages.WaitingForDeploy": "Waiting for deploy...",
4444
"loc.messages.CurrentStatus": "Current Status: {0}",
4545
"loc.messages.DeployFailed": "Deploy Failed\nStatus: {0}\nDetails: {1}",
46-
"loc.messages.CheckingComposeFile": "Checking compose file"
47-
}
46+
"loc.messages.CheckingComposeFile": "Checking compose file",
47+
"loc.messages.UsingPreviewAPI": "Using the preview APIs"
48+
}

Tasks/ServiceFabricComposeDeploy/Tests/Deploy.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ $vstsEndpoint = @{
4141
}
4242
Register-Mock Get-VstsEndpoint { $vstsEndpoint } -- -Name $serviceConnectionName -Require
4343

44+
# Setup mock Registry for Service Fabric
45+
$SfRegistry = @{
46+
"FabricVersion" = "5.6.1.2"
47+
}
48+
Register-Mock Get-ItemProperty { $SfRegistry } -- -Path 'HKLM:\SOFTWARE\Microsoft\Service Fabric\' -ErrorAction SilentlyContinue
49+
4450
# Setup mock results of cluster connection
4551
Register-Mock Connect-ServiceFabricClusterFromServiceEndpoint { } -- -ClusterConnectionParameters @{} -ConnectedServiceEndpoint $vstsEndpoint
4652

47-
$serviceFabricComposeApplicationStatusPaged = @{
53+
$serviceFabricComposeApplicationStatus = @{
4854
"ApplicationName" = $applicationName
4955
"ComposeApplicationStatus" = "Created"
5056
"StatusDetails" = ""
@@ -54,14 +60,14 @@ $serviceFabricComposeApplicationStatusPaged = @{
5460
$removed = New-Object 'System.Collections.Generic.Dictionary[string, bool]'
5561
$removed.Value = $true
5662

57-
Register-Mock Get-ServiceFabricComposeApplicationStatusPaged {
63+
Register-Mock Get-ServiceFabricComposeApplicationStatus {
5864
if (($removed.Value -eq $true))
5965
{
6066
return $null;
6167
}
6268
else
6369
{
64-
return $serviceFabricComposeApplicationStatusPaged
70+
return $serviceFabricComposeApplicationStatus
6571
}
6672
} -ApplicationName: $applicationName
6773

@@ -80,6 +86,6 @@ Register-Mock New-ServiceFabricComposeApplication {
8086
@( & $PSScriptRoot/../../../Tasks/ServiceFabricComposeDeploy/ServiceFabricComposeDeploy.ps1 )
8187

8288
# Assert
83-
Assert-WasCalled Get-ServiceFabricComposeApplicationStatusPaged -Times 2
89+
Assert-WasCalled Get-ServiceFabricComposeApplicationStatus -Times 2
8490
Assert-WasCalled Remove-ServiceFabricComposeApplication -Times 0
8591
Assert-WasCalled New-ServiceFabricComposeApplication -Times 1
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
5+
6+
$serviceConnectionName = "random connection name"
7+
$composeFilePath = "docker-compose.yml"
8+
$applicationName = "fabric:/Application1"
9+
$serverCertThumbprint = "random thumbprint"
10+
$userName = "random user"
11+
$password = "random password"
12+
$connectionEndpointFullUrl = "https://mycluster.com:19000"
13+
$connectionEndpoint = ([System.Uri]$connectionEndpointFullUrl).Authority
14+
15+
# Setup input arguments
16+
Register-Mock Get-VstsInput { $serviceConnectionName } -Name serviceConnectionName -Require
17+
Register-Mock Get-VstsInput { $composeFilePath } -Name composeFilePath -Require
18+
Register-Mock Get-VstsInput { $applicationName } -Name applicationName -Require
19+
Register-Mock Get-VstsInput { $null } -Name deployTimeoutSec
20+
Register-Mock Get-VstsInput { $null } -Name removeTimeoutSec
21+
Register-Mock Get-VstsInput { $null } -Name getStatusTimeoutSec
22+
Register-Mock Get-VstsInput { "None" } -Name registryCredentials -Require
23+
24+
# Setup file resolution
25+
Register-Mock Find-VstsFiles { $composeFilePath } -- -LegacyPattern $composeFilePath
26+
27+
Register-Mock Assert-VstsPath
28+
Register-Mock Test-Path { $true } -- "HKLM:\SOFTWARE\Microsoft\Service Fabric SDK"
29+
30+
# Setup mock VSTS service endpoint
31+
$vstsEndpoint = @{
32+
"url" = $connectionEndpointFullUrl
33+
"Auth" = @{
34+
"Scheme" = "UserNamePassword"
35+
"Parameters" = @{
36+
"ServerCertThumbprint" = $serverCertThumbprint
37+
"Username" = $userName
38+
"Password" = $password
39+
}
40+
}
41+
}
42+
Register-Mock Get-VstsEndpoint { $vstsEndpoint } -- -Name $serviceConnectionName -Require
43+
44+
# Setup mock Registry for Service Fabric
45+
$SfRegistry = @{
46+
"FabricVersion" = "255.255.1.2"
47+
}
48+
Register-Mock Get-ItemProperty { $SfRegistry } -- -Path 'HKLM:\SOFTWARE\Microsoft\Service Fabric\' -ErrorAction SilentlyContinue
49+
50+
# Setup mock results of cluster connection
51+
Register-Mock Connect-ServiceFabricClusterFromServiceEndpoint { } -- -ClusterConnectionParameters @{} -ConnectedServiceEndpoint $vstsEndpoint
52+
53+
$serviceFabricComposeApplicationStatusPaged = @{
54+
"ApplicationName" = $applicationName
55+
"ComposeApplicationStatus" = "Created"
56+
"StatusDetails" = ""
57+
}
58+
59+
# Need to store the bool in an object so the lambdas will share the reference
60+
$removed = New-Object 'System.Collections.Generic.Dictionary[string, bool]'
61+
$removed.Value = $true
62+
63+
Register-Mock Get-ServiceFabricComposeApplicationStatusPaged {
64+
if (($removed.Value -eq $true))
65+
{
66+
return $null;
67+
}
68+
else
69+
{
70+
return $serviceFabricComposeApplicationStatusPaged
71+
}
72+
} -ApplicationName: $applicationName
73+
74+
Register-Mock Remove-ServiceFabricComposeApplication {
75+
$removed.Value = $true
76+
} -Force: True -ApplicationName: $applicationName
77+
78+
Register-Mock Test-ServiceFabricApplicationPackage { } -- -ComposeFilePath: $composeFilePath -ErrorAction: Stop
79+
80+
Register-Mock New-ServiceFabricComposeApplication {
81+
$removed.Value = $false
82+
} -- -Compose: $composeFilePath -ApplicationName: $applicationName
83+
84+
# Act
85+
. $PSScriptRoot\..\..\..\Tasks\ServiceFabricComposeDeploy\ps_modules\ServiceFabricHelpers\Connect-ServiceFabricClusterFromServiceEndpoint.ps1
86+
@( & $PSScriptRoot/../../../Tasks/ServiceFabricComposeDeploy/ServiceFabricComposeDeploy.ps1 )
87+
88+
# Assert
89+
Assert-WasCalled Get-ServiceFabricComposeApplicationStatusPaged -Times 2
90+
Assert-WasCalled Remove-ServiceFabricComposeApplication -Times 0
91+
Assert-WasCalled New-ServiceFabricComposeApplication -Times 1

Tasks/ServiceFabricComposeDeploy/Tests/L0.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ describe('ServiceFabricComposeDeploy Suite', function () {
3030
it('Deploy', (done) => {
3131
psr.run(path.join(__dirname, 'Deploy.ps1'), done);
3232
})
33+
it('Deploy Preview', (done) => {
34+
psr.run(path.join(__dirname, 'DeployPreview.ps1'), done);
35+
})
3336
it('Upgrade', (done) => {
3437
psr.run(path.join(__dirname, 'Upgrade.ps1'), done);
3538
})
39+
it('Upgrade Preview', (done) => {
40+
psr.run(path.join(__dirname, 'UpgradePreview.ps1'), done);
41+
})
3642
}
3743
});

Tasks/ServiceFabricComposeDeploy/Tests/Upgrade.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ $vstsEndpoint = @{
4141
}
4242
Register-Mock Get-VstsEndpoint { $vstsEndpoint } -- -Name $serviceConnectionName -Require
4343

44+
# Setup mock Registry for Service Fabric
45+
$SfRegistry = @{
46+
"FabricVersion" = "5.6.1.2"
47+
}
48+
Register-Mock Get-ItemProperty { $SfRegistry } -- -Path 'HKLM:\SOFTWARE\Microsoft\Service Fabric\' -ErrorAction SilentlyContinue
49+
4450
# Setup mock results of cluster connection
4551
Register-Mock Connect-ServiceFabricClusterFromServiceEndpoint { } -- -ClusterConnectionParameters @{} -ConnectedServiceEndpoint $vstsEndpoint
4652

47-
$serviceFabricComposeApplicationStatusPaged = @{
53+
$serviceFabricComposeApplicationStatus = @{
4854
"ApplicationName" = $applicationName
4955
"ComposeApplicationStatus" = "Created"
5056
"StatusDetails" = ""
@@ -54,14 +60,14 @@ $serviceFabricComposeApplicationStatusPaged = @{
5460
$removed = New-Object 'System.Collections.Generic.Dictionary[string, bool]'
5561
$removed.Value = $false
5662

57-
Register-Mock Get-ServiceFabricComposeApplicationStatusPaged {
63+
Register-Mock Get-ServiceFabricComposeApplicationStatus {
5864
if (($removed.Value -eq $true))
5965
{
6066
return $null;
6167
}
6268
else
6369
{
64-
return $serviceFabricComposeApplicationStatusPaged
70+
return $serviceFabricComposeApplicationStatus
6571
}
6672
} -ApplicationName: $applicationName
6773

@@ -80,6 +86,6 @@ Register-Mock New-ServiceFabricComposeApplication {
8086
@( & $PSScriptRoot/../../../Tasks/ServiceFabricComposeDeploy/ServiceFabricComposeDeploy.ps1 )
8187

8288
# Assert
83-
Assert-WasCalled Get-ServiceFabricComposeApplicationStatusPaged -Times 3
89+
Assert-WasCalled Get-ServiceFabricComposeApplicationStatus -Times 3
8490
Assert-WasCalled Remove-ServiceFabricComposeApplication -Times 1
8591
Assert-WasCalled New-ServiceFabricComposeApplication -Times 1
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
5+
6+
$serviceConnectionName = "random connection name"
7+
$composeFilePath = "docker-compose.yml"
8+
$applicationName = "fabric:/Application1"
9+
$serverCertThumbprint = "random thumbprint"
10+
$userName = "random user"
11+
$password = "random password"
12+
$connectionEndpointFullUrl = "https://mycluster.com:19000"
13+
$connectionEndpoint = ([System.Uri]$connectionEndpointFullUrl).Authority
14+
15+
# Setup input arguments
16+
Register-Mock Get-VstsInput { $serviceConnectionName } -Name serviceConnectionName -Require
17+
Register-Mock Get-VstsInput { $composeFilePath } -Name composeFilePath -Require
18+
Register-Mock Get-VstsInput { $applicationName } -Name applicationName -Require
19+
Register-Mock Get-VstsInput { $null } -Name deployTimeoutSec
20+
Register-Mock Get-VstsInput { $null } -Name removeTimeoutSec
21+
Register-Mock Get-VstsInput { $null } -Name getStatusTimeoutSec
22+
Register-Mock Get-VstsInput { "None" } -Name registryCredentials -Require
23+
24+
# Setup file resolution
25+
Register-Mock Find-VstsFiles { $composeFilePath } -- -LegacyPattern $composeFilePath
26+
27+
Register-Mock Assert-VstsPath
28+
Register-Mock Test-Path { $true } -- "HKLM:\SOFTWARE\Microsoft\Service Fabric SDK"
29+
30+
# Setup mock VSTS service endpoint
31+
$vstsEndpoint = @{
32+
"url" = $connectionEndpointFullUrl
33+
"Auth" = @{
34+
"Scheme" = "UserNamePassword"
35+
"Parameters" = @{
36+
"ServerCertThumbprint" = $serverCertThumbprint
37+
"Username" = $userName
38+
"Password" = $password
39+
}
40+
}
41+
}
42+
Register-Mock Get-VstsEndpoint { $vstsEndpoint } -- -Name $serviceConnectionName -Require
43+
44+
# Setup mock Registry for Service Fabric
45+
$SfRegistry = @{
46+
"FabricVersion" = "255.255.1.2"
47+
}
48+
Register-Mock Get-ItemProperty { $SfRegistry } -- -Path 'HKLM:\SOFTWARE\Microsoft\Service Fabric\' -ErrorAction SilentlyContinue
49+
50+
# Setup mock results of cluster connection
51+
Register-Mock Connect-ServiceFabricClusterFromServiceEndpoint { } -- -ClusterConnectionParameters @{} -ConnectedServiceEndpoint $vstsEndpoint
52+
53+
$serviceFabricComposeApplicationStatusPaged = @{
54+
"ApplicationName" = $applicationName
55+
"ComposeApplicationStatus" = "Created"
56+
"StatusDetails" = ""
57+
}
58+
59+
# Need to store the bool in an object so the lambdas will share the reference
60+
$removed = New-Object 'System.Collections.Generic.Dictionary[string, bool]'
61+
$removed.Value = $false
62+
63+
Register-Mock Get-ServiceFabricComposeApplicationStatusPaged {
64+
if (($removed.Value -eq $true))
65+
{
66+
return $null;
67+
}
68+
else
69+
{
70+
return $serviceFabricComposeApplicationStatusPaged
71+
}
72+
} -ApplicationName: $applicationName
73+
74+
Register-Mock Remove-ServiceFabricComposeApplication {
75+
$removed.Value = $true
76+
} -Force: True -ApplicationName: $applicationName
77+
78+
Register-Mock Test-ServiceFabricApplicationPackage { } -- -ComposeFilePath: $composeFilePath -ErrorAction: Stop
79+
80+
Register-Mock New-ServiceFabricComposeApplication {
81+
$removed.Value = $false
82+
} -- -Compose: $composeFilePath -ApplicationName: $applicationName
83+
84+
# Act
85+
. $PSScriptRoot\..\..\..\Tasks\ServiceFabricComposeDeploy\ps_modules\ServiceFabricHelpers\Connect-ServiceFabricClusterFromServiceEndpoint.ps1
86+
@( & $PSScriptRoot/../../../Tasks/ServiceFabricComposeDeploy/ServiceFabricComposeDeploy.ps1 )
87+
88+
# Assert
89+
Assert-WasCalled Get-ServiceFabricComposeApplicationStatusPaged -Times 3
90+
Assert-WasCalled Remove-ServiceFabricComposeApplication -Times 1
91+
Assert-WasCalled New-ServiceFabricComposeApplication -Times 1

0 commit comments

Comments
 (0)