Skip to content

Commit 02d89bc

Browse files
committed
Code and tests update
This commit actually implements the _getIsTransient and _pensieveLocationIsTransient methods in the CountWorker.js previously implemented on arsenal and only used by the CountWorker.js. Issue: S3UTILS-191
1 parent ef3f1ce commit 02d89bc

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

CountItems/CountWorker.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { BucketInfo } = require('arsenal').models;
44
const monitoring = require('../utils/monitoring');
55
const { deserializeBigInts, serializeBigInts } = require('./utils/utils');
66

7+
const PENSIEVE = 'PENSIEVE';
78
class CountWorker {
89
constructor(params) {
910
this.log = params.log;
@@ -27,6 +28,40 @@ class CountWorker {
2728
return this.client.setup(callback);
2829
}
2930

31+
getIsTransient(bucketInfo, cb) {
32+
const locConstraint = bucketInfo.getLocationConstraint();
33+
34+
if (this.client.isLocationTransient) {
35+
this.client.isLocationTransient(locConstraint, this.log, cb);
36+
return;
37+
}
38+
this.pensieveLocationIsTransient(locConstraint, cb);
39+
}
40+
41+
pensieveLocationIsTransient(locConstraint, cb) {
42+
const overlayVersionId = 'configuration/overlay-version';
43+
44+
async.waterfall([
45+
next => this.client.getObject(PENSIEVE, overlayVersionId, null, this.log, next),
46+
(version, next) => {
47+
const overlayConfigId = `configuration/overlay/${version}`;
48+
return this.client.getObject(PENSIEVE, overlayConfigId, null, this.log, next);
49+
},
50+
], (err, res) => {
51+
if (err) {
52+
this.log.error('error getting configuration overlay', {
53+
method: '_getIsTransient',
54+
error: err,
55+
});
56+
return cb(err);
57+
}
58+
const isTransient =
59+
Boolean(res.locations[locConstraint].isTransient);
60+
61+
return cb(null, isTransient);
62+
});
63+
}
64+
3065
countItems(bucketInfoObj, callback) {
3166
if (!this.client.client) {
3267
return callback(new Error('NotConnected'));
@@ -40,7 +75,7 @@ class CountWorker {
4075
const bucketName = bucketInfo.getName();
4176
this.log.info(`${process.pid} handling ${bucketName}`);
4277
return async.waterfall([
43-
next => this.client._getIsTransient(bucketInfo, this.log, next),
78+
next => this.getIsTransient(bucketInfo, next),
4479
(isTransient, next) => this.client.getObjectMDStats(bucketName, bucketInfo, isTransient, this.log, next),
4580
], (err, results) => {
4681
monitoring.bucketsCount.inc({ status: err ? 'error' : 'success' });

tests/mocks/mongoClient.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = {
44
},
55
setup: jest.fn(),
66
close: jest.fn(),
7-
_getIsTransient: jest.fn(),
87
getObjectMDStats: jest.fn(),
98
getBucketInfos: jest.fn(),
109
updateStorageConsumptionMetrics: jest.fn(),

tests/unit/CountItems/CountWorker.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ describe('CountItems::CountWorker', () => {
1010
mongoMock.close.mockReset();
1111
mongoMock.setup.mockReset();
1212
mongoMock.client.isConnected.mockReset();
13-
mongoMock._getIsTransient.mockReset();
1413
mongoMock.getObjectMDStats.mockReset();
1514
});
1615

@@ -22,7 +21,6 @@ describe('CountItems::CountWorker', () => {
2221
setup: [null],
2322
close: [],
2423
isConnected: false,
25-
getIsTransient: [],
2624
getObjectMDStats: [],
2725
},
2826
incomingMessage: {
@@ -47,7 +45,6 @@ describe('CountItems::CountWorker', () => {
4745
setup: [new Error('failed setup')],
4846
close: [],
4947
isConnected: false,
50-
getIsTransient: [],
5148
getObjectMDStats: [],
5249
},
5350
incomingMessage: {
@@ -98,7 +95,6 @@ describe('CountItems::CountWorker', () => {
9895
setup: [],
9996
close: [new Error('failed teardown')],
10097
isConnected: true,
101-
getIsTransient: [],
10298
getObjectMDStats: [],
10399
},
104100
incomingMessage: {
@@ -124,7 +120,6 @@ describe('CountItems::CountWorker', () => {
124120
setup: [],
125121
close: [],
126122
isConnected: true,
127-
getIsTransient: [null, true],
128123
getObjectMDStats: [null, { value: 42 }],
129124
},
130125
incomingMessage: {
@@ -151,7 +146,6 @@ describe('CountItems::CountWorker', () => {
151146
setup: [],
152147
close: [],
153148
isConnected: true,
154-
getIsTransient: [null, true],
155149
getObjectMDStats: [new Error('count error')],
156150
},
157151
incomingMessage: {
@@ -180,13 +174,11 @@ describe('CountItems::CountWorker', () => {
180174
sendFn: testSendFn,
181175
client: mongoMock,
182176
});
177+
w.getIsTransient = jest.fn((bucketInfo, cb) => cb(null, true));
183178
mongoMock.setup.mockImplementationOnce(cb => cb(...tc.mock.setup));
184179
mongoMock.close.mockImplementationOnce(cb => cb(...tc.mock.close));
185180
mongoMock.client.isConnected
186181
.mockImplementationOnce(() => tc.mock.isConnected);
187-
mongoMock._getIsTransient.mockImplementationOnce(
188-
(_a, _b, cb) => cb(...tc.mock.getIsTransient),
189-
);
190182
mongoMock.getObjectMDStats.mockImplementationOnce(
191183
(_a, _b, _c, _d, cb) => cb(...tc.mock.getObjectMDStats),
192184
);
@@ -213,10 +205,10 @@ describe('CountItems::CountWorker', () => {
213205
_creationDate: Date.now().toString(),
214206
website: { indexDocument: 'index.html' },
215207
};
208+
w.getIsTransient = jest.fn((bucketInfo, cb) => cb(null, true));
216209
mongoMock.setup.mockImplementationOnce(cb => cb());
217210
mongoMock.close.mockImplementationOnce(cb => cb());
218211
mongoMock.client.isConnected.mockImplementationOnce(() => false);
219-
mongoMock._getIsTransient.mockImplementationOnce((_a, _b, cb) => cb(null, true));
220212
mongoMock.getObjectMDStats.mockImplementationOnce((_a, _b, _c, _d, cb) => cb(null, { value: 42 }));
221213
w.countItems(bucketInfo, (err, results) => {
222214
expect(err).toBeNull();

0 commit comments

Comments
 (0)