Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Upgrade: Migrating Tree View to V2 #2477

Merged
merged 120 commits into from
Feb 19, 2025
Merged
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
6afb950
first step, added v2 provider and creating account tree items for Mon…
tnaum-ms Nov 29, 2024
c4909eb
added entrypoint for nosql + renamed classes for simplicity
tnaum-ms Dec 2, 2024
ed2a0c7
added database support to monogodb ru on v2
tnaum-ms Dec 2, 2024
cb911b2
Merge branch 'main' into dev/tnaum/tree-api-migration
tnaum-ms Dec 12, 2024
67eb3e9
wip
tnaum-ms Dec 13, 2024
7f55aaa
feat: Migrating TreeView to V2
bk201- Dec 16, 2024
bc53d00
feat: Migrating TreeView to V2
bk201- Dec 17, 2024
7fd96bd
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Dec 17, 2024
9c71293
integrating with 'provider' changes during API unification
tnaum-ms Dec 17, 2024
fca14b1
expanding contextValue for mongo* workloads
tnaum-ms Dec 18, 2024
f69ed35
typo
tnaum-ms Jan 7, 2025
fea71e5
build fix
tnaum-ms Jan 7, 2025
98dcec2
vCore: added "create document..." menu item
tnaum-ms Jan 7, 2025
a20a6e6
vCore: removed old mongodb create document command
tnaum-ms Jan 7, 2025
3be3615
MongoDB: added azureDatabases.refresh_v2 for Tree APIv2
tnaum-ms Jan 7, 2025
680fafc
removed obsolete test code
tnaum-ms Jan 7, 2025
5758550
updated azuredatabases.refresh behavior to support v2 tree api
tnaum-ms Jan 8, 2025
38a4854
build fixes
tnaum-ms Jan 8, 2025
4e84fde
MongoDB: V1->V2, removed unused commands, deleted and commented out o…
tnaum-ms Jan 8, 2025
2f2490c
MongoDB: V1->V2, removed unused commands, deleted and commented out o…
tnaum-ms Jan 8, 2025
5ad2fd0
resolved build errors, wip
tnaum-ms Jan 8, 2025
674ad10
feat: Migrating TreeView to V2
bk201- Jan 9, 2025
f2fcaad
feat: Migrating TreeView to V2
bk201- Jan 9, 2025
54b7ed8
added command 'copy connection string'
tnaum-ms Jan 9, 2025
198c70e
feat: Migrating TreeView to V2
bk201- Jan 9, 2025
52985b0
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Jan 9, 2025
8940375
resolved merge conflicts
tnaum-ms Jan 9, 2025
915ea9f
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Jan 9, 2025
91c928f
updated command order for mongodb/vcore
tnaum-ms Jan 9, 2025
582f034
feat: Launch Shell available to both MongoDB implementations.
tnaum-ms Jan 9, 2025
8bb68e4
feat: adding 'create database' feature to monogodb-ru
tnaum-ms Jan 10, 2025
9002b6d
feat: added 'delete account' option to mongodb-ru
tnaum-ms Jan 10, 2025
e663ddc
feat: Migrating TreeView to V2
bk201- Jan 13, 2025
e009f7c
feat: enabled "Open Collection" context menu for MongoDB RU+vCore
tnaum-ms Jan 13, 2025
f7b14ca
feat: Migrating TreeView to V2
bk201- Jan 14, 2025
913228e
Merge remote-tracking branch 'origin/dev/tnaum/tree-api-migration' in…
bk201- Jan 14, 2025
f5a9763
feat: added "Delete Account" to MongoDB vCore
tnaum-ms Jan 14, 2025
a677716
feat: Migrating TreeView to V2
bk201- Jan 15, 2025
e3b3247
Merge remote-tracking branch 'origin/dev/tnaum/tree-api-migration' in…
bk201- Jan 15, 2025
2518a39
Updated 'copy connection string' command activation in package.json
tnaum-ms Jan 15, 2025
ff895fe
Dev/sda/tree api migration (#2533)
bk201- Jan 15, 2025
a918687
feat: Migrating TreeView to V2
bk201- Jan 16, 2025
59a4edf
Merge remote-tracking branch 'origin/dev/sda/tree-api-migration' into…
bk201- Jan 16, 2025
c102c05
Merge remote-tracking branch 'origin/dev/tnaum/tree-api-migration' in…
bk201- Jan 16, 2025
80e56fe
Dev/sda/tree api migration (#2535)
bk201- Jan 16, 2025
d15ed0a
feat: "copy connection string" for account nodes
tnaum-ms Jan 16, 2025
3c580f5
feat: "copy connection string" for account nodes
tnaum-ms Jan 17, 2025
66d2ca4
fix: build errors after SettingUtils update
tnaum-ms Jan 17, 2025
90d1b74
feat: "copy connection string" for account nodes
tnaum-ms Jan 17, 2025
f65cbfa
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Jan 17, 2025
31538a9
fix: post-merge build error
tnaum-ms Jan 17, 2025
4b90c8e
feat: Migrating TreeView to V2
bk201- Jan 20, 2025
6f30876
feat: Migrating TreeView to V2
bk201- Jan 20, 2025
d57ec92
feat: Migrating TreeView to V2
bk201- Jan 20, 2025
47abf6a
feat: Update version to 0.24.2
bk201- Jan 21, 2025
c6cc72b
feat: Update version to 0.24.2
bk201- Jan 21, 2025
020594b
feat: scrapbook for mongo, clean up and wire up commands
tnaum-ms Jan 22, 2025
2738367
feat: scrapbook for mongo: mongo lens provider twaks
tnaum-ms Jan 22, 2025
89549c1
feat: Migrating TreeView to V2
bk201- Jan 22, 2025
e29a72c
feat: Migrating TreeView to V2
bk201- Jan 23, 2025
215b352
feat: Migrating TreeView to V2
bk201- Jan 23, 2025
867c6a0
feat: Migrating TreeView to V2
bk201- Jan 23, 2025
fb653e8
feat: Migrating TreeView to V2
bk201- Jan 27, 2025
b864b61
feat: Mongo Shell (wip)
tnaum-ms Jan 27, 2025
ded24a7
feat: mongo scrapbook, dynamic code lens, with progress, output focus
tnaum-ms Jan 28, 2025
075ad88
feat: mongo scrapbook, improved UX, refactored, simplified code
tnaum-ms Jan 28, 2025
c624b8d
feat: Migrating TreeView to V2
bk201- Jan 29, 2025
f2a49b6
feat: Migrating TreeView to V2
bk201- Jan 29, 2025
b2dcc49
feat: mongo scrapbook: imroved progress notification
tnaum-ms Jan 30, 2025
460ae45
feat: mongo scrapbook: presecting a db ahead of command execution
tnaum-ms Jan 30, 2025
664b861
feat: mongo scrapbook: ensure JSON outputs
tnaum-ms Jan 30, 2025
30d39d5
feat: mongo scrapbook: ensure correct removal of prompt from script o…
tnaum-ms Jan 30, 2025
dea29a8
feat: mongo scrapbook: ensure correct removal of prompt from script o…
tnaum-ms Jan 30, 2025
9ffa803
feat: mongo scrapbook: stopped leaking passwords in debug output
tnaum-ms Jan 30, 2025
5767deb
feat: mongo scrapbook: simplified debug output
tnaum-ms Jan 30, 2025
b805ffb
fix: mongo scrapbook: fix for results with cursor
tnaum-ms Jan 30, 2025
0531649
feat: Migrating TreeView to V2
bk201- Jan 31, 2025
25b7aa2
feat: Migrating TreeView to V2
bk201- Jan 31, 2025
cf87d95
Merge branch 'dev/tnaum/tree-api-migration' into dev/sda/tree-api-mig…
tnaum-ms Feb 2, 2025
3eea104
Update src/commands/attachEmulator/PromptExperienceStep.ts
tnaum-ms Feb 2, 2025
ec12fcb
restoring+adding comments
tnaum-ms Feb 2, 2025
fd38df2
syncing with dev/sda/tree api migration (#2554)
tnaum-ms Feb 2, 2025
9b3452f
package.json commands sync
tnaum-ms Feb 2, 2025
fc8ea55
restoring mongo scrapook functionality post merge
tnaum-ms Feb 2, 2025
3c49897
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Feb 2, 2025
2d2e117
feat: Migrating TreeView to V2
bk201- Feb 3, 2025
f5d8976
feat: Migrating TreeView to V2
bk201- Feb 4, 2025
07942a7
feat: Migrating TreeView to V2
bk201- Feb 4, 2025
883b728
feat: Migrating TreeView to V2
bk201- Feb 4, 2025
27dcfd4
feat: Migrating TreeView to V2
bk201- Feb 4, 2025
8cff886
feat: Migrating TreeView to V2
bk201- Feb 4, 2025
f19126e
feat: Migrating TreeView to V2
bk201- Feb 5, 2025
3bec14b
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Feb 6, 2025
573e64e
fix: post-merge issues + command registration issues
tnaum-ms Feb 7, 2025
85b8eaa
feat: Migrating TreeView to V2
bk201- Feb 10, 2025
5615dc5
feat: Migrating TreeView to V2
bk201- Feb 10, 2025
dd0d1c5
feat: Migrating TreeView to V2
bk201- Feb 11, 2025
b046a01
feat: Migrating TreeView to V2
bk201- Feb 11, 2025
4f91687
feat: Migrating TreeView to V2
bk201- Feb 11, 2025
1bea0f7
Add missing multi-tenant support. (#2560)
sevoku Feb 11, 2025
3a93a91
feat: Migrating TreeView to V2
bk201- Feb 12, 2025
8e321ca
feat: Migrating TreeView to V2
bk201- Feb 13, 2025
ce45faa
Enable Attach Emulator on Linux and MacOS (#2450)
sevoku Feb 13, 2025
ccf23a5
feat: Migrating TreeView to V2
bk201- Feb 13, 2025
8934c4c
Merge remote-tracking branch 'origin/dev/sda/tree-api-migration' into…
bk201- Feb 13, 2025
e2d6ef8
feat: Migrating TreeView to V2
bk201- Feb 13, 2025
b520829
feat: emulator support updated with UX, refactor, and fixes (#2557)
tnaum-ms Feb 15, 2025
5f1c870
feat: emulator: added "local emulators" to nosql
tnaum-ms Feb 15, 2025
ab7c022
fix: emulator: extract emulator port correctly when connection string…
tnaum-ms Feb 15, 2025
a68a3c6
feat: emulator: tooltips for nosql
tnaum-ms Feb 17, 2025
6c5c3cd
feat: Migrating TreeView to V2
bk201- Feb 18, 2025
6e313b4
Merge branch 'main' into dev/sda/tree-api-migration
bk201- Feb 18, 2025
e97d0d0
feat: Migrating TreeView to V2
bk201- Feb 18, 2025
b764329
feat: emulator: removed code duplication
tnaum-ms Feb 18, 2025
0a1d5c1
Merge branch 'dev/sda/tree-api-migration' into dev/tnaum/tree-api-mig…
tnaum-ms Feb 18, 2025
3bc48bf
feat: attach/detach to new/remove connection
tnaum-ms Feb 18, 2025
e7a220e
fix: workspace: new mongo connection shown twice
tnaum-ms Feb 18, 2025
be2ae60
feat: confirm removing workspace accounts
tnaum-ms Feb 18, 2025
570015f
fix: unified mongodb categories in the command palette
tnaum-ms Feb 18, 2025
f023214
NoSQL Emulator supports key auth only. (#2569)
sevoku Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: adding 'create database' feature to monogodb-ru
tnaum-ms committed Jan 10, 2025
commit 8bb68e4ecfd5db9e28c83763f5030df5cba02772
2 changes: 1 addition & 1 deletion src/mongoClusters/MongoClustersClient.ts
Original file line number Diff line number Diff line change
@@ -363,7 +363,7 @@ export class MongoClustersClient {
const newCollection = await this._mongoClient
.db(databaseName)
.createCollection('_dummy_collection_creation_forces_db_creation');
await newCollection.drop();
await newCollection.drop({ writeConcern: { w: 'majority', wtimeout: 5000 } });
} catch (_e) {
console.error(_e); //todo: add to telemetry
return false;
35 changes: 27 additions & 8 deletions src/mongoClusters/commands/createDatabase.ts
Original file line number Diff line number Diff line change
@@ -4,38 +4,57 @@
*--------------------------------------------------------------------------------------------*/

import { AzureWizard, nonNullValue, type IActionContext } from '@microsoft/vscode-azext-utils';
import { MongoAccountResourceItem } from '../../tree/mongo/MongoAccountResourceItem';
import { showConfirmationAsInSettings } from '../../utils/dialogs/showConfirmation';
import { localize } from '../../utils/localize';
import { CredentialCache } from '../CredentialCache';
import { type MongoClusterResourceItem } from '../tree/MongoClusterResourceItem';
import { MongoClusterItemBase } from '../tree/MongoClusterItemBase';
import {
type CreateCollectionWizardContext,
type CreateDatabaseWizardContext,
} from '../wizards/create/createWizardContexts';
import { DatabaseNameStep } from '../wizards/create/PromptDatabaseNameStep';

export async function createDatabase(context: IActionContext, clusterNode?: MongoClusterResourceItem): Promise<void> {
context.telemetry.properties.experience = clusterNode?.mongoCluster.dbExperience?.api;

export async function createDatabase(
context: IActionContext,
clusterNode?: MongoClusterItemBase | MongoAccountResourceItem,
): Promise<void> {
// node ??= ... pick a node if not provided
if (!clusterNode) {
throw new Error('No cluster selected.');
}

if (!CredentialCache.hasCredentials(clusterNode.mongoCluster.id)) {
let connectionId: string = '';
let clusterName: string = '';

// TODO: currently MongoAccountResourceItem does not reuse MongoClusterItemBase, this will be refactored after the v1 to v2 tree migration

if (clusterNode instanceof MongoAccountResourceItem) {
context.telemetry.properties.experience = clusterNode.experience?.api;
connectionId = clusterNode.id;
clusterName = clusterNode.account.name;
}

if (clusterNode instanceof MongoClusterItemBase) {
context.telemetry.properties.experience = clusterNode.mongoCluster.dbExperience?.api;
connectionId = clusterNode.mongoCluster.id;
clusterName = clusterNode.mongoCluster.name;
}

if (!CredentialCache.hasCredentials(connectionId)) {
throw new Error(
localize(
'mongoClusters.notSignedIn',
'You are not signed in to the MongoDB Cluster. Please sign in (by expanding the node "{0}") and try again.',
clusterNode.mongoCluster.name,
clusterName,
),
);
}

const wizardContext: CreateDatabaseWizardContext = {
...context,
credentialsId: clusterNode.mongoCluster.id,
mongoClusterItem: clusterNode,
credentialsId: connectionId,
clusterName: clusterName,
};

const wizard: AzureWizard<CreateCollectionWizardContext> = new AzureWizard(wizardContext, {
16 changes: 10 additions & 6 deletions src/mongoClusters/tree/DatabaseItem.ts
Original file line number Diff line number Diff line change
@@ -74,17 +74,21 @@ export class DatabaseItem implements TreeElementWithId, TreeElementWithExperienc
async createCollection(_context: IActionContext, collectionName: string): Promise<boolean> {
const client = await MongoClustersClient.getClient(this.mongoCluster.id);

let success = false;

await ext.state.showCreatingChild(
return ext.state.showCreatingChild(
this.id,
localize('mongoClusters.tree.creating', 'Creating "{0}"...', collectionName),
async () => {
success = await client.createCollection(this.databaseInfo.name, collectionName);
// Adding a delay to ensure the "creating child" animation is visible.
// The `showCreatingChild` function refreshes the parent to show the
// "creating child" animation and label. Refreshing the parent triggers its
// `getChildren` method. If the database creation completes too quickly,
// the dummy node with the animation might be shown alongside the actual
// database entry, as it will already be available in the database.
// Note to future maintainers: Do not remove this delay.
await new Promise((resolve) => setTimeout(resolve, 250));
return client.createCollection(this.databaseInfo.name, collectionName);
},
);

return success;
}

getTreeItem(): TreeItem {
19 changes: 12 additions & 7 deletions src/mongoClusters/tree/MongoClusterItemBase.ts
Original file line number Diff line number Diff line change
@@ -124,17 +124,22 @@ export abstract class MongoClusterItemBase implements TreeElementWithId, TreeEle
async createDatabase(_context: IActionContext, databaseName: string): Promise<boolean> {
const client = await MongoClustersClient.getClient(this.mongoCluster.id);

let success = false;

await ext.state.showCreatingChild(
return ext.state.showCreatingChild<boolean>(
this.id,
localize('mongoClusters.tree.creating', 'Creating "{0}"...', databaseName),
async () => {
success = await client.createDatabase(databaseName);
async (): Promise<boolean> => {
// Adding a delay to ensure the "creating child" animation is visible.
// The `showCreatingChild` function refreshes the parent to show the
// "creating child" animation and label. Refreshing the parent triggers its
// `getChildren` method. If the database creation completes too quickly,
// the dummy node with the animation might be shown alongside the actual
// database entry, as it will already be available in the database.
// Note to future maintainers: Do not remove this delay.
await new Promise((resolve) => setTimeout(resolve, 250));

return client.createDatabase(databaseName);
},
);

return success;
}

/**
3 changes: 2 additions & 1 deletion src/mongoClusters/tree/MongoClustersBranchDataProvider.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import * as vscode from 'vscode';
import { API, MongoClustersExprience } from '../../AzureDBExperiences';
import { ext } from '../../extensionVariables';
import { createMongoClustersManagementClient } from '../../utils/azureClients';
import { type MongoClusterItemBase } from './MongoClusterItemBase';
import { type MongoClusterModel } from './MongoClusterModel';
import { MongoClusterResourceItem } from './MongoClusterResourceItem';

@@ -115,7 +116,7 @@ export class MongoClustersBranchDataProvider
);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return ext.state.wrapItemInStateHandling(resourceItem!, () => this.refresh(resourceItem));
return ext.state.wrapItemInStateHandling(resourceItem!, (item: MongoClusterItemBase) => this.refresh(item));
}

async updateResourceCache(
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ export class DatabaseNameStep extends AzureWizardPromptStep<CreateDatabaseWizard
'The database "{0}" already exists in the MongoDB Cluster "{1}". \n' +
'Do not rely on case to distinguish between databases. For example, you cannot use two databases with names like, salesData and SalesData.',
name,
context.mongoClusterItem.mongoCluster.name,
context.clusterName,
);
}
} catch (_error) {
3 changes: 1 addition & 2 deletions src/mongoClusters/wizards/create/createWizardContexts.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@

import { type IActionContext } from '@microsoft/vscode-azext-utils';
import { type DatabaseItem } from '../../tree/DatabaseItem';
import { type MongoClusterResourceItem } from '../../tree/MongoClusterResourceItem';

export interface CreateCollectionWizardContext extends IActionContext {
/** These values have to be provided for the wizard to function correctly. */
@@ -19,7 +18,7 @@ export interface CreateCollectionWizardContext extends IActionContext {
export interface CreateDatabaseWizardContext extends IActionContext {
/** These values have to be provided for the wizard to function correctly. */
credentialsId: string;
mongoClusterItem: MongoClusterResourceItem;
clusterName: string;

/** These values will be populated by the wizard. */
newDatabaseName?: string;
42 changes: 41 additions & 1 deletion src/tree/mongo/MongoAccountResourceItem.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import { MongoClustersClient, type DatabaseItemModel } from '../../mongoClusters
import { DatabaseItem } from '../../mongoClusters/tree/DatabaseItem';
import { type MongoClusterModel } from '../../mongoClusters/tree/MongoClusterModel';
import { createCosmosDBManagementClient } from '../../utils/azureClients';
import { localize } from '../../utils/localize';
import { CosmosAccountResourceItemBase } from '../CosmosAccountResourceItemBase';
import { type CosmosDBTreeElement, type ExtTreeElementBase } from '../CosmosDBTreeElement';
import { type MongoAccountModel } from './MongoAccountModel';
@@ -22,8 +23,11 @@ import { type MongoAccountModel } from './MongoAccountModel';
* This implementation relies on information from the MongoAccountModel, i.e.
* will only behave as expected when used in the context of an Azure Subscription.
*/

// TODO: currently MongoAccountResourceItem does not reuse MongoClusterItemBase, this will be refactored after the v1 to v2 tree migration

export class MongoAccountResourceItem extends CosmosAccountResourceItemBase {
protected declare account: MongoAccountModel;
declare account: MongoAccountModel;

constructor(
account: MongoAccountModel,
@@ -162,4 +166,40 @@ export class MongoAccountResourceItem extends CosmosAccountResourceItemBase {
// }
// }
}

/**
* Creates a new database in the cluster.
*
* TODO: this is a plain copy&paste from mongoclusters. It will be cleaned up in one shared base class after v1 to v2 tree migration
*
* @param _context The action context.
* @param databaseName The name of the database to create.
* @returns A boolean indicating success.
*/
/**
* Creates a new MongoDB database with the specified name.
*
* @param _context - The action context.
* @param databaseName - The name of the database to create.
* @returns A promise that resolves to a boolean indicating the success of the operation.
*/
async createDatabase(_context: IActionContext, databaseName: string): Promise<boolean> {
const client = await MongoClustersClient.getClient(this.id);

return ext.state.showCreatingChild<boolean>(
this.id,
localize('mongoClusters.tree.creating', 'Creating "{0}"...', databaseName),
async (): Promise<boolean> => {
// Adding a delay to ensure the "creating child" animation is visible.
// The `showCreatingChild` function refreshes the parent to show the
// "creating child" animation and label. Refreshing the parent triggers its
// `getChildren` method. If the database creation completes too quickly,
// the dummy node with the animation might be shown alongside the actual
// database entry, as it will already be available in the database.
// Note to future maintainers: Do not remove this delay.
await new Promise((resolve) => setTimeout(resolve, 250));
return client.createDatabase(databaseName);
},
);
}
}