function Get-PackageServerMapping { <# .SYNOPSIS The bulk of the Classify logic. Determines what packages go where. Utilized by Classify-Packages. .PARAMETER AllAppTierPackages App tier packages to install. .PARAMETER AllWebTierPackages Web tier packages to install. .PARAMETER BuildCheckoutDirectory Directory where the code is checked out by TC. .PARAMETER DebugMetadata Meta object used to determine what goes where. .PARAMETER NugetCredential, Credentials to access nuget/proget. .PARAMETER PackageMetadata Packages object to populate. .PARAMETER UseV2PackageMetadata Whether or not to use the new version of the PackageMetadata functions. .PARAMETER DependencyReleaseValue Used for determining what version of orb we're installing, if it's an orb deploy. #> [CmdletBinding()] param( $AllAppTierPackages, $AllWebTierPackages, $BuildCheckoutDirectory, $DebugMetadata, [System.Management.Automation.PSCredential]$NugetCredential, [PSObject]$PackageMetadata, [switch]$UseV2PackageMetadata, [string]$DependencyReleaseValue = "" ) $loglead = Get-LogLeadName # Force the results of these two calls into arrays. Necessary for testing, and it's what we should be getting anyways. # PS tries to unbox single items. No bueno. Write-Host "$loglead Classifying Web Packages Being Installed" $PackageMetadata.WebPackagesToInstall = @(Get-PackageInstallationData -ChocoPackages $AllWebTierPackages -Servers $PackageMetadata.Servers -FilterFeeds -FilterPowerShellModules -NugetCredential $NugetCredential -IncludeMissingPackages -UseV2PackageMetadata:$UseV2PackageMetadata -PackageToServerMap $PackageMetadata.PackageToServers -ErrorAction Continue) Write-Host "$loglead Classifying App Packages Being Installed" $PackageMetadata.AppPackagesToInstall = @(Get-PackageInstallationData -ChocoPackages $AllAppTierPackages -Servers $PackageMetadata.Servers -FilterFeeds -FilterPowerShellModules -NugetCredential $NugetCredential -IncludeMissingPackages -UseV2PackageMetadata:$UseV2PackageMetadata -PackageToServerMap $PackageMetadata.PackageToServers -ErrorAction Continue) # The above forced typecasting into an array broke a bunch of stuff because it forced the values to be @($null) rather than just $null # This puts it back the way it was, but we're not removing any of the down the line null checks. if($PackageMetadata.WebPackagesToInstall.Count -eq 1 -and $null -eq $PackageMetadata.WebPackagesToInstall[0]) { $PackageMetadata.WebPackagesToInstall = @() } if($PackageMetadata.AppPackagesToInstall.Count -eq 1 -and $null -eq $PackageMetadata.AppPackagesToInstall[0]) { $PackageMetadata.AppPackagesToInstall = @() } $PackageMetadata = Remove-OutdatedNewHotfixPackages -PackageMetadata $PackageMetadata -DependencyReleaseValue $DependencyReleaseValue # Set which microservices should have New Relic enabled/disabled. $PackageMetadata = Get-MicroserviceNewRelicMapping -BuildCheckoutDirectory $BuildCheckoutDirectory -PackageMetadata $PackageMetadata # Notify TC of missing packages. if ($PackageMetadata.WebPackagesToInstall.Where({ $_.IsValid -eq $false}).Count -gt 0 -or $PackageMetadata.AppPackagesToInstall.Where({ $_.IsValid -eq $false}).Count -gt 0) { $message = "Packages currently deployed to the system cannot be located in any configured feed. Were they renamed or removed from the feed?" Write-Warning "$loglead MISSING_PACKAGES : $message" Write-Warning "$loglead ORB Platform deploys reinstall Widgets and Providers that are currently installed." Write-Host "##teamcity[buildProblem description='$message' identity='MISSING_PACKAGES']" } if ($PackageMetadata.WebPackagesToInstall.Where({ $_.IsValid -eq $false}).Count -gt 0) { $missingWebPackages = $PackageMetadata.WebPackagesToInstall | Where-Object { $_.IsValid -eq $false } foreach ($missingWebPackage in $missingWebPackages) { $missingWebPackageDetail = "$($missingWebPackage.Name)|$($missingWebPackage.Version)" $tcMissingWebPackageDetail = ConvertTo-SafeTeamCityMessage -InputText $missingWebPackageDetail $missingWebPackageName = $missingWebPackage.Name Write-Warning "$loglead MISSING_WEB_PACKAGE : $missingWebPackageDetail" Write-Host "##teamcity[buildProblem description='Missing web package: $tcMissingWebPackageDetail' identity='MISSINGWEB_$missingWebPackageName']" } } if ($PackageMetadata.AppPackagesToInstall.Where({ $_.IsValid -eq $false}).Count -gt 0) { $missingAppPackages = $PackageMetadata.AppPackagesToInstall | Where-Object { $_.IsValid -eq $false } foreach ($missingAppPackage in $missingAppPackages) { $missingAppPackageDetail = "$($missingAppPackage.Name)|$($missingAppPackage.Version)" $tcMissingAppPackageDetail = ConvertTo-SafeTeamCityMessage -InputText $missingAppPackageDetail $missingAppPackageName = $missingAppPackage.Name Write-Warning "$loglead MISSING_APP_PACKAGE : $missingAppPackageDetail" Write-Host "##teamcity[buildProblem description='Missing app package: $tcMissingAppPackageDetail' identity='MISSINGAPP_$missingAppPackageName']" } } # Determine if app packages are going to app servers, mic servers, or both. if ($PackageMetadata.InstallToAppsAndMics) { foreach ($package in $PackageMetadata.AppPackagesToInstall) { $install = $package.InstallToApp -or $package.InstallToMic $package.InstallToApp = $PackageMetadata.HasAppServers -and $install $package.InstallToMic = $PackageMetadata.HasMicServers -and $install } } # Create a map of classified packages, so we can more easily find name->classifiedPackage if (!(Test-IsCollectionNullOrEmpty $PackageMetadata.WebPackagesToInstall)) { Write-Host "$loglead Creating Web Package Map:" foreach ($package in $PackageMetadata.WebPackagesToInstall) { if([string]::IsNullOrWhiteSpace($package.Name)){ Write-Warning "$loglead Got an empty Web package name: $package!" } else { $DebugMetadata.ClassifiedPackagesMap[$package.Name.ToLower()] = $package; } } } if (!(Test-IsCollectionNullOrEmpty $PackageMetadata.AppPackagesToInstall)) { Write-Host "$loglead Creating App Package Map:" foreach ($package in $PackageMetadata.AppPackagesToInstall) { if([string]::IsNullOrWhiteSpace($package.Name)){ Write-Warning "$loglead Got an empty App package name: $package!" } else { $DebugMetadata.ClassifiedPackagesMap[$package.Name.ToLower()] = $package; } } } #region Get MigrationOnly Packages # It is ok, per Cole, that migration packages can be specified in either the web or app install boxes in the UI # We do not care that they show up in the uninstall boxes, yet (future work SRE-16946) $webIsMigrationPackage = $PackageMetadata.WebPackagesToInstall.Where({$_.IsMigrationPackage -eq $true}) $appIsMigrationPackage = $PackageMetadata.AppPackagesToInstall.Where({$_.IsMigrationPackage -eq $true}) $migrationOnlyPackages = @() if (-not (Test-IsCollectionNullOrEmpty -Collection $webIsMigrationPackage)) { foreach ($migrationPackage in $webIsMigrationPackage) { Write-Host "$logLead : Found a migration package in the web inputs: $($migrationPackage.Name)" $DebugMetadata.IsMigrationPackage.Web += $migrationPackage if ($migrationPackage.Name -notin $migrationOnlyPackages.Name) { $migrationOnlyPackages += $migrationPackage } else { # TODO - This is not aware of versions, this may bite us later, not worth the effort to pre-worry about that today # The circumstances of them putting two different migration versions in the install lists for the same package name is so low, we should just tell them to do better # There is a point of diminishing returns on holding their hands - cbrand 2022-07-12 Write-Host "$logLead : Migration package with Name $($migrationPackage.Name) already in `$migrationOnlyPackages collection, not adding a duplicate-by-name" } } } else { Write-Host "$logLead : Did not find any migration packages to be installed in the web inputs" } if (-not (Test-IsCollectionNullOrEmpty -Collection $appIsMigrationPackage)) { foreach ($migrationPackage in $appIsMigrationPackage) { Write-Host "$logLead : Found a migration package in the app inputs: $($migrationPackage.Name)" $DebugMetadata.IsMigrationPackage.App += $migrationPackage if ($migrationPackage.Name -notin $migrationOnlyPackages.Name) { $migrationOnlyPackages += $migrationPackage } else { # TODO - This is not aware of versions, this may bite us later, not worth the effort to pre-worry about that today # The circumstances of them putting two different migration versions in the install lists for the same package name is so low, we should just tell them to do better # There is a point of diminishing returns on holding their hands - cbrand 2022-07-12 Write-Host "$logLead : Migration package with Name $($migrationPackage.Name) already in `$migrationOnlyPackages collection, not adding a duplicate-by-name" } } } else { Write-Host "$logLead : Did not find any migration packages to be installed in the app inputs" } $PackageMetadata.MigrationOnlyPackages = $migrationOnlyPackages #endregion Get MigrationOnly Packages return $PackageMetadata, $DebugMetadata }