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

Full mode #201

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions app/src/controllers/sync.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { NIL: SYSTEM_USER } = require('uuid');

const errorToProblem = require('../components/errorToProblem');
const { addDashesToUuid, getCurrentIdentity, isTruthy } = require('../components/utils');
const { addDashesToUuid, getCurrentIdentity } = require('../components/utils');
const { objectService, storageService, objectQueueService, userService } = require('../services');

const SERVICE = 'ObjectQueueService';
Expand Down Expand Up @@ -37,7 +37,7 @@ const controller = {
...s3Response.Versions.map(object => object.Key)
])].map(path => ({ path: path, bucketId: bucketId }));

const response = await objectQueueService.enqueue({ jobs: jobs, full: isTruthy(req.query.full), createdBy: userId });
const response = await objectQueueService.enqueue({ jobs: jobs, createdBy: userId });
res.status(202).json(response);
} catch (e) {
next(errorToProblem(SERVICE, e));
Expand All @@ -60,7 +60,6 @@ const controller = {

const response = await objectQueueService.enqueue({
jobs: [{ path: path, bucketId: bucketId }],
full: isTruthy(req.query.full),
createdBy: userId
});
res.status(202).json(response);
Expand Down
14 changes: 0 additions & 14 deletions app/src/docs/v1.api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ paths:
operationId: syncBucket
parameters:
- $ref: "#/components/parameters/Path-BucketId"
- $ref: "#/components/parameters/Query-Full"
responses:
"202":
$ref: "#/components/responses/AddedQueueLength"
Expand Down Expand Up @@ -809,7 +808,6 @@ paths:
operationId: syncObject
parameters:
- $ref: "#/components/parameters/Path-ObjectId"
- $ref: "#/components/parameters/Query-Full"
responses:
"202":
description: Returns the number of objects that have been added to the queue.
Expand Down Expand Up @@ -1260,8 +1258,6 @@ paths:
operationId: syncDefault
tags:
- Sync
parameters:
- $ref: "#/components/parameters/Query-Full"
responses:
"202":
$ref: "#/components/responses/AddedQueueLength"
Expand Down Expand Up @@ -1625,16 +1621,6 @@ components:
type: string
format: uuid
example: 48a65990-2e48-46b2-94eb-7f4fe13468ea
Query-Full:
in: query
name: full
description: >-
Boolean on whether to force-synchronize all versions, metadata, and
tags, as opposed to only synchronizing those that have since been
updated externally.
schema:
type: boolean
example: true
Query-DeleteMarker:
in: query
name: deleteMarker
Expand Down
3 changes: 1 addition & 2 deletions app/src/routes/v1/sync.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const router = require('express').Router();

const { syncController } = require('../../controllers');
const { syncValidator } = require('../../validators');
const { checkAppMode } = require('../../middleware/authorization');
const { requireBasicAuth, requireSomeAuth } = require('../../middleware/featureToggle');

router.use(checkAppMode);
router.use(requireSomeAuth);

/** Synchronizes the default bucket */
router.get('/', requireBasicAuth, syncValidator.syncDefault, (req, res, next) => {
router.get('/', requireBasicAuth, (req, res, next) => {
req.params.bucketId = null;
syncController.syncBucket(req, res, next);
});
Expand Down
17 changes: 10 additions & 7 deletions app/src/services/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,26 @@ const service = {

return await utils.trxWrapper(async (trx) => {
// 1. Sync Object
const { modified: modifiedObject, object } = await service.syncObject(path, bucketId, userId, trx);
const object = await service.syncObject(path, bucketId, userId, trx)
.then(obj => obj.object);

// 2. Sync Object Versions
let versions = [];
if (modifiedObject || full && object) {
if (object) {
versions = await service.syncVersions(object, userId, trx);
}

// 3. Sync Version Metadata & Tags
for (const v of versions) {
// Only Update Metadata and Tags if version has modifications or full mode
const tasks = [ // Always Update Tags regardless of modification state
service.syncTags(v.version, path, bucketId, userId, trx)
];
// Only Update Metadata if version has modifications or full mode
if (v.modified || full) {
await Promise.all([
service.syncTags(v.version, path, bucketId, userId, trx),
service.syncMetadata(v.version, path, bucketId, userId, trx)
]);
tasks.push(service.syncMetadata(v.version, path, bucketId, userId, trx));
}

await Promise.all(tasks);
}

return Promise.resolve(object?.id);
Expand Down
3 changes: 0 additions & 3 deletions app/src/validators/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ const schema = {
syncBucket: {
params: Joi.object({
bucketId: type.uuidv4.required()
}),
query: Joi.object({
full: type.truthy
})
},

Expand Down
1 change: 0 additions & 1 deletion app/src/validators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = {
metadataValidator: require('./metadata'),
objectValidator: require('./object'),
objectPermissionValidator: require('./objectPermission'),
syncValidator: require('./sync'),
tagValidator: require('./tag'),
userValidator: require('./user'),
versionValidator: require('./version'),
Expand Down
3 changes: 0 additions & 3 deletions app/src/validators/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ const schema = {
syncObject: {
params: Joi.object({
objectId: type.uuidv4.required()
}),
query: Joi.object({
full: type.truthy
})
},

Expand Down
18 changes: 0 additions & 18 deletions app/src/validators/sync.js

This file was deleted.

6 changes: 4 additions & 2 deletions app/tests/unit/services/metadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ describe('fetchMetadataForObject', () => {
});

describe('fetchMetadataForVersion', () => {
it('Fetch metadata for specific versions', () => {
it('Fetch metadata for specific versions', async () => {
Version.then.mockResolvedValue([
{
...metadata,
map: jest.fn()
}
]);

service.fetchMetadataForVersion(params);
await service.fetchMetadataForVersion(params);

expect(Metadata.startTransaction).toHaveBeenCalledTimes(1);
expect(Version.query).toHaveBeenCalledTimes(1);
expect(Version.select).toHaveBeenCalledTimes(1);
expect(Version.select).toHaveBeenCalledWith('version.id as versionId', 'version.s3VersionId');
Expand All @@ -217,6 +218,7 @@ describe('fetchMetadataForVersion', () => {
expect(Version.orderBy).toHaveBeenCalledTimes(1);
expect(Version.orderBy).toHaveBeenCalledWith('version.createdAt', 'desc');
expect(Version.then).toHaveBeenCalledTimes(1);
expect(metadataTrx.commit).toHaveBeenCalledTimes(1);
});
});

Expand Down
14 changes: 10 additions & 4 deletions app/tests/unit/services/object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('getBucketKey', () => {
});

describe('searchObjects', () => {
it('Search and filter for specific object records', () => {
it('Search and filter for specific object records', async () => {
ObjectModel.then.mockImplementation(() => { });
const params = {
bucketId: BUCKET_ID,
Expand All @@ -113,9 +113,11 @@ describe('searchObjects', () => {
userId: SYSTEM_USER
};

service.searchObjects(params);
await service.searchObjects(params);

expect(ObjectModel.startTransaction).toHaveBeenCalledTimes(1);
expect(ObjectModel.query).toHaveBeenCalledTimes(1);
expect(ObjectModel.query).toHaveBeenCalledWith(expect.anything());
expect(ObjectModel.allowGraph).toHaveBeenCalledTimes(1);
expect(ObjectModel.modify).toHaveBeenCalledTimes(11);
expect(ObjectModel.modify).toHaveBeenNthCalledWith(1, 'filterIds', params.id);
Expand All @@ -133,18 +135,22 @@ describe('searchObjects', () => {
});
expect(ObjectModel.modify).toHaveBeenNthCalledWith(11, 'hasPermission', params.userId, 'READ');
expect(ObjectModel.then).toHaveBeenCalledTimes(1);
expect(objectModelTrx.commit).toHaveBeenCalledTimes(1);
});
});

describe('read', () => {
it('Get an object db record', () => {
service.read(SYSTEM_USER);
it('Get an object db record', async () => {
await service.read(SYSTEM_USER);

expect(ObjectModel.startTransaction).toHaveBeenCalledTimes(1);
expect(ObjectModel.query).toHaveBeenCalledTimes(1);
expect(ObjectModel.query).toHaveBeenCalledWith(expect.anything());
expect(ObjectModel.findById).toHaveBeenCalledTimes(1);
expect(ObjectModel.findById).toBeCalledWith(OBJECT_ID);
expect(ObjectModel.throwIfNotFound).toHaveBeenCalledTimes(1);
expect(ObjectModel.throwIfNotFound).toBeCalledWith();
expect(objectModelTrx.commit).toHaveBeenCalledTimes(1);
});
});

Expand Down
4 changes: 3 additions & 1 deletion app/tests/unit/services/tag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ describe('fetchTagsForVersion', () => {
}
]);

service.fetchTagsForVersion(params);
await service.fetchTagsForVersion(params);

expect(Tag.startTransaction).toHaveBeenCalledTimes(1);
expect(Version.query).toHaveBeenCalledTimes(1);
expect(Version.select).toHaveBeenCalledTimes(1);
expect(Version.select).toBeCalledWith('version.id as versionId', 'version.s3VersionId');
Expand All @@ -287,6 +288,7 @@ describe('fetchTagsForVersion', () => {
expect(Version.orderBy).toHaveBeenCalledTimes(1);
expect(Version.orderBy).toBeCalledWith('version.createdAt', 'desc');
expect(Version.then).toHaveBeenCalledTimes(1);
expect(tagTrx.commit).toHaveBeenCalledTimes(1);
});
});

Expand Down
5 changes: 4 additions & 1 deletion app/tests/unit/services/version.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jest.mock('../../../src/db/models/tables/version', () => ({
delete: jest.fn(),
first: jest.fn(),
insert: jest.fn(),
modify: jest.fn(),
orderBy: jest.fn(),
patch: jest.fn(),
query: jest.fn(),
Expand Down Expand Up @@ -174,7 +175,9 @@ describe('list', () => {
expect(Version.startTransaction).toHaveBeenCalledTimes(1);
expect(Version.query).toHaveBeenCalledTimes(1);
expect(Version.query).toHaveBeenCalledWith(expect.anything());
expect(Version.where).toHaveBeenCalledWith({ objectId: 'abc' });
expect(Version.modify).toHaveBeenCalledTimes(1);
expect(Version.modify).toHaveBeenCalledWith('filterObjectId', 'abc');
expect(Version.orderBy).toHaveBeenCalledTimes(1);
expect(Version.orderBy).toHaveBeenCalledWith('createdAt', 'DESC');
});
});
Expand Down
13 changes: 0 additions & 13 deletions app/tests/unit/validators/bucket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,6 @@ describe('syncBucket', () => {
});
});
});

describe('query', () => {
const query = schema.syncBucket.query.describe();

describe('full', () => {
const full = query.keys.full;

it('is the expected schema', () => {
expect(full).toEqual(type.truthy.describe());
});
});
});

});

describe('updateBucket', () => {
Expand Down
13 changes: 0 additions & 13 deletions app/tests/unit/validators/object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,6 @@ describe('syncObject', () => {
});
});
});

describe('query', () => {
const query = schema.syncObject.query.describe();

describe('full', () => {
const full = query.keys.full;

it('is the expected schema', () => {
expect(full).toEqual(type.truthy.describe());
});
});
});

});

describe('togglePublic', () => {
Expand Down
38 changes: 0 additions & 38 deletions app/tests/unit/validators/sync.spec.js

This file was deleted.

2 changes: 1 addition & 1 deletion k6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ The simple test scripts (for example: [createObject.js](createObject.js) can be

### Command example

`k6 run -e BUCKET_ID=41046be7-43d8-486f-a97e-ee360043d454 -e API_PATH=http://localhost:3000/api/v1 -e AUTH_TOKEN=dXNlcjE6cGFzczE= -e FILE_PATH=./file.txt --vus=1 --iterations=1 createObject.js`
`k6 run -e BUCKET_ID=95fc01c4-c900-4fe6-b5af-b39bfd047036 -e API_PATH=http://localhost:3000/api/v1 -e AUTH_TOKEN=dXNlcjE6cGFzczE= -e FILE_PATH=./test.txt --vus=1 --iterations=10 createObject.js`
Loading