Skip to content

Commit

Permalink
Merge pull request #1359 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 12.5.0.0 of SqlServerDsc
  • Loading branch information
kwirkykat authored May 15, 2019
2 parents 13cc150 + 4f45ea0 commit af2cbb0
Show file tree
Hide file tree
Showing 82 changed files with 3,331 additions and 1,717 deletions.
86 changes: 86 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,92 @@

## Unreleased

## 12.5.0.0

- Changes to SqlServerSecureConnection
- Updated README and added example for SqlServerSecureConnection,
instructing users to use the 'SYSTEM' service account instead of
'LocalSystem'.
- Changes to SqlScript
- Correctly passes the `$VerbosePreference` to the helper function
`Invoke-SqlScript` so that `PRINT` statements is outputted correctly
when verbose output is requested, e.g
`Start-DscConfiguration -Verbose`.
- Added en-US localization ([issue #624](https://github.com/PowerShell/SqlServerDsc/issues/624)).
- Added additional unit tests for code coverage.
- Changes to SqlScriptQuery
- Correctly passes the `$VerbosePreference` to the helper function
`Invoke-SqlScript` so that `PRINT` statements is outputted correctly
when verbose output is requested, e.g
`Start-DscConfiguration -Verbose`.
- Added en-US localization.
- Added additional unit tests for code coverage.
- Changes to SqlSetup
- Concatenated Robocopy localization strings ([issue #694](https://github.com/PowerShell/SqlServerDsc/issues/694)).
- Made the error message more descriptive when the Set-TargetResource
function calls the Test-TargetResource function to verify the desired
state.
- Changes to SqlWaitForAG
- Added en-US localization ([issue #625](https://github.com/PowerShell/SqlServerDsc/issues/625)).
- Changes to SqlServerPermission
- Added en-US localization ([issue #619](https://github.com/PowerShell/SqlServerDsc/issues/619)).
- Changes to SqlServerMemory
- Added en-US localization ([issue #617](https://github.com/PowerShell/SqlServerDsc/issues/617)).
- No longer will the resource set the MinMemory value if it was provided
in a configuration that also set the `Ensure` parameter to 'Absent'
([issue #1329](https://github.com/PowerShell/SqlServerDsc/issues/1329)).
- Refactored unit tests to simplify them add add slightly more code
coverage.
- Changes to SqlServerMaxDop
- Added en-US localization ([issue #616](https://github.com/PowerShell/SqlServerDsc/issues/616)).
- Changes to SqlRS
- Reporting Services are restarted after changing settings, unless
`$SuppressRestart` parameter is set ([issue #1331](https://github.com/PowerShell/SqlServerDsc/issues/1331)).
`$SuppressRestart` will also prevent Reporting Services restart after initialization.
- Fixed one of the error handling to use localization, and made the
error message more descriptive when the Set-TargetResource function
calls the Test-TargetResource function to verify the desired
state. *This was done prior to adding full en-US localization.*
- Fixed ([issue #1258](https://github.com/PowerShell/SqlServerDsc/issues/1258)).
When initializing Reporting Services, there is no need to execute `InitializeReportServer`
CIM method, since executing `SetDatabaseConnection` CIM method initializes
Reporting Services.
- [issue #864](https://github.com/PowerShell/SqlServerDsc/issues/864) SqlRs
can now initialise SSRS 2017 instances
- Changes to SqlServerLogin
- Added en-US localization ([issue #615](https://github.com/PowerShell/SqlServerDsc/issues/615)).
- Added unit tests to improved code coverage.
- Changes to SqlWindowsFirewall
- Added en-US localization ([issue #614](https://github.com/PowerShell/SqlServerDsc/issues/614)).
- Changes to SqlServerEndpoint
- Added en-US localization ([issue #611](https://github.com/PowerShell/SqlServerDsc/issues/611)).
- Changes to SqlServerEndpointPermission
- Added en-US localization ([issue #612](https://github.com/PowerShell/SqlServerDsc/issues/612)).
- Changes to SqlServerEndpointState
- Added en-US localization ([issue #613](https://github.com/PowerShell/SqlServerDsc/issues/613)).
- Changes to SqlDatabaseRole
- Added en-US localization ([issue #610](https://github.com/PowerShell/SqlServerDsc/issues/610)).
- Changes to SqlDatabaseRecoveryModel
- Added en-US localization ([issue #609](https://github.com/PowerShell/SqlServerDsc/issues/609)).
- Changes to SqlDatabasePermission
- Added en-US localization ([issue #608](https://github.com/PowerShell/SqlServerDsc/issues/608)).
- Changes to SqlDatabaseOwner
- Added en-US localization ([issue #607](https://github.com/PowerShell/SqlServerDsc/issues/607)).
- Changes to SqlDatabase
- Added en-US localization ([issue #606](https://github.com/PowerShell/SqlServerDsc/issues/606)).
- Changes to SqlAGListener
- Added en-US localization ([issue #604](https://github.com/PowerShell/SqlServerDsc/issues/604)).
- Changes to SqlAlwaysOnService
- Added en-US localization ([issue #603](https://github.com/PowerShell/SqlServerDsc/issues/608)).
- Changes to SqlAlias
- Added en-US localization ([issue #602](https://github.com/PowerShell/SqlServerDsc/issues/602)).
- Removed ShouldProcess for the code, since it has no purpose in a DSC
resource ([issue #242](https://github.com/PowerShell/SqlServerDsc/issues/242)).
- Changes to SqlServerReplication
- Added en-US localization ([issue #620](https://github.com/PowerShell/SqlServerDsc/issues/620)).
- Refactored Get-TargetResource slightly so it provide better verbose
messages.

## 12.4.0.0

- Changes to SqlServerDsc
Expand Down
123 changes: 91 additions & 32 deletions DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.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_SqlAGListener'

<#
.SYNOPSIS
Returns the current state of the Availability Group listener.
Expand Down Expand Up @@ -47,13 +49,19 @@ function Get-TargetResource
$AvailabilityGroup
)

Write-Verbose -Message (
$script:localizedData.GetAvailabilityGroupListener -f $Name, $AvailabilityGroup, $InstanceName
)

try
{
$availabilityGroupListener = Get-SQLAlwaysOnAvailabilityGroupListener -Name $Name -AvailabilityGroup $AvailabilityGroup -ServerName $ServerName -InstanceName $InstanceName

if ($null -ne $availabilityGroupListener)
{
New-VerboseMessage -Message "Listener $Name exist."
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerIsPresent -f $Name
)

$ensure = 'Present'
$port = [uint16]( $availabilityGroupListener | Select-Object -ExpandProperty PortNumber )
Expand All @@ -69,7 +77,9 @@ function Get-TargetResource
}
else
{
New-VerboseMessage -Message "Listener $Name does not exist"
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerIsNotPresent -f $Name
)

$ensure = 'Absent'
$port = 0
Expand All @@ -79,7 +89,8 @@ function Get-TargetResource
}
catch
{
throw New-TerminatingError -ErrorType AvailabilityGroupListenerNotFound -FormatArgs @($Name) -ErrorCategory ObjectNotFound -InnerException $_.Exception
$errorMessage = $script:localizedData.AvailabilityGroupListenerNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage -ErrorRecord $_
}

return @{
Expand Down Expand Up @@ -176,7 +187,9 @@ function Set-TargetResource
{
if ($Ensure -eq 'Present')
{
New-VerboseMessage -Message "Create listener on $AvailabilityGroup"
Write-Verbose -Message (
$script:localizedData.CreateAvailabilityGroupListener -f $Name, $AvailabilityGroup, $InstanceName
)

$sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName

Expand All @@ -190,41 +203,53 @@ function Set-TargetResource

if ($Port)
{
New-VerboseMessage -Message "Listener port set to $Port"
Write-Verbose -Message (
$script:localizedData.SetAvailabilityGroupListenerPort -f $Port
)

$newListenerParams += @{
Port = $Port
}
}

if ($DHCP -and $IpAddress.Count -gt 0)
{
New-VerboseMessage -Message "Listener set to DHCP with subnet $IpAddress"
Write-Verbose -Message (
$script:localizedData.SetAvailabilityGroupListenerDhcp -f $IpAddress
)

$newListenerParams += @{
DhcpSubnet = [System.String] $IpAddress
}
}
elseif (-not $DHCP -and $IpAddress.Count -gt 0)
{
New-VerboseMessage -Message "Listener set to static IP-address(es); $($IpAddress -join ', ')"
Write-Verbose -Message (
$script:localizedData.SetAvailabilityGroupListenerStaticIpAddress -f ($IpAddress -join ', ')
)

$newListenerParams += @{
StaticIp = $IpAddress
}
}
else
{
New-VerboseMessage -Message 'Listener using DHCP with server default subnet'
Write-Verbose -Message $script:localizedData.SetAvailabilityGroupListenerDhcpDefaultSubnet
}

New-SqlAvailabilityGroupListener @newListenerParams -ErrorAction Stop | Out-Null
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.AvailabilityGroupNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}
}
else
{
New-VerboseMessage -Message "Remove listener from $AvailabilityGroup"
Write-Verbose -Message (
$script:localizedData.DropAvailabilityGroupListener -f $Name, $AvailabilityGroup, $InstanceName
)

$sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName

Expand All @@ -238,27 +263,29 @@ function Set-TargetResource
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupListenerNotFound -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.AvailabilityGroupListenerNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.AvailabilityGroupNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}
}
}
else
{
if ($Ensure -ne '')
{
New-VerboseMessage -Message "State is already $Ensure"
}

if ($availabilityGroupListenerState.Ensure -eq 'Present')
{
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerIsPresent -f $Name
)

if (-not $DHCP -and $availabilityGroupListenerState.IpAddress.Count -lt $IpAddress.Count) # Only able to add a new IP-address, not change existing ones.
{
New-VerboseMessage -Message 'Found at least one new IP-address.'
Write-Verbose -Message $script:localizedData.FoundNewIpAddress

$ipAddressEqual = $false
}
else
Expand All @@ -270,13 +297,15 @@ function Set-TargetResource
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupListenerIPChangeError -FormatArgs @($($IpAddress -join ', '), $($availabilityGroupListenerState.IpAddress -join ', ')) -ErrorCategory InvalidOperation
$errorMessage = $script:localizedData.AvailabilityGroupListenerIPChangeError -f ($IpAddress -join ', '), ($availabilityGroupListenerState.IpAddress -join ', ')
New-InvalidOperationException -Message $errorMessage
}
}

if ($($PSBoundParameters.ContainsKey('DHCP')) -and $availabilityGroupListenerState.DHCP -ne $DHCP)
{
throw New-TerminatingError -ErrorType AvailabilityGroupListenerDHCPChangeError -FormatArgs @( $DHCP, $($availabilityGroupListenerState.DHCP) ) -ErrorCategory InvalidOperation
$errorMessage = $script:localizedData.AvailabilityGroupListenerDHCPChangeError -f $DHCP, $availabilityGroupListenerState.DHCP
New-InvalidOperationException -Message $errorMessage
}

$sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName
Expand All @@ -289,11 +318,15 @@ function Set-TargetResource
{
if ($availabilityGroupListenerState.Port -ne $Port -or -not $ipAddressEqual)
{
New-VerboseMessage -Message 'Listener differ in configuration.'
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerNotInDesiredState -f $Name, $AvailabilityGroup, $InstanceName
)

if ($availabilityGroupListenerState.Port -ne $Port)
{
New-VerboseMessage -Message 'Changing port configuration'
Write-Verbose -Message (
$script:localizedData.ChangingAvailabilityGroupListenerPort -f $Port
)

$setListenerParams = @{
InputObject = $availabilityGroupListenerObject
Expand All @@ -305,14 +338,16 @@ function Set-TargetResource

if (-not $ipAddressEqual)
{
New-VerboseMessage -Message 'Adding IP-address(es)'

$newIpAddress = @()

foreach ($currentIpAddress in $IpAddress)
{
if (-not ( $availabilityGroupListenerState.IpAddress -contains $currentIpAddress))
{
Write-Verbose -Message (
$script:localizedData.AddingAvailabilityGroupListenerIpAddress -f $currentIpAddress
)

$newIpAddress += $currentIpAddress
}
}
Expand All @@ -327,24 +362,29 @@ function Set-TargetResource
}
else
{
New-VerboseMessage -Message 'Listener configuration is already correct.'
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerInDesiredState -f $Name, $AvailabilityGroup, $InstanceName
)
}
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupListenerNotFound -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.AvailabilityGroupListenerNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.AvailabilityGroupNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}
}
}
}
else
{
throw New-TerminatingError -ErrorType UnexpectedErrorFromGet -ErrorCategory InvalidResult
$errorMessage = $script:localizedData.UnexpectedErrorFromGet
New-InvalidResultException -Message $errorMessage
}
}

Expand Down Expand Up @@ -424,7 +464,9 @@ function Test-TargetResource
AvailabilityGroup = [System.String] $AvailabilityGroup
}

New-VerboseMessage -Message "Testing state of listener $Name"
Write-Verbose -Message (
$script:localizedData.TestingConfiguration -f $Name, $AvailabilityGroup, $InstanceName
)

$availabilityGroupListenerState = Get-TargetResource @parameters
if ($null -ne $availabilityGroupListenerState)
Expand Down Expand Up @@ -459,7 +501,21 @@ function Test-TargetResource
}
else
{
throw New-TerminatingError -ErrorType UnexpectedErrorFromGet -ErrorCategory InvalidResult
$errorMessage = $script:localizedData.UnexpectedErrorFromGet
New-InvalidResultException -Message $errorMessage
}

if ($result)
{
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerInDesiredState -f $Name, $AvailabilityGroup, $InstanceName
)
}
else
{
Write-Verbose -Message (
$script:localizedData.AvailabilityGroupListenerNotInDesiredState -f $Name, $AvailabilityGroup, $InstanceName
)
}

return $result
Expand Down Expand Up @@ -488,7 +544,9 @@ function Get-SQLAlwaysOnAvailabilityGroupListener
$ServerName
)

Write-Debug "Connecting to availability group $Name as $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)"
Write-Debug -Message (
$script:localizedData.DebugConnectingAvailabilityGroup -f $Name, [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
)

$sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName

Expand All @@ -499,7 +557,8 @@ function Get-SQLAlwaysOnAvailabilityGroupListener
}
else
{
throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.AvailabilityGroupNotFound -f $AvailabilityGroup, $InstanceName
New-ObjectNotFoundException -Message $errorMessage
}

return $availabilityGroupListener
Expand Down
Loading

0 comments on commit af2cbb0

Please sign in to comment.