Skip to content

Commit 22d54d4

Browse files
authored
qfix: Allow tool to create workspace with dataid for testing (#9404)
Signed-off-by: Andrey Sobolev <[email protected]>
1 parent 3d33954 commit 22d54d4

File tree

5 files changed

+72
-63
lines changed

5 files changed

+72
-63
lines changed

.vscode/launch.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,8 @@
311311
"ACCOUNTS_URL": "http://localhost:3000",
312312
"FRONT_URL": "http://localhost:8080",
313313
"MAIL_URL": "",
314-
"MINIO_ACCESS_KEY": "minioadmin",
315-
"MINIO_SECRET_KEY": "minioadmin",
316-
"MINIO_ENDPOINT": "localhost",
317-
"MODEL_VERSION": "0.7.110",
314+
"STORAGE_CONFIG": "datalake|http://localhost:4030",
315+
"MODEL_VERSION": "0.7.153",
318316
"WS_OPERATION": "all+backup",
319317
"BACKUP_STORAGE": "minio|minio?accessKey=minioadmin&secretKey=minioadmin",
320318
"BACKUP_BUCKET": "dev-backups",
@@ -729,11 +727,11 @@
729727
"request": "launch",
730728
"args": ["src/index.ts"],
731729
"env": {
732-
"ACCOUNTS_URL" : "http://localhost:3000",
733-
"Credentials" : "",
734-
"KVS_URL" : "http://localhost:8094",
735-
"SECRET" : "secret",
736-
"WATCH_URL" : "https://calendar.hc.engineering/push"
730+
"ACCOUNTS_URL": "http://localhost:3000",
731+
"Credentials": "",
732+
"KVS_URL": "http://localhost:8094",
733+
"SECRET": "secret",
734+
"WATCH_URL": "https://calendar.hc.engineering/push"
737735
},
738736
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
739737
"runtimeVersion": "20",

dev/tool/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/tool staging",
2222
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/tool",
2323
"run-local-mongo": "rush bundle --to @hcengineering/tool >/dev/null && cross-env SERVER_SECRET=secret FULLTEXT_URL=http://localhost:4700 ACCOUNTS_URL=http://localhost:3000 TRANSACTOR_URL=ws://localhost:3333 MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost ACCOUNT_DB_URL=mongodb://localhost:27017 DB_URL=mongodb://localhost:27017 TELEGRAM_DATABASE=telegram-service REKONI_URL=http://localhost:4004 MODEL_VERSION=$(node ../../common/scripts/show_version.js) GIT_REVISION=$(git describe --all --long) QUEUE_CONFIG='localhost:19092' node --expose-gc --max-old-space-size=18000 ./bundle/bundle.js",
24-
"run-local": "rush bundle --to @hcengineering/tool >/dev/null && cross-env SERVER_SECRET=secret FULLTEXT_URL=http://localhost:4702 ACCOUNTS_URL=http://localhost:3000 TRANSACTOR_URL=ws://localhost:3332 MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost ACCOUNT_DB_URL=postgresql://[email protected]:26257/defaultdb?sslmode=disable DB_URL=postgresql://[email protected]:26257/defaultdb?sslmode=disable TELEGRAM_DATABASE=telegram-service REKONI_URL=http://localhost:4004 MODEL_VERSION=$(node ../../common/scripts/show_version.js) GIT_REVISION=$(git describe --all --long) QUEUE_CONFIG='localhost:19092' node --expose-gc --max-old-space-size=18000 $TOOL_OPT ./bundle/bundle.js",
24+
"run-local": "rush bundle --to @hcengineering/tool >/dev/null && cross-env SERVER_SECRET=secret FULLTEXT_URL=http://localhost:4702 ACCOUNTS_URL=http://localhost:3000 TRANSACTOR_URL=ws://localhost:3332 STORAGE_CONFIG='datalake|http://localhost:4030' ACCOUNT_DB_URL=postgresql://[email protected]:26257/defaultdb?sslmode=disable DB_URL=postgresql://[email protected]:26257/defaultdb?sslmode=disable TELEGRAM_DATABASE=telegram-service REKONI_URL=http://localhost:4004 REGION_INFO='cockroach|CockroachDB' MODEL_VERSION=$(node ../../common/scripts/show_version.js) GIT_REVISION=$(git describe --all --long) QUEUE_CONFIG='localhost:19092' node --expose-gc --max-old-space-size=18000 $TOOL_OPT ./bundle/bundle.js",
2525
"run-local-brk": "rush bundle --to @hcengineering/tool >/dev/null && cross-env SERVER_SECRET=secret ACCOUNTS_URL=http://localhost:3000 TRANSACTOR_URL=ws://localhost:3333 MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost ACCOUNT_DB_URL=mongodb://localhost:27017 DB_URL=mongodb://localhost:27017 TELEGRAM_DATABASE=telegram-service REKONI_URL=http://localhost:4004 MODEL_VERSION=$(node ../../common/scripts/show_version.js) GIT_REVISION=$(git describe --all --long) node --inspect-brk --enable-source-maps --max-old-space-size=18000 ./bundle/bundle.js",
2626
"run": "rush bundle --to @hcengineering/tool >/dev/null && cross-env node --max-old-space-size=8000 ./bundle/bundle.js",
2727
"upgrade-mongo": "rushx run-local-mongo upgrade-workspace -- $1",

dev/tool/src/index.ts

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -348,62 +348,70 @@ export function devTool (
348348
.description('create workspace')
349349
.option('-i, --init <ws>', 'Init from workspace')
350350
.option('-r, --region <region>', 'Region')
351+
.option('-d, --dataId <dataId>', 'DataId for workspace')
351352
.option('-b, --branding <key>', 'Branding key')
352-
.action(async (name, socialString, cmd: { account: string, init?: string, branding?: string, region?: string }) => {
353-
const { txes, version, migrateOperations } = prepareTools()
354-
await withAccountDatabase(async (db) => {
355-
const measureCtx = new MeasureMetricsContext('create-workspace', {})
356-
const brandingObj =
357-
cmd.branding !== undefined || cmd.init !== undefined ? { key: cmd.branding, initWorkspace: cmd.init } : null
358-
const socialId = await db.socialId.findOne({ key: socialString as PersonId })
359-
if (socialId == null) {
360-
throw new Error(`Social id ${socialString} not found`)
361-
}
353+
.action(
354+
async (
355+
name,
356+
socialString,
357+
cmd: { account: string, init?: string, branding?: string, region?: string, dataId?: string }
358+
) => {
359+
const { txes, version, migrateOperations } = prepareTools()
360+
await withAccountDatabase(async (db) => {
361+
const measureCtx = new MeasureMetricsContext('create-workspace', {})
362+
const brandingObj =
363+
cmd.branding !== undefined || cmd.init !== undefined ? { key: cmd.branding, initWorkspace: cmd.init } : null
364+
const socialId = await db.socialId.findOne({ key: socialString as PersonId })
365+
if (socialId == null) {
366+
throw new Error(`Social id ${socialString} not found`)
367+
}
362368

363-
const res = await createWorkspaceRecord(
364-
measureCtx,
365-
db,
366-
brandingObj,
367-
name,
368-
socialId.personUuid,
369-
cmd.region,
370-
'manual-creation'
371-
)
372-
const wsInfo = await getWorkspaceInfoWithStatusById(db, res.workspaceUuid)
369+
const res = await createWorkspaceRecord(
370+
measureCtx,
371+
db,
372+
brandingObj,
373+
name,
374+
socialId.personUuid,
375+
cmd.region,
376+
'manual-creation',
377+
cmd.dataId as WorkspaceDataId
378+
)
379+
const wsInfo = await getWorkspaceInfoWithStatusById(db, res.workspaceUuid)
380+
381+
if (wsInfo == null) {
382+
throw new Error(`Created workspace record ${res.workspaceUuid} not found`)
383+
}
384+
const coreWsInfo = flattenStatus(wsInfo)
385+
const accountClient = getAccountClient(getToolToken())
373386

374-
if (wsInfo == null) {
375-
throw new Error(`Created workspace record ${res.workspaceUuid} not found`)
376-
}
377-
const coreWsInfo = flattenStatus(wsInfo)
378-
const accountClient = getAccountClient(getToolToken())
387+
const queue = getPlatformQueue('tool', cmd.region)
388+
const wsProducer = queue.getProducer<QueueWorkspaceMessage>(toolCtx, QueueTopic.Workspace)
379389

380-
const queue = getPlatformQueue('tool', cmd.region)
381-
const wsProducer = queue.getProducer<QueueWorkspaceMessage>(toolCtx, QueueTopic.Workspace)
390+
await createWorkspace(
391+
measureCtx,
392+
version,
393+
brandingObj,
394+
coreWsInfo,
395+
txes,
396+
migrateOperations,
397+
accountClient,
398+
wsProducer,
399+
undefined,
400+
true
401+
)
402+
await updateWorkspaceInfo(measureCtx, db, brandingObj, getToolToken(), {
403+
workspaceUuid: res.workspaceUuid,
404+
event: 'create-done',
405+
version,
406+
progress: 100
407+
})
382408

383-
await createWorkspace(
384-
measureCtx,
385-
version,
386-
brandingObj,
387-
coreWsInfo,
388-
txes,
389-
migrateOperations,
390-
accountClient,
391-
wsProducer,
392-
undefined,
393-
true
394-
)
395-
await updateWorkspaceInfo(measureCtx, db, brandingObj, getToolToken(), {
396-
workspaceUuid: res.workspaceUuid,
397-
event: 'create-done',
398-
version,
399-
progress: 100
409+
await wsProducer.send(res.workspaceUuid, [workspaceEvents.created()])
410+
await queue.shutdown()
411+
console.log(queue)
400412
})
401-
402-
await wsProducer.send(res.workspaceUuid, [workspaceEvents.created()])
403-
await queue.shutdown()
404-
console.log(queue)
405-
})
406-
})
413+
}
414+
)
407415

408416
program
409417
.command('set-user-role <email> <workspace> <role>')

server/account/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,14 @@ export async function createWorkspaceRecord (
835835
workspaceName: string,
836836
account: PersonUuid,
837837
region: string = '',
838-
initMode: WorkspaceMode = 'pending-creation'
838+
initMode: WorkspaceMode = 'pending-creation',
839+
dataId?: WorkspaceDataId
839840
): Promise<CreateWorkspaceRecordResult> {
840841
const brandingKey = branding?.key ?? 'huly'
841842
const regionInfo = getRegions().find((it) => it.region === region)
842843

843844
if (regionInfo === undefined) {
844-
ctx.error('Region not found', { region })
845+
ctx.error('Region not found', { region, regions: getRegions() })
845846

846847
throw new PlatformError(
847848
new Status(Severity.ERROR, platform.status.InternalServerError, {
@@ -871,6 +872,7 @@ export async function createWorkspaceRecord (
871872
{
872873
name: workspaceName,
873874
url: workspaceUrl,
875+
dataId,
874876
branding: brandingKey,
875877
createdBy: account,
876878
billingAccount: account,

server/backup/src/service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ class BackupWorker {
285285
const st = Date.now()
286286
rootCtx.warn('\n\nBACKUP WORKSPACE ', {
287287
workspace: ws.uuid,
288-
url: ws.url
288+
url: ws.url,
289+
dataId: ws.dataId
289290
})
290291
const ctx = rootCtx.newChild('doBackup', {})
291292
const dataId = ws.dataId ?? (ws.uuid as unknown as WorkspaceDataId)

0 commit comments

Comments
 (0)