Skip to content

Commit be4b08d

Browse files
[DataMigration] Codegen/data migration (#17208)
* Move DataMigration to main * update changelog * suppress signature issue Co-authored-by: azure-powershell-bot <[email protected]>
1 parent 671452f commit be4b08d

File tree

89 files changed

+7422
-265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+7422
-265
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
using System;
16+
using System.Reflection;
17+
using System.Runtime.InteropServices;
18+
19+
[assembly: AssemblyTitle("Microsoft Azure Powershell - DataMigration")]
20+
[assembly: AssemblyCompany(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCompany)]
21+
[assembly: AssemblyProduct(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyProduct)]
22+
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
23+
24+
[assembly: ComVisible(false)]
25+
[assembly: CLSCompliant(false)]
26+
[assembly: Guid("85d56cd6-867f-4b62-8330-08cb17d2f429")]
27+
[assembly: AssemblyVersion("0.1.0")]
28+
[assembly: AssemblyFileVersion("0.1.0")]

src/DataMigration/DataMigration.Autorest/create-model-cmdlets.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,20 @@ function CreateModelCmdlet {
112112
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
113113
}
114114
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
115+
# check whether completer is needed
116+
$completer = '';
117+
if($Type.Split('.').Split('.')[-2] -eq 'Support') {
118+
$completer += "`n [ArgumentCompleter([${Type}])]"
119+
}
115120
$ParameterDefineScript = "
116-
[Parameter($ParameterDefineProperty)]
121+
[Parameter($ParameterDefineProperty)]${completer}
117122
[${Type}]
118123
`$${Identifier}"
119124
$ParameterDefineScriptList.Add($ParameterDefineScript)
120125
$ParameterAssignScriptList.Add("
121-
`$Object.${Identifier} = `$${Identifier}")
126+
if (`$PSBoundParameters.ContainsKey('${Identifier}')) {
127+
`$Object.${Identifier} = `$${Identifier}
128+
}")
122129
}
123130
}
124131
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","

