Adding notebooks to migration extension (#14189)

* Adding migration notebooks to extension

* Adding toast notification instead of printing error in the console

* removed localization info from the links in the notebook

* Removed localization info from the links 2

* Fixed comments, placeholder and letter cases.
This commit is contained in:
Aasim Khan
2021-02-09 08:07:30 -08:00
committed by GitHub
parent a3cddbc8aa
commit b2eb0e6958
7 changed files with 1104 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,153 @@
{
"metadata": {
"kernelspec": {
"name": "powershell",
"display_name": "PowerShell",
"language": "powershell"
},
"language_info": {
"name": "powershell",
"codemirror_mode": "shell",
"mimetype": "text/x-sh",
"file_extension": ".ps1"
}
},
"nbformat_minor": 2,
"nbformat": 4,
"cells": [
{
"cell_type": "markdown",
"source": [
"# Perform a SQL Server migration assessment\n",
"\n",
"To perform a SQL Server migration assessment:\n",
"\n",
"0. Download the SqlAssessment utility\n",
"1. Set up notebook environment\n",
"2. Run the assessment action to get the recommended target platform\n",
"3. Run the data collection action\n",
"4. Run the SKU recommendation action to get the right Azure SQL Database/Managed Instance SKU based on the collected performance data"
],
"metadata": {
"azdata_cell_guid": "8ae742ab-7de7-457c-8b8b-28b342d6c854"
}
},
{
"cell_type": "markdown",
"source": [
"**1) Set up notebook environment**"
],
"metadata": {
"azdata_cell_guid": "6f04d64d-9fa2-4be4-9121-831ad764e5b9"
}
},
{
"cell_type": "code",
"source": [
"# The working folder where you downloaded the SqlAssessment utility\r\n",
"$workingDirectory = \"<folder containing SqlAssessment utility>\"\r\n",
"$fileName = \"SqlAssessment.exe\"\r\n",
"\r\n",
"# SQL Server connection string.\r\n",
"$connectionStrings =\"Data Source=.;Initial Catalog=master;Integrated Security=True\"\r\n",
"\r\n",
"# By default, collect the performance data every 30 seconds and saving into the file every 20 iterations.\r\n",
"$perfQueryIntervalInSec = 30\r\n",
"$numberOfIterations = 20"
],
"metadata": {
"azdata_cell_guid": "b2eec551-678e-4644-885f-319aa461833e",
"tags": [
"parameters"
]
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"**2) Run the assessment action to get the recommended target platform**"
],
"metadata": {
"azdata_cell_guid": "df3790c7-0677-427c-a82d-98e2404cd075"
}
},
{
"cell_type": "code",
"source": [
"$args = \"Assess --sqlConnectionStrings `\"$connectionStrings`\"\"\r\n",
"Start-Process -Wait -FilePath $fileName -ArgumentList $args -WorkingDirectory $workingDirectory\r\n",
"$json = Get-Content $workingDirectory\\SqlAssessmentReport.json | ConvertFrom-Json \r\n",
"\r\n",
"# Show high level target platform recommendations, for more detail please look at SqlAssessmentReport.json in the output folder\r\n",
"$json.Servers.TargetReadinesses.AzureSqlDatabase | Select-Object -Property AppliesToMigrationTargetPlatform, DatabasesListReadyForMigration, RecommendationStatus\r\n",
"$json.Servers.TargetReadinesses.AzureSqlManagedInstance | Select-Object -Property AppliesToMigrationTargetPlatform, DatabasesListReadyForMigration, RecommendationStatus"
],
"metadata": {
"azdata_cell_guid": "b2e2733a-a3cc-430d-8f88-170ace82f4b4",
"tags": []
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"**3) Run the data collection action**\n",
"\n",
"     You can end the collection process by pressing the Enter key or by closing the collection process. \n",
"\n",
"     Keep the process running for longer durations, preferably during both peak and off-peak hours, to improve recommendation accuracy."
],
"metadata": {
"azdata_cell_guid": "bc76c698-c2f2-4aff-a388-f3a9c81ef99a"
}
},
{
"cell_type": "code",
"source": [
"$args = \"PerfDataCollection --outputFolder $outputFolder --sqlConnectionStrings `\"$connectionStrings`\" --perfQueryIntervalInSec $perfQueryIntervalInSec --numberOfIterations $numberOfIterations\"\r\n",
"Start-Process -FilePath $fileName -ArgumentList $args -WorkingDirectory $workingDirectory"
],
"metadata": {
"azdata_cell_guid": "51466298-63af-4eee-8fca-b862b5ce2920",
"tags": []
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"**4) Run the SKU recommendation action to get the right Azure SQL Database/Managed Instance SKU based on the collected performance data**"
],
"metadata": {
"azdata_cell_guid": "3b6ad488-8eea-4434-bcb9-f6b37da3136a"
}
},
{
"cell_type": "code",
"source": [
"# Select your desired target platform here\r\n",
"$targetPlatform = \"AzureSqlDatabase\"\r\n",
"# $targetPlatform = \"AzureSqlManagedInstance\"\r\n",
"# $targetPlatform = \"AzureSqlVirtualMachine\"\r\n",
"\r\n",
"$args= \"GetSkuRecommendation --targetPlatform $targetPlatform --perfQueryIntervalInSec $perfQueryIntervalInSec\"\r\n",
"\r\n",
"Start-Process -Wait -FilePath $fileName -ArgumentList $args -WorkingDirectory $workingDirectory \r\n",
"\r\n",
"# Show high level target SKU recommendations, for more detail + reasoning please look at SkuRecommendationReport.json in the output folder\r\n",
"$json = Get-Content $workingDirectory\\SkuRecommendationReport.json | ConvertFrom-Json \r\n",
"$json | Select-Object -ExpandProperty RecommendedSku -Property SqlInstanceName, DatabaseName "
],
"metadata": {
"azdata_cell_guid": "e208e132-c3e2-4975-bc4c-c3810f2b74c5",
"tags": []
},
"outputs": [],
"execution_count": null
}
]
}

View File

@@ -13,7 +13,8 @@
},
"activationEvents": [
"onCommand:sqlmigration.start",
"onCommand:sqlmigration.testDialog"
"onCommand:sqlmigration.testDialog",
"onCommand:sqlmigration.openNotebooks"
],
"main": "./out/main",
"repository": {
@@ -34,6 +35,11 @@
"command": "sqlmigration.testDialog",
"title": "SQL Migration test dialog",
"category": "SQL Migration"
},
{
"command": "sqlmigration.openNotebooks",
"title": "%migration-notebook-command-title%",
"category": "SQL Migration"
}
]
},

