mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +00:00
Portal changes for DedicatedGateway. CR feedback
This commit is contained in:
@@ -126,5 +126,5 @@ export interface SelfServeNotification {
|
|||||||
|
|
||||||
export interface RefreshResult {
|
export interface RefreshResult {
|
||||||
isUpdateInProgress: boolean;
|
isUpdateInProgress: boolean;
|
||||||
notificationMessage?: string;
|
notificationMessage: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ import {
|
|||||||
|
|
||||||
const apiVersion = "2020-06-01-preview";
|
const apiVersion = "2020-06-01-preview";
|
||||||
|
|
||||||
|
export enum ResourceStatus {
|
||||||
|
Running,
|
||||||
|
Creating,
|
||||||
|
Updating,
|
||||||
|
Deleting
|
||||||
|
}
|
||||||
|
|
||||||
export interface DedicatedGatewayResponse {
|
export interface DedicatedGatewayResponse {
|
||||||
sku: string;
|
sku: string;
|
||||||
instances: number;
|
instances: number;
|
||||||
@@ -16,16 +23,13 @@ export interface DedicatedGatewayResponse {
|
|||||||
endpoint: string;
|
endpoint: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SKU {
|
export const getPath = (subscriptionId: string, resourceGroup: string, name: string): string => {
|
||||||
CosmosD4s = "Cosmos.D4s",
|
return `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${name}/services/sqlx`;
|
||||||
CosmosD8s = "Cosmos.D8s",
|
|
||||||
CosmosD16s = "Cosmos.D16s",
|
|
||||||
CosmosD32s = "Cosmos.D32s"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
const path = `/subscriptions/${userContext.subscriptionId}/resourceGroups/${userContext.resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${userContext.databaseAccount.name}/services/sqlx`;
|
const path = getPath(userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name);
|
||||||
const body: UpdateDedicatedGatewayRequestParameters = {
|
const body: UpdateDedicatedGatewayRequestParameters = {
|
||||||
properties: {
|
properties: {
|
||||||
instanceSize: sku,
|
instanceSize: sku,
|
||||||
@@ -37,12 +41,12 @@ export const updateDedicatedGatewayResource = async (sku: string, instances: num
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const deleteDedicatedGatewayResource = async (): Promise<void> => {
|
export const deleteDedicatedGatewayResource = async (): Promise<void> => {
|
||||||
const path = `/subscriptions/${userContext.subscriptionId}/resourceGroups/${userContext.resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${userContext.databaseAccount.name}/services/sqlx`;
|
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 = `/subscriptions/${userContext.subscriptionId}/resourceGroups/${userContext.resourceGroup}/providers/Microsoft.DocumentDB/databaseAccounts/${userContext.databaseAccount.name}/services/sqlx`;
|
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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +58,7 @@ export const getCurrentProvisioningState = async (): Promise<DedicatedGatewayRes
|
|||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
return {sku: null, instances: null, status: null, endpoint: null};
|
return {sku: undefined, instances: undefined, status: undefined, endpoint: undefined};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,27 +67,25 @@ export const refreshDedicatedGatewayProvisioning = async (): Promise<RefreshResu
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
const response = await getDedicatedGatewayResource();
|
const response = await getDedicatedGatewayResource();
|
||||||
if (response.properties.status == "Running")
|
if (response.properties.status === ResourceStatus.Running.toString())
|
||||||
{
|
{
|
||||||
return {isUpdateInProgress: false}
|
return {isUpdateInProgress: false, notificationMessage: undefined}
|
||||||
}
|
}
|
||||||
else if (response.properties.status == "Creating")
|
else if (response.properties.status === ResourceStatus.Creating.toString())
|
||||||
{
|
{
|
||||||
return {isUpdateInProgress: true, notificationMessage: "CreateMessage"};
|
return {isUpdateInProgress: true, notificationMessage: "CreateMessage"};
|
||||||
}
|
}
|
||||||
else if (response.properties.status == "Deleting")
|
else if (response.properties.status === ResourceStatus.Deleting.toString())
|
||||||
{
|
{
|
||||||
console.log(response.properties.status);
|
|
||||||
return {isUpdateInProgress: true, notificationMessage: "DeleteMessage"};
|
return {isUpdateInProgress: true, notificationMessage: "DeleteMessage"};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log(response.properties.status);
|
|
||||||
return {isUpdateInProgress: true, notificationMessage: "UpdateMessage"};
|
return {isUpdateInProgress: true, notificationMessage: "UpdateMessage"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return {isUpdateInProgress: false}
|
return {isUpdateInProgress: false, notificationMessage: undefined}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { IsDisplayable, OnChange, Values } from "../Decorators";
|
import { IsDisplayable, OnChange, Values } from "../Decorators";
|
||||||
import { userContext } from "../../UserContext";
|
|
||||||
import {
|
import {
|
||||||
ChoiceItem,
|
ChoiceItem,
|
||||||
InputType,
|
InputType,
|
||||||
@@ -11,14 +10,12 @@ import {
|
|||||||
SmartUiInput,
|
SmartUiInput,
|
||||||
} from "../SelfServeTypes";
|
} from "../SelfServeTypes";
|
||||||
import {
|
import {
|
||||||
|
ResourceStatus,
|
||||||
refreshDedicatedGatewayProvisioning,
|
refreshDedicatedGatewayProvisioning,
|
||||||
getDedicatedGatewayResource,
|
|
||||||
updateDedicatedGatewayResource,
|
updateDedicatedGatewayResource,
|
||||||
deleteDedicatedGatewayResource,
|
deleteDedicatedGatewayResource,
|
||||||
SKU,
|
|
||||||
getCurrentProvisioningState
|
getCurrentProvisioningState
|
||||||
} from "./SqlX.rp";
|
} from "./SqlX.rp";
|
||||||
import { Console } from "console";
|
|
||||||
|
|
||||||
let disableAttributesOnDedicatedGatewayChange = false;
|
let disableAttributesOnDedicatedGatewayChange = false;
|
||||||
|
|
||||||
@@ -26,7 +23,6 @@ const onEnableDedicatedGatewayChange = (
|
|||||||
currentState: Map<string, SmartUiInput>,
|
currentState: Map<string, SmartUiInput>,
|
||||||
newValue: InputType
|
newValue: InputType
|
||||||
): Map<string, SmartUiInput> => {
|
): Map<string, SmartUiInput> => {
|
||||||
console.log("Disable Attributes is " + disableAttributesOnDedicatedGatewayChange);
|
|
||||||
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);
|
||||||
@@ -37,10 +33,10 @@ const onEnableDedicatedGatewayChange = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const skuDropDownItems: ChoiceItem[] = [
|
const skuDropDownItems: ChoiceItem[] = [
|
||||||
{ label: "CosmosD4s", key: SKU.CosmosD4s },
|
{ label: "CosmosD4s", key: "Cosmos.D4s" },
|
||||||
{ label: "CosmosD8s", key: SKU.CosmosD8s },
|
{ label: "CosmosD8s", key: "Cosmos.D8s" },
|
||||||
{ label: "CosmosD16s", key: SKU.CosmosD16s },
|
{ label: "CosmosD16s", key: "Cosmos.D16s" },
|
||||||
{ label: "CosmosD32s", key: SKU.CosmosD32s },
|
{ label: "CosmosD32s", key: "Cosmos.D32s" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const getSkus = async (): Promise<ChoiceItem[]> => {
|
const getSkus = async (): Promise<ChoiceItem[]> => {
|
||||||
@@ -58,11 +54,6 @@ const getInstancesMax = async (): Promise<number> => {
|
|||||||
return 5;
|
return 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validate = (currentValues: Map<string, SmartUiInput>): void => {
|
|
||||||
// TODO: add cusom validation logic to be called before Saving the data.
|
|
||||||
throw new Error(`validate not implemented. No. of properties to validate: ${currentValues.size}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
@IsDisplayable()
|
@IsDisplayable()
|
||||||
export default class SqlX extends SelfServeBaseClass {
|
export default class SqlX extends SelfServeBaseClass {
|
||||||
public onRefresh = async (): Promise<RefreshResult> => {
|
public onRefresh = async (): Promise<RefreshResult> => {
|
||||||
@@ -73,25 +64,24 @@ 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 != null && response.status != "Running")
|
if (response.status !== undefined && response.status !== ResourceStatus.Running.toString())
|
||||||
{
|
{
|
||||||
switch(response.status)
|
switch(response.status)
|
||||||
{
|
{
|
||||||
case "Creating":
|
case ResourceStatus.Creating.toString():
|
||||||
return {message: "CreateMessage", type: SelfServeNotificationType.error};
|
return {message: "CreateMessage", type: SelfServeNotificationType.error};
|
||||||
case "Updating":
|
case ResourceStatus.Updating.toString():
|
||||||
return {message: "UpdateMessage", type: SelfServeNotificationType.error};
|
return {message: "UpdateMessage", type: SelfServeNotificationType.error};
|
||||||
case "Deleting":
|
case ResourceStatus.Deleting.toString():
|
||||||
return {message: "DeleteMessage", type: SelfServeNotificationType.error};
|
return {message: "DeleteMessage", type: SelfServeNotificationType.error};
|
||||||
default:
|
default:
|
||||||
console.log("UnexpectedStatus: " + response.status);
|
|
||||||
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 != null)
|
if (response.status !== undefined)
|
||||||
{
|
{
|
||||||
if (!enableDedicatedGateway)
|
if (!enableDedicatedGateway)
|
||||||
{
|
{
|
||||||
@@ -102,7 +92,6 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
console.log(e);
|
|
||||||
return { message: "Deleting Dedicated Gateway resource failed. DedicatedGateway will not be deleted.", type: SelfServeNotificationType.error };
|
return { message: "Deleting Dedicated Gateway resource failed. DedicatedGateway will not be deleted.", type: SelfServeNotificationType.error };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +112,6 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
console.log(e);
|
|
||||||
return { message: "Updating Dedicated Gateway resource failed. Dedicated Gateway will not be updated.", type: SelfServeNotificationType.error };
|
return { message: "Updating Dedicated Gateway resource failed. Dedicated Gateway will not be updated.", type: SelfServeNotificationType.error };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,10 +126,10 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
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: SKU.CosmosD4s, 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 != null)
|
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});
|
||||||
|
|||||||
Reference in New Issue
Block a user