Skip to content

Commit

Permalink
SqlWaitForAG: Added localization (dsccommunity#1325)
Browse files Browse the repository at this point in the history
- Changes to SqlWaitForAG
  - Added en-US localization (issue dsccommunity#625).
  • Loading branch information
johlju authored Apr 23, 2019
1 parent 7a05776 commit a252cca
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
`Start-DscConfiguration -Verbose`.
- Changes to SqlSetup
- Concatenated Robocopy localization strings ([issue #694](https://github.com/PowerShell/SqlServerDsc/issues/694)).
- Changes to SqlWaitForAG
- Added en-US localization ([issue #625](https://github.com/PowerShell/SqlServerDsc/issues/625)).

## 12.4.0.0

Expand Down
49 changes: 42 additions & 7 deletions DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath '
$script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'DscResource.Common'
Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'DscResource.Common.psm1')

$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlWaitForAG'

<#
.SYNOPSIS
Returns the cluster role/group that is waiting to be created,
Expand Down Expand Up @@ -43,13 +45,27 @@ function Get-TargetResource
$RetryCount = 30
)

Write-Verbose -Message (
$script:localizedData.GetCurrentState -f $Name
)

$clusterGroupFound = $false

$clusterGroup = Get-ClusterGroup -Name $Name -ErrorAction SilentlyContinue
if ($null -ne $clusterGroup)
{
Write-Verbose -Message (
$script:localizedData.FoundClusterGroup -f $Name
)

$clusterGroupFound = $true
}
else
{
Write-Verbose -Message (
$script:localizedData.MissingClusterGroup -f $Name
)
}

return @{
Name = $Name
Expand Down Expand Up @@ -93,7 +109,9 @@ function Set-TargetResource
$RetryCount = 30
)

New-VerboseMessage -Message "Checking for cluster group $Name. Will try for a total of $($RetryIntervalSec*$RetryCount) seconds."
Write-Verbose -Message (
$script:localizedData.WaitingClusterGroup -f $Name, $RetryCount, ($RetryIntervalSec * $RetryCount)
)

$getTargetResourceParameters = @{
Name = $Name
Expand All @@ -106,18 +124,29 @@ function Set-TargetResource
$clusterGroupFound = (Get-TargetResource @getTargetResourceParameters).GroupExist
if ($clusterGroupFound)
{
New-VerboseMessage -Message "Found cluster group $Name. Will sleep for another $RetryIntervalSec seconds before continuing."
Write-Verbose -Message (
'{0} {1}' -f `
($script:localizedData.FoundClusterGroup -f $Name, $RetryCount, ($RetryIntervalSec * $RetryCount)),
($script:localizedData.SleepMessage -f $RetryIntervalSec)
)

Start-Sleep -Seconds $RetryIntervalSec
break
}

New-VerboseMessage -Message "Cluster group $Name not found. Will retry again after $RetryIntervalSec sec"
Write-Verbose -Message (
'{0} {1}' -f `
($script:localizedData.MissingClusterGroup -f $Name, $RetryCount, ($RetryIntervalSec * $RetryCount)),
($script:localizedData.RetryMessage -f $RetryIntervalSec)
)

Start-Sleep -Seconds $RetryIntervalSec
}

if (-not $clusterGroupFound)
{
throw "Cluster group $Name not found after $RetryCount attempts with $RetryIntervalSec sec interval"
$errorMessage = $script:localizedData.FailedMessage -f $Name
New-InvalidOperationException -Message $errorMessage
}
}

Expand Down Expand Up @@ -156,7 +185,9 @@ function Test-TargetResource
$RetryCount = 30
)

New-VerboseMessage -Message "Testing for cluster group $Name."
Write-Verbose -Message (
$script:localizedData.TestingConfiguration -f $Name
)

$getTargetResourceParameters = @{
Name = $Name
Expand All @@ -167,11 +198,15 @@ function Test-TargetResource
$clusterGroupFound = (Get-TargetResource @getTargetResourceParameters).GroupExist
if ($clusterGroupFound)
{
New-VerboseMessage -Message "Found cluster group $Name"
Write-Verbose -Message (
$script:localizedData.FoundClusterGroup -f $Name
)
}
else
{
New-VerboseMessage -Message "Cluster group $Name not found"
Write-Verbose -Message (
$script:localizedData.MissingClusterGroup -f $Name
)
}

return $clusterGroupFound
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ConvertFrom-StringData @'
GetCurrentState = Get the current state of the Always On Availability Group with the cluster group name '{0}'.
FoundClusterGroup = Found the cluster group '{0}'.
MissingClusterGroup = Did not find the cluster group '{0}'.
WaitingClusterGroup = Waiting for the Always On Availability Group with the cluster group name '{0}'. Will make {1} attempts during a total of {2} seconds.
SleepMessage = Will sleep for another {0} seconds before continuing.
RetryMessage = Will retry again after {0} seconds.
FailedMessage = Did not find the cluster group '{0}' within the timeout period.
TestingConfiguration = Determines the current state of the Always On Availability Group with the cluster group name '{0}'.
'@
2 changes: 1 addition & 1 deletion Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ try
It 'Should throw the correct error message' {
$testParameters.Name = $mockOtherClusterGroupName

{ Set-TargetResource @testParameters } | Should -Throw 'Cluster group UnknownAG not found after 2 attempts with 1 sec interval'
{ Set-TargetResource @testParameters } | Should -Throw ($script:localizedData.FailedMessage -f $mockOtherClusterGroupName)

Assert-MockCalled -CommandName Get-ClusterGroup `
-ParameterFilter $mockGetClusterGroup_ParameterFilter_KnownGroup `
Expand Down

0 comments on commit a252cca

Please sign in to comment.