View File

@@ -1,4 +1,5 @@
{
"displayName": "SQL Migration",
"description": "SQL migration description"
"description": "SQL migration description",
"migration-notebook-command-title": "Open SQL migration notebooks"
}

View File

@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as loc from './models/strings';
export class NotebookPathHelper {
private static context: vscode.ExtensionContext;
public static inlineMigrationNotebook: MigrationNotebookInfo;
public static sqlAssessmentNotebook: MigrationNotebookInfo;
public static setExtensionContext(context: vscode.ExtensionContext) {
NotebookPathHelper.context = context;
NotebookPathHelper.inlineMigrationNotebook = {
label: loc.NOTEBOOK_INLINE_MIGRATION_TITLE,
notebookPath: NotebookPathHelper.context.asAbsolutePath('notebooks/Inline_Migration_Notebook.ipynb')
};
NotebookPathHelper.sqlAssessmentNotebook = {
label: loc.NOTEBOOK_SQL_MIGRATION_ASSESSMENT_TITLE,
notebookPath: NotebookPathHelper.context.asAbsolutePath('notebooks/SQL_Assessment_Notebook.ipynb')
};
}
public static getAllMigrationNotebooks(): MigrationNotebookInfo[] {
return [
NotebookPathHelper.inlineMigrationNotebook,
NotebookPathHelper.sqlAssessmentNotebook
];
}
}
export interface MigrationNotebookInfo {
label: string;
notebookPath: string
}

View File

@@ -7,10 +7,15 @@ import * as vscode from 'vscode';
import * as azdata from 'azdata';
import { WizardController } from './wizard/wizardController';
import { AssessmentResultsDialog } from './dialog/assessmentResults/assessmentResultsDialog';
import { MigrationNotebookInfo, NotebookPathHelper } from './contants';
import { promises as fs } from 'fs';
import * as loc from './models/strings';
class SQLMigration {
constructor(private readonly context: vscode.ExtensionContext) {
NotebookPathHelper.setExtensionContext(context);
}
async start(): Promise<void> {
@@ -37,6 +42,31 @@ class SQLMigration {
vscode.commands.registerCommand('sqlmigration.testDialog', async () => {
let dialog = new AssessmentResultsDialog('ownerUri', undefined!, 'Assessment Dialog');
await dialog.openDialog();
}),
vscode.commands.registerCommand('sqlmigration.openNotebooks', async () => {
const input = vscode.window.createQuickPick<MigrationNotebookInfo>();
input.placeholder = loc.NOTEBOOK_QUICK_PICK_PLACEHOLDER;
input.items = NotebookPathHelper.getAllMigrationNotebooks();
input.onDidAccept(async (e) => {
const selectedNotebook = input.selectedItems[0];
if (selectedNotebook) {
try {
azdata.nb.showNotebookDocument(vscode.Uri.parse(`untitled: ${selectedNotebook.label}`), {
preview: false,
initialContent: (await fs.readFile(selectedNotebook.notebookPath)).toString(),
initialDirtyState: false
});
} catch (e) {
vscode.window.showErrorMessage(`${loc.NOTEBOOK_OPEN_ERROR} - ${e.toString()}`);
}
input.hide();
}
});
input.show();
})
];

View File

@@ -143,3 +143,10 @@ export const REFRESH = localize('sql.migration.refresh', "Refresh");
export const SUBMIT = localize('sql.migration.submit', "Submit");
export const CREATE = localize('sql.migration.create', "Create");
export const CANCEL = localize('sql.migration.cancel', "Cancel");
// Open notebook quick pick string
export const NOTEBOOK_QUICK_PICK_PLACEHOLDER = localize('sql.migration.quick.pick.placeholder', "Select the operation you'd like to perform");
export const NOTEBOOK_INLINE_MIGRATION_TITLE = localize('sql.migration.inline.migration.notebook.title', "Inline migration");
export const NOTEBOOK_SQL_MIGRATION_ASSESSMENT_TITLE = localize('sql.migration.sql.assessment.notebook.title', "SQL migration assessment");
export const NOTEBOOK_OPEN_ERROR = localize('sql.migration.notebook.open.error', "Error opening migration notebook");