Skip to content

Commit

Permalink
feature: Make the count items job configurable
Browse files Browse the repository at this point in the history
* Do not hardcode the 'metadata' database
* Authenticate to mongodb when needed
* Support locationConfig.json file instead of the PENSIEVE collection
  • Loading branch information
rachedbenmustapha committed Nov 19, 2019
1 parent e778af3 commit ade9559
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions countItems.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
const { MongoClientInterface } =
require('arsenal').storage.metadata.mongoclient;
const { Logger } = require('werelogs');
const fs = require('fs');

const log = new Logger('S3Utils::ScanItemCount');
const replicaSetHosts = process.env.MONGODB_REPLICASET;
const database = process.env.MONGODB_DATABASE || 'metadata';

const config = {
function getIsLocationTransientCb() {
const locationConfigFile = 'conf/locationConfig.json';
if (!fs.existsSync(locationConfigFile)) {
log.info('location conf file missing, falling back to PENSIEVE coll',
{ filename: locationConfigFile });
return null;
}

const buf = fs.readFileSync(locationConfigFile);
const locationConfig = JSON.parse(buf.toString());

return function locationIsTransient(locationName, log, cb) {
if (!locationConfig[locationName]) {
log.error('unknown location', { locationName });
process.nextTick(cb, null, false);
return;
}
const isTransient = Boolean(locationConfig[locationName].isTransient);
process.nextTick(cb, null, isTransient);
};
}

const params = {
replicaSetHosts,
database,
isLocationTransient: getIsLocationTransientCb(),
writeConcern: 'majority',
replicaSet: 'rs0',
readPreference: 'secondaryPreferred',
database: 'metadata',
replicationGroupId: 'RG001',
logger: log,
};

const mongoclient = new MongoClientInterface(config);
if (process.env.MONGODB_AUTH_USERNAME &&
process.env.MONGODB_AUTH_PASSWORD) {
params.authCredentials = {
username: process.env.MONGODB_AUTH_USERNAME,
password: process.env.MONGODB_AUTH_PASSWORD,
};
}

const mongoclient = new MongoClientInterface(params);

mongoclient.setup(err => {
if (err) {
log.error('error connecting to mongodb', {
Expand Down

0 comments on commit ade9559

Please sign in to comment.