Manual azdata installation/upgrade using Readme (#12023)

* code complete

* string fixes

* show logger

* pr feedback
This commit is contained in:
Arvind Ranasaria
2020-08-31 12:50:10 -07:00
committed by GitHub
parent 61e5003931
commit 7495259e13
4 changed files with 34 additions and 14 deletions

View File

@@ -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<void> {
/**
* 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<boolean> {
@@ -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<void> {
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

View File

@@ -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';

View File

@@ -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<azdataExt.IExtension> {
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: {

View File

@@ -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);