Created
March 9, 2017 07:00
-
-
Save aelij/6f811d741b67b9feba777d275f136374 to your computer and use it in GitHub Desktop.
Cmdlet that downloads files from Service Fabric's image store
This file contains hidden or 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
# Examples: | |
# | |
# List image store content: | |
# $connectionString = Get-ServiceFabricImageStoreConnectionString | |
# Get-ServiceFabricApplicationType | % { Get-ServiceFabricImageStoreContent -Application -ApplicationTypeName $_.ApplicationTypeName -ApplicationTypeVersion $_.ApplicationTypeVersion -ImageStoreConnectionString $connectionString } | |
# > StoreRelativePath : Store\Application1Type\Stateless1Pkg.Code.1.0.0 | |
# > Type : Folder [5 files] | |
# > ServiceManifestName : Stateless1Pkg | |
# > ServiceManifestVersion : 1.0.0 | |
# > ApplicationVersion : 1.0.0 | |
# | |
# Download a folder (or a file): | |
# Download-ServiceFabricImageStoreContent -StoreRelativePath 'Store\Application1Type\Stateless1Pkg.Code.1.0.0' -TargetPath .\code | |
function Download-ServiceFabricImageStoreContent | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[String] $StoreRelativePath, | |
[Parameter(Mandatory=$true)] | |
[String] $TargetPath | |
) | |
$ErrorActionPreference = 'Stop' | |
$TargetPath = [IO.Path]::GetFullPath([IO.Path]::Combine((Get-Location), $TargetPath)).TrimEnd('.') | |
$store = Get-ServiceFabricImageStore | |
$store.DownloadContent($StoreRelativePath, $TargetPath, [TimeSpan]::FromMinutes(10), 'AtomicCopy') | |
Write-Output "Downloaded $RelativePath" | |
} | |
function Get-ServiceFabricImageStore | |
{ | |
[CmdletBinding()] | |
Param () | |
$connectionString = Get-ServiceFabricImageStoreConnectionString | |
$factoryMethod = [Type]::GetType('System.Fabric.Management.ImageStore.ImageStoreFactory, System.Fabric.Management', $true). ` | |
GetMethod('CreateImageStore', ('NonPublic', 'Public', 'Static'), $null, ([string], [string], [string[]], $ClusterConnection.GetType().GetProperty('SecurityCredentials').PropertyType, [string], [bool]), $null); | |
if (!$factoryMethod) | |
{ | |
throw "Unable to find the image store factory method" | |
} | |
$store = $factoryMethod.Invoke($null, ($connectionString, $null, $ClusterConnection.ConnectionEndpoint, $ClusterConnection.SecurityCredentials, [IO.Path]::GetTempPath(), $false)) | |
return $store | |
} | |
function Get-ServiceFabricImageStoreConnectionString | |
{ | |
[CmdletBinding()] | |
Param () | |
$clusterManifest = [xml] (Get-ServiceFabricClusterManifest) | |
$managementSection = $clusterManifest.ClusterManifest.FabricSettings.Section | ? { $_.Name -eq 'Management' } | |
[string] $connectionString = $managementSection.ChildNodes | ? { $_.Name -eq 'ImageStoreConnectionString' } | Select-Object -Expand Value | |
return $connectionString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment