Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cmdlet that downloads files from Service Fabric's image store
# 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
You can’t perform that action at this time.