MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / setLocalDc

Function setLocalDc

lib/policies/load-balancing.js:843–870  ·  view source on GitHub ↗

* Validates and sets the local data center to be used. * @param {LoadBalancingPolicy} lbp * @param {Client} client * @param {HostMap} hosts * @private

(lbp, client, hosts)

Source from the content-addressed store, hash-verified

841 * @private
842 */
843function setLocalDc(lbp, client, hosts) {
844 if (!(lbp instanceof LoadBalancingPolicy)) {
845 throw new errors.DriverInternalError('LoadBalancingPolicy instance was not provided');
846 }
847
848 if (client && client.options) {
849 if (lbp.localDc && !client.options.localDataCenter) {
850 client.log('info', `Local data center '${lbp.localDc}' was provided as an argument to the load-balancing` +
851 ` policy. It is preferable to specify the local data center using 'localDataCenter' in Client` +
852 ` options instead when your application is targeting a single data center.`);
853 }
854
855 // If localDc is unset, use value set in client options.
856 lbp.localDc = lbp.localDc || client.options.localDataCenter;
857 }
858
859 const dcs = getDataCenters(hosts);
860
861 if (!lbp.localDc) {
862 throw new errors.ArgumentError(
863 `'localDataCenter' is not defined in Client options and also was not specified in constructor.` +
864 ` At least one is required. Available DCs are: [${Array.from(dcs)}]`);
865 }
866
867 if (!dcs.has(lbp.localDc)) {
868 throw new errors.ArgumentError(`Datacenter ${lbp.localDc} was not found. Available DCs are: [${Array.from(dcs)}]`);
869 }
870}
871
872function getDataCenters(hosts) {
873 return new Set(hosts.values().map(h => h.datacenter));

Callers 2

load-balancing.jsFile · 0.85
initMethod · 0.85

Calls 2

getDataCentersFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected