Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit of Get-DbaAvailabilityGroup #251

Merged
merged 4 commits into from
Oct 29, 2016
Merged

initial commit of Get-DbaAvailabilityGroup #251

merged 4 commits into from
Oct 29, 2016

Conversation

wsmelton
Copy link
Member

@wsmelton wsmelton commented Oct 9, 2016

Initial commit

@dansqldba dansqldba changed the title Initial commit of new command Get-DbaAvailabilityGroup initial commit of Get-DbaAvailabilityGroup Oct 10, 2016
@dansqldba dansqldba modified the milestone: October 2016 Release Oct 10, 2016
@potatoqualitee
Copy link
Member

potatoqualitee commented Oct 19, 2016

@ClaudioESSilva do you have an environment to support testing for this command? If so, would you be available to do so this week?

Here is the QA checklist

  • Working/useful help content, including link to command on dbatools web site
  • All examples work as advertised
  • Does not contain template content
  • Does not contain excessive/unnecessary amounts of comments
  • Works remotely
  • Works locally
  • Works on lower versions or throws error specifying version not supported
  • Works with named instances
  • Works with clustered instances
  • Handles offline/read only databases
  • Supports multiple servers (at the command line or piped from Get-SqlRegisteredServerName)
  • No un-handled errors which stop the command working with multiple servers

@ClaudioESSilva ClaudioESSilva self-assigned this Oct 19, 2016
@ClaudioESSilva
Copy link
Collaborator

@ctrlbold I have and I am.

Copy link
Collaborator

@ClaudioESSilva ClaudioESSilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main decision is if we go and use multi server or not and dynamic parameters

Param (
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Alias("ServerInstance", "SqlInstance")]
[object]$SqlServer,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this command supports mutiple servers?
I vote yes. I want be able to do something like @('server1', 'server2') | Get-SqlAvailabilityGroup.

If yes this should be an array [object[]]$SqlServer and we have to add foreach loop on process moving the code inside begin block to there.

[switch]$IsPrimary
)

# DynamicParam { if ($sqlserver) { return Get-ParamSqlDatabases -SqlServer $sqlserver -SqlCredential $SqlCredential } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help with this?

Change to:
DynamicParam { if ($sqlserver) { return Get-ParamSqlAvailabilityGroups -SqlServer $sqlserver -SqlCredential $SqlCredential } }

And add this block code to DynamicParams.ps1 files

Function Get-ParamSqlAvailabilityGroups
{
<#
 .SYNOPSIS
 Internal function. Returns System.Management.Automation.RuntimeDefinedParameterDictionary
 filled with ProxyAccounts from specified SQL Server Job Server (SQL Agent).
#>
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [Alias("ServerInstance","SqlInstance")]
        [object]$SqlServer,
        [System.Management.Automation.PSCredential]$SqlCredential
    )

    try { $server = Connect-SqlServer -SqlServer $SqlServer -SqlCredential $SqlCredential -ParameterConnection }
    catch { return }

    $list = @()

    # Populate arrays
    $list = $server.AvailabilityGroups.Name

    # Reusable parameter setup
    $newparams = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
    $attributes = New-Object System.Management.Automation.ParameterAttribute

    $attributes.ParameterSetName = "__AllParameterSets"
    $attributes.Mandatory = $false
    $attributes.Position = 3

    # Database list parameter setup
    if ($list) { $validationset = New-Object System.Management.Automation.ValidateSetAttribute -ArgumentList $list }
    $attributeCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
    $attributeCollection.Add($attributes)
    if ($list) { $attributeCollection.Add($validationset) }

    $AvailabilityGroups = New-Object -Type System.Management.Automation.RuntimeDefinedParameter("AvailabilityGroups", [String[]], $attributeCollection)

    $newparams.Add("AvailabilityGroups", $AvailabilityGroups)
    $server.ConnectionContext.Disconnect()

    return $newparams
}

[object]$SqlServer,
[object]$SqlCredential,
[switch]$Detailed,
[string]$AvailabilityGroupName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we will support dynamic param, this one should be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until fix is in place where dynamic parameters actually show up in help, I don't use them. Considering this would likely be a parameter that will/should get used I don't care to have it hidden.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is coming this month, but I would prefer that we try to be as standardized as possible and always try to support DynamicParams when possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the measure or test that passes to say dynamic parameters should be used?

I would also wonder where will dynamic parameters work? Examples I see folks using is in ISE, which I don't use. So do they work on the command line (support tab completion)?

{
if (!$server.IsHadrEnabled)
{
Return "Availability Group is not configured."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runned against SQL Server lower than 2012 (when AG feature appears) and the message is "Availability Group is not configured."

I suggest to validate server major version and if lower than 11 then say something like "Availability Groups is available only on SQL Server 2012 (v11) or higher versions. Server '$server' has version $($server.Major). Skipping."

We can validate the edition, too. AG is only available on Enterprise Edition so if running on, for example, Standard Edition should say "Availability Groups feature is only available on Entrepise edition. Server '$Server' is running '$server.Edition'. Skipping."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, being that Connect-SqlServer was going to be updated to have the version flags, figured wait until that is done. Instead of duplicating code.

Copy link
Member

@potatoqualitee potatoqualitee Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like this to be standard as well. It helps because I can do mass finds and replaces. In addition, it's part of the QA checks that we gotta check.

[object]$SqlCredential,
[switch]$Detailed,
[string]$AvailabilityGroupName,
[switch]$IsPrimary
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this parameter needs the $AvailabilityGroupName and if we don't use dynamic parameters, we should set a PARAMETERSET which enforce the mandatory of both parameters.
If we will use dynamic parameter maybe we should validate this on the beginning of the Process instead after get all the info.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already tried that and it does not work correctly but also IsPrimary should not be a required parameter if someone wants to pull back specific AG info.

@potatoqualitee
Copy link
Member

Sorry for the delay @wsmelton, gotta build a new AG cluster to test. But at least I'll finally have AGs in the lab again 💃

Shawn Melton added 2 commits October 29, 2016 09:17
…fied output for IsPrimary, addtion of switches for -simple, -detailed.

- Added check for major version, throw error if less than 11 (SQL Server 2012)
@potatoqualitee potatoqualitee merged commit f886dee into dataplat:development Oct 29, 2016
@wsmelton wsmelton deleted the NewCommand-Get-DbaAvailabilityGroup branch December 12, 2016 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants