Stylecop changes

This commit is contained in:
Balaji Sridharan 2021-02-16 00:21:44 -08:00
parent a09bcc7197
commit 67ebce444f
3 changed files with 101 additions and 114 deletions

View File

@ -2,10 +2,7 @@ import { RefreshResult } from "../SelfServeTypes";
import { userContext } from "../../UserContext";
import { armRequest } from "../../Utils/arm/request";
import { configContext } from "../../ConfigContext";
import {
SqlxServiceResource,
UpdateDedicatedGatewayRequestParameters
} from "./SqlxTypes"
import { SqlxServiceResource, UpdateDedicatedGatewayRequestParameters } from "./SqlxTypes";
const apiVersion = "2020-06-01-preview";
@ -13,7 +10,7 @@ export enum ResourceStatus {
Running,
Creating,
Updating,
Deleting
Deleting,
}
export interface DedicatedGatewayResponse {
@ -25,7 +22,7 @@ export interface DedicatedGatewayResponse {
export const getPath = (subscriptionId: string, resourceGroup: string, name: string): string => {
return `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${name}/services/sqlx`;
}
};
export const updateDedicatedGatewayResource = async (sku: string, instances: number): Promise<void> => {
// TODO: write RP call to update dedicated gateway provisioning
@ -34,8 +31,8 @@ export const updateDedicatedGatewayResource = async (sku: string, instances: num
properties: {
instanceSize: sku,
instanceCount: instances,
serviceType: "Sqlx"
}
serviceType: "Sqlx",
},
};
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> => {
const path = getPath(userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name);
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);
return armRequest<SqlxServiceResource>({ host: configContext.ARM_ENDPOINT, path, method: "GET", apiVersion });
}
};
export const getCurrentProvisioningState = async (): Promise<DedicatedGatewayResponse> => {
try
{
const response = await getDedicatedGatewayResource();
return { sku: response.properties.instanceSize, instances: response.properties.instanceCount, status: response.properties.status, endpoint: response.properties.sqlxEndPoint}
}
catch (e)
{
return {sku: undefined, instances: undefined, status: undefined, endpoint: undefined};
try {
const response = await getDedicatedGatewayResource();
return {
sku: response.properties.instanceSize,
instances: response.properties.instanceCount,
status: response.properties.status,
endpoint: response.properties.sqlxEndPoint,
};
} catch (e) {
return { sku: undefined, instances: undefined, status: undefined, endpoint: undefined };
}
};
export const refreshDedicatedGatewayProvisioning = async (): Promise<RefreshResult> => {
// TODO: write RP call to check if dedicated gateway update has gone through
try
{
try {
const response = await getDedicatedGatewayResource();
if (response.properties.status === ResourceStatus.Running.toString())
{
return {isUpdateInProgress: false, notificationMessage: undefined}
if (response.properties.status === ResourceStatus.Running.toString()) {
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())
{
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}
} catch {
return { isUpdateInProgress: false, notificationMessage: undefined };
}
};

View File

@ -14,7 +14,7 @@ import {
refreshDedicatedGatewayProvisioning,
updateDedicatedGatewayResource,
deleteDedicatedGatewayResource,
getCurrentProvisioningState
getCurrentProvisioningState,
} from "./SqlX.rp";
let disableAttributesOnDedicatedGatewayChange = false;
@ -23,13 +23,21 @@ const onEnableDedicatedGatewayChange = (
currentState: Map<string, SmartUiInput>,
newValue: InputType
): Map<string, SmartUiInput> => {
const sku = currentState.get("sku");
const instances = currentState.get("instances");
const hideAttributes = newValue === undefined || !(newValue as boolean);
currentState.set("enableDedicatedGateway", { value: newValue });
currentState.set("sku", { value: sku.value, hidden: hideAttributes, disabled: disableAttributesOnDedicatedGatewayChange});
currentState.set("instances", { value: instances.value, hidden: hideAttributes, disabled: disableAttributesOnDedicatedGatewayChange});
return currentState;
const sku = currentState.get("sku");
const instances = currentState.get("instances");
const hideAttributes = newValue === undefined || !(newValue as boolean);
currentState.set("enableDedicatedGateway", { value: newValue });
currentState.set("sku", {
value: sku.value,
hidden: hideAttributes,
disabled: disableAttributesOnDedicatedGatewayChange,
});
currentState.set("instances", {
value: instances.value,
hidden: hideAttributes,
disabled: disableAttributesOnDedicatedGatewayChange,
});
return currentState;
};
const skuDropDownItems: ChoiceItem[] = [
@ -64,57 +72,48 @@ export default class SqlX extends SelfServeBaseClass {
const response = await getCurrentProvisioningState();
// null implies the resource has not been provisioned.
if (response.status !== undefined && response.status !== ResourceStatus.Running.toString())
{
switch(response.status)
{
if (response.status !== undefined && response.status !== ResourceStatus.Running.toString()) {
switch (response.status) {
case ResourceStatus.Creating.toString():
return {message: "CreateMessage", type: SelfServeNotificationType.error};
return { message: "CreateMessage", type: SelfServeNotificationType.error };
case ResourceStatus.Updating.toString():
return {message: "UpdateMessage", type: SelfServeNotificationType.error};
return { message: "UpdateMessage", type: SelfServeNotificationType.error };
case ResourceStatus.Deleting.toString():
return {message: "DeleteMessage", type: SelfServeNotificationType.error};
return { message: "DeleteMessage", type: SelfServeNotificationType.error };
default:
return {message: "CannotSave", type: SelfServeNotificationType.error}
return { message: "CannotSave", type: SelfServeNotificationType.error };
}
}
const enableDedicatedGateway = currentValues.get("enableDedicatedGateway")?.value as boolean;
if (response.status !== undefined)
{
if (!enableDedicatedGateway)
{
try
{
if (response.status !== undefined) {
if (!enableDedicatedGateway) {
try {
await deleteDedicatedGatewayResource();
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)
{
return { message: "Deleting Dedicated Gateway resource failed. DedicatedGateway will not be deleted.", type: SelfServeNotificationType.error };
}
} else {
// Check for scaling up/down/in/out
}
else
{
// Check for scaling up/down/in/out
}
}
else
{
} else {
if (enableDedicatedGateway) {
const sku = currentValues.get("sku")?.value as string;
const instances = currentValues.get("instances").value as number;
try
{
try {
await updateDedicatedGatewayResource(sku, instances);
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 };
@ -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.
const defaults = new Map<string, SmartUiInput>();
const enableDedicatedGateway = false;
defaults.set("enableDedicatedGateway", { value: enableDedicatedGateway, hidden: false, disabled: false});
defaults.set("sku", { value: "Cosmos.D4s", hidden: !enableDedicatedGateway, disabled: false});
defaults.set("instances", { value: await getInstancesMin(), hidden: !enableDedicatedGateway, disabled: false});
const response = await getCurrentProvisioningState()
if (response.status !== undefined)
{
defaults.set("enableDedicatedGateway", { value: enableDedicatedGateway, hidden: false, disabled: false });
defaults.set("sku", { value: "Cosmos.D4s", hidden: !enableDedicatedGateway, disabled: false });
defaults.set("instances", { value: await getInstancesMin(), hidden: !enableDedicatedGateway, disabled: false });
const response = await getCurrentProvisioningState();
if (response.status !== undefined) {
disableAttributesOnDedicatedGatewayChange = true;
defaults.set("enableDedicatedGateway", { value: true, hidden: false, disabled: false});
defaults.set("sku", { value: response.sku, hidden: false, disabled: true});
defaults.set("instances", { value: response.instances, hidden: false, disabled: true});
defaults.set("enableDedicatedGateway", { value: true, hidden: false, disabled: false });
defaults.set("sku", { value: response.sku, hidden: false, disabled: true });
defaults.set("instances", { value: response.instances, hidden: false, disabled: true });
}
return defaults;

View File

@ -1,31 +1,31 @@
export type SqlxServiceResource = {
id: string,
name: string,
type: string,
properties: SqlxServiceProps
locations: SqlxServiceLocations
}
id: string;
name: string;
type: string;
properties: SqlxServiceProps;
locations: SqlxServiceLocations;
};
export type SqlxServiceProps = {
serviceType: string,
creationTime: string,
status: string,
instanceSize: string,
instanceCount: number,
sqlxEndPoint: string
}
serviceType: string;
creationTime: string;
status: string;
instanceSize: string;
instanceCount: number;
sqlxEndPoint: string;
};
export type SqlxServiceLocations = {
location: string,
status: string,
sqlxEndpoint: string
}
location: string;
status: string;
sqlxEndpoint: string;
};
export type UpdateDedicatedGatewayRequestParameters = {
properties: UpdateDedicatedGatewayRequestProperties
}
properties: UpdateDedicatedGatewayRequestProperties;
};
export type UpdateDedicatedGatewayRequestProperties = {
instanceSize: string,
instanceCount: number,
serviceType: string
}
instanceSize: string;
instanceCount: number;
serviceType: string;
};