How to use the cassandra-driver.policies function in cassandra-driver

To help you get started, we’ve selected a few cassandra-driver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wikimedia / restbase-mod-table-cassandra / lib / index.js View on Github external
'use strict';

const P = require('bluebird');
const cass = require('cassandra-driver');
const fs = require('fs');
const loadBalancing = cass.policies.loadBalancing;
const reconnection = cass.policies.reconnection;
const DB = require('./db');

function validateAndNormalizeDcConf(conf) {
    // Default to 'datacenter1'
    conf.localDc = conf.localDc || 'datacenter1';
    conf.datacenters = conf.datacenters || ['datacenter1'];
    if (!(conf.datacenters instanceof Array)) {
        throw new Error('invalid datacenters configuration (not an array)');
    }
    if (conf.datacenters.indexOf(conf.localDc) < 0) {
        throw new Error('localDc not in configured datacenters');
    }
}

// sync
github godaddy / node-priam / test / unit / driver.basic.tests.js View on Github external
driver.connect('myKeyspace', () => {
        const dsOptions = cql.Client.lastCall.args[0];
        expect(dsOptions.policies).to.be.an('object');
        expect(dsOptions.policies.loadBalancing)
          .to.be.instanceOf(cql.policies.loadBalancing.TokenAwarePolicy);
        expect(dsOptions.policies.loadBalancing.childPolicy)
          .to.be.instanceOf(cql.policies.loadBalancing.DCAwareRoundRobinPolicy);
        expect(dsOptions.policies.loadBalancing.childPolicy.localDc)
          .to.equal('some_dc');
        done();
      });
    });
github godaddy / node-priam / test / unit / driver.basic.tests.js View on Github external
driver.connect('myKeyspace', () => {
        const dsOptions = cql.Client.lastCall.args[0];
        expect(dsOptions.policies).to.be.an('object');
        expect(dsOptions.policies.loadBalancing)
          .to.be.instanceOf(cql.policies.loadBalancing.TokenAwarePolicy);
        expect(dsOptions.policies.loadBalancing.childPolicy)
          .to.be.instanceOf(cql.policies.loadBalancing.DCAwareRoundRobinPolicy);
        expect(dsOptions.policies.loadBalancing.childPolicy.localDc)
          .to.equal('some_dc');
        done();
      });
    });
github oaeproject / Hilary / packages / oae-util / lib / cassandra.js View on Github external
const _createNewClient = function(hosts, keyspace) {
  const loadBalancingPolicy = new cassandra.policies.loadBalancing.RoundRobinPolicy();
  const reconnectionPolicy = new cassandra.policies.reconnection.ConstantReconnectionPolicy(CONFIG.timeout);
  return new cassandra.Client({
    contactPoints: hosts,
    policies: {
      timestampGeneration: null,
      loadBalancing: loadBalancingPolicy,
      reconnection: reconnectionPolicy
    },
    keyspace,
    protocolOptions: { maxVersion: 3 },
    socketOptions: {
      connectTimeout: CONFIG.timeout,
      readTimeout: CONFIG.timeout
    },
    consistency: cassandra.types.consistencies.quorum
  });
github oaeproject / Hilary / node_modules / oae-util / lib / cassandra.js View on Github external
const _createNewClient = function(hosts, keyspace) {
  const loadBalancingPolicy = new cassandra.policies.loadBalancing.RoundRobinPolicy();
  const reconnectionPolicy = new cassandra.policies.reconnection.ConstantReconnectionPolicy(
    CONFIG.timeout
  );
  return new cassandra.Client({
    contactPoints: hosts,
    policies: {
      timestampGeneration: null,
      loadBalancing: loadBalancingPolicy,
      reconnection: reconnectionPolicy
    },
    keyspace,
    protocolOptions: { maxVersion: 3 },
    socketOptions: {
      connectTimeout: CONFIG.timeout
    },
    consistency: cassandra.types.consistencies.quorum
github godaddy / node-priam / lib / driver.js View on Github external
};

    if (typeof this.config.consistency === 'string') {
      const level = this.config.consistency;

      if (typeof this.consistencyLevel[level] !== 'undefined') {
        this.poolConfig.consistencyLevel = this.consistencyLevel[level];
      } else {
        throw new Error(`Error: "${level}" is not a valid consistency level`);
      }
    }

    if (typeof this.config.localDataCenter === 'string') {
      this.poolConfig.policies = this.poolConfig.policies || {};
      if (!this.poolConfig.policies.loadBalancing) {
        this.poolConfig.policies.loadBalancing = new cqlDriver.policies.loadBalancing.TokenAwarePolicy(
          new cqlDriver.policies.loadBalancing.DCAwareRoundRobinPolicy(this.config.localDataCenter)
        );
      }
    }
  }
github oaeproject / Hilary / packages / oae-util / lib / cassandra.js View on Github external
const _createNewClient = function(hosts, keyspace) {
  const loadBalancingPolicy = new cassandra.policies.loadBalancing.RoundRobinPolicy();
  const reconnectionPolicy = new cassandra.policies.reconnection.ConstantReconnectionPolicy(CONFIG.timeout);
  return new cassandra.Client({
    contactPoints: hosts,
    policies: {
      timestampGeneration: null,
      loadBalancing: loadBalancingPolicy,
      reconnection: reconnectionPolicy
    },
    keyspace,
    protocolOptions: { maxVersion: 3 },
    socketOptions: {
      connectTimeout: CONFIG.timeout,
      readTimeout: CONFIG.timeout
    },
    consistency: cassandra.types.consistencies.quorum
  });
};
github godaddy / node-priam / lib / driver.js View on Github external
if (typeof this.config.consistency === 'string') {
      const level = this.config.consistency;

      if (typeof this.consistencyLevel[level] !== 'undefined') {
        this.poolConfig.consistencyLevel = this.consistencyLevel[level];
      } else {
        throw new Error(`Error: "${level}" is not a valid consistency level`);
      }
    }

    if (typeof this.config.localDataCenter === 'string') {
      this.poolConfig.policies = this.poolConfig.policies || {};
      if (!this.poolConfig.policies.loadBalancing) {
        this.poolConfig.policies.loadBalancing = new cqlDriver.policies.loadBalancing.TokenAwarePolicy(
          new cqlDriver.policies.loadBalancing.DCAwareRoundRobinPolicy(this.config.localDataCenter)
        );
      }
    }
  }