From commits-return-7687-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Tue Mar 19 00:12:36 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id EFEF5180651 for ; Tue, 19 Mar 2019 01:12:35 +0100 (CET) Received: (qmail 25164 invoked by uid 500); 19 Mar 2019 00:12:35 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 25152 invoked by uid 99); 19 Mar 2019 00:12:35 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Mar 2019 00:12:35 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6B3C882F24; Tue, 19 Mar 2019 00:12:34 +0000 (UTC) Date: Tue, 19 Mar 2019 00:12:34 +0000 To: "commits@zookeeper.apache.org" Subject: [zookeeper] branch branch-3.5 updated: ZOOKEEPER-2168: Add C APIs for new createContainer Methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <155295435431.14070.4905478657607161256@gitbox.apache.org> From: andor@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: zookeeper X-Git-Refname: refs/heads/branch-3.5 X-Git-Reftype: branch X-Git-Oldrev: 7461a2b0d1e5d0522e58e608c9b6ee1b771faffd X-Git-Newrev: 7b36fd550c0e5c85388918d1467a87f0b129ada6 X-Git-Rev: 7b36fd550c0e5c85388918d1467a87f0b129ada6 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. andor pushed a commit to branch branch-3.5 in repository https://gitbox.apache.org/repos/asf/zookeeper.git The following commit(s) were added to refs/heads/branch-3.5 by this push: new 7b36fd5 ZOOKEEPER-2168: Add C APIs for new createContainer Methods 7b36fd5 is described below commit 7b36fd550c0e5c85388918d1467a87f0b129ada6 Author: Balazs Meszaros AuthorDate: Mon Mar 18 17:12:03 2019 -0700 ZOOKEEPER-2168: Add C APIs for new createContainer Methods I rebased and addressed the comments of https://github.com/apache/zookeeper/pull/33 by Randgalt Author: randgalt Author: Balazs Meszaros Reviewers: andor@apache.org Closes #838 from meszibalu/my/container and squashes the following commits: c6c9dc0a6 [Balazs Meszaros] ZOOKEEPER-2168 - added test case for containers ed4b842e6 [Balazs Meszaros] ZOOKEEPER-2168 - rebase and review comment fixes f0f144129 [randgalt] ZOOKEEPER-2168 - fixed typo 4cea8d412 [randgalt] ZOOKEEPER-2168 - first pass at C changes for containers (cherry picked from commit 9fba2f6c93a78928df4841a66185f51e242653aa) Signed-off-by: Andor Molnar --- zookeeper-client/zookeeper-client-c/include/proto.h | 2 ++ zookeeper-client/zookeeper-client-c/include/zookeeper.h | 1 + zookeeper-client/zookeeper-client-c/src/zookeeper.c | 12 ++++++++---- zookeeper-client/zookeeper-client-c/tests/TestClient.cc | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/zookeeper-client/zookeeper-client-c/include/proto.h b/zookeeper-client/zookeeper-client-c/include/proto.h index 7c3fc16..f9489f0 100644 --- a/zookeeper-client/zookeeper-client-c/include/proto.h +++ b/zookeeper-client/zookeeper-client-c/include/proto.h @@ -40,6 +40,8 @@ extern "C" { #define ZOO_RECONFIG_OP 16 #define ZOO_CHECK_WATCHES 17 #define ZOO_REMOVE_WATCHES 18 +#define ZOO_CREATE_CONTAINER_OP 19 +#define ZOO_DELETE_CONTAINER_OP 20 #define ZOO_CLOSE_OP -11 #define ZOO_SETAUTH_OP 100 #define ZOO_SETWATCHES_OP 101 diff --git a/zookeeper-client/zookeeper-client-c/include/zookeeper.h b/zookeeper-client/zookeeper-client-c/include/zookeeper.h index cc19c90..95c7b3b 100644 --- a/zookeeper-client/zookeeper-client-c/include/zookeeper.h +++ b/zookeeper-client/zookeeper-client-c/include/zookeeper.h @@ -194,6 +194,7 @@ extern ZOOAPI const int ZOOKEEPER_READ; // @{ extern ZOOAPI const int ZOO_EPHEMERAL; extern ZOOAPI const int ZOO_SEQUENCE; +extern ZOOAPI const int ZOO_CONTAINER; // @} /** diff --git a/zookeeper-client/zookeeper-client-c/src/zookeeper.c b/zookeeper-client/zookeeper-client-c/src/zookeeper.c index fc04555..25baa9c 100644 --- a/zookeeper-client/zookeeper-client-c/src/zookeeper.c +++ b/zookeeper-client/zookeeper-client-c/src/zookeeper.c @@ -99,6 +99,7 @@ const int ZOOKEEPER_READ = 1 << 1; const int ZOO_EPHEMERAL = 1 << 0; const int ZOO_SEQUENCE = 1 << 1; +const int ZOO_CONTAINER = 1 << 2; const int ZOO_EXPIRED_SESSION_STATE = EXPIRED_SESSION_STATE_DEF; const int ZOO_AUTH_FAILED_STATE = AUTH_FAILED_STATE_DEF; @@ -108,6 +109,8 @@ const int ZOO_CONNECTED_STATE = CONNECTED_STATE_DEF; const int ZOO_READONLY_STATE = READONLY_STATE_DEF; const int ZOO_NOTCONNECTED_STATE = NOTCONNECTED_STATE_DEF; +#define ZOOKEEPER_IS_CONTAINER(flags) (((flags) & ZOO_CONTAINER) == ZOO_CONTAINER) + static __attribute__ ((unused)) const char* state2String(int state){ switch(state){ case 0: @@ -3559,7 +3562,7 @@ int zoo_acreate(zhandle_t *zh, const char *path, const char *value, string_completion_t completion, const void *data) { struct oarchive *oa; - struct RequestHeader h = {get_xid(), ZOO_CREATE_OP}; + struct RequestHeader h = {get_xid(), ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE_OP}; struct CreateRequest req; int rc = CreateRequest_init(zh, &req, @@ -3591,7 +3594,7 @@ int zoo_acreate2(zhandle_t *zh, const char *path, const char *value, string_stat_completion_t completion, const void *data) { struct oarchive *oa; - struct RequestHeader h = { get_xid(), ZOO_CREATE2_OP }; + struct RequestHeader h = { get_xid(), ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE2_OP }; struct CreateRequest req; int rc = CreateRequest_init(zh, &req, path, value, valuelen, acl_entries, flags); @@ -3956,6 +3959,7 @@ int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, rc = rc < 0 ? rc : serialize_MultiHeader(oa, "multiheader", &mh); switch(op->type) { + case ZOO_CREATE_CONTAINER_OP: case ZOO_CREATE_OP: { struct CreateRequest req; @@ -4138,7 +4142,7 @@ void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value, char *path_buffer, int path_buffer_len) { assert(op); - op->type = ZOO_CREATE_OP; + op->type = ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE_OP; op->create_op.path = path; op->create_op.data = value; op->create_op.datalen = valuelen; @@ -4153,7 +4157,7 @@ void zoo_create2_op_init(zoo_op_t *op, const char *path, const char *value, char *path_buffer, int path_buffer_len) { assert(op); - op->type = ZOO_CREATE2_OP; + op->type = ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE2_OP; op->create_op.path = path; op->create_op.data = value; op->create_op.datalen = valuelen; diff --git a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc index 89bf856..b6d8a64 100644 --- a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc +++ b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc @@ -210,6 +210,7 @@ class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testIPV6); #endif CPPUNIT_TEST(testCreate); + CPPUNIT_TEST(testCreateContainer); CPPUNIT_TEST(testPath); CPPUNIT_TEST(testPathValidation); CPPUNIT_TEST(testPing); @@ -698,6 +699,19 @@ public: CPPUNIT_ASSERT(Stat_eq(&stat_a, &stat_b) != 1); } + void testCreateContainer() { + watchctx_t ctx; + int rc = 0; + zhandle_t *zk = createClient(&ctx); + CPPUNIT_ASSERT(zk); + char pathbuf[80]; + struct Stat stat = {0}; + + rc = zoo_create2(zk, "/testContainer", "", 0, &ZOO_OPEN_ACL_UNSAFE, + ZOO_CONTAINER, pathbuf, sizeof(pathbuf), &stat); + CPPUNIT_ASSERT_EQUAL((int) ZOK, rc); + } + void testGetChildren2() { int rc; watchctx_t ctx;