Skip to content

[DataMigration] Codegen/data migration #17208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Microsoft Azure Powershell - DataMigration")]
[assembly: AssemblyCompany(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCompany)]
[assembly: AssemblyProduct(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyProduct)]
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]

[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: Guid("85d56cd6-867f-4b62-8330-08cb17d2f429")]
[assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyFileVersion("0.1.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,20 @@ function CreateModelCmdlet {
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
# check whether completer is needed
$completer = '';
if($Type.Split('.').Split('.')[-2] -eq 'Support') {
$completer += "`n [ArgumentCompleter([${Type}])]"
}
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]
[Parameter($ParameterDefineProperty)]${completer}
[${Type}]
`$${Identifier}"
$ParameterDefineScriptList.Add($ParameterDefineScript)
$ParameterAssignScriptList.Add("
`$Object.${Identifier} = `$${Identifier}")
if (`$PSBoundParameters.ContainsKey('${Identifier}')) {
`$Object.${Identifier} = `$${Identifier}
}")
}
}
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Get-AzDataMigrationAssessment
}
else
{
Test-ConfigFile $PSBoundParameters.ConfigFilePath
Test-ConfigFile $PSBoundParameters.ConfigFilePath "Assess"
& $ExePath --configFile $PSBoundParameters.ConfigFilePath
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
<#
.Synopsis
Collect performance data for given SQL instance .
.Description
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.
#>

function Get-AzDataMigrationPerformanceDataCollection
{
[OutputType([System.Boolean])]
[CmdletBinding(PositionalBinding=$false)]
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Description('Collect performance data for given SQL Server instance(s)')]

param(
[Parameter(ParameterSetName='CommandLine', Mandatory, HelpMessage='Sql Server Connection Strings')]
[System.String[]]
${SqlConnectionStrings},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Folder which data and result reports will be written to/read from.')]
[System.String]
${OutputFolder},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Interval at which to query performance data, in seconds. (Default: 30)')]
[System.String]
${PerfQueryInterval},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Interval at which to query and persist static configuration data, in seconds. (Default: 3600)')]
[System.String]
${StaticQueryInterval},

[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)
')]
[System.String]
${NumberOfIterations},

[Parameter(ParameterSetName='ConfigFile', Mandatory, HelpMessage='Path of the ConfigFile')]
[System.String]
${ConfigFilePath},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Returns true when the command succeeds
${PassThru}
)

process
{
try
{
$OSPlatform = Get-OSName

if(-Not $OSPlatform.Contains("Windows"))
{
throw "This command cannot be run in non-windows environment"
Break;
}
#Defining Default Output Path
$DefaultOutputFolder = Get-DefaultOutputFolder

#Defining Base and Exe paths
$BaseFolder = Join-Path -Path $DefaultOutputFolder -ChildPath Downloads;
$ExePath = Join-Path -Path $BaseFolder -ChildPath SqlAssessment.Console.csproj\SqlAssessment.exe;

#Checking if BaseFolder Path is valid or not
if(-Not (Test-Path $BaseFolder))
{
$null = New-Item -Path $BaseFolder -ItemType "directory"
}

#Testing Whether Console App is downloaded or not
$TestExePath = Test-Path -Path $ExePath;

#Downloading and extracting SqlAssessment Zip file
if(-Not $TestExePath)
{
$ZipSource = "https://sqlassess.blob.core.windows.net/app/SqlAssessment.zip";
$ZipDestination = Join-Path -Path $BaseFolder -ChildPath "SqlAssessment.zip";
Invoke-RestMethod -Uri $ZipSource -OutFile $ZipDestination;

Expand-Archive -Path $ZipDestination -DestinationPath $BaseFolder -Force;
}

#Collecting performance data
if(('CommandLine') -contains $PSCmdlet.ParameterSetName)
{
# The array list $splat contains all the parameters that will be passed to '.\SqlAssessment.exe PerfDataCollection'
[System.Collections.ArrayList] $splat = @(
'--sqlConnectionStrings', $SqlConnectionStrings
'--outputfolder', $OutputFolder
'--perfQueryIntervalInSec', $PerfQueryInterval
'--staticQueryIntervalInSec', $StaticQueryInterval
'--numberOfIterations', $NumberOfIterations
)

# Removing the parameters for which the user did not provide any values
for($i = $splat.Count-1; $i -gt -1; $i = $i-2)
{
$currVal = $splat[$i]
if($currVal -ne "")
{

}
else {
$splat.RemoveAt($i)
$i2 = $i -1
$splat.RemoveAt($i2)
}
}

# Running PerfDataCollection
& $ExePath PerfDataCollection @splat

}
else
{
Test-ConfigFile $PSBoundParameters.ConfigFilePath "PerfDataCollection"
& $ExePath --configFile $PSBoundParameters.ConfigFilePath
}

$LogFilePath = Join-Path -Path $DefaultOutputFolder -ChildPath Logs;
Write-Host "Event and Error Logs Folder Path: $LogFilePath";

if($PSBoundParameters.ContainsKey("PassThru"))
{
return $true;
}
}
catch
{
throw $_
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
<#
.Synopsis
Gives SKU recommendations for Azure SQL offerings.
.Description
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.
#>

function Get-AzDataMigrationSkuRecommendation
{
[OutputType([System.Boolean])]
[CmdletBinding(PositionalBinding=$false)]
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Description('Gives SKU recommendations for Azure SQL offerings')]

param(

[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')]
[System.String]
${OutputFolder},

[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)')]
[System.String]
${TargetPlatform},

[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)')]
[System.String]
${TargetSqlInstance},

[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)')]
[System.String]
${TargetPercentile},

[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)')]
[System.String]
${ScalingFactor},

[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)')]
[System.String]
${StartTime},

[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)')]
[System.String]
${EndTime},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Whether or not to overwrite any existing SKU recommendation reports.')]
[System.Management.Automation.SwitchParameter]
${Overwrite},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Whether or not to print the SKU recommendation results to the console.')]
[System.Management.Automation.SwitchParameter]
${DisplayResult},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Whether or not to use the elastic strategy for SKU recommendations based on resource usage profiling.')]
[System.Management.Automation.SwitchParameter]
${ElasticStrategy},

[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)')]
[System.String]
${DatabaseAllowList},

[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)
')]
[System.String]
${DatabaseDenyList},

[Parameter(ParameterSetName='ConfigFile', Mandatory, HelpMessage='Path of the ConfigFile')]
[System.String]
${ConfigFilePath},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Returns true when the command succeeds
${PassThru}
)

process
{
try
{
$OSPlatform = Get-OSName

if(-Not $OSPlatform.Contains("Windows"))
{
throw "This command cannot be run in non-windows environment"
Break;
}
#Defining Default Output Path
$DefaultOutputFolder = Get-DefaultOutputFolder

#Defining Base and Exe paths
$BaseFolder = Join-Path -Path $DefaultOutputFolder -ChildPath Downloads;
$ExePath = Join-Path -Path $BaseFolder -ChildPath SqlAssessment.Console.csproj\SqlAssessment.exe;

#Checking if BaseFolder Path is valid or not
if(-Not (Test-Path $BaseFolder))
{
$null = New-Item -Path $BaseFolder -ItemType "directory"
}

#Testing Whether Console App is downloaded or not
$TestExePath = Test-Path -Path $ExePath;

#Downloading and extracting SqlAssessment Zip file
if(-Not $TestExePath)
{
$ZipSource = "https://sqlassess.blob.core.windows.net/app/SqlAssessment.zip";
$ZipDestination = Join-Path -Path $BaseFolder -ChildPath "SqlAssessment.zip";
Invoke-RestMethod -Uri $ZipSource -OutFile $ZipDestination;

Expand-Archive -Path $ZipDestination -DestinationPath $BaseFolder -Force;
}

#Collecting performance data
if(('CommandLine') -contains $PSCmdlet.ParameterSetName)
{
# The array list $splat contains all the parameters that will be passed to '.\SqlAssessment.exe GetSkuRecommendation'

$DatabaseAllowList2 = $($DatabaseAllowList -split " ")
$DatabaseDenyList2 = $($DatabaseDenyList -split " ")
[System.Collections.ArrayList] $splat = @(
'--outputFolder', $OutputFolder
'--targetPlatform', $TargetPlatform
'--targetSqlInstance', $TargetSqlInstance
'--scalingFactor', $ScalingFactor
'--targetPercentile', $TargetPercentile
'--startTime', $StartTime
'--endTime', $EndTime
'--overwrite', $Overwrite
'--displayResult', $DisplayResult
'--elasticStrategy', $ElasticStrategy
'--databaseAllowList', $DatabaseAllowList2
'--databaseDenyList', $DatabaseDenyList2
)
# Removing the parameters for which the user did not provide any values
for($i = $splat.Count-1; $i -gt -1; $i = $i-2)
{
$currVal = $splat[$i]
if($currVal -ne "")
{
}
else {
$splat.RemoveAt($i)
$i2 = $i -1
$splat.RemoveAt($i2)

}
}
# Running GetSkuRecommendation
& $ExePath GetSkuRecommendation @splat
}
else
{
Test-ConfigFile $PSBoundParameters.ConfigFilePath "GetSkuRecommendation"
& $ExePath --configFile $PSBoundParameters.ConfigFilePath
}

$LogFilePath = Join-Path -Path $DefaultOutputFolder -ChildPath Logs;
Write-Host "Event and Error Logs Folder Path: $LogFilePath";

if($PSBoundParameters.ContainsKey("PassThru"))
{
return $true;
}
}
catch
{
throw $_
}
}
}


Loading