mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 09:35:38 -05:00
* add install tools button (#7454) * add install tools button * address comments * remove description for install tools hint message * First working version of AutoDeployment of tools (#7647) First working version of AutoDeployment of tools. This pull request adds feature to install the tools needed for doing BDC/TINA deployments. This has been tested so far only on win32 and testing on other platforms is in progress. * removing TODO and redundant code * Not localizing azuredatastudio product name * convert methods returning Promises to async-await * changing from null to undefined * Localize all the command labels * using existing sudo-prompt typings * progres/error status in ModalDialogue && PR fixes * review feedback to change warning to information * revert settings.json changes * fix resource-Deployment Extension Unit Test * ensuring platform service's working directory * incorporate review feedback * review feedback * addressing PR feedback * PR fixes * PR Feedback * remove debug logs * disable UI deployment containers when installing * addding data type to stdout/stderr messaging * remove commented code * revert accidental change * addressing review feedback * fix failed install with zero exit code * fixing bug due to typo * fixes for linux * Misc fixes during mac testing * PR fixes
88 lines
3.8 KiB
TypeScript
88 lines
3.8 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import * as path from 'path';
|
|
import { IPlatformService } from './platformService';
|
|
import { BigDataClusterDeploymentProfile } from './bigDataClusterDeploymentProfile';
|
|
import { BdcDeploymentType } from '../interfaces';
|
|
|
|
interface BdcConfigListOutput {
|
|
result: string[];
|
|
}
|
|
|
|
export interface BdcEndpoint {
|
|
endpoint: string;
|
|
name: 'sql-server-master';
|
|
}
|
|
|
|
export interface IAzdataService {
|
|
getDeploymentProfiles(deploymentType: BdcDeploymentType): Promise<BigDataClusterDeploymentProfile[]>;
|
|
getEndpoints(clusterName: string, userName: string, password: string): Promise<BdcEndpoint[]>;
|
|
}
|
|
|
|
export class AzdataService implements IAzdataService {
|
|
constructor(private platformService: IPlatformService) {
|
|
}
|
|
|
|
public async getDeploymentProfiles(deploymentType: BdcDeploymentType): Promise<BigDataClusterDeploymentProfile[]> {
|
|
let profilePrefix: string;
|
|
switch (deploymentType) {
|
|
case BdcDeploymentType.NewAKS:
|
|
case BdcDeploymentType.ExistingAKS:
|
|
profilePrefix = 'aks';
|
|
break;
|
|
case BdcDeploymentType.ExistingKubeAdm:
|
|
profilePrefix = 'kubeadm';
|
|
break;
|
|
default:
|
|
throw new Error(`Unknown deployment type: ${deploymentType}`);
|
|
}
|
|
await this.ensureWorkingDirectoryExists();
|
|
const profileNames = await this.getDeploymentProfileNames();
|
|
return await Promise.all(profileNames.filter(profile => profile.startsWith(profilePrefix)).map(profile => this.getDeploymentProfileInfo(profile)));
|
|
}
|
|
|
|
private async getDeploymentProfileNames(): Promise<string[]> {
|
|
const env: NodeJS.ProcessEnv = {};
|
|
// azdata requires this environment variables to be set
|
|
env['ACCEPT_EULA'] = 'yes';
|
|
const cmd = 'azdata bdc config list -o json';
|
|
const stdout = await this.platformService.runCommand(cmd, { additionalEnvironmentVariables: env });
|
|
const output = <BdcConfigListOutput>JSON.parse(stdout);
|
|
return output.result;
|
|
}
|
|
|
|
private async getDeploymentProfileInfo(profileName: string): Promise<BigDataClusterDeploymentProfile> {
|
|
const env: NodeJS.ProcessEnv = {};
|
|
// azdata requires this environment variables to be set
|
|
env['ACCEPT_EULA'] = 'yes';
|
|
await this.platformService.runCommand(`azdata bdc config init --source ${profileName} --target ${profileName} --force`, { workingDirectory: this.platformService.storagePath(), additionalEnvironmentVariables: env });
|
|
const configObjects = await Promise.all([
|
|
this.getJsonObjectFromFile(path.join(this.platformService.storagePath(), profileName, 'bdc.json')),
|
|
this.getJsonObjectFromFile(path.join(this.platformService.storagePath(), profileName, 'control.json'))
|
|
]);
|
|
return new BigDataClusterDeploymentProfile(profileName, configObjects[0], configObjects[1]);
|
|
}
|
|
|
|
private async ensureWorkingDirectoryExists(): Promise<void> {
|
|
await this.platformService.ensureDirectoryExists(this.platformService.storagePath());
|
|
}
|
|
|
|
private async getJsonObjectFromFile(path: string): Promise<any> {
|
|
return JSON.parse(await this.platformService.readTextFile(path));
|
|
}
|
|
|
|
public async getEndpoints(clusterName: string, userName: string, password: string): Promise<BdcEndpoint[]> {
|
|
const env: NodeJS.ProcessEnv = {};
|
|
env['AZDATA_USERNAME'] = userName;
|
|
env['AZDATA_PASSWORD'] = password;
|
|
env['ACCEPT_EULA'] = 'yes';
|
|
let cmd = 'azdata login -n ' + clusterName;
|
|
await this.platformService.runCommand(cmd, { additionalEnvironmentVariables: env });
|
|
cmd = 'azdata bdc endpoint list';
|
|
const stdout = await this.platformService.runCommand(cmd, { additionalEnvironmentVariables: env });
|
|
return <BdcEndpoint[]>JSON.parse(stdout);
|
|
}
|
|
}
|