diff --git a/server/routerlicious/packages/lambdas/src/deli/lambdaFactory.ts b/server/routerlicious/packages/lambdas/src/deli/lambdaFactory.ts index 63c261bf46c2..388c3a194d95 100644 --- a/server/routerlicious/packages/lambdas/src/deli/lambdaFactory.ts +++ b/server/routerlicious/packages/lambdas/src/deli/lambdaFactory.ts @@ -86,8 +86,7 @@ export class DeliLambdaFactory extends EventEmitter implements IPartitionLambdaF let document: IDocument; try { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - gitManager = tenant.gitManager; + gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); // Lookup the last sequence number stored // TODO - is this storage specific to the orderer in place? Or can I generalize the output context? diff --git a/server/routerlicious/packages/lambdas/src/scribe/lambdaFactory.ts b/server/routerlicious/packages/lambdas/src/scribe/lambdaFactory.ts index cb6a479277c9..a4d6f8ad77a7 100644 --- a/server/routerlicious/packages/lambdas/src/scribe/lambdaFactory.ts +++ b/server/routerlicious/packages/lambdas/src/scribe/lambdaFactory.ts @@ -84,8 +84,7 @@ export class ScribeLambdaFactory extends EventEmitter implements IPartitionLambd LumberEventName.ScribeSessionResult, this.serviceConfiguration); try { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - gitManager = tenant.gitManager; + gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); summaryReader = new SummaryReader(tenantId, documentId, gitManager, this.enableWholeSummaryUpload); [latestSummary, document] = await Promise.all([ diff --git a/server/routerlicious/packages/lambdas/src/test/scribe/lambda.spec.ts b/server/routerlicious/packages/lambdas/src/test/scribe/lambda.spec.ts index 8f9143a00714..c1a165bf4209 100644 --- a/server/routerlicious/packages/lambdas/src/test/scribe/lambda.spec.ts +++ b/server/routerlicious/packages/lambdas/src/test/scribe/lambda.spec.ts @@ -63,8 +63,7 @@ describe("Routerlicious", () => { testKafka = new TestKafka(); testProducer = testKafka.createProducer(); testTenantManager = new TestTenantManager(); - const tenant = await testTenantManager.getTenant(testTenantId, testDocumentId); - testGitManager = tenant.gitManager as GitManager; + testGitManager = (await testTenantManager.getTenantGitManager(testTenantId, testDocumentId)) as GitManager; const createTreeEntry: ICreateTreeEntry[] = []; const requestBody: ICreateTreeParams = { tree: createTreeEntry, diff --git a/server/routerlicious/packages/routerlicious-base/src/alfred/services/deltaService.ts b/server/routerlicious/packages/routerlicious-base/src/alfred/services/deltaService.ts index 24e6c33fb34d..e178cfb07bdf 100644 --- a/server/routerlicious/packages/routerlicious-base/src/alfred/services/deltaService.ts +++ b/server/routerlicious/packages/routerlicious-base/src/alfred/services/deltaService.ts @@ -79,8 +79,7 @@ export class DeltaService implements IDeltaService { documentId: string, from?: number, to?: number) { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); const existingRef = await gitManager.getRef(encodeURIComponent(documentId)); if (!existingRef) { diff --git a/server/routerlicious/packages/services-core/src/tenant.ts b/server/routerlicious/packages/services-core/src/tenant.ts index c87ce4836a77..325e3191f264 100644 --- a/server/routerlicious/packages/services-core/src/tenant.ts +++ b/server/routerlicious/packages/services-core/src/tenant.ts @@ -86,6 +86,11 @@ export interface ITenantManager { */ getTenant(tenantId: string, documentId: string): Promise; + /** + * Retrieves GitManager instance for the given tenant + */ + getTenantGitManager(tenantId: string, documentId: string): Promise; + /** * Verifies that the given auth token is valid. A rejected promise indicates an invalid token. */ diff --git a/server/routerlicious/packages/services-shared/src/storage.ts b/server/routerlicious/packages/services-shared/src/storage.ts index 14657106ad26..6fc7134b947b 100644 --- a/server/routerlicious/packages/services-shared/src/storage.ts +++ b/server/routerlicious/packages/services-shared/src/storage.ts @@ -121,8 +121,7 @@ export class DocumentStorage implements IDocumentStorage { values: [string, ICommittedProposal][], enableDiscovery: boolean = false, ): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); const lumberjackProperties = { [BaseTelemetryProperties.tenantId]: tenantId, @@ -258,22 +257,20 @@ export class DocumentStorage implements IDocumentStorage { } public async getVersions(tenantId: string, documentId: string, count: number): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); return gitManager.getCommits(documentId, count); } public async getVersion(tenantId: string, documentId: string, sha: string): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); return gitManager.getCommit(sha); } public async getFullTree(tenantId: string, documentId: string): Promise<{ cache: IGitCache; code: string; }> { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const versions = await tenant.gitManager.getCommits(documentId, 1); + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); + const versions = await gitManager.getCommits(documentId, 1); if (versions.length === 0) { return { cache: { blobs: [], commits: [], refs: { [documentId]: (null as unknown) as string }, trees: [] }, @@ -281,7 +278,7 @@ export class DocumentStorage implements IDocumentStorage { }; } - const fullTree = await tenant.gitManager.getFullTree(versions[0].sha); + const fullTree = await gitManager.getFullTree(versions[0].sha); let code: string = (null as unknown) as string; if (fullTree.quorumValues) { @@ -373,8 +370,7 @@ export class DocumentStorage implements IDocumentStorage { } private async readFromSummary(tenantId: string, documentId: string): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); const existingRef = await gitManager.getRef(encodeURIComponent(documentId)); if (existingRef) { // Fetch ops from logTail and insert into deltas collection. diff --git a/server/routerlicious/packages/services/src/tenant.ts b/server/routerlicious/packages/services/src/tenant.ts index 839bb5fa2fc6..5167bc8adad6 100644 --- a/server/routerlicious/packages/services/src/tenant.ts +++ b/server/routerlicious/packages/services/src/tenant.ts @@ -9,6 +9,7 @@ import { ICredentials, BasicRestWrapper, getAuthorizationTokenFromCredentials, + IGitManager, } from "@fluidframework/server-services-client"; import { generateToken, getCorrelationId } from "@fluidframework/server-services-utils"; import * as core from "@fluidframework/server-services-core"; @@ -19,7 +20,7 @@ export class Tenant implements core.ITenant { return this.config.id; } - public get gitManager(): GitManager { + public get gitManager(): IGitManager { return this.manager; } @@ -31,7 +32,7 @@ export class Tenant implements core.ITenant { return this.config.orderer; } - constructor(private readonly config: core.ITenantConfig, private readonly manager: GitManager) { + constructor(private readonly config: core.ITenantConfig, private readonly manager: IGitManager) { } } @@ -53,10 +54,18 @@ export class TenantManager implements core.ITenantManager { public async getTenant(tenantId: string, documentId: string, includeDisabledTenant = false): Promise { const restWrapper = new BasicRestWrapper(); - const [details, key] = await Promise.all([ + const [details, gitManager] = await Promise.all([ restWrapper.get(`${this.endpoint}/api/tenants/${tenantId}`, { includeDisabledTenant }), - this.getKey(tenantId, includeDisabledTenant)]); + this.getTenantGitManager(tenantId, documentId, includeDisabledTenant)]); + + const tenant = new Tenant(details, gitManager); + + return tenant; + } + + public async getTenantGitManager(tenantId: string, documentId: string, includeDisabledTenant = false): Promise { + const key = await this.getKey(tenantId, includeDisabledTenant); const defaultQueryString = { token: fromUtf8ToBase64(`${tenantId}`), @@ -88,9 +97,8 @@ export class TenantManager implements core.ITenantManager { false, tenantRestWrapper); const gitManager = new GitManager(historian); - const tenant = new Tenant(details, gitManager); - return tenant; + return gitManager; } public async verifyToken(tenantId: string, token: string): Promise { diff --git a/server/routerlicious/packages/test-utils/src/testDocumentStorage.ts b/server/routerlicious/packages/test-utils/src/testDocumentStorage.ts index 7988dd7de597..98558ac21a79 100644 --- a/server/routerlicious/packages/test-utils/src/testDocumentStorage.ts +++ b/server/routerlicious/packages/test-utils/src/testDocumentStorage.ts @@ -65,8 +65,7 @@ export class TestDocumentStorage implements IDocumentStorage { values: [string, ICommittedProposal][], enableDiscovery: boolean = false, ): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); const blobsShaCache = new Set(); const handle = await writeSummaryTree(gitManager, summary, blobsShaCache, undefined); @@ -180,15 +179,13 @@ export class TestDocumentStorage implements IDocumentStorage { } public async getVersions(tenantId: string, documentId: string, count: number): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); return gitManager.getCommits(documentId, count); } public async getVersion(tenantId: string, documentId: string, sha: string): Promise { - const tenant = await this.tenantManager.getTenant(tenantId, documentId); - const gitManager = tenant.gitManager; + const gitManager = await this.tenantManager.getTenantGitManager(tenantId, documentId); return gitManager.getCommit(sha); } diff --git a/server/routerlicious/packages/test-utils/src/testTenantManager.ts b/server/routerlicious/packages/test-utils/src/testTenantManager.ts index b1b3ebc36f05..e378de9f1db6 100644 --- a/server/routerlicious/packages/test-utils/src/testTenantManager.ts +++ b/server/routerlicious/packages/test-utils/src/testTenantManager.ts @@ -71,6 +71,10 @@ export class TestTenantManager implements ITenantManager { return this.tenant; } + public async getTenantGitManager(tenantId: string, documentId: string): Promise { + return this.tenant.gitManager; + } + public async getKey(tenantId: string): Promise { return "test"; }