Skip to content

Commit

Permalink
condition the mongoClient setup based on config
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Oct 18, 2024
1 parent 31d9ca6 commit bb1db7a
Showing 1 changed file with 62 additions and 46 deletions.
108 changes: 62 additions & 46 deletions lib/api/BackbeatAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,40 +1260,10 @@ class BackbeatAPI {
this._healthcheck = new Healthcheck(this._repConfig, this._zkClient,
this._crrProducer, this._crrStatusProducer,
this._metricProducer);
this._locationStatusManager = new LocationStatusManager(
this._mongoClient,
this._zkClient,
this._redisPublisher,
{
crr: {
namespace: zookeeperReplicationNamespace,
statePath: zkReplicationStatePath,
topic: this._crrTopic,
isMongo: false,
},
ingestion: {
namespace: zookeeperIngestionNamespace,
statePath: zkIngestionStatePath,
topic: this._ingestionTopic,
isMongo: false,
},
lifecycle: {
isMongo: true,
}
},
this._logger,
);
return this._locationStatusManager._setupLocationStatusStore(err => {
if (err) {
this._logger.error('error setting up location status manager', {
method: 'BackbeatAPI.setupInternals',
error: err.message,
});
return cb(err);
}
this._logger.info('BackbeatAPI setup ready');
return cb();
});
if (this._queuePopulator.mongo) {
return this._setupLocationStatusManager(cb);
}
return cb();
});
}

Expand Down Expand Up @@ -1336,26 +1306,72 @@ class BackbeatAPI {
*/
_setupMongoClient(cb) {
const mongoConfig = this._config.queuePopulator.mongo;
const mongoUrl = constructConnectionString(mongoConfig);
MongoClient.connect(mongoUrl, {
if (!mongoConfig) {
this._logger.debug('MongoDB configuration not found, skipping MongoDB client setup', {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
} else {
// To be removed once the mongodb drivers are bumped
// BB-585
const mongoUrl = constructConnectionString(mongoConfig);
return MongoClient.connect(mongoUrl, {
replicaSet: mongoConfig.replicaSet,
useNewUrlParser: true,
useUnifiedTopology: true,
}, (err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
}, (err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
error: err.message,
});
return cb(err);
}
// connect to metadata DB
this._mongoClient = client.db(mongoConfig.database, {
ignoreUndefined: true,
});
this._logger.info('Connected to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
});
}
}

_setupLocationStatusManager(cb) {
this._locationStatusManager = new LocationStatusManager(
this._mongoClient,
this._zkClient,
this._redisPublisher,
{
crr: {
namespace: zookeeperReplicationNamespace,
statePath: zkReplicationStatePath,
topic: this._crrTopic,
isMongo: false,
},
ingestion: {
namespace: zookeeperIngestionNamespace,
statePath: zkIngestionStatePath,
topic: this._ingestionTopic,
isMongo: false,
},
lifecycle: {
isMongo: true,
}
},
this._logger,
);

return this._locationStatusManager._setupLocationStatusStore(err => {
if (err) {
this._logger.error('error setting up location status manager', {
method: 'BackbeatAPI._setupLocationStatusManager',
error: err.message,
});
return cb(err);
}
// connect to metadata DB
this._mongoClient = client.db(mongoConfig.database, {
ignoreUndefined: true,
});
this._logger.info('Connected to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
});
}
Expand Down

0 comments on commit bb1db7a

Please sign in to comment.