Skip to content

Commit

Permalink
Merge pull request #1211 from ykuijs/master
Browse files Browse the repository at this point in the history
SPSearchTopology: Fixes issue where exception was incorrectly thrown
  • Loading branch information
ykuijs committed Jun 9, 2020
2 parents 89fea3b + b5fa4f6 commit cf29794
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a call to Get-SPFarm without loading the snap-in first
- SPInstallLanguagePack
- Fixed issue with detection of Chinese language pack in SharePoint 2019
- SPSearchTopology
- Fixed issue where an issue was thrown when the FirstPartitionDirectory didn't
exist on the local server (which isn't always required)
- SPSite
- Fixed issue where the default groups were checked, even though
that parameter wasn't specified in the config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,19 @@ function Set-TargetResource
{
$networkPath = "\\$IndexPartitionServer\" + `
$params.FirstPartitionDirectory.Replace(":\", "$\")
New-Item $networkPath -ItemType Directory -Force
}

# Create the directory on the local server as it will not apply the topology without it
if ((Test-Path -Path $params.FirstPartitionDirectory) -eq $false)
{
New-Item $params.FirstPartitionDirectory -ItemType Directory -Force
try
{
$null = New-Item -Path $networkPath `
-ItemType Directory `
-Force `
-ErrorAction Stop
}
catch
{
Write-Verbose -Message ("Unable to create folder {$($params.FirstPartitionDirectory)} " + `
"on {$IndexPartitionServer}.")
Write-Verbose -Message " Error: $($_.Exception.Message)"
}
}

# Get all service service instances to assign topology components to
Expand Down Expand Up @@ -403,41 +409,61 @@ function Set-TargetResource
{
"AdminComponent"
{
New-SPEnterpriseSearchAdminComponent @NewComponentParams
Write-Verbose -Message "Adding $ComponentToAdd to run an AdminComponent"
$null = New-SPEnterpriseSearchAdminComponent @NewComponentParams
}
"CrawlComponent"
{
New-SPEnterpriseSearchCrawlComponent @NewComponentParams
Write-Verbose -Message "Adding $ComponentToAdd to run a CrawlComponent"
$null = New-SPEnterpriseSearchCrawlComponent @NewComponentParams
}
"ContentProcessingComponent"
{
New-SPEnterpriseSearchContentProcessingComponent @NewComponentParams
Write-Verbose -Message "Adding $ComponentToAdd to run a ContentProcessingComponent"
$null = New-SPEnterpriseSearchContentProcessingComponent @NewComponentParams
}
"AnalyticsProcessingComponent"
{
New-SPEnterpriseSearchAnalyticsProcessingComponent @NewComponentParams
Write-Verbose -Message "Adding $ComponentToAdd to run an AnalyticsProcessingComponent"
$null = New-SPEnterpriseSearchAnalyticsProcessingComponent @NewComponentParams
}
"QueryProcessingComponent"
{
New-SPEnterpriseSearchQueryProcessingComponent @NewComponentParams
Write-Verbose -Message "Adding $ComponentToAdd to run a QueryComponent"
$null = New-SPEnterpriseSearchQueryProcessingComponent @NewComponentParams
}
"IndexComponent"
{
$NewComponentParams.Add("IndexPartition", 0)
if ($params.ContainsKey("FirstPartitionDirectory") -eq $true)
Write-Verbose -Message "Adding $ComponentToAdd to run an IndexComponent"
$installedVersion = Get-SPDscInstalledProductVersion
if ($installedVersion.FileMajorPart -eq 15)
{
if ([string]::IsNullOrEmpty($params.FirstPartitionDirectory) -eq $false)
Write-Verbose -Message "Using SharePoint 2013"
$indexServer = (Get-SPServer $ComponentToAdd).Name
$indexComponent = (New-Object Microsoft.Office.Server.Search.Administration.Topology.IndexComponent $indexServer, 0);
$indexComponent.RootDirectory = $params.FirstPartitionDirectory
$newTopology.AddComponent($indexComponent)
}
else
{
Write-Verbose -Message "Using SharePoint 2016 or later"
$NewComponentParams.Add("IndexPartition", 0)
if ($params.ContainsKey("FirstPartitionDirectory") -eq $true)
{
$dir = $params.FirstPartitionDirectory
$NewComponentParams.Add("RootDirectory", $dir)
if ([string]::IsNullOrEmpty($params.FirstPartitionDirectory) -eq $false)
{
$dir = $params.FirstPartitionDirectory
$NewComponentParams.Add("RootDirectory", $dir)
}
}
$null = New-SPEnterpriseSearchIndexComponent @NewComponentParams
}
New-SPEnterpriseSearchIndexComponent @NewComponentParams
}
}
}
foreach ($ComponentToRemove in $ComponentsToRemove)
{
Write-Verbose -Message "Removing $($componentTypes.$CurrentSearchProperty) from $ComponentToRemove"
if ($componentTypes.$CurrentSearchProperty -eq "IndexComponent")
{
$component = Get-SPEnterpriseSearchComponent -SearchTopology $newTopology | `
Expand All @@ -455,10 +481,11 @@ function Set-TargetResource
-and ($_.ServerName -eq $ComponentToRemove)
}
}

if ($null -ne $component)
{
$component | Remove-SPEnterpriseSearchComponent -SearchTopology $newTopology `
-confirm:$false
-Confirm:$false
}
}
}
Expand All @@ -475,10 +502,11 @@ function Set-TargetResource
$_.ComponentId -eq $id
} | `
Remove-SPEnterpriseSearchComponent -SearchTopology $newTopology `
-confirm:$false
-Confirm:$false
}

# Apply the new topology to the farm
Write-Verbose -Message "Applying new Search topology"
Set-SPEnterpriseSearchTopology -Identity $newTopology
}
}
Expand Down
11 changes: 7 additions & 4 deletions tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Mocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,38 @@ public class CrawlComponent
{
public string ServerName { get; set; }
public System.Guid ComponentId { get; set; }
public System.Guid ServerId {get; set;}
public System.Guid ServerId { get; set; }
}

public class ContentProcessingComponent
{
public string ServerName { get; set; }
public System.Guid ComponentId { get; set; }
public System.Guid ServerId {get; set;}
public System.Guid ServerId { get; set; }
}

public class AnalyticsProcessingComponent
{
public string ServerName { get; set; }
public System.Guid ComponentId { get; set; }
public System.Guid ServerId {get; set;}
public System.Guid ServerId { get; set; }
}

public class QueryProcessingComponent
{
public string ServerName { get; set; }
public System.Guid ComponentId { get; set; }
public System.Guid ServerId {get; set;}
public System.Guid ServerId { get; set; }
}

public class IndexComponent
{
public IndexComponent() { }
public IndexComponent(string server, uint IndexPartitionOrdinal) { }
public string ServerName { get; set; }
public System.Guid ComponentId { get; set; }
public System.Int32 IndexPartitionOrdinal { get; set; }
public System.Guid ServerId { get; set; }
public System.String RootDirectory { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ try
return $null
}
Mock -CommandName New-SPEnterpriseSearchTopology -MockWith {
return @{ }
$returnval = @{ }
$returnval = $returnval | Add-Member -MemberType ScriptMethod `
-Name AddComponent `
-Value { } `
-PassThru `
-Force
return $returnval
}
Mock -CommandName New-SPEnterpriseSearchAdminComponent -MockWith {
return @{ }
Expand Down

0 comments on commit cf29794

Please sign in to comment.