Skip to content

Commit

Permalink
Changes to SqlAG
Browse files Browse the repository at this point in the history
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
    to ServerName and InstanceName respectivly (issue dsccommunity#308).
  • Loading branch information
johlju committed Dec 1, 2017
1 parent 9a1080c commit 4f3b010
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 187 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
- Fixed unit tests for Get-TargetResource to ensure correctly testing return
values ([issue #849](https://github.com/PowerShell/xSQLServer/issues/849))
- Changes to xSQLServerAlwaysOnAvailabilityGroup
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
- Refactored the unit tests to allow them to be more user friendly and to test
additional SQLServer variations.
- Each test will utilize the Import-SQLModuleStub to ensure the correct
Expand Down
52 changes: 26 additions & 26 deletions DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare
.PARAMETER Name
The name of the availability group.
.PARAMETER SQLServer
.PARAMETER ServerName
Hostname of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
Name of the SQL instance to be configured.
#>
function Get-TargetResource
Expand All @@ -27,15 +27,15 @@ function Get-TargetResource

[Parameter(Mandatory = $true)]
[String]
$SQLServer,
$ServerName,

[Parameter(Mandatory = $true)]
[String]
$SQLInstanceName
$InstanceName
)

# Connect to the instance
$serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

# Define current version for check compatibility
$sqlMajorVersion = $serverObject.Version.Major
Expand All @@ -56,8 +56,8 @@ function Get-TargetResource
# Create the return object. Default ensure to Absent.
$alwaysOnAvailabilityGroupResource = @{
Name = $Name
SQLServer = $SQLServer
SQLInstanceName = $SQLInstanceName
ServerName = $ServerName
InstanceName = $InstanceName
Ensure = 'Absent'
IsActiveNode = $isActiveNode
}
Expand Down Expand Up @@ -98,10 +98,10 @@ function Get-TargetResource
.PARAMETER Name
The name of the availability group.
.PARAMETER SQLServer
.PARAMETER ServerName
Hostname of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
Name of the SQL instance to be configured.
.PARAMETER Ensure
Expand Down Expand Up @@ -155,11 +155,11 @@ function Set-TargetResource

[Parameter(Mandatory = $true)]
[String]
$SQLServer,
$ServerName,

[Parameter(Mandatory = $true)]
[String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
Expand Down Expand Up @@ -235,12 +235,12 @@ function Set-TargetResource
Import-SQLPSModule

# Connect to the instance
$serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

# Determine if HADR is enabled on the instance. If not, throw an error
if ( -not $serverObject.IsHadrEnabled )
{
throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $SQLInstanceName -ErrorCategory NotImplemented
throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $InstanceName -ErrorCategory NotImplemented
}

# Define current version for check compatibility
Expand All @@ -265,12 +265,12 @@ function Set-TargetResource
}
catch
{
throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $SQLInstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception
throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $InstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception
}
}
else
{
throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $SQLInstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable
throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $InstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable
}
}
}
Expand All @@ -284,7 +284,7 @@ function Set-TargetResource
$endpoint = $serverObject.Endpoints | Where-Object { $_.EndpointType -eq 'DatabaseMirroring' }
if ( -not $endpoint )
{
throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $SQLServer, $SQLInstanceName -ErrorCategory ObjectNotFound
throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $ServerName, $InstanceName -ErrorCategory ObjectNotFound
}

if ( -not $EndpointHostName )
Expand Down Expand Up @@ -327,7 +327,7 @@ function Set-TargetResource
}
catch
{
throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $SQLInstanceName -ErrorCategory OperationStopped -InnerException $_.Exception
throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $InstanceName -ErrorCategory OperationStopped -InnerException $_.Exception
}

# Set up the parameters for the new availability group
Expand Down Expand Up @@ -477,10 +477,10 @@ function Set-TargetResource
.PARAMETER Name
The name of the availability group.
.PARAMETER SQLServer
.PARAMETER ServerName
Hostname of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
Name of the SQL instance to be configured.
.PARAMETER Ensure
Expand Down Expand Up @@ -534,11 +534,11 @@ function Test-TargetResource

[Parameter(Mandatory = $true)]
[String]
$SQLServer,
$ServerName,

[Parameter(Mandatory = $true)]
[String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
Expand Down Expand Up @@ -606,8 +606,8 @@ function Test-TargetResource
)

$getTargetResourceParameters = @{
SQLInstanceName = $SQLInstanceName
SQLServer = $SQLServer
InstanceName = $InstanceName
ServerName = $ServerName
Name = $Name
}

Expand All @@ -622,7 +622,7 @@ function Test-TargetResource
#>
if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode )
{
New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName )
New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName )
return $result
}

