Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aultt authored and johlju committed Aug 19, 2016
1 parent 2a46851 commit 12b924b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 60 deletions.
59 changes: 25 additions & 34 deletions DSCResources/MSFT_xSQLAOGroupEnsure/MSFT_xSQLAOGroupEnsure.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ function Set-TargetResource

$FailoverCondition = 3
$HealthCheckTimeout = 30000
$ConnectionModeInPrimary ="AllowAllConnections"
$ConnectionModeInPrimary = "AllowAllConnections"
$ConnectionModeInSecondaryRole = switch ($ReadableSecondary)
{
'None' {"AllowNoConnections"}
'ReadOnly' {"AllowAllConnections"}
'ReadIntent'{"AllowReadIntentConnectionsOnly"}
'ReadIntent' {"AllowReadIntentConnectionsOnly"}
Default {"AllowAllConnections"}
}

Expand All @@ -149,17 +149,16 @@ function Set-TargetResource
$availabilityGroup.AutomatedBackupPreference = $AutoBackupPreference
$availabilityGroup.FailureConditionLevel = $FailoverCondition
$availabilityGroup.HealthCheckTimeout = $HealthCheckTimeout
}
}
Catch
{
Throw "Failed to connect to Cluster Nodes from $($sql.ClusterName)"

Exit
}
}

#Loop through Sync nodes Create Replica Object Assign properties and add it to AvailabilityGroup
foreach ($node in $syncNodes)
{
#Loop through Sync nodes Create Replica Object Assign properties and add it to AvailabilityGroup
foreach ($node in $syncNodes)
{
Try
{
$Replica = New-Object -typename Microsoft.SqlServer.Management.Smo.AvailabilityReplica -ArgumentList $availabilityGroup, $node
Expand All @@ -176,8 +175,7 @@ function Set-TargetResource
{
Throw "Failed to add $Replica to the Availability Group $AvailabilityGroupName"
Exit
}

}
}

#Loop through ASync nodes Create Replica Object Assign properties and add it to AvailabilityGroup
Expand Down Expand Up @@ -236,50 +234,45 @@ function Set-TargetResource
}
Catch{
Throw "Failed to Add $AvailabilityGroupNameListener to $AvailabilityGroupName..."
Exit
}
}

#Add Availabilty Group to the SQL connection
Try{
$SQL.AvailabilityGroups.Add($availabilityGroup)
New-VerboseMessage -Message "Added $availabilityGroupName Availability Group to Connection"
}
}
Catch{
Throw "Unable to Add $AvailabilityGroup to $SQLServer\$SQLInstanceName"
Exit
}
}

#Create Availability Group
Try
{
Try{
$availabilityGroup.Create()
New-VerboseMessage -Message "Created Availability Group $availabilityGroupName"
}
Catch
{
}
Catch{
Throw "Unable to Create $AvailabilityGroup on $SQLServer\$SQLInstanceName"
Exit
}
}

}
"Absent"
{
Try
{
Try{
$sql.AvailabilityGroups[$AvailabilityGroupName].Drop()
New-VerboseMessage -Message "Dropped $AvailabilityGroupName"
}
}
Catch{
Throw "Unable to Drop $AvailabilityGroup on $SQLServer\$SQLInstanceName"
}
}
}
}



}


function Test-TargetResource
{
[CmdletBinding()]
Expand Down Expand Up @@ -340,15 +333,13 @@ function Test-TargetResource
Switch ($Ensure)
{
"Present"
{

$AGPresent=$sql.AvailabilityGroups.Contains($AvailabilityGroupName)

if ($AGPresent)
{$Return = $true}
else
{$Return = $false}
}
{
$AGPresent=$sql.AvailabilityGroups.Contains($AvailabilityGroupName)
if ($AGPresent)
{$Return = $true}
else
{$Return = $false}
}
"Absent"
{
if(!$sql.AvailabilityGroups[$AvailabilityGroupName])
Expand Down
23 changes: 10 additions & 13 deletions DSCResources/MSFT_xSQLAlias/MSFT_xSQLAlias.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Get-TargetResource
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name
Expand All @@ -17,13 +17,13 @@ function Get-TargetResource
Write-Verbose -Message 'Get-TargetResource'

$returnValue = @{
Name = [System.String]
Protocol = [System.String]
ServerName = [System.String]
TCPPort = [System.Int32]
PipeName = [System.String]
Ensure = [System.String]
}
Name = [System.String]
Protocol = [System.String]
ServerName = [System.String]
TCPPort = [System.Int32]
PipeName = [System.String]
Ensure = [System.String]
}

if ($null -ne (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' -Name "$Name" -ErrorAction SilentlyContinue))
{
Expand Down Expand Up @@ -54,7 +54,7 @@ function Set-TargetResource
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,
Expand Down Expand Up @@ -161,18 +161,15 @@ function Set-TargetResource
}
}
}


}


function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,
Expand Down
Binary file modified DSCResources/MSFT_xSQLAlias/MSFT_xSQLAlias.schema.mof
Binary file not shown.
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
### Unreleased
* Added resources
- xSQLServerReplication
- xSQLAlias
* Added tests for resources
- xSQLServerPermission
- xSQLServerEndpointState
Expand All @@ -345,6 +346,8 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
- Fixed the issue when trying to add a static IP to a listener was ignored.
* Fixes in xSQLAOGroupEnsure
- Added parameters to New-ListenerADObject to allow usage of a named instance.
* Pester Test for xSQLAlias
* Correction on xSQLAOGroupEnsure to pass Setup Credential Correctly

### 1.8.0.0
* Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey.
Expand All @@ -358,26 +361,13 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
- xSQLServerEndpointPermission
- xSQLServerAvailabilityGroupListener
* xSQLServerHelper
- added functions
- Import-SQLPSModule
- Get-SQLPSInstanceName
- Get-SQLPSInstance
- Get-SQLAlwaysOnEndpoint
- modified functions
- New-TerminatingError - *added optional parameter `InnerException` to be able to give the user more information in the returned message*

- added functions
- Import-SQLPSModule
- Get-SQLPSInstanceName
- Get-SQLPSInstance
- Get-SQLAlwaysOnEndpoint
- modified functions
- New-TerminatingError - *added optional parameter `InnerException` to be able to give the user more information in the returned message*
* Pester Tests for xSQLAOGroupEnsure and xSQLAlias
* Correction on xSQLAOGroupEnsure to pass Setup Credential Correctly

* Resources Added
* xSQLAlias

### 1.7.0.0

Expand Down

0 comments on commit 12b924b

Please sign in to comment.