Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"checkpointing",
"HRESULT",
"RSDB",
"RSIP"
"RSIP",
"contoso"
],
"cSpell.ignorePaths": [
".git"
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
by calling the `InitializeReportServer` CIM method. Used to complete initial
configuration after database and URL setup
([issue #2014](https://github.com/dsccommunity/SqlServerDsc/issues/2014)).
- Added public commands `Set-SqlDscRSUnattendedExecutionAccount` and
`Remove-SqlDscRSUnattendedExecutionAccount` to manage the unattended execution
account for Reporting Services. These wrap the `SetUnattendedExecutionAccount`
CIM method.
- Added public command `Get-SqlDscRSSslCertificate` to list available SSL
certificates that can be used for Reporting Services. Wraps the
`ListSSLCertificates` CIM method.
Expand Down Expand Up @@ -338,6 +342,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Prerequisites Integration Tests
- Added `svc-RS` local Windows user for Reporting Services service account
integration testing.
- `Get-SqlDscRSConfiguration`
- Added retry logic with parameters `RetryCount`, `RetryDelaySeconds`, and
`SkipRetry` to handle intermittent CIM instance retrieval failures when
the Report Server service or WMI provider is not immediately ready.

### Fixed

Expand Down
10 changes: 10 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ stages:
'tests/Integration/Commands/Get-SqlDscRSServiceAccount.Integration.Tests.ps1'
'tests/Integration/Commands/Post.ServiceAccountChange.SQL2017.RS.Integration.Tests.ps1'
'tests/Integration/Commands/Post.ServiceAccountChange.SQL2019-2022.RS.Integration.Tests.ps1'
# Group 7
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
# Group 8
'tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRSUrlReservation.Integration.Tests.ps1'
Expand Down Expand Up @@ -693,6 +696,9 @@ stages:
'tests/Integration/Commands/Set-SqlDscRSServiceAccount.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscRSServiceAccount.Integration.Tests.ps1'
'tests/Integration/Commands/Post.ServiceAccountChange.PowerBI.RS.Integration.Tests.ps1'
# Group 7
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
# Group 8
'tests/Integration/Commands/Repair-SqlDscPowerBIReportServer.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRSUrlReservation.Integration.Tests.ps1'
Expand Down Expand Up @@ -778,6 +784,9 @@ stages:
'tests/Integration/Commands/Get-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
'tests/Integration/Commands/Set-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
# Group 7
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
)
name: test
displayName: 'Run Integration Test'
Expand Down Expand Up @@ -1196,6 +1205,7 @@ stages:
- Integration_Test_Commands_SqlServer_PreparedImage
- Integration_Test_Commands_ReportingServices
- Integration_Test_Commands_BIReportServer
- Integration_Test_Commands_BIReportServer_Secure
- Integration_Test_Resources_SqlServer
- Integration_Test_Resources_SqlServer_dbatools
- Integration_Test_Resources_ReportingServices
Expand Down
15 changes: 7 additions & 8 deletions source/Public/Add-SqlDscRSSslCertificateBinding.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,13 @@ function Add-SqlDscRSSslCertificateBinding
}
catch
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
($script:localizedData.Add_SqlDscRSSslCertificateBinding_FailedToAdd -f $instanceName, $_.Exception.Message),
'ASRSSCB0001',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Configuration
)
)
$errorMessage = $script:localizedData.Add_SqlDscRSSslCertificateBinding_FailedToAdd -f $instanceName, $_.Exception.Message

$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru

$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'ASRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}

Expand Down
98 changes: 85 additions & 13 deletions source/Public/Get-SqlDscRSConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
'WindowsServiceIdentityConfigured' and methods for managing Reporting
Services configuration.

By default, if the CIM instance is not found on the first attempt, the
command will retry after a delay. This handles intermittent failures
when the Report Server service or WMI provider is not immediately ready.
Use `-SkipRetry` to disable retry behavior.

.PARAMETER InstanceName
Specifies the name of the Reporting Services instance. This is a
mandatory parameter.
Expand All @@ -25,11 +30,23 @@
If not specified, the version is automatically detected using
`Get-SqlDscRSSetupConfiguration`.

.PARAMETER RetryCount
Specifies the number of retry attempts if the CIM instance is not found.
Default is 1 retry attempt.

.PARAMETER RetryDelaySeconds
Specifies the delay in seconds between retry attempts. Default is 30
seconds.

.PARAMETER SkipRetry
If specified, skips retry attempts and throws an error immediately if
the CIM instance is not found.

.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS'

Returns the configuration CIM instance for the SSRS instance. The version
is automatically detected.
is automatically detected. Retries once after 30 seconds if not found.

.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' -Version 15
Expand All @@ -43,6 +60,18 @@
Gets the configuration CIM instance for the SSRS instance and enables
secure connection using the pipeline.