src/DataMigration/DataMigration.Autorest/custom/Cmdlets/Get-AzDataMigrationAssessment.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function Get-AzDataMigrationAssessment
119119
}
120120
else
121121
{
122-
Test-ConfigFile $PSBoundParameters.ConfigFilePath
122+
Test-ConfigFile $PSBoundParameters.ConfigFilePath "Assess"
123123
& $ExePath --configFile $PSBoundParameters.ConfigFilePath
124124
}
125125

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
Collect performance data for given SQL instance .
17+
.Description
18+
Collect performance data for given SQL instance over an extended period of time. The collected data can then be aggregated and analysed, and by examining the performance characteristics of your source instance, SKU recommendations can be determined for Azure SQL offerings.
19+
#>
20+
21+
function Get-AzDataMigrationPerformanceDataCollection
22+
{
23+
[OutputType([System.Boolean])]
24+
[CmdletBinding(PositionalBinding=$false)]
25+
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Description('Collect performance data for given SQL Server instance(s)')]
26+
27+
param(
28+
[Parameter(ParameterSetName='CommandLine', Mandatory, HelpMessage='Sql Server Connection Strings')]
29+
[System.String[]]
30+
${SqlConnectionStrings},
31+
32+
[Parameter(ParameterSetName='CommandLine', HelpMessage='Folder which data and result reports will be written to/read from.')]
33+
[System.String]
34+
${OutputFolder},
35+
36+
[Parameter(ParameterSetName='CommandLine', HelpMessage='Interval at which to query performance data, in seconds. (Default: 30)')]
37+
[System.String]
38+
${PerfQueryInterval},
39+
40+
[Parameter(ParameterSetName='CommandLine', HelpMessage='Interval at which to query and persist static configuration data, in seconds. (Default: 3600)')]
41+
[System.String]
42+
${StaticQueryInterval},
43+
44+
[Parameter(ParameterSetName='CommandLine', HelpMessage='Number of iterations of performance data collection to perform before persisting to file. For example, with default values, performance data will be persisted every 30 seconds * 20 iterations = 10 minutes. (Default: 20, Minimum: 2)
45+
')]
46+
[System.String]
47+
${NumberOfIterations},
48+
49+
[Parameter(ParameterSetName='ConfigFile', Mandatory, HelpMessage='Path of the ConfigFile')]
50+
[System.String]
51+
${ConfigFilePath},
52+
53+
[Parameter()]
54+
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Category('Runtime')]
55+
[System.Management.Automation.SwitchParameter]
56+
# Returns true when the command succeeds
57+
${PassThru}
58+
)
59+
60+
process
61+
{
62+
try
63+
{
64+
$OSPlatform = Get-OSName
65+
66+
if(-Not $OSPlatform.Contains("Windows"))
67+
{
68+
throw "This command cannot be run in non-windows environment"
69+
Break;
70+
}
71+
#Defining Default Output Path
72+
$DefaultOutputFolder = Get-DefaultOutputFolder
73+
74+
#Defining Base and Exe paths
75+
$BaseFolder = Join-Path -Path $DefaultOutputFolder -ChildPath Downloads;
76+
$ExePath = Join-Path -Path $BaseFolder -ChildPath SqlAssessment.Console.csproj\SqlAssessment.exe;
77+
78+
#Checking if BaseFolder Path is valid or not
79+
if(-Not (Test-Path $BaseFolder))
80+
{
81+
$null = New-Item -Path $BaseFolder -ItemType "directory"
82+
}
83+
84+
#Testing Whether Console App is downloaded or not
85+
$TestExePath = Test-Path -Path $ExePath;
86+
87+
#Downloading and extracting SqlAssessment Zip file
88+
if(-Not $TestExePath)
89+
{
90+
$ZipSource = "https://sqlassess.blob.core.windows.net/app/SqlAssessment.zip";
91+
$ZipDestination = Join-Path -Path $BaseFolder -ChildPath "SqlAssessment.zip";
92+
Invoke-RestMethod -Uri $ZipSource -OutFile $ZipDestination;
93+
94+
Expand-Archive -Path $ZipDestination -DestinationPath $BaseFolder -Force;
95+
}
96+
97+
#Collecting performance data
98+
if(('CommandLine') -contains $PSCmdlet.ParameterSetName)
99+
{
100+
# The array list $splat contains all the parameters that will be passed to '.\SqlAssessment.exe PerfDataCollection'
101+
[System.Collections.ArrayList] $splat = @(
102+
'--sqlConnectionStrings', $SqlConnectionStrings
103+
'--outputfolder', $OutputFolder
104+
'--perfQueryIntervalInSec', $PerfQueryInterval
105+
'--staticQueryIntervalInSec', $StaticQueryInterval
106+
'--numberOfIterations', $NumberOfIterations
107+
)
108+
109+
# Removing the parameters for which the user did not provide any values
110+
for($i = $splat.Count-1; $i -gt -1; $i = $i-2)
111+
{
112+
$currVal = $splat[$i]
113+
if($currVal -ne "")
114+
{
115+
116+
}
117+
else {
118+
$splat.RemoveAt($i)
119+
$i2 = $i -1
120+
$splat.RemoveAt($i2)
121+
}
122+
}
123+
124+
# Running PerfDataCollection
125+
& $ExePath PerfDataCollection @splat
126+
127+
}
128+
else
129+
{
130+
Test-ConfigFile $PSBoundParameters.ConfigFilePath "PerfDataCollection"
131+
& $ExePath --configFile $PSBoundParameters.ConfigFilePath
132+
}
133+
134+
$LogFilePath = Join-Path -Path $DefaultOutputFolder -ChildPath Logs;
135+
Write-Host "Event and Error Logs Folder Path: $LogFilePath";
136+
137+
if($PSBoundParameters.ContainsKey("PassThru"))
138+
{
139+
return $true;
140+
}
141+
}
142+
catch
143+
{
144+
throw $_
145+
}
146+
}
147+
}
148+
149+
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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

Comments
 (0)