|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Copyright Microsoft Corporation |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ---------------------------------------------------------------------------------- |
| 14 | +<# |
| 15 | +.Synopsis |
| 16 | +Gives SKU recommendations for Azure SQL offerings. |
| 17 | +.Description |
| 18 | +Gives SKU recommendations for Azure SQL offerings (including SQL Database, SQL Managed Instance, and SQL on Azure VM) that best suit your workload while also being cost-effective. |
| 19 | +#> |
| 20 | + |
| 21 | +function Get-AzDataMigrationSkuRecommendation |
| 22 | +{ |
| 23 | + [OutputType([System.Boolean])] |
| 24 | + [CmdletBinding(PositionalBinding=$false)] |
| 25 | + [Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Description('Gives SKU recommendations for Azure SQL offerings')] |
| 26 | + |
| 27 | + param( |
| 28 | + |
| 29 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Folder which data and result reports will be written to/read from. The value here must be the same as the one used in PerfDataCollection')] |
| 30 | + [System.String] |
| 31 | + ${OutputFolder}, |
| 32 | + |
| 33 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Target platform for SKU recommendation: either AzureSqlDatabase, AzureSqlManagedInstance, AzureSqlVirtualMachine, or Any. If Any is selected, then SKU recommendations for all three target platforms will be evaluated, and the best fit will be returned. (Default: Any)')] |
| 34 | + [System.String] |
| 35 | + ${TargetPlatform}, |
| 36 | + |
| 37 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Name of the SQL instance that SKU recommendation will be targeting. (Default: outputFolder will be scanned for files created by the PerfDataCollection action, and recommendations will be provided for every instance found)')] |
| 38 | + [System.String] |
| 39 | + ${TargetSqlInstance}, |
| 40 | + |
| 41 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Percentile of data points to be used during aggregation of the performance data. Only used for baseline (non-elastic) strategy. (Default: 95)')] |
| 42 | + [System.String] |
| 43 | + ${TargetPercentile}, |
| 44 | + |
| 45 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Scaling (comfort) factor used during SKU recommendation. For example, if it is determined that there is a 4 vCore CPU requirement with a scaling factor of 150%, then the true CPU requirement will be 6 vCores. (Default: 100)')] |
| 46 | + [System.String] |
| 47 | + ${ScalingFactor}, |
| 48 | + |
| 49 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. UTC start time of performance data points to consider during aggregation, in YYYY-MM-DD HH:MM format. Only used for baseline (non-elastic) strategy. (Default: all data points collected will be considered)')] |
| 50 | + [System.String] |
| 51 | + ${StartTime}, |
| 52 | + |
| 53 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. UTC end time of performance data points to consider during aggregation, in YYYY-MM-DD HH:MM format. Only used for baseline (non-elastic) strategy. (Default: all data points collected will be considered)')] |
| 54 | + [System.String] |
| 55 | + ${EndTime}, |
| 56 | + |
| 57 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Whether or not to overwrite any existing SKU recommendation reports.')] |
| 58 | + [System.Management.Automation.SwitchParameter] |
| 59 | + ${Overwrite}, |
| 60 | + |
| 61 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Whether or not to print the SKU recommendation results to the console.')] |
| 62 | + [System.Management.Automation.SwitchParameter] |
| 63 | + ${DisplayResult}, |
| 64 | + |
| 65 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Whether or not to use the elastic strategy for SKU recommendations based on resource usage profiling.')] |
| 66 | + [System.Management.Automation.SwitchParameter] |
| 67 | + ${ElasticStrategy}, |
| 68 | + |
| 69 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Space separated list of names of databases to be allowed for SKU recommendation consideration while excluding all others. Only set one of the following or neither: databaseAllowList, databaseDenyList. How to pass - "Database1 Database2" (Default: null)')] |
| 70 | + [System.String] |
| 71 | + ${DatabaseAllowList}, |
| 72 | + |
| 73 | + [Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Space separated list of names of databases to not be considered for SKU recommendation. Only set one of the following or neither: databaseAllowList, databaseDenyList. How to pass - "Database1 Database2" (Default: null) |
| 74 | + ')] |
| 75 | + [System.String] |
| 76 | + ${DatabaseDenyList}, |
| 77 | + |
| 78 | + [Parameter(ParameterSetName='ConfigFile', Mandatory, HelpMessage='Path of the ConfigFile')] |
| 79 | + [System.String] |
| 80 | + ${ConfigFilePath}, |
| 81 | + |
| 82 | + [Parameter()] |
| 83 | + [Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Category('Runtime')] |
| 84 | + [System.Management.Automation.SwitchParameter] |
| 85 | + # Returns true when the command succeeds |
| 86 | + ${PassThru} |
| 87 | + ) |
| 88 | + |
| 89 | + process |
| 90 | + { |
| 91 | + try |
| 92 | + { |
| 93 | + $OSPlatform = Get-OSName |
| 94 | + |
| 95 | + if(-Not $OSPlatform.Contains("Windows")) |
| 96 | + { |
| 97 | + throw "This command cannot be run in non-windows environment" |
| 98 | + Break; |
| 99 | + } |
| 100 | + #Defining Default Output Path |
| 101 | + $DefaultOutputFolder = Get-DefaultOutputFolder |
| 102 | + |
| 103 | + #Defining Base and Exe paths |
| 104 | + $BaseFolder = Join-Path -Path $DefaultOutputFolder -ChildPath Downloads; |
| 105 | + $ExePath = Join-Path -Path $BaseFolder -ChildPath SqlAssessment.Console.csproj\SqlAssessment.exe; |
| 106 | + |
| 107 | + #Checking if BaseFolder Path is valid or not |
| 108 | + if(-Not (Test-Path $BaseFolder)) |
| 109 | + { |
| 110 | + $null = New-Item -Path $BaseFolder -ItemType "directory" |
| 111 | + } |
| 112 | + |
| 113 | + #Testing Whether Console App is downloaded or not |
| 114 | + $TestExePath = Test-Path -Path $ExePath; |
| 115 | + |
| 116 | + #Downloading and extracting SqlAssessment Zip file |
| 117 | + if(-Not $TestExePath) |
| 118 | + { |
| 119 | + $ZipSource = "https://sqlassess.blob.core.windows.net/app/SqlAssessment.zip"; |
| 120 | + $ZipDestination = Join-Path -Path $BaseFolder -ChildPath "SqlAssessment.zip"; |
| 121 | + Invoke-RestMethod -Uri $ZipSource -OutFile $ZipDestination; |
| 122 | + |
| 123 | + Expand-Archive -Path $ZipDestination -DestinationPath $BaseFolder -Force; |
| 124 | + } |
| 125 | + |
| 126 | + #Collecting performance data |
| 127 | + if(('CommandLine') -contains $PSCmdlet.ParameterSetName) |
| 128 | + { |
| 129 | + # The array list $splat contains all the parameters that will be passed to '.\SqlAssessment.exe GetSkuRecommendation' |
| 130 | + |
| 131 | + $DatabaseAllowList2 = $($DatabaseAllowList -split " ") |
| 132 | + $DatabaseDenyList2 = $($DatabaseDenyList -split " ") |
| 133 | + [System.Collections.ArrayList] $splat = @( |
| 134 | + '--outputFolder', $OutputFolder |
| 135 | + '--targetPlatform', $TargetPlatform |
| 136 | + '--targetSqlInstance', $TargetSqlInstance |
| 137 | + '--scalingFactor', $ScalingFactor |
| 138 | + '--targetPercentile', $TargetPercentile |
| 139 | + '--startTime', $StartTime |
| 140 | + '--endTime', $EndTime |
| 141 | + '--overwrite', $Overwrite |
| 142 | + '--displayResult', $DisplayResult |
| 143 | + '--elasticStrategy', $ElasticStrategy |
| 144 | + '--databaseAllowList', $DatabaseAllowList2 |
| 145 | + '--databaseDenyList', $DatabaseDenyList2 |
| 146 | + ) |
| 147 | + # Removing the parameters for which the user did not provide any values |
| 148 | + for($i = $splat.Count-1; $i -gt -1; $i = $i-2) |
| 149 | + { |
| 150 | + $currVal = $splat[$i] |
| 151 | + if($currVal -ne "") |
| 152 | + { |
| 153 | + } |
| 154 | + else { |
| 155 | + $splat.RemoveAt($i) |
| 156 | + $i2 = $i -1 |
| 157 | + $splat.RemoveAt($i2) |
| 158 | + |
| 159 | + } |
| 160 | + } |
| 161 | + # Running GetSkuRecommendation |
| 162 | + & $ExePath GetSkuRecommendation @splat |
| 163 | + } |
| 164 | + else |
| 165 | + { |
| 166 | + Test-ConfigFile $PSBoundParameters.ConfigFilePath "GetSkuRecommendation" |
| 167 | + & $ExePath --configFile $PSBoundParameters.ConfigFilePath |
| 168 | + } |
| 169 | + |
| 170 | + $LogFilePath = Join-Path -Path $DefaultOutputFolder -ChildPath Logs; |
| 171 | + Write-Host "Event and Error Logs Folder Path: $LogFilePath"; |
| 172 | + |
| 173 | + if($PSBoundParameters.ContainsKey("PassThru")) |
| 174 | + { |
| 175 | + return $true; |
| 176 | + } |
| 177 | + } |
| 178 | + catch |
| 179 | + { |
| 180 | + throw $_ |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | + |
0 commit comments