105 lines
5.0 KiB
PowerShell
105 lines
5.0 KiB
PowerShell
|
function Get-BadPackages {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Determine if some packages are on the wrong servers. Utilized by Classify-Packages.
|
||
|
|
||
|
.PARAMETER DebugMetadata
|
||
|
Meta object used to determine what goes where.
|
||
|
|
||
|
.PARAMETER PackageMetadata
|
||
|
Packages object to populate.
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
param(
|
||
|
$DebugMetadata,
|
||
|
$PackageMetadata
|
||
|
)
|
||
|
# Produce a list of bad packages on the wrong servers, to be uninstalled.
|
||
|
if (!(Test-IsCollectionNullOrEmpty $DebugMetadata.WebServerPackages)) {
|
||
|
$packages = @()
|
||
|
foreach($package in $DebugMetadata.WebServerPackages) {
|
||
|
if($null -ne $package) {
|
||
|
## if the package was found on the web server but it wasn't supposed to be on the web, remove it
|
||
|
$packageNameLower = $package.Name.ToLower()
|
||
|
$foundPackage = $DebugMetadata.ClassifiedPackagesMap.$packageNameLower
|
||
|
if (($null -ne $foundPackage) -and (!$foundPackage.InstallToWeb)) {
|
||
|
$packages += $foundPackage
|
||
|
$packageMetadata.HasBadPackages = $true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$packages.ForEach({
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionType" -NotePropertyValue "Uninstall" -Force
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionReason" -NotePropertyValue "Wrong_Host_Type" -Force
|
||
|
})
|
||
|
$PackageMetadata.BadWebPackagesToUninstall = $packages
|
||
|
}
|
||
|
|
||
|
if (!(Test-IsCollectionNullOrEmpty $DebugMetadata.AppServerPackages)) {
|
||
|
$packages = @()
|
||
|
foreach ($package in $DebugMetadata.AppServerPackages) {
|
||
|
if ($null -ne $package) {
|
||
|
## if the package was found on the app server but it wasn't supposed to be on the app, remove it
|
||
|
$packageNameLower = $package.Name.ToLower()
|
||
|
$foundPackage = $DebugMetadata.ClassifiedPackagesMap.$packageNameLower
|
||
|
if (($null -ne $foundPackage) -and (!$foundPackage.InstallToApp)) {
|
||
|
$packages += $foundPackage
|
||
|
$PackageMetadata.HasBadPackages = $true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$packages.ForEach({
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionType" -NotePropertyValue "Uninstall" -Force
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionReason" -NotePropertyValue "Wrong_Host_Type" -Force
|
||
|
})
|
||
|
$PackageMetadata.BadAppPackagesToUninstall = $packages
|
||
|
}
|
||
|
|
||
|
if (!(Test-IsCollectionNullOrEmpty $DebugMetadata.MicServerPackages)) {
|
||
|
$packages = @()
|
||
|
foreach($package in $DebugMetadata.MicServerPackages) {
|
||
|
if ($null -ne $package) {
|
||
|
## if the package was found on the mic server but it wasn't supposed to be on the mic, remove it
|
||
|
$packageNameLower = $package.Name.ToLower()
|
||
|
$foundPackage = $DebugMetadata.ClassifiedPackagesMap.$packageNameLower
|
||
|
if (($null -ne $foundPackage) -and (!$foundPackage.InstallToMic)) {
|
||
|
$packages += $foundPackage
|
||
|
$PackageMetadata.HasBadPackages = $true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$packages.ForEach({
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionType" -NotePropertyValue "Uninstall" -Force
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionReason" -NotePropertyValue "Wrong_Host_Type" -Force
|
||
|
})
|
||
|
$PackageMetadata.BadMicPackagesToUninstall = $packages
|
||
|
}
|
||
|
|
||
|
if (!(Test-IsCollectionNullOrEmpty $DebugMetadata.FabServerPackages)) {
|
||
|
$packages = @()
|
||
|
foreach ($package in $DebugMetadata.FabServerPackages) {
|
||
|
if ($null -ne $package) {
|
||
|
## if the package was found on the fab server but it wasn't supposed to be on the fab, remove it
|
||
|
$packageNameLower = $package.Name.ToLower()
|
||
|
$foundPackage = $DebugMetadata.ClassifiedPackagesMap.$packageNameLower
|
||
|
if (($null -ne $foundPackage) -and (!$foundPackage.InstallToFab)) {
|
||
|
$packages += $foundPackage
|
||
|
$PackageMetadata.HasBadPackages = $true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$packages.ForEach({
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionType" -NotePropertyValue "Uninstall" -Force
|
||
|
Add-Member -InputObject $_ -NotePropertyName "ActionReason" -NotePropertyValue "Wrong_Host_Type" -Force
|
||
|
})
|
||
|
$PackageMetadata.BadFabPackagesToUninstall = $packages
|
||
|
}
|
||
|
|
||
|
# Combine the mic/fab uninstalls into mics only. Mics/Fabs are mutually exclusive in the eyes of the deploy, might as well use one var.
|
||
|
$PackageMetadata.BadMicPackagesToUninstall = (Select-UniqueServerPackages @($PackageMetadata.BadMicPackagesToUninstall, $PackageMetadata.BadFabPackagesToUninstall))
|
||
|
$PackageMetadata.BadFabPackagesToUninstall = @()
|
||
|
|
||
|
# NOTE: The bad packages lists are added to the web/app/mic uninstall lists below, where the mic uninstalls are separate from the app installs.
|
||
|
|
||
|
return $PackageMetadata
|
||
|
}
|