From 7495259e13d0e637ddca1102c751a91e50b6bb7c Mon Sep 17 00:00:00 2001 From: Arvind Ranasaria Date: Mon, 31 Aug 2020 12:50:10 -0700 Subject: [PATCH] Manual azdata installation/upgrade using Readme (#12023) * code complete * string fixes * show logger * pr feedback --- extensions/azdata/src/azdata.ts | 28 +++++++++++++++++++-- extensions/azdata/src/constants.ts | 3 ++- extensions/azdata/src/extension.ts | 15 +++-------- extensions/azdata/src/localizedConstants.ts | 2 ++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/extensions/azdata/src/azdata.ts b/extensions/azdata/src/azdata.ts index 23fcb5deda..af36fabcd3 100644 --- a/extensions/azdata/src/azdata.ts +++ b/extensions/azdata/src/azdata.ts @@ -12,7 +12,7 @@ import { HttpClient } from './common/httpClient'; import Logger from './common/logger'; import { getErrorMessage, searchForCmd } from './common/utils'; import * as loc from './localizedConstants'; -import { azdataConfigSection, debugConfigKey } from './constants'; +import { azdataConfigSection, debugConfigKey, requiredVersion as requiredVersion, installationReadmeUrl } from './constants'; export const azdataHostname = 'https://aka.ms'; export const azdataUri = 'azdata-msi'; @@ -228,7 +228,7 @@ export async function upgradeAzdata(): Promise { /** * Checks whether a newer version of azdata is available - and if it is prompts the user to download and * install it. - * @param currentAzdata The current version of azdata to check . This function is a no-o if currentAzdata is undefined. + * @param currentAzdata The current version of azdata to check . This function is a no-op if currentAzdata is undefined. * returns true if an upgrade was performed and false otherwise. */ export async function checkAndUpgradeAzdata(currentAzdata: IAzdataTool | undefined): Promise { @@ -250,6 +250,30 @@ export async function checkAndUpgradeAzdata(currentAzdata: IAzdataTool | undefin return false; } +/** + * Prompts user to install azdata using opened documentation if it is not installed. + * If it is installed it verifies that the installed version is correct else it prompts user + * to install the correct version using opened documentation + * @param currentAzdata The current version of azdata to check. + */ +export async function manuallyInstallOrUpgradeAzdata(currentAzdata: IAzdataTool | undefined): Promise { + if (currentAzdata === undefined) { + vscode.window.showInformationMessage(loc.installManually(requiredVersion, installationReadmeUrl), 'Ok'); + Logger.show(); + Logger.log(loc.installManually(requiredVersion, installationReadmeUrl)); + } else { + const requiredSemVersion = new SemVer(requiredVersion); + if (requiredSemVersion.compare(currentAzdata.cachedVersion) === 0) { + return; // if we have the required version then nothing more needs to be eon. + } + vscode.window.showInformationMessage(loc.installCorrectVersionManually(currentAzdata.cachedVersion.raw, requiredVersion, installationReadmeUrl), 'Ok'); + Logger.show(); + Logger.log(loc.installCorrectVersionManually(currentAzdata.cachedVersion.raw, requiredVersion, installationReadmeUrl)); + } + // display the instructions document in a new editor window. + // const downloadedFile = await HttpClient.downloadFile(installationInstructionDoc, os.tmpdir()); + // await vscode.window.showTextDocument(vscode.Uri.parse(downloadedFile)); +} /** * Downloads the Windows installer and runs it diff --git a/extensions/azdata/src/constants.ts b/extensions/azdata/src/constants.ts index 8e84ed117d..68df09fd6c 100644 --- a/extensions/azdata/src/constants.ts +++ b/extensions/azdata/src/constants.ts @@ -4,5 +4,6 @@ *--------------------------------------------------------------------------------------------*/ export const azdataConfigSection = 'azdata'; - export const debugConfigKey = 'logDebugInfo'; +export const requiredVersion = '20.1.1'; +export const installationReadmeUrl = 'https://github.com/microsoft/Azure-data-services-on-Azure-Arc/blob/Aug-2020/scenarios-new/001-install-client-tools.md'; diff --git a/extensions/azdata/src/extension.ts b/extensions/azdata/src/extension.ts index e3e69abc16..a70c0893b1 100644 --- a/extensions/azdata/src/extension.ts +++ b/extensions/azdata/src/extension.ts @@ -4,23 +4,16 @@ *--------------------------------------------------------------------------------------------*/ import * as azdataExt from 'azdata-ext'; -import * as vscode from 'vscode'; -import { checkAndUpgradeAzdata, findAzdata, IAzdataTool } from './azdata'; +import { findAzdata, IAzdataTool, manuallyInstallOrUpgradeAzdata } from './azdata'; import * as loc from './localizedConstants'; let localAzdata: IAzdataTool | undefined = undefined; export async function activate(): Promise { localAzdata = await checkForAzdata(); - // Don't block on this since we want the extension to finish activating without needing user input - // upgrade if available and user wants it. - checkAndUpgradeAzdata(localAzdata) - .then(async upgradePerformed => { - if (upgradePerformed) { // If upgrade was performed then find and save the new azdata - localAzdata = await findAzdata(); - } - }) - .catch(err => vscode.window.showWarningMessage(loc.upgradeError(err))); + // Don't block on this since we want the extension to finish activating without user actions + manuallyInstallOrUpgradeAzdata(localAzdata) + .catch(err => console.log(err)); return { azdata: { arc: { diff --git a/extensions/azdata/src/localizedConstants.ts b/extensions/azdata/src/localizedConstants.ts index 41a72905bf..dbb4aa10a8 100644 --- a/extensions/azdata/src/localizedConstants.ts +++ b/extensions/azdata/src/localizedConstants.ts @@ -36,3 +36,5 @@ export const upgradeError = (err: any): string => localize('azdata.upgradeError' export const upgradeCheckSkipped = localize('azdata.updateCheckSkipped', "No check for new azdata version availability performed as azdata was not found to be installed"); export const unexpectedExitCode = (code: number, err: string): string => localize('azdata.unexpectedExitCode', "Unexpected exit code from command : {1} ({0})", code, err); export const noAzdata = localize('azdata.NoAzdata', "No azdata available"); +export const installManually = (expectedVersion: string, instructionsUrl: string) => localize('azdata.installManually', "azdata is not installed. Version: {0} needs to be installed or some features may not work. Please install it manually using these [instructions]({1}). Restart ADS when installation is done.", expectedVersion, instructionsUrl); +export const installCorrectVersionManually = (currentVersion: string, expectedVersion: string, instructionsUrl: string) => localize('azdata.installCorrectVersionManually', "azdata version: {0} is installed, version: {1} needs to be installed or some features may not work. Please uninstall the current version and then install the correct version manually using these [instructions]({2}). Restart ADS when installation is done.", currentVersion, expectedVersion, instructionsUrl);