.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' -RetryCount 3 -RetryDelaySeconds 10

Returns the configuration CIM instance for the SSRS instance, retrying
up to 3 times with a 10-second delay between attempts if not found.

.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' -SkipRetry

Returns the configuration CIM instance for the SSRS instance without
any retry attempts. Throws an error immediately if not found.

.INPUTS
None.

Expand All @@ -64,7 +93,21 @@ function Get-SqlDscRSConfiguration

[Parameter()]
[System.Int32]
$Version
$Version,

[Parameter()]
[ValidateRange(1, [System.Int32]::MaxValue)]
[System.Int32]
$RetryCount = 1,

[Parameter()]
[ValidateRange(1, [System.Int32]::MaxValue)]
[System.Int32]
$RetryDelaySeconds = 30,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$SkipRetry
)

if (-not $PSBoundParameters.ContainsKey('Version'))
Expand Down Expand Up @@ -102,25 +145,54 @@ function Get-SqlDscRSConfiguration
ErrorAction = 'Stop'
}

try
$maxAttempts = if ($SkipRetry.IsPresent)
{
$reportingServicesConfiguration = Get-CimInstance @getCimInstanceParameters
1
}
catch
else
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName, $_.Exception.Message
1 + $RetryCount
}

$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru) -ErrorId 'GSRSCD0003' -ErrorCategory 'InvalidOperation' -TargetObject $InstanceName
$attempt = 0
$reportingServicesConfiguration = $null

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
while ($attempt -lt $maxAttempts)
{
$attempt++

try
{
$reportingServicesConfiguration = Get-CimInstance @getCimInstanceParameters
}
catch
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName, $_.Exception.Message

$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru) -ErrorId 'GSRSCD0003' -ErrorCategory 'InvalidOperation' -TargetObject $InstanceName

$PSCmdlet.ThrowTerminatingError($errorRecord)
}

# Filter to ensure we get the correct instance if multiple are returned.
$reportingServicesConfiguration = $reportingServicesConfiguration |
Where-Object -FilterScript {
$_.InstanceName -eq $InstanceName
}

# Filter to ensure we get the correct instance if multiple are returned.
$reportingServicesConfiguration = $reportingServicesConfiguration |
Where-Object -FilterScript {
$_.InstanceName -eq $InstanceName
if ($reportingServicesConfiguration)
{
break
}

if ($attempt -lt $maxAttempts)
{
Write-Debug -Message ($script:localizedData.Get_SqlDscRSConfiguration_RetryingAfterDelay -f $InstanceName, $attempt, $maxAttempts, $RetryDelaySeconds)

Start-Sleep -Seconds $RetryDelaySeconds
}
}

if (-not $reportingServicesConfiguration)
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_ConfigurationNotFound -f $InstanceName
Expand Down
15 changes: 7 additions & 8 deletions source/Public/Get-SqlDscRSSslCertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ function Get-SqlDscRSSslCertificate
}
catch
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
($script:localizedData.Get_SqlDscRSSslCertificate_FailedToGet -f $instanceName, $_.Exception.Message),
'GSRSSC0001',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Configuration
)
)
$errorMessage = $script:localizedData.Get_SqlDscRSSslCertificate_FailedToGet -f $instanceName, $_.Exception.Message

$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru

$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSSC0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
}
15 changes: 7 additions & 8 deletions source/Public/Get-SqlDscRSSslCertificateBinding.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ function Get-SqlDscRSSslCertificateBinding
}
catch
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
($script:localizedData.Get_SqlDscRSSslCertificateBinding_FailedToGet -f $instanceName, $_.Exception.Message),
'GSRSSCB0001',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Configuration
)
)
$errorMessage = $script:localizedData.Get_SqlDscRSSslCertificateBinding_FailedToGet -f $instanceName, $_.Exception.Message

$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru

$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
}
17 changes: 8 additions & 9 deletions source/Public/Remove-SqlDscRSSslCertificateBinding.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function Remove-SqlDscRSSslCertificateBinding
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
[OutputType([System.Object])]
[OutputType([Microsoft.Management.Infrastructure.CimInstance])]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
Expand Down Expand Up @@ -169,14 +169,13 @@ function Remove-SqlDscRSSslCertificateBinding
}
catch
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
($script:localizedData.Remove_SqlDscRSSslCertificateBinding_FailedToRemove -f $instanceName, $_.Exception.Message),
'RSRSSCB0001',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Configuration
)
)
$errorMessage = $script:localizedData.Remove_SqlDscRSSslCertificateBinding_FailedToRemove -f $instanceName, $_.Exception.Message

$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru

$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'RSRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration

$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}

Expand Down
Loading
Loading