Skip to content

Commit 064f059

Browse files
authored
Initialize-SqlDscRS: Add new command (#2400)
1 parent b9d7f8f commit 064f059

File tree

44 files changed

+1750
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1750
-509
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
177177
- Added public command `Install-SqlDscFailoverCluster` to install SQL Server in
178178
a failover cluster configuration. Extracted from `Install-SqlDscServer`
179179
InstallFailoverCluster parameter set.
180+
- Added public command `Restart-SqlDscRSService` to restart the Windows service
181+
for SQL Server Reporting Services or Power BI Report Server. Supports waiting
182+
for dependent services, configurable wait time, and accepts pipeline input
183+
from `Get-SqlDscRSConfiguration`.
184+
- Added public command `Test-SqlDscRSInitialized` to test whether a Reporting
185+
Services instance is initialized by checking the `IsInitialized` property of
186+
the configuration CIM instance
187+
([issue #2014](https://github.com/dsccommunity/SqlServerDsc/issues/2014)).
188+
- Added public command `Initialize-SqlDscRS` to initialize Reporting Services
189+
by calling the `InitializeReportServer` CIM method. Used to complete initial
190+
configuration after database and URL setup
191+
([issue #2014](https://github.com/dsccommunity/SqlServerDsc/issues/2014)).
180192

181193
### Changed
182194

@@ -210,6 +222,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
210222
([issue #2017](https://github.com/dsccommunity/SqlServerDsc/issues/2017))
211223
([issue #2019](https://github.com/dsccommunity/SqlServerDsc/issues/2019))
212224
([issue #2021](https://github.com/dsccommunity/SqlServerDsc/issues/2021)).
225+
- Refactored to use the public command `Restart-SqlDscRSService` for restarting
226+
the Reporting Services Windows service instead of calling the private
227+
function `Restart-ReportingServicesService` directly.
228+
- Refactored to use the public commands `Test-SqlDscRSInitialized` and
229+
`Initialize-SqlDscRS` for checking and performing Reporting Services
230+
initialization instead of accessing the `IsInitialized` property and
231+
calling the CIM method directly
232+
([issue #2014](https://github.com/dsccommunity/SqlServerDsc/issues/2014)).
213233
- `Assert-SetupActionProperties`
214234
- Refactored to use the command `Get-FileVersion` from the DscResource.Common
215235
module instead of the private function `Get-FileVersionInformation`

azure-pipelines.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ stages:
552552
'tests/Integration/Commands/Remove-SqlDscRSUrlReservation.Integration.Tests.ps1'
553553
'tests/Integration/Commands/Set-SqlDscRSUrlReservation.Integration.Tests.ps1'
554554
'tests/Integration/Commands/Set-SqlDscRSDatabaseConnection.Integration.Tests.ps1'
555+
'tests/Integration/Commands/Restart-SqlDscRSService.Integration.Tests.ps1'
556+
'tests/Integration/Commands/Request-SqlDscRSDatabaseUpgradeScript.Integration.Tests.ps1'
557+
'tests/Integration/Commands/Test-SqlDscRSInitialized.Integration.Tests.ps1'
558+
# Group 4
559+
'tests/Integration/Commands/Initialize-SqlDscRS.Integration.Tests.ps1'
555560
# Group 8
556561
'tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1'
557562
# Group 9
@@ -631,6 +636,10 @@ stages:
631636
'tests/Integration/Commands/Remove-SqlDscRSUrlReservation.Integration.Tests.ps1'
632637
'tests/Integration/Commands/Set-SqlDscRSUrlReservation.Integration.Tests.ps1'
633638
'tests/Integration/Commands/Set-SqlDscRSDatabaseConnection.Integration.Tests.ps1'
639+
'tests/Integration/Commands/Restart-SqlDscRSService.Integration.Tests.ps1'
640+
'tests/Integration/Commands/Test-SqlDscRSInitialized.Integration.Tests.ps1'
641+
# Group 4
642+
'tests/Integration/Commands/Initialize-SqlDscRS.Integration.Tests.ps1'
634643
# Group 8
635644
'tests/Integration/Commands/Repair-SqlDscPowerBIReportServer.Integration.Tests.ps1'
636645
# Group 9

source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function Get-TargetResource
8080
$getTargetResourceResult.DatabaseInstanceName = 'MSSQLSERVER'
8181
}
8282

83-
$isInitialized = $rsConfiguration.IsInitialized
83+
$isInitialized = $rsConfiguration | Test-SqlDscRSInitialized
8484

8585
[System.Boolean] $getTargetResourceResult.IsInitialized = $isInitialized
8686

@@ -348,7 +348,7 @@ function Set-TargetResource
348348
$language = $wmiOperatingSystem.OSLanguage
349349
$restartReportingService = $false
350350

351-
if (-not $rsConfiguration.IsInitialized)
351+
if (-not ($rsConfiguration | Test-SqlDscRSInitialized))
352352
{
353353
Write-Verbose -Message "Initializing Reporting Services on $DatabaseServerName\$DatabaseInstanceName."
354354

@@ -456,7 +456,7 @@ function Set-TargetResource
456456
#>
457457
Write-Verbose -Message $script:localizedData.RestartToFinishInitialization
458458

459-
Restart-ReportingServicesService -ServiceName $reportingServicesServiceName -WaitTime 30
459+
Restart-SqlDscRSService -ServiceName $reportingServicesServiceName -WaitTime 30 -Force
460460

461461
<#
462462
Wait for the service to be fully ready after restart before attempting
@@ -481,7 +481,7 @@ function Set-TargetResource
481481
InitializeReportServer will fail on SQL Server Standard and
482482
lower editions.
483483
#>
484-
if (-not $rsConfiguration.IsInitialized)
484+
if (-not ($rsConfiguration | Test-SqlDscRSInitialized))
485485
{
486486
Write-Verbose -Message "Did not help restarting the Reporting Services service, running the CIM method to initialize report server on $DatabaseServerName\$DatabaseInstanceName for instance ID '$($rsConfiguration.InstallationID)'."
487487

@@ -498,15 +498,7 @@ function Set-TargetResource
498498

499499
$restartReportingService = $true
500500

501-
$invokeRsCimMethodParameters = @{
502-
CimInstance = $rsConfiguration
503-
MethodName = 'InitializeReportServer'
504-
Arguments = @{
505-
InstallationId = $rsConfiguration.InstallationID
506-
}
507-
}
508-
509-
Invoke-RsCimMethod @invokeRsCimMethodParameters -ErrorAction 'Stop'
501+
$rsConfiguration | Initialize-SqlDscRS -Force -ErrorAction 'Stop'
510502
}
511503
else
512504
{
@@ -646,7 +638,7 @@ function Set-TargetResource
646638
elseif ( $restartReportingService -and (-not $SuppressRestart) )
647639
{
648640
Write-Verbose -Message $script:localizedData.Restart
649-
Restart-ReportingServicesService -ServiceName $reportingServicesServiceName -WaitTime 30
641+
Restart-SqlDscRSService -ServiceName $reportingServicesServiceName -WaitTime 30 -Force
650642

651643
<#
652644
Wait for the service to be fully ready after restart before attempting
@@ -850,81 +842,3 @@ function Test-TargetResource
850842

851843
$result
852844
}
853-
854-
<#
855-
.SYNOPSIS
856-
A wrapper for Invoke-CimMethod to be able to handle errors in one place.
857-
858-
.PARAMETER CimInstance
859-
The CIM instance object that contains the method to call.
860-
861-
.PARAMETER MethodName
862-
The method to call in the CIM Instance object.
863-
864-
.PARAMETER Arguments
865-
The arguments that should be
866-
#>
867-
function Invoke-RsCimMethod
868-
{
869-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('AvoidThrowOutsideOfTry', '', Justification = 'Because the code throws based on an prior expression')]
870-
[CmdletBinding()]
871-
[OutputType([Microsoft.Management.Infrastructure.CimMethodResult])]
872-
param
873-
(
874-
875-
[Parameter(Mandatory = $true)]
876-
[Microsoft.Management.Infrastructure.CimInstance]
877-
$CimInstance,
878-
879-
[Parameter(Mandatory = $true)]
880-
[System.String]
881-
$MethodName,
882-
883-
[Parameter()]
884-
[System.Collections.Hashtable]
885-
$Arguments
886-
)
887-
888-
$invokeCimMethodParameters = @{
889-
MethodName = $MethodName
890-
ErrorAction = 'Stop'
891-
}
892-
893-
if ($PSBoundParameters.ContainsKey('Arguments'))
894-
{
895-
$invokeCimMethodParameters['Arguments'] = $Arguments
896-
}
897-
898-
$invokeCimMethodResult = $CimInstance | Invoke-CimMethod @invokeCimMethodParameters
899-
900-
<#
901-
Successfully calling the method returns $invokeCimMethodResult.HRESULT -eq 0.
902-
If an general error occur in the Invoke-CimMethod, like calling a method
903-
that does not exist, returns $null in $invokeCimMethodResult.
904-
905-
cSpell: ignore HRESULT
906-
#>
907-
if ($invokeCimMethodResult -and $invokeCimMethodResult.HRESULT -ne 0)
908-
{
909-
if ($invokeCimMethodResult | Get-Member -Name 'ExtendedErrors')
910-
{
911-
<#
912-
The returned object property ExtendedErrors is an array
913-
so that needs to be concatenated.
914-
#>
915-
$errorMessage = $invokeCimMethodResult.ExtendedErrors -join ';'
916-
}
917-
else
918-
{
919-
$errorMessage = $invokeCimMethodResult.Error
920-
}
921-
922-
throw 'Method {0}() failed with an error. Error: {1} (HRESULT:{2})' -f @(
923-
$MethodName
924-
$errorMessage
925-
$invokeCimMethodResult.HRESULT
926-
)
927-
}
928-
929-
return $invokeCimMethodResult
930-
}

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
'Connect-SQLAnalysis'
3232
'Get-SqlInstanceMajorVersion'
3333
'Restart-SqlService'
34-
'Restart-ReportingServicesService'
3534
'Update-AvailabilityGroupReplica'
3635
'Test-LoginEffectivePermissions'
3736
'Test-AvailabilityReplicaSeedingModeAutomatic'

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,64 +1128,6 @@ function Restart-SqlClusterService
11281128
}
11291129
}
11301130

1131-
<#
1132-
.SYNOPSIS
1133-
Restarts a Reporting Services instance and associated services
1134-
1135-
.PARAMETER ServiceName
1136-
Name of the service to be restarted.
1137-
1138-
.PARAMETER WaitTime
1139-
Number of seconds to wait between service stop and service start.
1140-
Default value is 0 seconds.
1141-
#>
1142-
function Restart-ReportingServicesService
1143-
{
1144-
[CmdletBinding()]
1145-
param
1146-
(
1147-
[Parameter(Mandatory = $true)]
1148-
[System.String]
1149-
$ServiceName,
1150-
1151-
[Parameter()]
1152-
[System.UInt16]
1153-
$WaitTime = 0
1154-
)
1155-
1156-
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose
1157-
$reportingServicesService = Get-Service -Name $ServiceName
1158-
1159-
<#
1160-
Get all dependent services that are running.
1161-
There are scenarios where an automatic service is stopped and should
1162-
not be restarted automatically.
1163-
#>
1164-
$dependentService = $reportingServicesService.DependentServices | Where-Object -FilterScript {
1165-
$_.Status -eq 'Running'
1166-
}
1167-
1168-
Write-Verbose -Message ($script:localizedData.RestartService -f $reportingServicesService.DisplayName) -Verbose
1169-
1170-
Write-Verbose -Message ($script:localizedData.StoppingService -f $reportingServicesService.DisplayName) -Verbose
1171-
$reportingServicesService | Stop-Service -Force
1172-
1173-
if ($WaitTime -ne 0)
1174-
{
1175-
Write-Verbose -Message ($script:localizedData.WaitServiceRestart -f $WaitTime, $reportingServicesService.DisplayName) -Verbose
1176-
Start-Sleep -Seconds $WaitTime
1177-
}
1178-
1179-
Write-Verbose -Message ($script:localizedData.StartingService -f $reportingServicesService.DisplayName) -Verbose
1180-
$reportingServicesService | Start-Service
1181-
1182-
# Start dependent services
1183-
$dependentService | ForEach-Object -Process {
1184-
Write-Verbose -Message ($script:localizedData.StartingDependentService -f $_.DisplayName) -Verbose
1185-
$_ | Start-Service
1186-
}
1187-
}
1188-
11891131
<#
11901132
.SYNOPSIS
11911133
Executes the alter method on an Availability Group Replica object.

source/Modules/SqlServerDsc.Common/en-US/SqlServerDsc.Common.strings.psd1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ ConvertFrom-StringData @'
2424
BringSqlServerAgentClusterResourcesOnline = Bringing the SQL Server Agent resource online. (SQLCOMMON0036)
2525
GetServiceInformation = Getting information about service '{0}'. (SQLCOMMON0037)
2626
RestartService = '{0}' service is restarting. (SQLCOMMON0038)
27-
StoppingService = '{0}' service is stopping. (SQLCOMMON0039)
28-
StartingService = '{0}' service is starting. (SQLCOMMON0040)
29-
WaitServiceRestart = Waiting {0} seconds before starting service '{1}'. (SQLCOMMON0041)
3027
StartingDependentService = Starting service '{0}'. (SQLCOMMON0042)
3128
WaitingInstanceTimeout = Waiting for instance {0}\\{1} to report status online, with a timeout value of {2} seconds. (SQLCOMMON0043)
3229
FailedToConnectToInstanceTimeout = Failed to connect to the instance {0}\\{1} within the timeout period of {2} seconds. (SQLCOMMON0044)

source/Modules/SqlServerDsc.Common/sv-SE/SqlServerDsc.Common.strings.psd1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ ConvertFrom-StringData @'
3030
BringSqlServerAgentClusterResourcesOnline = Tar SQL Server Agent resurser online. (SQLCOMMON0036)
3131
GetServiceInformation = Hämtar information om SQL Server-tjänst '{0}'. (SQLCOMMON0037)
3232
RestartService = '{0}' service is restarting. (SQLCOMMON0038)
33-
StoppingService = '{0}' service is stopping. (SQLCOMMON0039)
34-
StartingService = '{0}' service is starting. (SQLCOMMON0040)
35-
WaitServiceRestart = Waiting {0} seconds before starting service '{1}'. (SQLCOMMON0041)
3633
StartingDependentService = Startar tjänst {0} (SQLCOMMON0042)
3734
WaitingInstanceTimeout = Waiting for instance {0}\\{1} to report status online, with a timeout value of {2} seconds. (SQLCOMMON0043)
3835
FailedToConnectToInstanceTimeout = Failed to connect to the instance {0}\\{1} within the timeout period of {2} seconds. (SQLCOMMON0044)

source/Public/Get-SqlDscRSConfiguration.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#>
5252
function Get-SqlDscRSConfiguration
5353
{
54-
# cSpell: ignore PBIRS
5554
[CmdletBinding()]
5655
[OutputType([Microsoft.Management.Infrastructure.CimInstance])]
5756
param

source/Public/Get-SqlDscRSPackage.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#>
4747
function Get-SqlDscRSPackage
4848
{
49-
# cSpell: ignore PBIRS
5049
[CmdletBinding()]
5150
[OutputType([System.Diagnostics.FileVersionInfo])]
5251
param

source/Public/Get-SqlDscRSSetupConfiguration.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#>
5050
function Get-SqlDscRSSetupConfiguration
5151
{
52-
# cSpell: ignore PBIRS
5352
[CmdletBinding()]
5453
[OutputType([PSCustomObject[]])]
5554
param

0 commit comments

Comments
 (0)