Expand All @@ -647,8 +647,8 @@ function Test-TargetResource
{
$parametersToCheck = @(
'Name',
'SQLServer',
'SQLInstanceName',
'ServerName',
'InstanceName',
'Ensure',
'AutomatedBackupPreference',
'AvailabilityMode',
Expand Down
4 changes: 2 additions & 2 deletions DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
class MSFT_SqlAG : OMI_BaseResource
{
[Key, Description("The name of the availability group.")] String Name;
[Required, Description("Hostname of the SQL Server to be configured.")] String SQLServer;
[Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName;
[Required, Description("Hostname of the SQL Server to be configured.")] String ServerName;
[Key, Description("Name of the SQL instance to be configured.")] String InstanceName;
[Write, Description("Specifies if the availability group should be present or absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("Specifies the automated backup preference for the availability group. Default is None"), ValueMap{"Primary","SecondaryOnly","Secondary","None"}, Values{"Primary","SecondaryOnly","Secondary","None"}] String AutomatedBackupPreference;
[Write, Description("Specifies the replica availability mode. Default is 'AsynchronousCommit'."), ValueMap{"AsynchronousCommit","SynchronousCommit"}, Values{"AsynchronousCommit","SynchronousCommit"}] String AvailabilityMode;
Expand Down
18 changes: 9 additions & 9 deletions Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
SQLInstanceName = 'MSSQLSERVER'
NodeName = '*'
InstanceName = 'MSSQLSERVER'
},

@{
Expand All @@ -34,8 +34,8 @@ Configuration Example
Ensure = 'Present'
Name = 'NT SERVICE\ClusSvc'
LoginType = 'WindowsUser'
SQLServer = $Node.NodeName
SQLInstanceName = $Node.SQLInstanceName
ServerName = $Node.NodeName
InstanceName = $Node.InstanceName
PsDscRunAsCredential = $SysAdminAccount
}

Expand All @@ -45,7 +45,7 @@ Configuration Example
DependsOn = '[SqlServerLogin]AddNTServiceClusSvc'
Ensure = 'Present'
NodeName = $Node.NodeName
InstanceName = $Node.SqlInstanceName
InstanceName = $Node.InstanceName
Principal = 'NT SERVICE\ClusSvc'
Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState'
PsDscRunAsCredential = $SysAdminAccount
Expand All @@ -57,8 +57,8 @@ Configuration Example
EndPointName = 'HADR'
Ensure = 'Present'
Port = 5022
SQLServer = $Node.NodeName
SQLInstanceName = $Node.SQLInstanceName
ServerName = $Node.NodeName
InstanceName = $Node.InstanceName
PsDscRunAsCredential = $SysAdminAccount
}

Expand All @@ -69,8 +69,8 @@ Configuration Example
{
Ensure = 'Present'
Name = 'TestAG'
SQLInstanceName = $Node.SQLInstanceName
SQLServer = $Node.NodeName
InstanceName = $Node.InstanceName
ServerName = $Node.NodeName
DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions'
PsDscRunAsCredential = $SysAdminAccount
}
Expand Down
8 changes: 4 additions & 4 deletions Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This example shows how to ensure that the Availability Group 'TestAG' does not e
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
SQLInstanceName = 'MSSQLSERVER'
NodeName = '*'
InstanceName = 'MSSQLSERVER'
},

@{
Expand Down Expand Up @@ -35,8 +35,8 @@ Configuration Example
{
Ensure = 'Absent'
Name = 'TestAG'
SQLInstanceName = $Node.SQLInstanceName
SQLServer = $Node.NodeName
InstanceName = $Node.InstanceName
ServerName = $Node.NodeName
PsDscRunAsCredential = $SysAdminAccount
}
}
Expand Down
20 changes: 10 additions & 10 deletions Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
SQLInstanceName = 'MSSQLSERVER'
InstanceName = 'MSSQLSERVER'
ProcessOnlyOnActiveNode = $true

AutomatedBackupPreference = 'Primary'
Expand All @@ -29,8 +29,8 @@ $ConfigurationData = @{
},

@{
NodeName = 'SP23-VM-SQL1'
Role = 'PrimaryReplica'
NodeName = 'SP23-VM-SQL1'
Role = 'PrimaryReplica'
}
)
}
Expand All @@ -52,8 +52,8 @@ Configuration Example
Ensure = 'Present'
Name = 'NT SERVICE\ClusSvc'
LoginType = 'WindowsUser'
SQLServer = $Node.NodeName
SQLInstanceName = $Node.SQLInstanceName
ServerName = $Node.NodeName
InstanceName = $Node.InstanceName
PsDscRunAsCredential = $SysAdminAccount
}

Expand All @@ -63,7 +63,7 @@ Configuration Example
DependsOn = '[SqlServerLogin]AddNTServiceClusSvc'
Ensure = 'Present'
NodeName = $Node.NodeName
InstanceName = $Node.SqlInstanceName
InstanceName = $Node.InstanceName
Principal = 'NT SERVICE\ClusSvc'
Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState'
PsDscRunAsCredential = $SysAdminAccount
Expand All @@ -75,8 +75,8 @@ Configuration Example
EndPointName = 'HADR'
Ensure = 'Present'
Port = 5022
SQLServer = $Node.NodeName
SQLInstanceName = $Node.SQLInstanceName
ServerName = $Node.NodeName
InstanceName = $Node.InstanceName
PsDscRunAsCredential = $SysAdminAccount
}

Expand All @@ -87,8 +87,8 @@ Configuration Example
{
Ensure = 'Present'
Name = 'TestAG'
SQLInstanceName = $Node.SQLInstanceName
SQLServer = $Node.NodeName
InstanceName = $Node.InstanceName
ServerName = $Node.NodeName
ProcessOnlyOnActiveNode = $Node.ProcessOnlyOnActiveNode

AutomatedBackupPreference = $Node.AutomatedBackupPreference
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ It will also manage the Availability Group replica on the specified node.
#### Parameters

* **`[String]` Name** _(Key)_: The name of the availability group.
* **`[String]` SQLServer** _(Required)_: Hostname of the SQL Server to be configured.
* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance to be configured.
* **`[String]` ServerName** _(Required)_: Hostname of the SQL Server to be configured.
* **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured.
* **`[String]` Ensure** _(Write)_: Specifies if the availability group should be
present or absent. Default is Present. { *Present* | Absent }
* **`[String]` AutomatedBackupPreference** _(Write)_: Specifies the automated backup
Expand Down
Loading

0 comments on commit 4f3b010

Please sign in to comment.