-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to change Service Fabric reliable registry.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<# | ||
.Synopsis.DESCRIPTION | ||
This script set HPC related properties from service fabric cluster property store | ||
.EXAMPLE | ||
Set-HpcReliableProperty.ps1 -PropertyName SSLThumbprint -PropertyValue C54DA9DE74AB45957EF04A72EC893199A238908B | ||
#> | ||
Param | ||
( | ||
[Parameter(Mandatory=$false)] | ||
[String] $ConnectionEndpoint = "", | ||
|
||
[Parameter(Mandatory=$true)] | ||
[String] $PropertyName, | ||
|
||
[Parameter(Mandatory=$true)] | ||
$PropertyValue | ||
) | ||
|
||
$ccpHome = Get-ChildItem env:CCP_HOME | ||
Add-Type -Path "$($ccpHome.Value)bin\HpcCommon.dll" | ||
|
||
$script:ParentNames = [Microsoft.Hpc.HpcConstants]::ParentNames | ||
$script:ReliableProperties = [Microsoft.Hpc.HpcConstants]::ReliableProperties | ||
if($ReliableProperties.ContainsKey($PropertyName) -eq $false) | ||
{ | ||
throw "Property name $PropertyName is not existed for current cluster" | ||
} | ||
$prop = $ReliableProperties[$PropertyName] | ||
if($prop.ReadOnly) | ||
{ | ||
throw "Property name $PropertyName is not allowed to modify" | ||
} | ||
$propValue = $PropertyValue | ||
$type = $prop.ValueType | ||
if($type -eq [Int32]) | ||
{ | ||
$type = [Long] | ||
[Long]$propValue = $PropertyValue | ||
} | ||
elseif($type -eq [String[]]) | ||
{ | ||
$type = [String] | ||
[String]$propValue = [String[]]$PropertyValue -join "," | ||
} | ||
|
||
[Uri]$parentName = new-object system.uri("fabric:/$($prop.ParentName -replace '\\','/')".ToLower()) | ||
[String]$propName = $PropertyName | ||
if([String]::IsNullOrWhiteSpace($ConnectionEndpoint)) | ||
{ | ||
$cluster = Connect-ServiceFabricCluster | ||
} | ||
else | ||
{ | ||
$cluster = Connect-ServiceFabricCluster -ConnectionEndpoint $ConnectionEndpoint | ||
} | ||
|
||
$client = $cluster.FabricClient.PropertyManager | ||
|
||
$CreateNameAsync = $client.GetType().GetMethod("CreateNameAsync", [Type[]]@([Uri])) | ||
[Object[]]$params = @($parentName) | ||
$CreateNameAsync.Invoke($client,$params).Result | Out-Null | ||
|
||
[Object[]]$params = @($parentName,$propName,$propValue) | ||
$PutPropertyAsync = $client.GetType().GetMethod("PutPropertyAsync", [Type[]]@([Uri], [String], $type)) | ||
$PutPropertyAsync.Invoke($client,$params).Result | ||
Write-Host "Update $PropertyName to $PropertyValue" |