Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createClient(connectionString, options) {
const zkClient = zookeeper.createClient(connectionString, options);
zkClient.once('connected', () => {
// for some reason zkClient.exists() does not return
// NO_NODE when base path does not exist, hence use
// getData() instead
zkClient.getData('/', err => {
if (err && err.name !== 'NO_NODE') {
return zkClient.emit('error', err);
}
// NO_NODE error and autoCreateNamespace is enabled
if (err && options && options.autoCreateNamespace) {
const nsIndex = connectionString.indexOf('/');
const hostPort = connectionString.slice(0, nsIndex);
const namespace = connectionString.slice(nsIndex);
const rootZkClient = zookeeper.createClient(hostPort, options);
rootZkClient.connect();
return rootZkClient.mkdirp(namespace, err => {
}, (next) => { // fn
count++;
logger.debug('%s server is try to connect to zookeeper',
mon.app.serverId);
mon.client.close();
mon.client = zookeeper.createClient(mon.servers, {
sessionTimeout: mon.timeout,
retries: 0,
spinDelay: mon.spinDelay
});
mon.cbTimer = setTimeout(() => {
logger.info('reconnect to zookeeper timeout');
mon.state = ZK_CONNECT_FAIL;
utils.invokeCallback(next);
}, constants.TIME.DEFAULT_ZK_CONNECT_TIMEOUT);
mon.client.once('connected', () => {
logger.info('%s connect zookeeper successfully.', mon.app.serverId);
mon.state = ZK_CONNECTED;
mon.client.addAuthInfo('digest', new Buffer(mon.authentication));
this.connectingString = connectingString;
this.options = options;
this.root = root || "/illyria";
this.prefix = prefix || "/t";
this.path = null;
this.root = this.root.trim();
this.prefix = this.prefix.trim();
if(!this.root.length) this.root = "/illyria";
if(this.root[0] !== "/") this.root = "/" + this.root;
if(!this.prefix.length) this.prefix = "/t";
if(this.prefix[0] !== "/") this.prefix = "/" + this.prefix;
// zookeeper core object
this.client = zookeeper.createClient(this.connectingString, options);
this.server = {
host: "127.0.0.1",
port: 3721,
clients: 0
};
this.clientStatus = ZK_STATUS.NOT_CONNECTED;
};
before(done => {
const zkClient = zookeeper.createClient('localhost:2181');
zkClient.connect();
zkClient.on('connected', () => {
zkClient.mkdirp(ZK_TEST_PATH, err => {
assert.ifError(err);
const prov = new ProvisionDispatcher(zkConf);
prov.addProvisions(provisionList, done);
});
});
});
afterEach(done => {
_setupZookeeper(done) {
const populatorZkPath = this.cluesoConfig.queuePopulator.zookeeperPath;
const zookeeperUrl =
`${this.zkConfig.connectionString}${populatorZkPath}`;
this.log.info('opening zookeeper connection for persisting ' +
'populator state',
{ zookeeperUrl });
this.zkClient = zookeeper.createClient(zookeeperUrl);
console.log("creating zookeeper client!!", this.zkClient);
this.zkClient.connect();
console.log("just called connect!!")
this._readLogOffset((err, offset) => {
console.log("in callback for read offset log", err, offset);
if (err) {
return done(err);
}
this.logOffset = offset;
return done();
});
}
initClient() {
this.client = zookeeper.createClient(this.registry, {
sessionTimeout: 30000,
spinDelay: 1000,
retries: 5
});
this.client.connect();
this.client.once("connected", this.onOnceConnected.bind(this));
this.checkConnection();
}
this.connectString = connectString;
this.options = options;
this.root = root || "/illyria";
this.prefix = prefix || "/HB_";
this.path = null;
this.root = this.root.trim();
this.prefix = this.prefix.trim();
if(!this.root.length) this.root = "/illyria";
if(!this.prefix.length) this.prefix = "/HB_";
if(this.root[0] !== "/") this.root = "/" + this.root;
if(this.prefix[0] !== "/") this.prefix = "/" + this.prefix;
this.client = zookeeper.createClient(this.connectString, options);
this.server = {
host: "127.0.0.1",
port: 3721,
clients: 0
};
this.clientStatus = ZK_STATUS.NOT_CONNECTED;
this._setup();
};
function ZD(conf) {
if (!(this instanceof ZD)) return new ZD(conf);
conf = conf || {};
this._dubbo = conf.dubbo;
this._conn = conf.conn;
this._client = this.client = zookeeper.createClient(this._conn, {
sessionTimeout: conf.sessionTimeout,
spinDelay: conf.spinDelay,
retries: conf.retries
});
this._cache = this.cache = {};
}
module.exports.createZookeeperClient = function(options) {
var zookeeper = require('node-zookeeper-client');
var addr = 'localhost:2181';
if (options.zookeeper) {
if (typeof options.zookeeper === 'string' || options.zookeeper instanceof String) {
addr = options.zookeeper;
} else {
if (options.zookeeper.address) addr = options.zookeeper.address;
}
}
var zkClient = zookeeper.createClient(addr, {
retries: 2
});
return zkClient;
};
module.exports.createRedisManager = function(options) {