Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((found)=>{
if(found) {
return Promise.resolve();
}
else {
return zkUtil.createP(zk, zkUtil.NODE_CLIENT, null, ZooKeeper.CreateMode.PERSISTENT, 'Failed to create clients node due to');
}
})
.then(()=>{ // create client node
private async _createRootConsumer(consumer: string) {
let {res, err} = await go(this._exists(consumer));
//check error
if (err) {
return err;
}
// current consumer root path was existed.
if (res) {
return null;
}
//create current consumer path
({err} = await go(this._create(consumer, zookeeper.CreateMode.PERSISTENT)));
if (err) {
return err;
}
log('create root comsumer %s successfull', consumer);
}
* manage zookeeper client
*
* @author zzxun
*/
'use strict';
/**
* module dependencies
*/
const _ = require('lodash');
const zookeeper = require('node-zookeeper-client');
const Promises = require('bluebird');
const EventEmitter = require('events').EventEmitter;
const utils = require('./util');
const CreateMode = zookeeper.CreateMode;
class ZookeeperService extends EventEmitter {
constructor(options) {
super();
let self = this;
self._root = options.root;
// initial
options = _.merge({
connect : '127.0.0.1:2181',
sessionTimeout: 200000
}, options);
self._zk = zookeeper.createClient(options.connect, options);
var createConsumer = function() {
var url = 'consumer://' + ip.address() + '/' + provider + '?' + qs.stringify(params);
this._client.create(
consumers + '/' + qs.escape(url), new Buffer(''),
zookeeper.CreateMode.EPHEMERAL,
function (err, path) {
//console.log(err, path);
});
}.bind(this);
self._zk.exists(path, function (err, stat) {
if (!err && !stat) {
log.info('persistent node does need to create. path: %s', path);
self._zk.mkdirp(
path,
new Buffer(data),
zookeeper.CreateMode.PERSISTENT,
callback
);
} else {
callback(err, path);
}
});
return this;
'use strict';
const zookeeper = require('node-zookeeper-client');
const ZookeeperClient = require('./api_client');
exports.createClient = (connectionString, options) => {
options = options || {};
options.connectionString = connectionString || 'localhost:2181';
return new ZookeeperClient(options);
};
exports.ACL = zookeeper.ACL;
exports.Id = zookeeper.Id;
exports.Permission = zookeeper.Permission;
exports.CreateMode = zookeeper.CreateMode;
exports.State = zookeeper.State;
exports.Event = zookeeper.Event;
exports.Exception = zookeeper.Exception;
function (callback) {
that.client.create(path + '/ids/' + consumerId, null, null, zookeeper.CreateMode.EPHEMERAL, function (
error,
path
) {
if (error) {
callback(error);
} else {
callback();
}
});
},
function (callback) {
(function() {
var Enum = require("enum");
var EventEmitter = require("events").EventEmitter;
var util = require("util");
var async = require("async");
var zookeeper = require("node-zookeeper-client");
var helper = require("./helper");
var CREATE_MODE = zookeeper.CreateMode;
var ZK_STATUS = new Enum([
"NOT_CONNECTED",
"CONNECTING",
"CONNECTED"
]);
/**
* illyria zookeeper wrapper
* @param {String|Array} connectString the connect string(s)
* @param {Object} options the connect options, refer to
* https://github.com/alexguan/node-zookeeper-client
* #client-createclientconnectionstring-options
* @param {String} [root] the root path
* @param {String} [prefix] the path's prefix
* @constructor
*/
() => this._client.create(
zkPath, null, zookeeper.ACL.OPEN_ACL_UNSAFE,
zookeeper.CreateMode.EPHEMERAL,
err => {
if (err) {
return cb(err);
}
this._log.debug('registered owner zk node',
{ zkPath: `${this._zkEndpoint}${zkPath}` });
return cb(null, zkPath);
})
);
zkUtil.existsP(self.zk, zkUtil.NODE_ROOT, 'Failed to find NODE_ROOT due to').then((found)=>{
if(found) {
return Promise.resolve();
}
else {
return zkUtil.createP(self.zk, zkUtil.NODE_ROOT, null, ZooKeeper.CreateMode.PERSISTENT, 'Failed to create NODE_ROOT due to');
}
}).then(()=>{
return zkUtil.existsP(self.zk, zkUtil.NODE_CLIENT, 'Failed to find clients node due to');