mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-02-24 04:57:50 +00:00
Stylecop changes
This commit is contained in:
parent
a09bcc7197
commit
67ebce444f
@ -2,10 +2,7 @@ import { RefreshResult } from "../SelfServeTypes";
|
|||||||
import { userContext } from "../../UserContext";
|
import { userContext } from "../../UserContext";
|
||||||
import { armRequest } from "../../Utils/arm/request";
|
import { armRequest } from "../../Utils/arm/request";
|
||||||
import { configContext } from "../../ConfigContext";
|
import { configContext } from "../../ConfigContext";
|
||||||
import {
|
import { SqlxServiceResource, UpdateDedicatedGatewayRequestParameters } from "./SqlxTypes";
|
||||||
SqlxServiceResource,
|
|
||||||
UpdateDedicatedGatewayRequestParameters
|
|
||||||
} from "./SqlxTypes"
|
|
||||||
|
|
||||||
const apiVersion = "2020-06-01-preview";
|
const apiVersion = "2020-06-01-preview";
|
||||||
|
|
||||||
@ -13,7 +10,7 @@ export enum ResourceStatus {
|
|||||||
Running,
|
Running,
|
||||||
Creating,
|
Creating,
|
||||||
Updating,
|
Updating,
|
||||||
Deleting
|
Deleting,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DedicatedGatewayResponse {
|
export interface DedicatedGatewayResponse {
|
||||||
@ -25,7 +22,7 @@ export interface DedicatedGatewayResponse {
|
|||||||
|
|
||||||
export const getPath = (subscriptionId: string, resourceGroup: string, name: string): string => {
|
export const getPath = (subscriptionId: string, resourceGroup: string, name: string): string => {
|
||||||
return `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${name}/services/sqlx`;
|
return `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${name}/services/sqlx`;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const updateDedicatedGatewayResource = async (sku: string, instances: number): Promise<void> => {
|
export const updateDedicatedGatewayResource = async (sku: string, instances: number): Promise<void> => {
|
||||||
// TODO: write RP call to update dedicated gateway provisioning
|
// TODO: write RP call to update dedicated gateway provisioning
|
||||||
@ -34,8 +31,8 @@ export const updateDedicatedGatewayResource = async (sku: string, instances: num
|
|||||||
properties: {
|
properties: {
|
||||||
instanceSize: sku,
|
instanceSize: sku,
|
||||||
instanceCount: instances,
|
instanceCount: instances,
|
||||||
serviceType: "Sqlx"
|
serviceType: "Sqlx",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "PUT", apiVersion, body });
|
return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "PUT", apiVersion, body });
|
||||||
};
|
};
|
||||||
@ -43,49 +40,41 @@ export const updateDedicatedGatewayResource = async (sku: string, instances: num
|
|||||||
export const deleteDedicatedGatewayResource = async (): Promise<void> => {
|
export const deleteDedicatedGatewayResource = async (): Promise<void> => {
|
||||||
const path = getPath(userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name);
|
const path = getPath(userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name);
|
||||||
return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "DELETE", apiVersion });
|
return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "DELETE", apiVersion });
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getDedicatedGatewayResource = async() : Promise<SqlxServiceResource> => {
|
export const getDedicatedGatewayResource = async (): Promise<SqlxServiceResource> => {
|
||||||
const path = getPath(userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name);
|
const path = getPath(userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name);
|
||||||
return armRequest<SqlxServiceResource>({ host: configContext.ARM_ENDPOINT, path, method: "GET", apiVersion });
|
return armRequest<SqlxServiceResource>({ host: configContext.ARM_ENDPOINT, path, method: "GET", apiVersion });
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getCurrentProvisioningState = async (): Promise<DedicatedGatewayResponse> => {
|
export const getCurrentProvisioningState = async (): Promise<DedicatedGatewayResponse> => {
|
||||||
try
|
try {
|
||||||
{
|
const response = await getDedicatedGatewayResource();
|
||||||
const response = await getDedicatedGatewayResource();
|
return {
|
||||||
return { sku: response.properties.instanceSize, instances: response.properties.instanceCount, status: response.properties.status, endpoint: response.properties.sqlxEndPoint}
|
sku: response.properties.instanceSize,
|
||||||
}
|
instances: response.properties.instanceCount,
|
||||||
catch (e)
|
status: response.properties.status,
|
||||||
{
|
endpoint: response.properties.sqlxEndPoint,
|
||||||
return {sku: undefined, instances: undefined, status: undefined, endpoint: undefined};
|
};
|
||||||
|
} catch (e) {
|
||||||
|
return { sku: undefined, instances: undefined, status: undefined, endpoint: undefined };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const refreshDedicatedGatewayProvisioning = async (): Promise<RefreshResult> => {
|
export const refreshDedicatedGatewayProvisioning = async (): Promise<RefreshResult> => {
|
||||||
// TODO: write RP call to check if dedicated gateway update has gone through
|
// TODO: write RP call to check if dedicated gateway update has gone through
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
const response = await getDedicatedGatewayResource();
|
const response = await getDedicatedGatewayResource();
|
||||||
if (response.properties.status === ResourceStatus.Running.toString())
|
if (response.properties.status === ResourceStatus.Running.toString()) {
|
||||||
{
|
return { isUpdateInProgress: false, notificationMessage: undefined };
|
||||||
return {isUpdateInProgress: false, notificationMessage: undefined}
|
} else if (response.properties.status === ResourceStatus.Creating.toString()) {
|
||||||
|
return { isUpdateInProgress: true, notificationMessage: "CreateMessage" };
|
||||||
|
} else if (response.properties.status === ResourceStatus.Deleting.toString()) {
|
||||||
|
return { isUpdateInProgress: true, notificationMessage: "DeleteMessage" };
|
||||||
|
} else {
|
||||||
|
return { isUpdateInProgress: true, notificationMessage: "UpdateMessage" };
|
||||||
}
|
}
|
||||||
else if (response.properties.status === ResourceStatus.Creating.toString())
|
} catch {
|
||||||
{
|
return { isUpdateInProgress: false, notificationMessage: undefined };
|
||||||
return {isUpdateInProgress: true, notificationMessage: "CreateMessage"};
|
|
||||||
}
|
|
||||||
else if (response.properties.status === ResourceStatus.Deleting.toString())
|
|
||||||
{
|
|
||||||
return {isUpdateInProgress: true, notificationMessage: "DeleteMessage"};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return {isUpdateInProgress: true, notificationMessage: "UpdateMessage"};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return {isUpdateInProgress: false, notificationMessage: undefined}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
refreshDedicatedGatewayProvisioning,
|
refreshDedicatedGatewayProvisioning,
|
||||||
updateDedicatedGatewayResource,
|
updateDedicatedGatewayResource,
|
||||||
deleteDedicatedGatewayResource,
|
deleteDedicatedGatewayResource,
|
||||||
getCurrentProvisioningState
|
getCurrentProvisioningState,
|
||||||
} from "./SqlX.rp";
|
} from "./SqlX.rp";
|
||||||
|
|
||||||
let disableAttributesOnDedicatedGatewayChange = false;
|
let disableAttributesOnDedicatedGatewayChange = false;
|
||||||
@ -23,13 +23,21 @@ const onEnableDedicatedGatewayChange = (
|
|||||||
currentState: Map<string, SmartUiInput>,
|
currentState: Map<string, SmartUiInput>,
|
||||||
newValue: InputType
|
newValue: InputType
|
||||||
): Map<string, SmartUiInput> => {
|
): Map<string, SmartUiInput> => {
|
||||||
const sku = currentState.get("sku");
|
const sku = currentState.get("sku");
|
||||||
const instances = currentState.get("instances");
|
const instances = currentState.get("instances");
|
||||||
const hideAttributes = newValue === undefined || !(newValue as boolean);
|
const hideAttributes = newValue === undefined || !(newValue as boolean);
|
||||||
currentState.set("enableDedicatedGateway", { value: newValue });
|
currentState.set("enableDedicatedGateway", { value: newValue });
|
||||||
currentState.set("sku", { value: sku.value, hidden: hideAttributes, disabled: disableAttributesOnDedicatedGatewayChange});
|
currentState.set("sku", {
|
||||||
currentState.set("instances", { value: instances.value, hidden: hideAttributes, disabled: disableAttributesOnDedicatedGatewayChange});
|
value: sku.value,
|
||||||
return currentState;
|
hidden: hideAttributes,
|
||||||
|
disabled: disableAttributesOnDedicatedGatewayChange,
|
||||||
|
});
|
||||||
|
currentState.set("instances", {
|
||||||
|
value: instances.value,
|
||||||
|
hidden: hideAttributes,
|
||||||
|
disabled: disableAttributesOnDedicatedGatewayChange,
|
||||||
|
});
|
||||||
|
return currentState;
|
||||||
};
|
};
|
||||||
|
|
||||||
const skuDropDownItems: ChoiceItem[] = [
|
const skuDropDownItems: ChoiceItem[] = [
|
||||||
@ -64,57 +72,48 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
const response = await getCurrentProvisioningState();
|
const response = await getCurrentProvisioningState();
|
||||||
|
|
||||||
// null implies the resource has not been provisioned.
|
// null implies the resource has not been provisioned.
|
||||||
if (response.status !== undefined && response.status !== ResourceStatus.Running.toString())
|
if (response.status !== undefined && response.status !== ResourceStatus.Running.toString()) {
|
||||||
{
|
switch (response.status) {
|
||||||
switch(response.status)
|
|
||||||
{
|
|
||||||
case ResourceStatus.Creating.toString():
|
case ResourceStatus.Creating.toString():
|
||||||
return {message: "CreateMessage", type: SelfServeNotificationType.error};
|
return { message: "CreateMessage", type: SelfServeNotificationType.error };
|
||||||
case ResourceStatus.Updating.toString():
|
case ResourceStatus.Updating.toString():
|
||||||
return {message: "UpdateMessage", type: SelfServeNotificationType.error};
|
return { message: "UpdateMessage", type: SelfServeNotificationType.error };
|
||||||
case ResourceStatus.Deleting.toString():
|
case ResourceStatus.Deleting.toString():
|
||||||
return {message: "DeleteMessage", type: SelfServeNotificationType.error};
|
return { message: "DeleteMessage", type: SelfServeNotificationType.error };
|
||||||
default:
|
default:
|
||||||
return {message: "CannotSave", type: SelfServeNotificationType.error}
|
return { message: "CannotSave", type: SelfServeNotificationType.error };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const enableDedicatedGateway = currentValues.get("enableDedicatedGateway")?.value as boolean;
|
const enableDedicatedGateway = currentValues.get("enableDedicatedGateway")?.value as boolean;
|
||||||
|
|
||||||
if (response.status !== undefined)
|
if (response.status !== undefined) {
|
||||||
{
|
if (!enableDedicatedGateway) {
|
||||||
if (!enableDedicatedGateway)
|
try {
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await deleteDedicatedGatewayResource();
|
await deleteDedicatedGatewayResource();
|
||||||
return { message: "DedicatedGateway resource will be deleted.", type: SelfServeNotificationType.info };
|
return { message: "DedicatedGateway resource will be deleted.", type: SelfServeNotificationType.info };
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
message: "Deleting Dedicated Gateway resource failed. DedicatedGateway will not be deleted.",
|
||||||
|
type: SelfServeNotificationType.error,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch(e)
|
} else {
|
||||||
{
|
// Check for scaling up/down/in/out
|
||||||
return { message: "Deleting Dedicated Gateway resource failed. DedicatedGateway will not be deleted.", type: SelfServeNotificationType.error };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
// Check for scaling up/down/in/out
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (enableDedicatedGateway) {
|
if (enableDedicatedGateway) {
|
||||||
const sku = currentValues.get("sku")?.value as string;
|
const sku = currentValues.get("sku")?.value as string;
|
||||||
const instances = currentValues.get("instances").value as number;
|
const instances = currentValues.get("instances").value as number;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
await updateDedicatedGatewayResource(sku, instances);
|
await updateDedicatedGatewayResource(sku, instances);
|
||||||
return { message: "Dedicated Gateway resource will be provisioned.", type: SelfServeNotificationType.info };
|
return { message: "Dedicated Gateway resource will be provisioned.", type: SelfServeNotificationType.info };
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
message: "Updating Dedicated Gateway resource failed. Dedicated Gateway will not be updated.",
|
||||||
|
type: SelfServeNotificationType.error,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
return { message: "Updating Dedicated Gateway resource failed. Dedicated Gateway will not be updated.", type: SelfServeNotificationType.error };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { message: "No updates were applied at this time", type: SelfServeNotificationType.warning };
|
return { message: "No updates were applied at this time", type: SelfServeNotificationType.warning };
|
||||||
@ -125,16 +124,15 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
// Based on the RP call enableDedicatedGateway will be true if it has not yet been enabled and false if it has.
|
// Based on the RP call enableDedicatedGateway will be true if it has not yet been enabled and false if it has.
|
||||||
const defaults = new Map<string, SmartUiInput>();
|
const defaults = new Map<string, SmartUiInput>();
|
||||||
const enableDedicatedGateway = false;
|
const enableDedicatedGateway = false;
|
||||||
defaults.set("enableDedicatedGateway", { value: enableDedicatedGateway, hidden: false, disabled: false});
|
defaults.set("enableDedicatedGateway", { value: enableDedicatedGateway, hidden: false, disabled: false });
|
||||||
defaults.set("sku", { value: "Cosmos.D4s", hidden: !enableDedicatedGateway, disabled: false});
|
defaults.set("sku", { value: "Cosmos.D4s", hidden: !enableDedicatedGateway, disabled: false });
|
||||||
defaults.set("instances", { value: await getInstancesMin(), hidden: !enableDedicatedGateway, disabled: false});
|
defaults.set("instances", { value: await getInstancesMin(), hidden: !enableDedicatedGateway, disabled: false });
|
||||||
const response = await getCurrentProvisioningState()
|
const response = await getCurrentProvisioningState();
|
||||||
if (response.status !== undefined)
|
if (response.status !== undefined) {
|
||||||
{
|
|
||||||
disableAttributesOnDedicatedGatewayChange = true;
|
disableAttributesOnDedicatedGatewayChange = true;
|
||||||
defaults.set("enableDedicatedGateway", { value: true, hidden: false, disabled: false});
|
defaults.set("enableDedicatedGateway", { value: true, hidden: false, disabled: false });
|
||||||
defaults.set("sku", { value: response.sku, hidden: false, disabled: true});
|
defaults.set("sku", { value: response.sku, hidden: false, disabled: true });
|
||||||
defaults.set("instances", { value: response.instances, hidden: false, disabled: true});
|
defaults.set("instances", { value: response.instances, hidden: false, disabled: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaults;
|
return defaults;
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
export type SqlxServiceResource = {
|
export type SqlxServiceResource = {
|
||||||
id: string,
|
id: string;
|
||||||
name: string,
|
name: string;
|
||||||
type: string,
|
type: string;
|
||||||
properties: SqlxServiceProps
|
properties: SqlxServiceProps;
|
||||||
locations: SqlxServiceLocations
|
locations: SqlxServiceLocations;
|
||||||
}
|
};
|
||||||
export type SqlxServiceProps = {
|
export type SqlxServiceProps = {
|
||||||
serviceType: string,
|
serviceType: string;
|
||||||
creationTime: string,
|
creationTime: string;
|
||||||
status: string,
|
status: string;
|
||||||
instanceSize: string,
|
instanceSize: string;
|
||||||
instanceCount: number,
|
instanceCount: number;
|
||||||
sqlxEndPoint: string
|
sqlxEndPoint: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type SqlxServiceLocations = {
|
export type SqlxServiceLocations = {
|
||||||
location: string,
|
location: string;
|
||||||
status: string,
|
status: string;
|
||||||
sqlxEndpoint: string
|
sqlxEndpoint: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type UpdateDedicatedGatewayRequestParameters = {
|
export type UpdateDedicatedGatewayRequestParameters = {
|
||||||
properties: UpdateDedicatedGatewayRequestProperties
|
properties: UpdateDedicatedGatewayRequestProperties;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type UpdateDedicatedGatewayRequestProperties = {
|
export type UpdateDedicatedGatewayRequestProperties = {
|
||||||
instanceSize: string,
|
instanceSize: string;
|
||||||
instanceCount: number,
|
instanceCount: number;
|
||||||
serviceType: string
|
serviceType: string;
|
||||||
}
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user