mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-03 17:23:42 -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:
@@ -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