mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 09:35:39 -05:00
Fixed az sql mi-arc show for indirect scenario (#19378)
* Addressed sql mi show for indirect and direct * Throw error when output is not JSON Co-authored-by: Candice Ye <canye@microsoft.com>
This commit is contained in:
@@ -121,7 +121,7 @@ export class MiaaModel extends ResourceModel {
|
||||
}
|
||||
this._config = result.stdout;
|
||||
this.configLastUpdated = new Date();
|
||||
this.rpSettings.retentionDays = this._config?.properties?.k8SRaw?.spec?.backup?.retentionPeriodInDays?.toString() ?? '';
|
||||
this.rpSettings.retentionDays = this._config?.spec?.backup?.retentionPeriodInDays?.toString() ?? '';
|
||||
this._onConfigUpdated.fire(this._config);
|
||||
this._onDatabasesUpdated.fire(this._databases);
|
||||
} catch (err) {
|
||||
@@ -135,7 +135,7 @@ export class MiaaModel extends ResourceModel {
|
||||
}
|
||||
|
||||
// If we have an external endpoint configured then fetch the databases now
|
||||
if (this._config.properties?.k8SRaw?.status.primaryEndpoint) {
|
||||
if (this._config.status.primaryEndpoint) {
|
||||
this.getDatabases(false).catch(_err => {
|
||||
// If an error occurs still fire the event so callers can know to
|
||||
// update (e.g. so dashboards don't show the loading icon forever)
|
||||
@@ -217,7 +217,7 @@ export class MiaaModel extends ResourceModel {
|
||||
}
|
||||
|
||||
protected createConnectionProfile(): azdata.IConnectionProfile {
|
||||
const ipAndPort = parseIpAndPort(this.config?.properties?.k8SRaw?.status.primaryEndpoint || '');
|
||||
const ipAndPort = parseIpAndPort(this.config?.status.primaryEndpoint || '');
|
||||
return {
|
||||
serverName: `${ipAndPort.ip},${ipAndPort.port}`,
|
||||
databaseName: '',
|
||||
|
||||
@@ -288,7 +288,7 @@ export class MiaaBackupsPage extends DashboardPage {
|
||||
} else {
|
||||
// If we don't have an endpoint then there's no point in showing the connect button - but the logic
|
||||
// to display text informing the user of this is already handled by the handleMiaaConfigUpdated
|
||||
if (this._miaaModel?.config?.properties?.k8SRaw?.status.primaryEndpoint) {
|
||||
if (this._miaaModel?.config?.status.primaryEndpoint) {
|
||||
this._connectToServerLoading.loading = false;
|
||||
this._connectToServerButton.enabled = true;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ export class MiaaBackupsPage extends DashboardPage {
|
||||
}
|
||||
|
||||
private refreshRD(): void {
|
||||
this._saveArgs.retentionDays = this._miaaModel.config?.properties?.k8SRaw?.spec?.backup?.retentionPeriodInDays.toString() ?? '';
|
||||
this._saveArgs.retentionDays = this._miaaModel.config?.spec?.backup?.retentionPeriodInDays.toString() ?? '';
|
||||
}
|
||||
|
||||
// Create restore button for every database entry in the database table
|
||||
|
||||
@@ -330,7 +330,7 @@ export class MiaaComputeAndStoragePage extends DashboardPage {
|
||||
}
|
||||
|
||||
private editCores(): void {
|
||||
let currentCPUSize = this._miaaModel.config?.properties?.k8SRaw?.spec?.scheduling?.default?.resources?.requests?.cpu;
|
||||
let currentCPUSize = this._miaaModel.config?.spec?.scheduling?.default?.resources?.requests?.cpu;
|
||||
|
||||
if (!currentCPUSize) {
|
||||
currentCPUSize = '';
|
||||
@@ -340,7 +340,7 @@ export class MiaaComputeAndStoragePage extends DashboardPage {
|
||||
this.coresRequestBox!.value = '';
|
||||
this.saveArgs.coresRequest = undefined;
|
||||
|
||||
currentCPUSize = this._miaaModel.config?.properties?.k8SRaw?.spec?.scheduling?.default?.resources?.limits?.cpu;
|
||||
currentCPUSize = this._miaaModel.config?.spec?.scheduling?.default?.resources?.limits?.cpu;
|
||||
|
||||
if (!currentCPUSize) {
|
||||
currentCPUSize = '';
|
||||
@@ -353,7 +353,7 @@ export class MiaaComputeAndStoragePage extends DashboardPage {
|
||||
|
||||
private editMemory(): void {
|
||||
let currentMemSizeConversion: string;
|
||||
let currentMemorySize = this._miaaModel.config?.properties?.k8SRaw?.spec?.scheduling?.default?.resources?.requests?.memory;
|
||||
let currentMemorySize = this._miaaModel.config?.spec?.scheduling?.default?.resources?.requests?.memory;
|
||||
|
||||
if (!currentMemorySize) {
|
||||
currentMemSizeConversion = '';
|
||||
@@ -366,7 +366,7 @@ export class MiaaComputeAndStoragePage extends DashboardPage {
|
||||
|
||||
this.saveArgs.memoryRequest = undefined;
|
||||
|
||||
currentMemorySize = this._miaaModel.config?.properties?.k8SRaw?.spec?.scheduling?.default?.resources?.limits?.memory;
|
||||
currentMemorySize = this._miaaModel.config?.spec?.scheduling?.default?.resources?.limits?.memory;
|
||||
|
||||
if (!currentMemorySize) {
|
||||
currentMemSizeConversion = '';
|
||||
|
||||
@@ -74,11 +74,11 @@ export class MiaaConnectionStringsPage extends DashboardPage {
|
||||
|
||||
private getConnectionStrings(): KeyValue[] {
|
||||
const config = this._miaaModel.config;
|
||||
if (!config?.properties?.k8SRaw?.status.primaryEndpoint) {
|
||||
if (!config?.status.primaryEndpoint) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const externalEndpoint = parseIpAndPort(config.properties?.k8SRaw?.status.primaryEndpoint);
|
||||
const externalEndpoint = parseIpAndPort(config.status.primaryEndpoint);
|
||||
const username = this._miaaModel.username ?? '{your_username_here}';
|
||||
|
||||
return [
|
||||
@@ -97,7 +97,7 @@ $conn = sqlsrv_connect($serverName, $connectionInfo);`),
|
||||
}
|
||||
|
||||
private updateConnectionStrings(): void {
|
||||
this._connectionStringsMessage.value = !this._miaaModel.config?.properties?.k8SRaw?.status.primaryEndpoint ? loc.noExternalEndpoint : '';
|
||||
this._connectionStringsMessage.value = !this._miaaModel.config?.status.primaryEndpoint ? loc.noExternalEndpoint : '';
|
||||
this._keyValueContainer.refresh(this.getConnectionStrings());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,11 +335,11 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
|
||||
private handleMiaaConfigUpdated(): void {
|
||||
if (this._miaaModel.config) {
|
||||
this._instanceProperties.status = this._miaaModel.config.properties?.k8SRaw?.status.state || '-';
|
||||
this._instanceProperties.externalEndpoint = this._miaaModel.config.properties?.k8SRaw?.status.primaryEndpoint || loc.notConfigured;
|
||||
this._instanceProperties.vCores = this._miaaModel.config.properties?.k8SRaw?.spec?.scheduling?.default?.resources?.limits?.cpu?.toString() || '';
|
||||
this._databasesMessage.value = !this._miaaModel.config.properties?.k8SRaw?.status.primaryEndpoint ? loc.noExternalEndpoint : '';
|
||||
if (!this._miaaModel.config.properties?.k8SRaw?.status.primaryEndpoint) {
|
||||
this._instanceProperties.status = this._miaaModel.config.status.state || '-';
|
||||
this._instanceProperties.externalEndpoint = this._miaaModel.config.status.primaryEndpoint || loc.notConfigured;
|
||||
this._instanceProperties.vCores = this._miaaModel.config.spec?.scheduling?.default?.resources?.limits?.cpu?.toString() || '';
|
||||
this._databasesMessage.value = !this._miaaModel.config.status.primaryEndpoint ? loc.noExternalEndpoint : '';
|
||||
if (!this._miaaModel.config.status.primaryEndpoint) {
|
||||
this._databasesContainer.removeItem(this._connectToServerLoading);
|
||||
}
|
||||
}
|
||||
@@ -368,7 +368,7 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
} else {
|
||||
// If we don't have an endpoint then there's no point in showing the connect button - but the logic
|
||||
// to display text informing the user of this is already handled by the handleMiaaConfigUpdated
|
||||
if (this._miaaModel?.config?.properties?.k8SRaw?.status.primaryEndpoint) {
|
||||
if (this._miaaModel?.config?.status.primaryEndpoint) {
|
||||
this._connectToServerLoading.loading = false;
|
||||
this._connectToServerButton.enabled = true;
|
||||
}
|
||||
@@ -419,12 +419,12 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
|
||||
|
||||
private refreshDashboardLinks(): void {
|
||||
if (this._miaaModel.config) {
|
||||
const kibanaUrl = this._miaaModel.config.properties?.k8SRaw?.status.logSearchDashboard ?? '';
|
||||
const kibanaUrl = this._miaaModel.config.status.logSearchDashboard ?? '';
|
||||
this._kibanaLink.label = kibanaUrl;
|
||||
this._kibanaLink.url = kibanaUrl;
|
||||
this._kibanaLoading!.loading = false;
|
||||
|
||||
const grafanaUrl = this._miaaModel.config.properties?.k8SRaw?.status.metricsDashboard ?? '';
|
||||
const grafanaUrl = this._miaaModel.config.status.metricsDashboard ?? '';
|
||||
this._grafanaLink.label = grafanaUrl;
|
||||
this._grafanaLink.url = grafanaUrl;
|
||||
this._grafanaLoading!.loading = false;
|
||||
|
||||
@@ -179,7 +179,7 @@ export class MiaaUpgradeManagementPage extends DashboardPage {
|
||||
this._controllerModel.azAdditionalEnvVars
|
||||
);
|
||||
}
|
||||
return miaaShowResult.stdout.properties.k8SRaw.status.runningVersion;
|
||||
return miaaShowResult.stdout.status.runningVersion;
|
||||
} catch (e) {
|
||||
console.error(loc.showMiaaError, e);
|
||||
return undefined;
|
||||
|
||||
@@ -26,7 +26,7 @@ export class ConfigureRPOSqlDialog extends InitializingComponent {
|
||||
public showDialog(dialogTitle: string, retentionDays: string | undefined): azdata.window.Dialog {
|
||||
const dialog = azdata.window.createModelViewDialog(dialogTitle);
|
||||
dialog.cancelButton.onClick(() => this.handleCancel());
|
||||
retentionDays = (retentionDays === undefined ? this._model.config?.properties?.k8SRaw?.spec?.backup?.retentionPeriodInDays?.toString() : retentionDays);
|
||||
retentionDays = (retentionDays === undefined ? this._model.config?.spec?.backup?.retentionPeriodInDays?.toString() : retentionDays);
|
||||
dialog.registerContent(async view => {
|
||||
this.modelBuilder = view.modelBuilder;
|
||||
this.retentionDaysInputBox = this.modelBuilder.inputBox()
|
||||
|
||||
@@ -193,12 +193,14 @@ export class AzTool implements azExt.IAzApi {
|
||||
additionalEnvVars?: azExt.AdditionalEnvVars
|
||||
): Promise<azExt.AzOutput<azExt.SqlMiShowResult>> => {
|
||||
const argsArray = ['sql', 'mi-arc', 'show', '-n', name];
|
||||
if (args.resourceGroup) { argsArray.push('--resource-group', args.resourceGroup); }
|
||||
if (args.resourceGroup) {
|
||||
argsArray.push('--resource-group', args.resourceGroup);
|
||||
}
|
||||
if (args.namespace) {
|
||||
argsArray.push('--k8s-namespace', args.namespace);
|
||||
argsArray.push('--use-k8s');
|
||||
}
|
||||
return this.executeCommand<azExt.SqlMiShowResult>(argsArray, additionalEnvVars);
|
||||
return this.executeSqlMiShow(argsArray, additionalEnvVars);
|
||||
},
|
||||
update: (
|
||||
name: string,
|
||||
@@ -301,6 +303,64 @@ export class AzTool implements azExt.IAzApi {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes az sql mi-arc show and returns a normalized object, SqlMiShowResult, regardless of the indirect or direct mode raw output shape.
|
||||
* @param args The args to pass to az
|
||||
* @param additionalEnvVars Additional environment variables to set for this execution
|
||||
*/
|
||||
public async executeSqlMiShow(args: string[], additionalEnvVars?: azExt.AdditionalEnvVars): Promise<azExt.AzOutput<azExt.SqlMiShowResult>> {
|
||||
try {
|
||||
const result = await executeAzCommand(`"${this._path}"`, args.concat(['--output', 'json']), additionalEnvVars);
|
||||
|
||||
let stdout = <unknown>result.stdout;
|
||||
let stderr = <unknown>result.stderr;
|
||||
|
||||
try {
|
||||
// Automatically try parsing the JSON. This is expected to fail for some az commands such as resource delete.
|
||||
stdout = JSON.parse(result.stdout);
|
||||
} catch (err) {
|
||||
// If the output was not pure JSON, catch the error and log it here.
|
||||
Logger.log(loc.azOutputParseErrorCaught(args.concat(['--output', 'json']).toString()));
|
||||
throw err;
|
||||
}
|
||||
|
||||
if ((<azExt.SqlMiShowResultDirect>stdout).properties) {
|
||||
// Then it is direct mode
|
||||
return {
|
||||
stdout: {
|
||||
name: (<azExt.SqlMiShowResultDirect>stdout).name,
|
||||
spec: (<azExt.SqlMiShowResultDirect>stdout).properties.k8SRaw.spec,
|
||||
status: (<azExt.SqlMiShowResultDirect>stdout).properties.k8SRaw.status
|
||||
},
|
||||
stderr: <string[]>stderr
|
||||
};
|
||||
} else {
|
||||
// It must be indirect mode
|
||||
return {
|
||||
stdout: {
|
||||
name: (<azExt.SqlMiShowResultIndirect>stdout).metadata.name,
|
||||
spec: (<azExt.SqlMiShowResultIndirect>stdout).spec,
|
||||
status: (<azExt.SqlMiShowResultIndirect>stdout).status
|
||||
},
|
||||
stderr: <string[]>stderr
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof ExitCodeError) {
|
||||
try {
|
||||
await fs.promises.access(this._path);
|
||||
//this.path exists
|
||||
} catch (e) {
|
||||
// this.path does not exist
|
||||
await vscode.commands.executeCommand('setContext', azFound, false);
|
||||
throw new NoAzureCLIError();
|
||||
}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the specified az command.
|
||||
* @param args The args to pass to az
|
||||
|
||||
128
extensions/azcli/src/typings/az-ext.d.ts
vendored
128
extensions/azcli/src/typings/az-ext.d.ts
vendored
@@ -137,53 +137,89 @@ declare module 'az-ext' {
|
||||
port?: number // 5432
|
||||
}
|
||||
|
||||
// export interface SqlMiShowResult {
|
||||
// apiVersion: string, // "sql.arcdata.microsoft.com/v1alpha1"
|
||||
// kind: string, // "sqlmanagedinstance"
|
||||
// metadata: {
|
||||
// creationTimestamp: string, // "2020-08-19T17:35:45Z"
|
||||
// generation: number, // 1
|
||||
// name: string, // "miaa-instance"
|
||||
// namespace: string, // "arc"
|
||||
// resourceVersion: string, // "202623"
|
||||
// selfLink: string, // "/apis/sql.arcdata.microsoft.com/v1alpha1/namespaces/arc/sqlmanagedinstances/miaa-instance"
|
||||
// uid: string // "cea737aa-3f82-4f6a-9bed-2b51c2c33dff"
|
||||
// },
|
||||
// spec: {
|
||||
// backup?: {
|
||||
// retentionPeriodInDays: number, // 1
|
||||
// }
|
||||
// scheduling?: {
|
||||
// default?: {
|
||||
// resources?: {
|
||||
// limits?: SchedulingOptions,
|
||||
// requests?: SchedulingOptions
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// services: {
|
||||
// primary: ServiceSpec
|
||||
// }
|
||||
// storage: {
|
||||
// data: {
|
||||
// volumes: StorageVolume[]
|
||||
// },
|
||||
// logs: {
|
||||
// volumes: StorageVolume[]
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// status: {
|
||||
// readyReplicas: string, // "1/1"
|
||||
// state: string, // "Ready",
|
||||
// logSearchDashboard: string, // https://127.0.0.1:30777/kibana/app/kibana#/discover?_a=(query:(language:kuery,query:'custom_resource_name:miaa1'))
|
||||
// metricsDashboard: string, // https://127.0.0.1:30777/grafana/d/40q72HnGk/sql-managed-instance-metrics?var-hostname=miaa1-0
|
||||
// primaryEndpoint?: string // "10.91.86.39:32718"
|
||||
// runningVersion: string // "v1.5.0_2022-04-05"
|
||||
// }
|
||||
// }
|
||||
|
||||
export interface SqlMiShowResult {
|
||||
name: string, // "miaa-instance"
|
||||
spec: {
|
||||
backup?: {
|
||||
retentionPeriodInDays: number, // 1
|
||||
}
|
||||
scheduling?: {
|
||||
default?: {
|
||||
resources?: {
|
||||
limits?: SchedulingOptions,
|
||||
requests?: SchedulingOptions
|
||||
}
|
||||
}
|
||||
}
|
||||
services: {
|
||||
primary: ServiceSpec
|
||||
}
|
||||
storage: {
|
||||
data: {
|
||||
volumes: StorageVolume[]
|
||||
},
|
||||
logs: {
|
||||
volumes: StorageVolume[]
|
||||
}
|
||||
}
|
||||
},
|
||||
status: {
|
||||
readyReplicas: string, // "1/1"
|
||||
state: string, // "Ready",
|
||||
logSearchDashboard: string, // https://127.0.0.1:30777/kibana/app/kibana#/discover?_a=(query:(language:kuery,query:'custom_resource_name:miaa1'))
|
||||
metricsDashboard: string, // https://127.0.0.1:30777/grafana/d/40q72HnGk/sql-managed-instance-metrics?var-hostname=miaa1-0
|
||||
primaryEndpoint?: string // "10.91.86.39:32718"
|
||||
runningVersion: string // "v1.5.0_2022-04-05"
|
||||
}
|
||||
}
|
||||
|
||||
export interface SqlMiShowResultIndirect {
|
||||
apiVersion: string, // "sql.arcdata.microsoft.com/v1alpha1"
|
||||
kind: string, // "sqlmanagedinstance"
|
||||
metadata: {
|
||||
creationTimestamp: string, // "2020-08-19T17:35:45Z"
|
||||
generation: number, // 1
|
||||
name: string, // "miaa-instance"
|
||||
namespace: string, // "arc"
|
||||
resourceVersion: string, // "202623"
|
||||
selfLink: string, // "/apis/sql.arcdata.microsoft.com/v1alpha1/namespaces/arc/sqlmanagedinstances/miaa-instance"
|
||||
uid: string // "cea737aa-3f82-4f6a-9bed-2b51c2c33dff"
|
||||
},
|
||||
spec: {
|
||||
backup?: {
|
||||
retentionPeriodInDays: number, // 1
|
||||
}
|
||||
scheduling?: {
|
||||
default?: {
|
||||
resources?: {
|
||||
limits?: SchedulingOptions,
|
||||
requests?: SchedulingOptions
|
||||
}
|
||||
}
|
||||
}
|
||||
services: {
|
||||
primary: ServiceSpec
|
||||
}
|
||||
storage: {
|
||||
data: {
|
||||
volumes: StorageVolume[]
|
||||
},
|
||||
logs: {
|
||||
volumes: StorageVolume[]
|
||||
}
|
||||
}
|
||||
},
|
||||
status: {
|
||||
readyReplicas: string, // "1/1"
|
||||
state: string, // "Ready",
|
||||
logSearchDashboard: string, // https://127.0.0.1:30777/kibana/app/kibana#/discover?_a=(query:(language:kuery,query:'custom_resource_name:miaa1'))
|
||||
metricsDashboard: string, // https://127.0.0.1:30777/grafana/d/40q72HnGk/sql-managed-instance-metrics?var-hostname=miaa1-0
|
||||
primaryEndpoint?: string // "10.91.86.39:32718"
|
||||
runningVersion: string // "v1.5.0_2022-04-05"
|
||||
}
|
||||
}
|
||||
|
||||
export interface SqlMiShowResultDirect {
|
||||
extendedLocation: {
|
||||
name: string, // /subscriptions/a2382b66-3h2k-3h2k-2gdd-8ef45dgfdc33/resourcegroups/name-rg/providers/microsoft.extendedlocation/customlocations/custom-loc,
|
||||
type: string, // CustomLocation
|
||||
|
||||
Reference in New Issue
Block a user