mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 11:08:31 -05:00
Machine Learning Services - Enabling external script for package management only (#9519)
* Machine learning services extension - removed config table and added config update to package manager
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 azdata from 'azdata';
|
||||
import { QueryRunner } from '../common/queryRunner';
|
||||
import * as constants from '../common/constants';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as utils from '../common/utils';
|
||||
import * as nbExtensionApis from '../typings/notebookServices';
|
||||
|
||||
export class PackageManagementService {
|
||||
|
||||
/**
|
||||
* Creates a new instance of ServerConfigManager
|
||||
*/
|
||||
constructor(
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _queryRunner: QueryRunner,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens server config documents
|
||||
*/
|
||||
public async openDocuments(): Promise<boolean> {
|
||||
return await this._apiWrapper.openExternal(vscode.Uri.parse(constants.mlsDocuments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens ODBC driver documents
|
||||
*/
|
||||
public async openOdbcDriverDocuments(): Promise<boolean> {
|
||||
if (utils.isWindows()) {
|
||||
return await this._apiWrapper.openExternal(vscode.Uri.parse(constants.odbcDriverWindowsDocuments));
|
||||
} else {
|
||||
return await this._apiWrapper.openExternal(vscode.Uri.parse(constants.odbcDriverLinuxDocuments));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens install MLS documents
|
||||
*/
|
||||
public async openInstallDocuments(): Promise<boolean> {
|
||||
if (utils.isWindows()) {
|
||||
return await this._apiWrapper.openExternal(vscode.Uri.parse(constants.installMlsWindowsDocs));
|
||||
} else {
|
||||
return await this._apiWrapper.openExternal(vscode.Uri.parse(constants.installMlsLinuxDocs));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if mls is installed in the give SQL server instance
|
||||
*/
|
||||
public async isMachineLearningServiceEnabled(connection: azdata.connection.ConnectionProfile): Promise<boolean> {
|
||||
return this._queryRunner.isMachineLearningServiceEnabled(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if R installed in the give SQL server instance
|
||||
*/
|
||||
public async isRInstalled(connection: azdata.connection.ConnectionProfile): Promise<boolean> {
|
||||
return this._queryRunner.isRInstalled(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if python installed in the give SQL server instance
|
||||
*/
|
||||
public async isPythonInstalled(connection: azdata.connection.ConnectionProfile): Promise<boolean> {
|
||||
return this._queryRunner.isPythonInstalled(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates external script config
|
||||
* @param connection SQL Connection
|
||||
* @param enable if true external script will be enabled
|
||||
*/
|
||||
public async enableExternalScriptConfig(connection: azdata.connection.ConnectionProfile): Promise<boolean> {
|
||||
let current = await this._queryRunner.isMachineLearningServiceEnabled(connection);
|
||||
|
||||
if (current) {
|
||||
return current;
|
||||
}
|
||||
let confirmed = await utils.promptConfirm(constants.confirmEnableExternalScripts, this._apiWrapper);
|
||||
if (confirmed) {
|
||||
await this._queryRunner.updateExternalScriptConfig(connection, true);
|
||||
current = await this._queryRunner.isMachineLearningServiceEnabled(connection);
|
||||
if (current) {
|
||||
this._apiWrapper.showInfoMessage(constants.mlsEnabledMessage);
|
||||
} else {
|
||||
this._apiWrapper.showErrorMessage(constants.mlsConfigUpdateFailed);
|
||||
}
|
||||
} else {
|
||||
this._apiWrapper.showErrorMessage(constants.externalScriptsIsRequiredError);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns python packages installed in SQL server instance
|
||||
* @param connection SQL Connection
|
||||
*/
|
||||
public async getPythonPackages(connection: azdata.connection.ConnectionProfile): Promise<nbExtensionApis.IPackageDetails[]> {
|
||||
return this._queryRunner.getPythonPackages(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns python packages installed in SQL server instance
|
||||
* @param connection SQL Connection
|
||||
*/
|
||||
public async getRPackages(connection: azdata.connection.ConnectionProfile): Promise<nbExtensionApis.IPackageDetails[]> {
|
||||
return this._queryRunner.getRPackages(connection);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as nbExtensionApis from '../typings/notebookServices';
|
||||
import { SqlPythonPackageManageProvider } from './sqlPythonPackageManageProvider';
|
||||
import { QueryRunner } from '../common/queryRunner';
|
||||
import * as utils from '../common/utils';
|
||||
import * as constants from '../common/constants';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
@@ -17,6 +16,7 @@ import { isNullOrUndefined } from 'util';
|
||||
import { SqlRPackageManageProvider } from './sqlRPackageManageProvider';
|
||||
import { HttpClient } from '../common/httpClient';
|
||||
import { PackageConfigModel } from '../configurations/packageConfigModel';
|
||||
import { PackageManagementService } from './packageManagementService';
|
||||
|
||||
export class PackageManager {
|
||||
|
||||
@@ -31,12 +31,12 @@ export class PackageManager {
|
||||
private _outputChannel: vscode.OutputChannel,
|
||||
private _rootFolder: string,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _queryRunner: QueryRunner,
|
||||
private _service: PackageManagementService,
|
||||
private _processService: ProcessService,
|
||||
private _config: Config,
|
||||
private _httpClient: HttpClient) {
|
||||
this._sqlPythonPackagePackageManager = new SqlPythonPackageManageProvider(this._outputChannel, this._apiWrapper, this._queryRunner, this._processService, this._config, this._httpClient);
|
||||
this._sqlRPackageManager = new SqlRPackageManageProvider(this._outputChannel, this._apiWrapper, this._queryRunner, this._processService, this._config, this._httpClient);
|
||||
this._sqlPythonPackagePackageManager = new SqlPythonPackageManageProvider(this._outputChannel, this._apiWrapper, this._service, this._processService, this._config, this._httpClient);
|
||||
this._sqlRPackageManager = new SqlRPackageManageProvider(this._outputChannel, this._apiWrapper, this._service, this._processService, this._config, this._httpClient);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,11 +67,13 @@ export class PackageManager {
|
||||
*/
|
||||
public async managePackages(): Promise<void> {
|
||||
try {
|
||||
await this.enableExternalScript();
|
||||
|
||||
// Only execute the command if there's a valid connection with ml configuration enabled
|
||||
//
|
||||
let connection = await this.getCurrentConnection();
|
||||
let isPythonInstalled = await this._queryRunner.isPythonInstalled(connection);
|
||||
let isRInstalled = await this._queryRunner.isRInstalled(connection);
|
||||
let isPythonInstalled = await this._service.isPythonInstalled(connection);
|
||||
let isRInstalled = await this._service.isRInstalled(connection);
|
||||
let defaultProvider: SqlRPackageManageProvider | SqlPythonPackageManageProvider | undefined;
|
||||
if (connection && isPythonInstalled && this._sqlPythonPackagePackageManager.canUseProvider) {
|
||||
defaultProvider = this._sqlPythonPackagePackageManager;
|
||||
@@ -80,10 +82,10 @@ export class PackageManager {
|
||||
}
|
||||
if (connection && defaultProvider) {
|
||||
|
||||
await this.enableExternalScript();
|
||||
// Install dependencies
|
||||
//
|
||||
if (!this.dependenciesInstalled) {
|
||||
this._apiWrapper.showInfoMessage(constants.installingDependencies);
|
||||
await this.installDependencies();
|
||||
this.dependenciesInstalled = true;
|
||||
}
|
||||
@@ -99,7 +101,14 @@ export class PackageManager {
|
||||
this._apiWrapper.showInfoMessage(constants.managePackageCommandError);
|
||||
}
|
||||
} catch (err) {
|
||||
this._outputChannel.appendLine(err);
|
||||
this._apiWrapper.showErrorMessage(err);
|
||||
}
|
||||
}
|
||||
|
||||
public async enableExternalScript(): Promise<void> {
|
||||
let connection = await this.getCurrentConnection();
|
||||
if (!await this._service.enableExternalScriptConfig(connection)) {
|
||||
throw Error(constants.externalScriptsIsRequiredError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as nbExtensionApis from '../typings/notebookServices';
|
||||
import { QueryRunner } from '../common/queryRunner';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { ProcessService } from '../common/processService';
|
||||
import { Config } from '../configurations/config';
|
||||
import { SqlPackageManageProviderBase, ScriptMode } from './SqlPackageManageProviderBase';
|
||||
import { HttpClient } from '../common/httpClient';
|
||||
import * as utils from '../common/utils';
|
||||
import { PackageManagementService } from './packageManagementService';
|
||||
|
||||
/**
|
||||
* Manage Package Provider for python packages inside SQL server databases
|
||||
@@ -26,7 +26,7 @@ export class SqlPythonPackageManageProvider extends SqlPackageManageProviderBase
|
||||
constructor(
|
||||
private _outputChannel: vscode.OutputChannel,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _queryRunner: QueryRunner,
|
||||
private _service: PackageManagementService,
|
||||
private _processService: ProcessService,
|
||||
private _config: Config,
|
||||
private _httpClient: HttpClient) {
|
||||
@@ -51,7 +51,7 @@ export class SqlPythonPackageManageProvider extends SqlPackageManageProviderBase
|
||||
* Returns list of packages
|
||||
*/
|
||||
protected async fetchPackages(): Promise<nbExtensionApis.IPackageDetails[]> {
|
||||
return await this._queryRunner.getPythonPackages(await this.getCurrentConnection());
|
||||
return await this._service.getPythonPackages(await this.getCurrentConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ export class SqlPythonPackageManageProvider extends SqlPackageManageProviderBase
|
||||
return false;
|
||||
}
|
||||
let connection = await this.getCurrentConnection();
|
||||
if (connection && await this._queryRunner.isPythonInstalled(connection)) {
|
||||
if (connection && await this._service.isPythonInstalled(connection)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -7,13 +7,13 @@ import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as nbExtensionApis from '../typings/notebookServices';
|
||||
|
||||
import { QueryRunner } from '../common/queryRunner';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { ProcessService } from '../common/processService';
|
||||
import { Config } from '../configurations/config';
|
||||
import { SqlPackageManageProviderBase, ScriptMode } from './SqlPackageManageProviderBase';
|
||||
import { HttpClient } from '../common/httpClient';
|
||||
import * as constants from '../common/constants';
|
||||
import { PackageManagementService } from './packageManagementService';
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export class SqlRPackageManageProvider extends SqlPackageManageProviderBase impl
|
||||
constructor(
|
||||
private _outputChannel: vscode.OutputChannel,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _queryRunner: QueryRunner,
|
||||
private _service: PackageManagementService,
|
||||
private _processService: ProcessService,
|
||||
private _config: Config,
|
||||
private _httpClient: HttpClient) {
|
||||
@@ -55,7 +55,7 @@ export class SqlRPackageManageProvider extends SqlPackageManageProviderBase impl
|
||||
* Returns list of packages
|
||||
*/
|
||||
protected async fetchPackages(): Promise<nbExtensionApis.IPackageDetails[]> {
|
||||
return await this._queryRunner.getRPackages(await this.getCurrentConnection());
|
||||
return await this._service.getRPackages(await this.getCurrentConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +96,7 @@ export class SqlRPackageManageProvider extends SqlPackageManageProviderBase impl
|
||||
return false;
|
||||
}
|
||||
let connection = await this.getCurrentConnection();
|
||||
if (connection && await this._queryRunner.isRInstalled(connection)) {
|
||||
if (connection && await this._service.isRInstalled(connection)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user