Converting all SQL MIAA commands to use K8s API commands (#20203)

* refresh does not differentiate direct vs indirect

* For direct mode MIAA commands, always use --use-k8s

* Changed comment language to use ARM instead of direct and K8S API instead of indirect

Co-authored-by: Candice Ye <canye@microsoft.com>
This commit is contained in:
Candice Ye
2022-08-02 11:12:25 -07:00
committed by GitHub
parent 8f5b3ef81d
commit 5d23627165
9 changed files with 92 additions and 212 deletions

View File

@@ -6,7 +6,6 @@
import { ControllerInfo, ResourceType } from 'arc'; import { ControllerInfo, ResourceType } from 'arc';
import * as azExt from 'az-ext'; import * as azExt from 'az-ext';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { ConnectionMode } from '../constants';
import * as loc from '../localizedConstants'; import * as loc from '../localizedConstants';
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider'; import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
@@ -69,15 +68,6 @@ export class ControllerModel {
} }
public async refresh(showErrors: boolean = true, namespace: string): Promise<void> { public async refresh(showErrors: boolean = true, namespace: string): Promise<void> {
await this.refreshController(showErrors, namespace);
if (this._controllerConfig?.spec.settings.azure.connectionMode.toLowerCase() === ConnectionMode.direct) {
await this.refreshDirectMode(this._controllerConfig?.spec.settings.azure.resourceGroup, namespace);
} else {
await this.refreshIndirectMode(namespace);
}
}
public async refreshController(showErrors: boolean = true, namespace: string): Promise<void> {
await Promise.all([ await Promise.all([
this._azApi.az.arcdata.dc.config.show(namespace, this.azAdditionalEnvVars).then(result => { this._azApi.az.arcdata.dc.config.show(namespace, this.azAdditionalEnvVars).then(result => {
this._controllerConfig = result.stdout; this._controllerConfig = result.stdout;
@@ -108,38 +98,6 @@ export class ControllerModel {
throw err; throw err;
}) })
]); ]);
}
public async refreshDirectMode(resourceGroup: string, namespace: string): Promise<void> {
const newRegistrations: Registration[] = [];
await Promise.all([
this._azApi.az.postgres.arcserver.list(namespace, this.azAdditionalEnvVars).then(result => {
newRegistrations.push(...result.stdout.map(r => {
return {
instanceName: r.name,
state: r.state,
instanceType: ResourceType.postgresInstances
};
}));
}),
this._azApi.az.sql.miarc.list({ resourceGroup: resourceGroup, namespace: undefined }, this.azAdditionalEnvVars).then(result => {
newRegistrations.push(...result.stdout.map(r => {
return {
instanceName: r.name,
state: r.state,
instanceType: ResourceType.sqlManagedInstances
};
}));
})
]).then(() => {
this._registrations = newRegistrations;
this.registrationsLastUpdated = new Date();
this._onRegistrationsUpdated.fire(this._registrations);
});
}
public async refreshIndirectMode(namespace: string): Promise<void> {
const newRegistrations: Registration[] = []; const newRegistrations: Registration[] = [];
await Promise.all([ await Promise.all([
this._azApi.az.postgres.arcserver.list(namespace, this.azAdditionalEnvVars).then(result => { this._azApi.az.postgres.arcserver.list(namespace, this.azAdditionalEnvVars).then(result => {

View File

@@ -15,7 +15,6 @@ import { ConnectToMiaaSqlDialog } from '../ui/dialogs/connectMiaaDialog';
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider'; import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
import { ControllerModel, Registration } from './controllerModel'; import { ControllerModel, Registration } from './controllerModel';
import { ResourceModel } from './resourceModel'; import { ResourceModel } from './resourceModel';
import { ConnectionMode } from '../constants';
export type DatabaseModel = { name: string, status: string, earliestBackup: string, lastBackup: string }; export type DatabaseModel = { name: string, status: string, earliestBackup: string, lastBackup: string };
export type RPModel = { recoveryPointObjective: string, retentionDays: string }; export type RPModel = { recoveryPointObjective: string, retentionDays: string };
@@ -100,25 +99,14 @@ export class MiaaModel extends ResourceModel {
try { try {
try { try {
let result; let result;
if (this.controllerModel.info.connectionMode.toLowerCase() === ConnectionMode.direct) { result = await this._azApi.az.sql.miarc.show(
result = await this._azApi.az.sql.miarc.show( this.info.name,
this.info.name, {
{ resourceGroup: undefined,
resourceGroup: this.controllerModel.info.resourceGroup, namespace: this.controllerModel.info.namespace
namespace: undefined },
}, this.controllerModel.azAdditionalEnvVars
this.controllerModel.azAdditionalEnvVars );
);
} else {
result = await this._azApi.az.sql.miarc.show(
this.info.name,
{
resourceGroup: undefined,
namespace: this.controllerModel.info.namespace
},
this.controllerModel.azAdditionalEnvVars
);
}
this._config = result.stdout; this._config = result.stdout;
this.configLastUpdated = new Date(); this.configLastUpdated = new Date();
this.rpSettings.retentionDays = this._config?.spec?.backup?.retentionPeriodInDays?.toString() ?? ''; this.rpSettings.retentionDays = this._config?.spec?.backup?.retentionPeriodInDays?.toString() ?? '';

View File

@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as azExt from 'az-ext'; import * as azExt from 'az-ext';
import * as loc from '../../../localizedConstants'; import * as loc from '../../../localizedConstants';
import { IconPathHelper, cssStyles, ConnectionMode } from '../../../constants'; import { IconPathHelper, cssStyles } from '../../../constants';
import { DashboardPage } from '../../components/dashboardPage'; import { DashboardPage } from '../../components/dashboardPage';
import { MiaaModel, RPModel, DatabaseModel, systemDbs } from '../../../models/miaaModel'; import { MiaaModel, RPModel, DatabaseModel, systemDbs } from '../../../models/miaaModel';
import { ControllerModel } from '../../../models/controllerModel'; import { ControllerModel } from '../../../models/controllerModel';
@@ -220,23 +220,13 @@ export class MiaaBackupsPage extends DashboardPage {
cancellable: false cancellable: false
}, },
async (_progress, _token): Promise<void> => { async (_progress, _token): Promise<void> => {
if (this._miaaModel.controllerModel.info.connectionMode.toLowerCase() === ConnectionMode.direct) { await this._azApi.az.sql.miarc.update(
await this._azApi.az.sql.miarc.update( this._miaaModel.info.name,
this._miaaModel.info.name, this._saveArgs,
this._saveArgs, undefined, // Direct mode argument - resourceGroup
this._miaaModel.controllerModel.info.resourceGroup, this._miaaModel.controllerModel.info.namespace,
undefined, // Indirect mode argument - namespace true,
undefined, // Indirect mode argument - usek8s this._miaaModel.controllerModel.azAdditionalEnvVars);
this._miaaModel.controllerModel.azAdditionalEnvVars);
} else {
await this._azApi.az.sql.miarc.update(
this._miaaModel.info.name,
this._saveArgs,
undefined, // Direct mode argument - resourceGroup
this._miaaModel.controllerModel.info.namespace,
true,
this._miaaModel.controllerModel.azAdditionalEnvVars);
}
try { try {
await this._miaaModel.refresh(); await this._miaaModel.refresh();
} catch (error) { } catch (error) {

View File

@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as azExt from 'az-ext'; import * as azExt from 'az-ext';
import * as loc from '../../../localizedConstants'; import * as loc from '../../../localizedConstants';
import { IconPathHelper, cssStyles, ConnectionMode } from '../../../constants'; import { IconPathHelper, cssStyles } from '../../../constants';
import { DashboardPage } from '../../components/dashboardPage'; import { DashboardPage } from '../../components/dashboardPage';
import { convertToGibibyteString } from '../../../common/utils'; import { convertToGibibyteString } from '../../../common/utils';
import { MiaaModel } from '../../../models/miaaModel'; import { MiaaModel } from '../../../models/miaaModel';
@@ -132,23 +132,13 @@ export class MiaaComputeAndStoragePage extends DashboardPage {
}, },
async (_progress, _token): Promise<void> => { async (_progress, _token): Promise<void> => {
try { try {
if (this._miaaModel.controllerModel.info.connectionMode.toLowerCase() === ConnectionMode.direct) { await this._azApi.az.sql.miarc.update(
await this._azApi.az.sql.miarc.update( this._miaaModel.info.name,
this._miaaModel.info.name, this.saveArgs,
this.saveArgs, undefined, // Direct mode argument - resourceGroup
this._miaaModel.controllerModel.info.resourceGroup, this._miaaModel.controllerModel.info.namespace,
undefined, // Indirect mode argument - namespace true,
undefined, // Indirect mode argument - usek8s this._miaaModel.controllerModel.azAdditionalEnvVars);
this._miaaModel.controllerModel.azAdditionalEnvVars);
} else {
await this._azApi.az.sql.miarc.update(
this._miaaModel.info.name,
this.saveArgs,
undefined, // Direct mode argument - resourceGroup
this._miaaModel.controllerModel.info.namespace,
true,
this._miaaModel.controllerModel.azAdditionalEnvVars);
}
} catch (err) { } catch (err) {
this.saveButton!.enabled = true; this.saveButton!.enabled = true;
throw err; throw err;

View File

@@ -8,7 +8,7 @@ import * as azExt from 'az-ext';
import * as azurecore from 'azurecore'; import * as azurecore from 'azurecore';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { getDatabaseStateDisplayText, promptForInstanceDeletion } from '../../../common/utils'; import { getDatabaseStateDisplayText, promptForInstanceDeletion } from '../../../common/utils';
import { ConnectionMode, cssStyles, IconPathHelper, miaaTroubleshootDocsUrl } from '../../../constants'; import { cssStyles, IconPathHelper, miaaTroubleshootDocsUrl } from '../../../constants';
import * as loc from '../../../localizedConstants'; import * as loc from '../../../localizedConstants';
import { ControllerModel } from '../../../models/controllerModel'; import { ControllerModel } from '../../../models/controllerModel';
import { MiaaModel } from '../../../models/miaaModel'; import { MiaaModel } from '../../../models/miaaModel';
@@ -243,25 +243,14 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
cancellable: false cancellable: false
}, },
async (_progress, _token) => { async (_progress, _token) => {
if (this._controllerModel.info.connectionMode.toLowerCase() === ConnectionMode.direct) { return await this._azApi.az.sql.miarc.delete(
return await this._azApi.az.sql.miarc.delete( this._miaaModel.info.name,
this._miaaModel.info.name, {
{ resourceGroup: undefined,
resourceGroup: this._controllerModel.info.resourceGroup, namespace: this._controllerModel.info.namespace,
namespace: undefined, },
}, this._controllerModel.azAdditionalEnvVars
this._controllerModel.azAdditionalEnvVars );
);
} else {
return await this._azApi.az.sql.miarc.delete(
this._miaaModel.info.name,
{
resourceGroup: undefined,
namespace: this._controllerModel.info.namespace,
},
this._controllerModel.azAdditionalEnvVars
);
}
} }
); );
await this._controllerModel.refreshTreeNode(); await this._controllerModel.refreshTreeNode();

View File

@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as azExt from 'az-ext'; import * as azExt from 'az-ext';
import * as loc from '../../../localizedConstants'; import * as loc from '../../../localizedConstants';
import { IconPathHelper, cssStyles, ConnectionMode } from '../../../constants'; import { IconPathHelper, cssStyles } from '../../../constants';
import { DashboardPage } from '../../components/dashboardPage'; import { DashboardPage } from '../../components/dashboardPage';
import { ControllerModel } from '../../../models/controllerModel'; import { ControllerModel } from '../../../models/controllerModel';
import { UpgradeSqlMiaa } from '../../dialogs/upgradeSqlMiaa'; import { UpgradeSqlMiaa } from '../../dialogs/upgradeSqlMiaa';
@@ -160,25 +160,14 @@ export class MiaaUpgradeManagementPage extends DashboardPage {
private async getMiaaVersion(): Promise<string | undefined> { private async getMiaaVersion(): Promise<string | undefined> {
try { try {
let miaaShowResult; let miaaShowResult;
if (this._controllerModel.info.connectionMode.toLowerCase() === ConnectionMode.direct || this._controllerModel.controllerConfig?.spec.settings.azure.connectionMode.toLowerCase() === ConnectionMode.direct) { miaaShowResult = await this._azApi.az.sql.miarc.show(
miaaShowResult = await this._azApi.az.sql.miarc.show( this._miaaModel.info.name,
this._miaaModel.info.name, {
{ resourceGroup: undefined,
resourceGroup: this._controllerModel.info.resourceGroup, namespace: this._controllerModel.info.namespace
namespace: undefined },
}, this._controllerModel.azAdditionalEnvVars
this._controllerModel.azAdditionalEnvVars );
);
} else {
miaaShowResult = await this._azApi.az.sql.miarc.show(
this._miaaModel.info.name,
{
resourceGroup: undefined,
namespace: this._controllerModel.info.namespace
},
this._controllerModel.azAdditionalEnvVars
);
}
return miaaShowResult.stdout.status.runningVersion; return miaaShowResult.stdout.status.runningVersion;
} catch (e) { } catch (e) {
console.error(loc.showMiaaError, e); console.error(loc.showMiaaError, e);
@@ -263,51 +252,27 @@ export class MiaaUpgradeManagementPage extends DashboardPage {
try { try {
upgradeButton.enabled = false; upgradeButton.enabled = false;
vscode.window.showInformationMessage(loc.upgradingMiaa('kubectl get sqlmi -A\' should not be localized.')); vscode.window.showInformationMessage(loc.upgradingMiaa('kubectl get sqlmi -A\' should not be localized.'));
if (this._controllerModel.info.connectionMode.toLowerCase() === ConnectionMode.direct) { await vscode.window.withProgress(
await vscode.window.withProgress( {
{ location: vscode.ProgressLocation.Notification,
location: vscode.ProgressLocation.Notification, title: loc.upgradingIndirectMiaa(this._miaaModel.info.name, this._controllerModel.info.namespace),
title: loc.upgradingDirectMiaa(this._miaaModel.info.name, this._controllerModel.info.resourceGroup), cancellable: true
cancellable: true },
}, async (_progress, _token): Promise<void> => {
async (_progress, _token): Promise<void> => { await this._azApi.az.sql.miarc.upgrade(
await this._azApi.az.sql.miarc.upgrade( this._miaaModel.info.name,
this._miaaModel.info.name, {
{ resourceGroup: undefined,
resourceGroup: this._controllerModel.info.resourceGroup, namespace: this._controllerModel.info.namespace,
namespace: undefined
}
);
try {
await this._controllerModel.refresh(false, this._controllerModel.info.namespace);
} catch (error) {
vscode.window.showErrorMessage(loc.refreshFailed(error));
} }
);
try {
await this._controllerModel.refresh(false, this._controllerModel.info.namespace);
} catch (error) {
vscode.window.showErrorMessage(loc.refreshFailed(error));
} }
); }
} else { );
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: loc.upgradingIndirectMiaa(this._miaaModel.info.name, this._controllerModel.info.namespace),
cancellable: true
},
async (_progress, _token): Promise<void> => {
await this._azApi.az.sql.miarc.upgrade(
this._miaaModel.info.name,
{
resourceGroup: undefined,
namespace: this._controllerModel.info.namespace,
}
);
try {
await this._controllerModel.refresh(false, this._controllerModel.info.namespace);
} catch (error) {
vscode.window.showErrorMessage(loc.refreshFailed(error));
}
}
);
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }

View File

@@ -117,9 +117,9 @@ export function getAzApi(localAzDiscovered: Promise<IAzTool | undefined>, azTool
delete: async ( delete: async (
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string; resourceGroup?: string;
// Indirect mode arguments // K8s API arguments
namespace?: string; namespace?: string;
}, },
additionalEnvVars?: azExt.AdditionalEnvVars additionalEnvVars?: azExt.AdditionalEnvVars
@@ -130,9 +130,9 @@ export function getAzApi(localAzDiscovered: Promise<IAzTool | undefined>, azTool
}, },
list: async ( list: async (
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string; resourceGroup?: string;
// Indirect mode arguments // K8s API arguments
namespace?: string; namespace?: string;
}, },
additionalEnvVars?: azExt.AdditionalEnvVars additionalEnvVars?: azExt.AdditionalEnvVars
@@ -144,9 +144,9 @@ export function getAzApi(localAzDiscovered: Promise<IAzTool | undefined>, azTool
show: async ( show: async (
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string; resourceGroup?: string;
// Indirect mode arguments // K8s API arguments
namespace?: string; namespace?: string;
}, },
// Additional arguments // Additional arguments
@@ -166,9 +166,9 @@ export function getAzApi(localAzDiscovered: Promise<IAzTool | undefined>, azTool
noWait?: boolean; noWait?: boolean;
syncSecondaryToCommit?: string; syncSecondaryToCommit?: string;
}, },
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string, namespace?: string,
usek8s?: boolean, usek8s?: boolean,
// Additional arguments // Additional arguments
@@ -181,9 +181,9 @@ export function getAzApi(localAzDiscovered: Promise<IAzTool | undefined>, azTool
upgrade: async ( upgrade: async (
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string; resourceGroup?: string;
// Indirect mode arguments // K8s API arguments
namespace?: string; namespace?: string;
}, },
// Additional arguments // Additional arguments

View File

@@ -116,7 +116,7 @@ export class AzTool implements azExt.IAzApi {
const argsArray = ['arcdata', 'dc', 'upgrade', '--desired-version', desiredVersion, '--name', name]; const argsArray = ['arcdata', 'dc', 'upgrade', '--desired-version', desiredVersion, '--name', name];
// Direct mode argument // Direct mode argument
if (resourceGroup) { argsArray.push('--resource-group', resourceGroup); } if (resourceGroup) { argsArray.push('--resource-group', resourceGroup); }
// Indirect mode arguments // K8s API arguments
if (namespace) { if (namespace) {
argsArray.push('--k8s-namespace', namespace); argsArray.push('--k8s-namespace', namespace);
argsArray.push('--use-k8s'); argsArray.push('--use-k8s');
@@ -180,9 +180,9 @@ export class AzTool implements azExt.IAzApi {
delete: ( delete: (
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
// Additional arguments // Additional arguments
}, },
@@ -200,9 +200,9 @@ export class AzTool implements azExt.IAzApi {
}, },
list: ( list: (
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
// Additional arguments // Additional arguments
}, },
@@ -221,9 +221,9 @@ export class AzTool implements azExt.IAzApi {
show: ( show: (
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
// Additional arguments // Additional arguments
}, },
@@ -250,9 +250,9 @@ export class AzTool implements azExt.IAzApi {
retentionDays?: string, retentionDays?: string,
syncSecondaryToCommit?: string syncSecondaryToCommit?: string
}, },
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string, namespace?: string,
usek8s?: boolean, usek8s?: boolean,
// Additional arguments // Additional arguments
@@ -273,9 +273,9 @@ export class AzTool implements azExt.IAzApi {
upgrade: ( upgrade: (
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
// Additional arguments // Additional arguments
}, },

View File

@@ -575,9 +575,9 @@ declare module 'az-ext' {
delete( delete(
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
}, },
// Additional arguments // Additional arguments
@@ -585,9 +585,9 @@ declare module 'az-ext' {
): Promise<AzOutput<void>>, ): Promise<AzOutput<void>>,
list( list(
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
}, },
// Additional arguments // Additional arguments
@@ -596,9 +596,9 @@ declare module 'az-ext' {
show( show(
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
}, },
// Additional arguments // Additional arguments
@@ -615,9 +615,9 @@ declare module 'az-ext' {
retentionDays?: string, //5 retentionDays?: string, //5
syncSecondaryToCommit?: string //2 syncSecondaryToCommit?: string //2
}, },
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string, namespace?: string,
usek8s?: boolean, usek8s?: boolean,
// Additional arguments // Additional arguments
@@ -626,9 +626,9 @@ declare module 'az-ext' {
upgrade( upgrade(
name: string, name: string,
args: { args: {
// Direct mode arguments // ARM API arguments
resourceGroup?: string, resourceGroup?: string,
// Indirect mode arguments // K8s API arguments
namespace?: string namespace?: string
}, },
// Additional arguments // Additional arguments