Skip to content

Instantly share code, notes, and snippets.

@randomnote1
Last active Oct 30, 2017
Embed
What would you like to do?
xSQLServer: Make Resources Be Cluster Aware

...

xSQLServerAlwaysOnAvailabilityGroup

...

Parameters

...

  • [Boolean] ProcessOnlyOnActiveNode (Write): Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance.

Read-Only Properties from Get-TargetResource

...

  • [Boolean] IsActiveNode (Read): Determines if the current node is actively hosting the SQL Server instance.

...

Change log for xSQLServer

Unreleased

  • Changes to xSQLServerResource
    • Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance (issue #123).
function Get-TargetResource
{
...
# Is this node actively hosting the SQL instance?
$isActiveNode = Test-ActiveNode -ServerObject $serverObject
# Create the return object. Default ensure to Absent.
$getTargetResourceResults = @{
...
# Add the read-only property "IsActiveNode"
IsActiveNode = $isActiveNode
...
}
...
return $getTargetResourceResults
}
<#
...
.PARAMETER ProcessOnlyOnActiveNode
Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance.
Not used in Set-TargetResource.
#>
function Set-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
Param
(
...
[Parameter()]
[Boolean]
$ProcessOnlyOnActiveNode
)
...
}
<#
.PARAMETER ProcessOnlyOnActiveNode
Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance.
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
Param
(
...
[Parameter()]
[Boolean]
$ProcessOnlyOnActiveNode
)
...
$getTargetResourceResult = Get-TargetResource @getTargetResourceParameters
<#
If this is supposed to process only the active node, and this is not the
active node, don't bother evaluating the test.
#>
if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode )
{
# Use localization if the resource has been converted
New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName )
return $result
}
}
ClassVersion("1.0.0.0"), FriendlyName("xSQLServerResource")]
class MSFT_xSQLServerResource : OMI_BaseResource
{
...
[Write, Description("Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance.")] Boolean ProcessOnlyOnActiveNode;
...
[Read, Description("Determines if the current node is actively hosting the SQL Server instance.")] Boolean IsActiveNode;
};
<#
.EXAMPLE
This example shows how to ...
In the event this is applied to a Failover Cluster Instance (FCI), the
ProcessOnlyOnActiveNode property will tell the Test-TargetResource function
to evaluate if any changes are needed if the node is actively hosting the
SQL Server instance.
#>
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
SQLInstanceName = 'MSSQLSERVER'
ProcessOnlyOnActiveNode = $true
...
}
)
}
Configuration Example
{
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment