70 lines
2.7 KiB
PowerShell
70 lines
2.7 KiB
PowerShell
function Remove-AlkamiServiceFabricApplication {
|
|
<#
|
|
.SYNOPSIS
|
|
Removes applications from the service fabric cluster.
|
|
.PARAMETER packages
|
|
One or more packages to remove from the cluster.
|
|
.PARAMETER hostname
|
|
A single server hostname from the target Service Fabric cluster.
|
|
.PARAMETER Deregister
|
|
Deregisters the image the service is using, for a fresh deployment next time.
|
|
#>
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory = $true)]
|
|
[AllowNull()]
|
|
[object[]]$Packages,
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$Hostname = "localhost",
|
|
[Parameter(Mandatory = $false)]
|
|
[switch]$Deregister
|
|
)
|
|
|
|
$loglead = Get-LogLeadName;
|
|
|
|
if(Test-IsCollectionNullOrEmpty $Packages) {
|
|
Write-Verbose "$loglead There were no packages to remove. Returning..";
|
|
return;
|
|
}
|
|
|
|
# Connect to SF cluster.
|
|
Connect-AlkamiServiceFabricCluster -hostname $Hostname | Out-Null;
|
|
$applications = Get-AlkamiServiceFabricApplications -ComputerName $Hostname;
|
|
|
|
Write-Verbose "$loglead Searching for packages to remove:";
|
|
foreach($package in $Packages) {
|
|
Write-Verbose "$loglead $($package.Name) $($package.Version)";
|
|
}
|
|
|
|
# Filter down the applications to the packages we are actually removing.
|
|
$applicationsToRemove = @();
|
|
foreach($package in $Packages) {
|
|
# Just remove the package if a version isn't specified, or otherwise a specific version if it is specified.
|
|
$applicationToRemove = $applications | Where-Object { ($_.Name -eq $package.Name) -and (($null -eq $package.Version) -or $($_.Version -eq $package.Version)); };
|
|
if($null -ne $applicationToRemove) {
|
|
$applicationsToRemove += $applicationToRemove;
|
|
}
|
|
}
|
|
|
|
if(Test-IsCollectionNullOrEmpty $applicationsToRemove) {
|
|
Write-Verbose "$loglead Found no matching packages to remove. Returning..";
|
|
return;
|
|
}
|
|
|
|
Write-Verbose "$loglead Starting removal of $($Packages.Count) package(s).";
|
|
|
|
# Remove all of the relevant SF applications.
|
|
foreach($application in $applicationsToRemove) {
|
|
|
|
Write-Host "$loglead Removing $($application.ServiceFabricApplicationName)";
|
|
Remove-ServiceFabricApplication -ApplicationName $application.ServiceFabricApplicationName -Force | Out-Null;
|
|
|
|
if($Deregister.IsPresent) {
|
|
Write-Host "$loglead Unregistering $($application.ServiceFabricApplicationTypeName)-$($application.Version)";
|
|
Unregister-ServiceFabricApplicationType -ApplicationTypeName $application.ServiceFabricApplicationTypeName -ApplicationTypeVersion $application.Version -Force;
|
|
}
|
|
}
|
|
|
|
Write-Verbose "$loglead Application removal complete.";
|
|
}
|