From 0454fa80bd2ad8e3494b1e43969911ce6d3a51f1 Mon Sep 17 00:00:00 2001 From: Daniel Reus Date: Sun, 13 Dec 2020 05:03:57 +0100 Subject: [PATCH 1/2] Support for creating container nodes --- index.js | 4 +++- lib/ConnectionManager.js | 1 + lib/CreateMode.js | 8 +++++++- lib/Transaction.js | 6 +++++- lib/jute/index.js | 3 +++ package-lock.json | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2eb12ac..7c8c418 100644 --- a/index.js +++ b/index.js @@ -391,7 +391,9 @@ Client.prototype.create = function (path, data, acls, mode, callback) { assert(acls.length > 0, 'acls must be a non-empty array.'); header = new jute.protocol.RequestHeader(); - header.type = jute.OP_CODES.CREATE; + header.type = mode === CreateMode.CONTAINER ? + jute.OP_CODES.CREATE_CONTAINER : + jute.OP_CODES.CREATE; payload = new jute.protocol.CreateRequest(); payload.path = path; diff --git a/lib/ConnectionManager.js b/lib/ConnectionManager.js index f402243..51ab57e 100644 --- a/lib/ConnectionManager.js +++ b/lib/ConnectionManager.js @@ -512,6 +512,7 @@ ConnectionManager.prototype.onSocketData = function (buffer) { if (responseHeader.err === 0) { switch (pendingPacket.request.header.type) { case jute.OP_CODES.CREATE: + case jute.OP_CODES.CREATE_CONTAINER: responsePayload = new jute.protocol.CreateResponse(); break; case jute.OP_CODES.DELETE: diff --git a/lib/CreateMode.js b/lib/CreateMode.js index a5e0fe2..e95945a 100644 --- a/lib/CreateMode.js +++ b/lib/CreateMode.js @@ -27,7 +27,13 @@ var CREATE_MODES = { * The znode will be deleted upon the client's disconnect, and its name * will be appended with a monotonically increasing number. */ - EPHEMERAL_SEQUENTIAL : 3 + EPHEMERAL_SEQUENTIAL : 3, + + /** + * The znode will be deleted when it has been without any children for + * some time. + */ + CONTAINER : 4, }; module.exports = CREATE_MODES; diff --git a/lib/Transaction.js b/lib/Transaction.js index cdad9c2..1b8c58d 100644 --- a/lib/Transaction.js +++ b/lib/Transaction.js @@ -76,8 +76,12 @@ Transaction.prototype.create = function (path, data, acls, mode) { assert(acls.length > 0, 'acls must be a non-empty array.'); + var type = mode === CreateMode.CONTAINER ? + jute.OP_CODES.CREATE_CONTAINER : + jute.OP_CODES.CREATE; + this.ops.push({ - type : jute.OP_CODES.CREATE, + type : type, path : path, data : data, acls : acls, diff --git a/lib/jute/index.js b/lib/jute/index.js index 99e6216..00738a7 100644 --- a/lib/jute/index.js +++ b/lib/jute/index.js @@ -36,6 +36,7 @@ var OP_CODES = { GET_CHILDREN2 : 12, CHECK : 13, MULTI : 14, + CREATE_CONTAINER: 19, AUTH : 100, SET_WATCHES : 101, SASL : 102, @@ -504,6 +505,7 @@ function TransactionRequest(ops) { switch (op.type) { case jute.OP_CODES.CREATE: + case jute.OP_CODES.CREATE_CONTAINER: record = new jute.protocol.CreateRequest(); record.path = op.path; record.data = op.data; @@ -621,6 +623,7 @@ TransactionResponse.prototype.deserialize = function (buffer, offset) { switch (header.type) { case jute.OP_CODES.CREATE: + case jute.OP_CODES.CREATE_CONTAINER: response = new jute.protocol.CreateResponse(); response.setChrootPath(self.chrootPath); bytesRead += response.deserialize(buffer, offset + bytesRead); diff --git a/package-lock.json b/package-lock.json index e2d8053..fc8f1a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-zookeeper-client", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { From 9fbd3f535dc787776892bef30b08634a046a5b02 Mon Sep 17 00:00:00 2001 From: Daniel Reus Date: Sun, 13 Dec 2020 05:13:57 +0100 Subject: [PATCH 2/2] Up version and add changelog item --- CHANGELOG.md | 3 +++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459bcf4..022e990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 1.2.0 +1. [New: Support for container nodes](https://github.com/alexguan/node-zookeeper-client/pull/107) + ## 1.1.0 1. [New: Add removeRecursive and listSubTreeBFS methods](https://github.com/alexguan/node-zookeeper-client/pull/88) diff --git a/package-lock.json b/package-lock.json index fc8f1a7..f388e03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-zookeeper-client", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 23875a9..67e4f36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-zookeeper-client", - "version": "1.1.0", + "version": "1.2.0", "description": "A pure Javascript ZooKeeper client for Node.js.", "author": "Alex Guan ", "license": "MIT",