mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 17:30:46 +00:00
Move create collection to RP (#173)
This commit is contained in:
@@ -9,18 +9,15 @@ import * as PricingUtils from "../../Utils/PricingUtils";
|
||||
import * as SharedConstants from "../../Shared/Constants";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import editable from "../../Common/EditableUtility";
|
||||
import EnvironmentUtility from "../../Common/EnvironmentUtility";
|
||||
import Q from "q";
|
||||
import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||
import { configContext, Platform } from "../../ConfigContext";
|
||||
import { ContextualPaneBase } from "./ContextualPaneBase";
|
||||
import { createMongoCollectionWithARM, createMongoCollectionWithProxy } from "../../Common/MongoProxyClient";
|
||||
import { DynamicListItem } from "../Controls/DynamicList/DynamicListComponent";
|
||||
import { HashMap } from "../../Common/HashMap";
|
||||
import { PlatformType } from "../../PlatformType";
|
||||
import { refreshCachedResources, getOrCreateDatabaseAndCollection } from "../../Common/DocumentClientUtilityBase";
|
||||
import { userContext } from "../../UserContext";
|
||||
import { refreshCachedResources } from "../../Common/DocumentClientUtilityBase";
|
||||
import { createCollection } from "../../Common/dataAccess/createCollection";
|
||||
|
||||
export interface AddCollectionPaneOptions extends ViewModels.PaneOptions {
|
||||
isPreferredApiTable: ko.Computed<boolean>;
|
||||
@@ -811,7 +808,6 @@ export default class AddCollectionPane extends ContextualPaneBase {
|
||||
|
||||
let databaseId: string = this.databaseCreateNew() ? this.databaseId().trim() : this.databaseId();
|
||||
let collectionId: string = this.collectionId().trim();
|
||||
let rupm: boolean = this.rupm() === Constants.RUPMStates.on;
|
||||
|
||||
let indexingPolicy: DataModels.IndexingPolicy;
|
||||
// todo - remove mongo indexing policy ticket # 616274
|
||||
@@ -828,130 +824,28 @@ export default class AddCollectionPane extends ContextualPaneBase {
|
||||
}
|
||||
|
||||
this.formErrors("");
|
||||
|
||||
this.isExecuting(true);
|
||||
|
||||
const createRequest: DataModels.CreateDatabaseAndCollectionRequest = {
|
||||
const databaseLevelThroughput: boolean = this.databaseCreateNew()
|
||||
? this.databaseCreateNewShared()
|
||||
: this.databaseHasSharedOffer() && !this.collectionWithThroughputInShared();
|
||||
const autoPilotMaxThroughput: number = databaseLevelThroughput
|
||||
? this.isSharedAutoPilotSelected() && this.sharedAutoPilotThroughput()
|
||||
: this.isAutoPilotSelected() && this.autoPilotThroughput();
|
||||
const createCollectionParams: DataModels.CreateCollectionParams = {
|
||||
createNewDatabase: this.databaseCreateNew(),
|
||||
collectionId,
|
||||
databaseId,
|
||||
databaseLevelThroughput,
|
||||
offerThroughput,
|
||||
databaseLevelThroughput: this.databaseHasSharedOffer() && !this.collectionWithThroughputInShared(),
|
||||
rupmEnabled: rupm,
|
||||
partitionKey,
|
||||
indexingPolicy,
|
||||
uniqueKeyPolicy,
|
||||
autoPilot,
|
||||
analyticalStorageTtl: this._getAnalyticalStorageTtl(),
|
||||
hasAutoPilotV2FeatureFlag: this.hasAutoPilotV2FeatureFlag()
|
||||
autoPilotMaxThroughput,
|
||||
indexingPolicy,
|
||||
partitionKey,
|
||||
uniqueKeyPolicy
|
||||
};
|
||||
|
||||
const options: any = {};
|
||||
if (this.container.isPreferredApiMongoDB()) {
|
||||
options.initialHeaders = options.initialHeaders || {};
|
||||
options.initialHeaders[Constants.HttpHeaders.supportSpatialLegacyCoordinates] = true;
|
||||
options.initialHeaders[Constants.HttpHeaders.usePolygonsSmallerThanAHemisphere] = true;
|
||||
}
|
||||
|
||||
const databaseCreateNew = this.databaseCreateNew();
|
||||
const useDatabaseSharedOffer = this.shouldUseDatabaseThroughput();
|
||||
const isSharded: boolean = !!partitionKeyPath;
|
||||
const autopilotSettings: DataModels.RpOptions = this._getAutopilotSettings();
|
||||
|
||||
let createCollectionFunc: () => Q.Promise<DataModels.Collection | DataModels.CreateCollectionWithRpResponse>;
|
||||
|
||||
if (this.container.isPreferredApiMongoDB()) {
|
||||
const isFixedCollectionWithSharedThroughputBeingCreated =
|
||||
this.container.isFixedCollectionWithSharedThroughputSupported() &&
|
||||
!this.isUnlimitedStorageSelected() &&
|
||||
this.databaseHasSharedOffer();
|
||||
const isAadUser = EnvironmentUtility.isAadUser();
|
||||
|
||||
// note: v3 autopilot not supported yet for Mongo fixed collections (only tier supported)
|
||||
if (!isAadUser || isFixedCollectionWithSharedThroughputBeingCreated) {
|
||||
createCollectionFunc = () =>
|
||||
Q(
|
||||
createMongoCollectionWithProxy(
|
||||
databaseId,
|
||||
collectionId,
|
||||
offerThroughput,
|
||||
partitionKeyPath,
|
||||
databaseCreateNew,
|
||||
useDatabaseSharedOffer,
|
||||
isSharded,
|
||||
autopilotSettings
|
||||
)
|
||||
);
|
||||
} else {
|
||||
createCollectionFunc = () =>
|
||||
Q(
|
||||
createMongoCollectionWithARM(
|
||||
this.container.armEndpoint(),
|
||||
databaseId,
|
||||
this._getAnalyticalStorageTtl(),
|
||||
collectionId,
|
||||
offerThroughput,
|
||||
partitionKeyPath,
|
||||
databaseCreateNew,
|
||||
useDatabaseSharedOffer,
|
||||
isSharded,
|
||||
autopilotSettings
|
||||
)
|
||||
);
|
||||
}
|
||||
} else if (this.container.isPreferredApiTable() && EnvironmentUtility.isAadUser()) {
|
||||
createCollectionFunc = () =>
|
||||
Q(
|
||||
AddCollectionUtility.Utilities.createAzureTableWithARM(
|
||||
this.container.armEndpoint(),
|
||||
createRequest,
|
||||
autopilotSettings
|
||||
)
|
||||
);
|
||||
} else if (this.container.isPreferredApiGraph() && EnvironmentUtility.isAadUser()) {
|
||||
createCollectionFunc = () =>
|
||||
Q(
|
||||
AddCollectionUtility.CreateCollectionUtilities.createGremlinGraph(
|
||||
this.container.armEndpoint(),
|
||||
databaseId,
|
||||
collectionId,
|
||||
indexingPolicy,
|
||||
offerThroughput,
|
||||
partitionKeyPath,
|
||||
partitionKey.version,
|
||||
databaseCreateNew,
|
||||
useDatabaseSharedOffer,
|
||||
userContext.subscriptionId,
|
||||
userContext.resourceGroup,
|
||||
userContext.databaseAccount.name,
|
||||
autopilotSettings
|
||||
)
|
||||
);
|
||||
} else if (this.container.isPreferredApiDocumentDB() && EnvironmentUtility.isAadUser()) {
|
||||
createCollectionFunc = () =>
|
||||
Q(
|
||||
AddCollectionUtility.CreateSqlCollectionUtilities.createSqlCollection(
|
||||
this.container.armEndpoint(),
|
||||
databaseId,
|
||||
this._getAnalyticalStorageTtl(),
|
||||
collectionId,
|
||||
indexingPolicy,
|
||||
offerThroughput,
|
||||
partitionKeyPath,
|
||||
partitionKey.version,
|
||||
databaseCreateNew,
|
||||
useDatabaseSharedOffer,
|
||||
userContext.subscriptionId,
|
||||
userContext.resourceGroup,
|
||||
userContext.databaseAccount.name,
|
||||
uniqueKeyPolicy,
|
||||
autopilotSettings
|
||||
)
|
||||
);
|
||||
} else {
|
||||
createCollectionFunc = () => getOrCreateDatabaseAndCollection(createRequest, options);
|
||||
}
|
||||
|
||||
createCollectionFunc().then(
|
||||
createCollection(createCollectionParams).then(
|
||||
() => {
|
||||
this.isExecuting(false);
|
||||
this.close();
|
||||
@@ -1234,35 +1128,6 @@ export default class AddCollectionPane extends ContextualPaneBase {
|
||||
|
||||
return undefined;
|
||||
}
|
||||
private _getAutopilotSettings(): DataModels.RpOptions {
|
||||
if (
|
||||
(!this.hasAutoPilotV2FeatureFlag() &&
|
||||
this.databaseCreateNewShared() &&
|
||||
this.isSharedAutoPilotSelected() &&
|
||||
this.sharedAutoPilotThroughput()) ||
|
||||
(this.hasAutoPilotV2FeatureFlag() &&
|
||||
this.databaseCreateNewShared() &&
|
||||
this.isSharedAutoPilotSelected() &&
|
||||
this.selectedSharedAutoPilotTier())
|
||||
) {
|
||||
return !this.hasAutoPilotV2FeatureFlag()
|
||||
? {
|
||||
[Constants.HttpHeaders.autoPilotThroughput]: { maxThroughput: this.sharedAutoPilotThroughput() * 1 }
|
||||
}
|
||||
: { [Constants.HttpHeaders.autoPilotTier]: this.selectedSharedAutoPilotTier().toString() };
|
||||
}
|
||||
if (
|
||||
(!this.hasAutoPilotV2FeatureFlag() && this.isAutoPilotSelected() && this.autoPilotThroughput()) ||
|
||||
(this.hasAutoPilotV2FeatureFlag() && this.isAutoPilotSelected() && this.selectedAutoPilotTier())
|
||||
) {
|
||||
return !this.hasAutoPilotV2FeatureFlag()
|
||||
? {
|
||||
[Constants.HttpHeaders.autoPilotThroughput]: { maxThroughput: this.autoPilotThroughput() * 1 }
|
||||
}
|
||||
: { [Constants.HttpHeaders.autoPilotTier]: this.selectedAutoPilotTier().toString() };
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _calculateNumberOfPartitions(): number {
|
||||
// Note: this will not validate properly on accounts that have been set up for custom partitioning,
|
||||
|
||||
Reference in New Issue
Block a user