Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this._zk.create(path, new Buffer(data), mode, (error, path) => {
if (error) {
if (error.getCode() === zookeeper.Exception.NODE_EXISTS ||
error.getCode() === zookeeper.Exception.OK) {
this.emit(utils.EVENT.DEBUG, 'Create or Exist path: ' + (path || this._root));
} else {
// other error
return reject(error);
}
}
return resolve(true);
});
});
this._zk.create(path, new Buffer(data), mode, (error, path) => {
if (error) {
if (error.getCode() === zookeeper.Exception.NODE_EXISTS ||
error.getCode() === zookeeper.Exception.OK) {
this.emit(utils.EVENT.DEBUG, 'Create or Exist path: ' + (path || this._root));
} else {
// other error
return reject(error);
}
}
return resolve(true);
});
});
function (error, children, stat) {
if (error) {
console.warn('Failed to list children due to: %s.', error);
if (error.getCode() == zookeeper.Exception.CONNECTION_LOSS) { // TODO 나중에 좀더 확인이 필요함!
self.zkClient.close();
self._connect(self.isWatching, function (err) {
if (err) console.error(err);
})
}
} else {
var max = children.length;
var nodeTask = function (taskId, value, callback) {
self._getServerNode(children[taskId], function () {
taskId++
if (taskId < max) {
function_array.splice(function_array.length - 1, 0, nodeTask);
self.client.getChildren(_path, function (error, children) {
var zoo, parsed;
if (error) {
if (error.getCode() === zookeeper.Exception.CONNECTION_LOSS) {
error(error);
}
return cb(error);
}
if (children && !children.length) {
return cb('can\'t find the zoo: ' + path + ' ,please check dubbo service!');
}
try {
for (var i = 0, l = children.length; i < l; i++) {
zoo = querystring.parse(decodeURIComponent(children[i]));
if (zoo.version === version) {
break;
}
}
// Get the first zoo
self.zkClient.getData(zkPath, null, function (error, data, stat) {
self.logger.debug("error before if:" + JSON.stringify(error));
if (error) {
self.logger.debug("error:" + JSON.stringify(error));
// Check if node doesn't exist yet
if (error.getCode() === zookeeper.Exception.NO_NODE) {
self.logger.debug("Node " + zkPath + " doesn't exist yet. Will be created on framework launch");
// Add event handler for the SUBSCRIBE event, to set the framework id to ZooKeeper
self.once("subscribed", function (obj) {
self.logger.debug("Got subscribed event");
self.logger.debug("now creating path " + zkPath);
// Seperating path creation from data save due to various client bugs.
self.zkClient.mkdirp(zkPath, function (error, stat) {
if (error) {
self.logger.error("Got error when creating a ZK node for the framework ID: " + error.stack);
self.options.useZk = false;
this._zookeeper.getData(zkPath, (err, offsetData, offsetStat) => {
if (err) {
if (err.getCode() === zookeeper.Exception.NO_NODE) {
this._log.debug(
'requested kafka offset node does not exist', {
topic, partition, offsetType, label,
});
return cb(NoNodeError);
}
this._log.error(
'error reading kafka offset from zookeeper', {
topic, partition, offsetType, label,
error: err.message,
});
return cb(errors.InternalError);
}
const mtime = readUInt64BE(offsetStat.mtime);
const lastModAgeMs = Date.now() - mtime;
// if mtime of a consumer or topic node is older than
this._zkClient.getChildren(partitionsZkPath, (err, partitions) => {
if (err) {
if (err.getCode() === zookeeper.Exception.NO_NODE) {
// no consumer has yet published his offset
return done();
}
this.logger.error(
'error getting list of consumer offsets from zookeeper',
{ topic, error: err.message });
return done(err);
}
return async.eachSeries(partitions, (partition, partitionDone) => {
let consumerOffset;
let topicOffset;
async.waterfall([
next => this._readZkOffset(topic, partition,
'consumer', groupId, next),
(offset, next) => {
consumerOffset = offset;
function (error) {
if (error) {
if (error.getCode() == zookeeper.Exception.NODE_EXISTS) {
if (callback) callback(null, constants.BASE_ZNODE_PATH + nodePath, data);
} else {
console.error('Failed to create node: %s due to: %s.', constants.BASE_ZNODE_PATH + nodePath, error.getName());
if (callback) callback(error);
}
} else {
if (callback) callback(null, constants.BASE_ZNODE_PATH + nodePath, data);
}
}
);
(zkPath, done) => this._client.create(zkPath, err => {
if (err &&
err.getCode() !== zookeeper.Exception.NODE_EXISTS) {
this._log.error('error adding provision node',
{ zkPath: `${this._zkEndpoint}${zkPath}`,
error: err });
return done(err);
}
this._log.debug('added new provision zk node',
{ zkPath: `${this._zkEndpoint}${zkPath}` });
return done();
}), cb);
}
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;