mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 02:02:35 -05:00
Add static logger class for azdata extension (#11939)
* Add static logger class for arc extension * Fix compile errors * Fix test
This commit is contained in:
@@ -10,6 +10,7 @@ import * as loc from './localizedConstants';
|
||||
import { executeCommand, executeSudoCommand, ExitCodeError } from './common/childProcess';
|
||||
import { searchForCmd } from './common/utils';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import Logger from './common/logger';
|
||||
|
||||
export const azdataHostname = 'https://aka.ms';
|
||||
export const azdataUri = 'azdata-msi';
|
||||
@@ -26,7 +27,7 @@ export interface IAzdataTool extends azdataExt.IAzdataApi {
|
||||
}
|
||||
|
||||
class AzdataTool implements IAzdataTool {
|
||||
constructor(public path: string, public toolVersion: string, private _outputChannel: vscode.OutputChannel) { }
|
||||
constructor(public path: string, public toolVersion: string) { }
|
||||
|
||||
public arc = {
|
||||
dc: {
|
||||
@@ -97,7 +98,7 @@ class AzdataTool implements IAzdataTool {
|
||||
|
||||
public async executeCommand<R>(args: string[], additionalEnvVars?: { [key: string]: string }): Promise<azdataExt.AzdataOutput<R>> {
|
||||
try {
|
||||
const output = JSON.parse((await executeCommand(`"${this.path}"`, args.concat(['--output', 'json']), this._outputChannel, additionalEnvVars)).stdout);
|
||||
const output = JSON.parse((await executeCommand(`"${this.path}"`, args.concat(['--output', 'json']), additionalEnvVars)).stdout);
|
||||
return {
|
||||
logs: <string[]>output.log,
|
||||
stdout: <string[]>output.stdout,
|
||||
@@ -119,45 +120,43 @@ class AzdataTool implements IAzdataTool {
|
||||
/**
|
||||
* Finds the existing installation of azdata, or throws an error if it couldn't find it
|
||||
* or encountered an unexpected error.
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
export async function findAzdata(outputChannel: vscode.OutputChannel): Promise<IAzdataTool> {
|
||||
outputChannel.appendLine(loc.searchingForAzdata);
|
||||
export async function findAzdata(): Promise<IAzdataTool> {
|
||||
Logger.log(loc.searchingForAzdata);
|
||||
try {
|
||||
let azdata: IAzdataTool | undefined = undefined;
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
azdata = await findAzdataWin32(outputChannel);
|
||||
azdata = await findAzdataWin32();
|
||||
break;
|
||||
default:
|
||||
azdata = await findSpecificAzdata('azdata', outputChannel);
|
||||
azdata = await findSpecificAzdata('azdata');
|
||||
}
|
||||
outputChannel.appendLine(loc.foundExistingAzdata(azdata.path, azdata.toolVersion));
|
||||
Logger.log(loc.foundExistingAzdata(azdata.path, azdata.toolVersion));
|
||||
return azdata;
|
||||
} catch (err) {
|
||||
outputChannel.appendLine(loc.couldNotFindAzdata(err));
|
||||
Logger.log(loc.couldNotFindAzdata(err));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the appropriate installer and/or runs the command to install azdata
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
export async function downloadAndInstallAzdata(outputChannel: vscode.OutputChannel): Promise<void> {
|
||||
export async function downloadAndInstallAzdata(): Promise<void> {
|
||||
const statusDisposable = vscode.window.setStatusBarMessage(loc.installingAzdata);
|
||||
outputChannel.show();
|
||||
outputChannel.appendLine(loc.installingAzdata);
|
||||
Logger.show();
|
||||
Logger.log(loc.installingAzdata);
|
||||
try {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
await downloadAndInstallAzdataWin32(outputChannel);
|
||||
await downloadAndInstallAzdataWin32();
|
||||
break;
|
||||
case 'darwin':
|
||||
await installAzdataDarwin(outputChannel);
|
||||
await installAzdataDarwin();
|
||||
break;
|
||||
case 'linux':
|
||||
await installAzdataLinux(outputChannel);
|
||||
await installAzdataLinux();
|
||||
break;
|
||||
default:
|
||||
throw new Error(loc.platformUnsupported(process.platform));
|
||||
@@ -169,58 +168,55 @@ export async function downloadAndInstallAzdata(outputChannel: vscode.OutputChann
|
||||
|
||||
/**
|
||||
* Downloads the Windows installer and runs it
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
async function downloadAndInstallAzdataWin32(outputChannel: vscode.OutputChannel): Promise<void> {
|
||||
async function downloadAndInstallAzdataWin32(): Promise<void> {
|
||||
const downloadFolder = os.tmpdir();
|
||||
const downloadedFile = await HttpClient.download(`${azdataHostname}/${azdataUri}`, downloadFolder, outputChannel);
|
||||
await executeCommand('msiexec', ['/qn', '/i', downloadedFile], outputChannel);
|
||||
const downloadedFile = await HttpClient.download(`${azdataHostname}/${azdataUri}`, downloadFolder);
|
||||
await executeCommand('msiexec', ['/qn', '/i', downloadedFile]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs commands to install azdata on MacOS
|
||||
*/
|
||||
async function installAzdataDarwin(outputChannel: vscode.OutputChannel): Promise<void> {
|
||||
await executeCommand('brew', ['tap', 'microsoft/azdata-cli-release'], outputChannel);
|
||||
await executeCommand('brew', ['update'], outputChannel);
|
||||
await executeCommand('brew', ['install', 'azdata-cli'], outputChannel);
|
||||
async function installAzdataDarwin(): Promise<void> {
|
||||
await executeCommand('brew', ['tap', 'microsoft/azdata-cli-release']);
|
||||
await executeCommand('brew', ['update']);
|
||||
await executeCommand('brew', ['install', 'azdata-cli']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs commands to install azdata on Linux
|
||||
*/
|
||||
async function installAzdataLinux(outputChannel: vscode.OutputChannel): Promise<void> {
|
||||
async function installAzdataLinux(): Promise<void> {
|
||||
// https://docs.microsoft.com/en-us/sql/big-data-cluster/deploy-install-azdata-linux-package
|
||||
// Get packages needed for install process
|
||||
await executeSudoCommand('apt-get update', outputChannel);
|
||||
await executeSudoCommand('apt-get install gnupg ca-certificates curl wget software-properties-common apt-transport-https lsb-release -y', outputChannel);
|
||||
await executeSudoCommand('apt-get update');
|
||||
await executeSudoCommand('apt-get install gnupg ca-certificates curl wget software-properties-common apt-transport-https lsb-release -y');
|
||||
// Download and install the signing key
|
||||
await executeSudoCommand('curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null', outputChannel);
|
||||
await executeSudoCommand('curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null');
|
||||
// Add the azdata repository information
|
||||
const release = (await executeCommand('lsb_release', ['-rs'], outputChannel)).stdout.trim();
|
||||
await executeSudoCommand(`add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/${release}/mssql-server-2019.list)"`, outputChannel);
|
||||
const release = (await executeCommand('lsb_release', ['-rs'])).stdout.trim();
|
||||
await executeSudoCommand(`add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/${release}/mssql-server-2019.list)"`);
|
||||
// Update repository information and install azdata
|
||||
await executeSudoCommand('apt-get update', outputChannel);
|
||||
await executeSudoCommand('apt-get install -y azdata-cli', outputChannel);
|
||||
await executeSudoCommand('apt-get update');
|
||||
await executeSudoCommand('apt-get install -y azdata-cli');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds azdata specifically on Windows
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
async function findAzdataWin32(outputChannel: vscode.OutputChannel): Promise<IAzdataTool> {
|
||||
async function findAzdataWin32(): Promise<IAzdataTool> {
|
||||
const promise = searchForCmd('azdata.cmd');
|
||||
return findSpecificAzdata(await promise, outputChannel);
|
||||
return findSpecificAzdata(await promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version using a known azdata path
|
||||
* @param path The path to the azdata executable
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
async function findSpecificAzdata(path: string, outputChannel: vscode.OutputChannel): Promise<IAzdataTool> {
|
||||
const versionOutput = await executeCommand(`"${path}"`, ['--version'], outputChannel);
|
||||
return new AzdataTool(path, parseVersion(versionOutput.stdout), outputChannel);
|
||||
async function findSpecificAzdata(path: string): Promise<IAzdataTool> {
|
||||
const versionOutput = await executeCommand(`"${path}"`, ['--version']);
|
||||
return new AzdataTool(path, parseVersion(versionOutput.stdout));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user