mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-02-16 17:25:58 +00:00
Rough implementation of a client map. Need to figure out how to keep read client config in sync when other connection policy settings change. If number of retry change, etc.
This commit is contained in:
parent
18f1b416b2
commit
5d3454d973
@ -138,32 +138,37 @@ enum SDKSupportedCapabilities {
|
|||||||
// Need to put in some kind of function here to recreate the CosmosClient with a new endpoint.
|
// Need to put in some kind of function here to recreate the CosmosClient with a new endpoint.
|
||||||
// changeClientEndpoint.......
|
// changeClientEndpoint.......
|
||||||
|
|
||||||
|
let _clients: Map<string, Cosmos.CosmosClient> = new Map();
|
||||||
|
|
||||||
let _client: Cosmos.CosmosClient;
|
let _client: Cosmos.CosmosClient;
|
||||||
|
|
||||||
export function client(): Cosmos.CosmosClient {
|
export function client(): Cosmos.CosmosClient {
|
||||||
console.log(`Called primary client`);
|
console.log(`Called primary client`);
|
||||||
const currentUserContextDocumentEndpoint = userContext?.databaseAccount?.properties?.documentEndpoint;
|
const currentUserContextDocumentEndpoint = userContext?.databaseAccount?.properties?.documentEndpoint;
|
||||||
console.log(`Current selected endpoint in userContext: ${currentUserContextDocumentEndpoint}`);
|
console.log(`Current selected endpoint in userContext: ${currentUserContextDocumentEndpoint}`);
|
||||||
let mydatabaseAccountEndpoint = "Ahhhhhhhhh";
|
// let mydatabaseAccountEndpoint = "Ahhhhhhhhh";
|
||||||
if (_client) {
|
// if (_client) {
|
||||||
_client
|
// _client
|
||||||
.getDatabaseAccount()
|
// .getDatabaseAccount()
|
||||||
.then((databaseAccount) => {
|
// .then((databaseAccount) => {
|
||||||
console.log(
|
// console.log(
|
||||||
`Current primary client endpoint contacted: ${JSON.stringify(
|
// `Current primary client endpoint contacted: ${JSON.stringify(
|
||||||
databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted,
|
// databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted,
|
||||||
)}`,
|
// )}`,
|
||||||
);
|
// );
|
||||||
mydatabaseAccountEndpoint =
|
// mydatabaseAccountEndpoint =
|
||||||
databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted[0];
|
// databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted[0];
|
||||||
})
|
// })
|
||||||
.catch((error) => {
|
// .catch((error) => {
|
||||||
console.error("Error getting database account:", error);
|
// console.error("Error getting database account:", error);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (_client && currentUserContextDocumentEndpoint === mydatabaseAccountEndpoint) {
|
const retrievedEndpoint = endpoint() || "https://cosmos.azure.com";
|
||||||
return _client;
|
|
||||||
|
if (_clients.has(retrievedEndpoint)) {
|
||||||
|
console.log(`Current Client List: ${JSON.stringify(_clients)}`);
|
||||||
|
return _clients.get(retrievedEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _defaultHeaders: Cosmos.CosmosHeaders = {};
|
let _defaultHeaders: Cosmos.CosmosHeaders = {};
|
||||||
@ -183,7 +188,7 @@ export function client(): Cosmos.CosmosClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const options: Cosmos.CosmosClientOptions = {
|
const options: Cosmos.CosmosClientOptions = {
|
||||||
endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
endpoint: retrievedEndpoint, // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
||||||
key: userContext.masterKey,
|
key: userContext.masterKey,
|
||||||
tokenProvider,
|
tokenProvider,
|
||||||
userAgentSuffix: "Azure Portal",
|
userAgentSuffix: "Azure Portal",
|
||||||
@ -227,6 +232,7 @@ export function client(): Cosmos.CosmosClient {
|
|||||||
(options as any).plugins = plugins;
|
(options as any).plugins = plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
_client = new Cosmos.CosmosClient(options);
|
_clients.set(retrievedEndpoint, new Cosmos.CosmosClient(options));
|
||||||
return _client;
|
|
||||||
|
return _clients.get(retrievedEndpoint);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user