Skip to content

Commit

Permalink
condition the mongoClient setup based on config
Browse files Browse the repository at this point in the history
Issue: BB-541
  • Loading branch information
benzekrimaha committed Oct 10, 2024
1 parent 5cbb606 commit 3f33f4c
Showing 1 changed file with 63 additions and 46 deletions.
109 changes: 63 additions & 46 deletions lib/api/BackbeatAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,40 +1260,12 @@ 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');
if (this._config.queuePopulator.mongo) {
return this._setupLocationStatusManager(cb);
} else {
this._logger.debug('BackbeatAPI setup ready without Mongo');
return cb();
});
}
});
}

Expand Down Expand Up @@ -1335,28 +1307,73 @@ class BackbeatAPI {
* @returns {undefined} undefined
*/
_setupMongoClient(cb) {
const mongoConfig = this._config.queuePopulator.mongo;
const mongoUrl = constructConnectionString(mongoConfig);
MongoClient.connect(mongoUrl, {
if (this._config.queuePopulator.mongo) {
const mongoConfig = this._config.queuePopulator.mongo;
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',
error: err.message,
});
return cb(err);
}
// connect to metadata DB
this._mongoClient = client.db(mongoConfig.database, {
ignoreUndefined: true,
return cb();
});
this._logger.info('Connected to MongoDB', {
} else {
this._logger.debug('MongoDB configuration not found, skipping MongoDB client setup', {
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.setupInternals',
error: err.message,
});
return cb(err);
}
this._logger.info('BackbeatAPI setup ready');
return cb();
});
}
}
Expand Down

0 comments on commit 3f33f4c

Please sign in to comment.