How to use the node-zookeeper-client.Exception function in node-zookeeper-client

To help you get started, we’ve selected a few node-zookeeper-client 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 MZMonster / node-thrift-service / lib / zookeeper.js View on Github external
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);
      });
    });
github MZMonster / node-thrift-service / lib / zookeeper.js View on Github external
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);
      });
    });
github xpush / node-xpush / lib / node-manager / node-manager.js View on Github external
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);
github Corey600 / zoodubbo / lib / registry.js View on Github external
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
github tobilg / mesos-framework / lib / scheduler.js View on Github external
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;
github scality / backbeat / lib / KafkaBacklogMetrics.js View on Github external
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
github scality / backbeat / extensions / lifecycle / conductor / LifecycleConductor.js View on Github external
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;
github xpush / node-xpush / lib / node-manager / node-manager.js View on Github external
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);
      }
    }
  );
github scality / backbeat / lib / provisioning / ProvisionDispatcher.js View on Github external
(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);
    }
github node-modules / zookeeper-cluster-client / lib / index.js View on Github external
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;