# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
A REST HTTP gateway for ZooKeeper
=================================
Specification Version: 2
ZooKeeper is meant to enable distributed coordination and also store
system configuration and other relatively small amounts of information
that must be stored in a persistent and consistent manner. The
information stored in ZooKeeper is meant to be highly available to a
large number of nodes in a distributed-computing cluster.
ZooKeeper offers a client-side library that supports rich semantics
that include strict ordering guarantees on operations, the creation of
ephemeral znodes, and the ability to watch for changes to state.
However, where clients need simple "CRUD" (create, read, update,
delete) operations, the ZooKeeper libraries can be cumbersome, both to
the programmers who have to use them (who are increasingly used to
REST-style APIs), and to the operators who have to deploy and update
them (for whom deploying and updating client libraries can be very
painful).
It turns out that most languages comes with client libraries for HTTP
that are easy and familiar to program against, and deployed as part of
the language runtime. Thus, for simple CRUD clients, an HTTP gateway
would be a less cumbersome interface than the ZooKeeper library.
This document describes a gatway for using HTTP to interact with a
ZooKeeper repository.
Binding ZooKeeper to HTTP
-------------------------
Encoding
--------
UTF-8 unless otherwise noted
Paths
-----
A ZooKeeper paths are mapped to IRIs and URIs as follows. ZK paths
are converted to IRIs by simply percent-encoding any characters in the
ZK path that are not allowed in IRI paths. ZK paths are converted to
URIs by mapping them first to IRIs, then converting to URIs in the
standard way.
Going from URIs and IRIs is the reverse of the above but for one
difference: any "." and ".." segments in an IRI or URI must be folded
before conversion. (Fortunately, ZK does not allow "." and ".."
segments in its paths.)
ZK and IRIs recommend the same practices when it comes to Unicode
normalization: ultimately, normalization is left to application
designers, but both recommend that application designers use NFC as a
best practice.
Root
----
The following examples assume that the ZooKeeper znode heirarchy is
bound to the root of the HTTP servers namespace. This may not be the
case in practice however, the gateway may bind to some prefix, for
example the URL for accessing /a/b/c may be:
http://localhost/zookeeper/znodes/v1/a/b/c
This is perfectly valid. Users of the REST service should be aware of
this fact and code their clients to support any root (in this case
"/zookeeper" on the server localhost).
Basics: GET, PUT, HEAD, and DELETE
----------------------------------
HTTP's GET, PUT, HEAD, and DELETE operations map naturally to
ZooKeeper's "get," "set," "exists," and "delete" operations.
ZooKeeper znodes have a version number that changes each time the
znode's value is updated. This number is returned by "get," "set," and
"exists" operations. The "set" and "delete" operations optionally take
a version number. If one is supplied, then "set" or "delete" will fail
if the current version of the znode doesn't match the version-number
supplied in the call. This mechanism supports atomic read-modify-write
cycles. Set/delete requests may include an optional parameter
"version" which defaults to no version check.
Getting ZooKeeper children
--------------------------
We overload the GET method to return the children of a ZooKeeper. In
particular, the GET method takes an optional parameter "view" which
could be set to one of type values, either "data" or "children". The
default is "data". Thus, to get the children of a znode named
"/a/b/c", then the GET request should start:
GET /znodes/v1/a/b/c?view=children HTTP/1.1
If the requested view is "data", then the data of a znode is returned
as described in the previous section. If the requested view is
"children", then a list of children is returned in either an XML
document, or in a JSON object. (The default is JSON, but this can be
controlled changed by setting the Accept header.)
Creating a ZooKeeper session
----------------------------
In order to be able to create ephemeral nodes you first need to start
a new session.
POST /sessions/v1?op=create&expire=<SECONDS> HTTP/1.1
If the session creation is successful, then a 201 code will be returned.
A session is just an UUID that you can pass around as a parameter and
the REST server will foward your request on the attached persistent
connection.
Keeping a session alive
-----------------------
To keep a session alive you must send hearbeat requests:
PUT /sessions/v1/<SESSION-UUID> HTTP/1.1
Closing a ZooKeeper session
---------------------------
You can close a connection by sending a DELETE request.
DELETE /sessions/v1/<SESSION-UUID> HTTP/1.1
If you don't close a session it will automatically expire after
the amount of time you specified on creation.
Creating a ZooKeeper znode
--------------------------
We use the POST method to create a ZooKeeper znode. For example, to
create a znode named "c" under a parent named "/a/b", then the POST
request should start:
POST /znodes/v1/a/b?op=create&name=c HTTP/1.1
If the creation is successful, then a 201 code will be returned. If
it fails, then a number of different codes might be returned
(documented in a later subsection).
ZooKeeper's create operation has a flag that tells the server to
append a sequence-number to the client-supplied znode-name in order to
make the znode-name unique. If you set this flag and ask to create a
znode named "/a/b/c", and a znode named "/a/b" already exists, then
"create" will create a znode named "/a/b/c-#" instead, where "#" is and
integer required to generate a unique name in for format %10d.
To obtain this behavior, an additional "sequence=true" parameter
should be added to the parameters of the POST. (Note that "sequence"
is an optional parameter, that defaults to "false"; this default may
be provided explicitly if desired.)
On success the actual path of the created znode will be returned.
If you want to create an ephemeral node you need to specify an
additional "ephemeral=true" parameter. (Note that "ephemeral" is an optional
parameter, that defaults to "false")
(Note: ZooKeeper also allows the client to set ACLs for the
newly-created znode. This feature is not currently supported by the
HTTP gateway to ZooKeeper.)
Content types and negotiation
-----------------------------
ZooKeeper REST gateway implementations may support three content-types
for request and response messages:
* application/octet-stream
HEAD - returns nothing (note below: status = 204)
GET - returns the znode data as an octet-stream
PUT - send binary data, returns nothing
POST - send binary data, returns the name of the znode
DELETE - returns nothing
For PUT and HEAD some other content-type (i.e. JSON or XML) must be
used to access the Stat information of a znode.
* application/json, application/javascript & application/xml
HEAD - returns nothing
GET - returns a STAT or CHILD structure
PUT - send binary data, returns a STAT structure (sans da
没有合适的资源?快使用搜索试试~ 我知道了~
apache-zookeeper-3.5.8.tar.gz
1 下载量 102 浏览量
2024-06-18
09:54:45
上传
评论
收藏 2.99MB GZ 举报
温馨提示
zookeeper_分布式应用程序集群协调服务,各个版本 下载 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。 ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。 ZooKeeper包含一个简单的原语集,提供Java和C的接口。
资源推荐
资源详情
资源评论
收起资源包目录
apache-zookeeper-3.5.8.tar.gz (1189个子文件)
snapshot.0 296B
snapshot.0 296B
snapshot.0 296B
snapshot.0 296B
log.1 58KB
log.1 50KB
log.1 50KB
log.1 50KB
snapshot.100000000 73B
log.100000001 2.34MB
snapshot.100001bec 2.45MB
log.100001bf0 1001KB
snapshot.2 5KB
snapshot.272 55KB
snapshot.273 55KB
log.274 89KB
log.42 184B
snapshot.639 140KB
log.63b 48KB
snapshot.83f 5KB
configure.ac 6KB
configure.ac 2KB
configure.ac 2KB
configure.ac 2KB
configure.ac 2KB
Makefile.am 5KB
aminclude.am 5KB
aminclude.am 5KB
aminclude.am 5KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 265B
Makefile.am 74B
Makefile.am 74B
lastRevision.bat 1006B
zookeeper.c 159KB
zookeeper.c 49KB
cli.c 28KB
mt_adaptor.c 16KB
zoo_queue.c 14KB
zk_hashtable.c 13KB
zoo_lock.c 13KB
winport.c 9KB
recordio.c 9KB
hashtable.c 9KB
load_gen.c 8KB
addrvec.c 6KB
hashtable_itr.c 5KB
zk_log.c 5KB
st_adaptor.c 2KB
check_zk_version.c 1KB
zkfuse.cc 142KB
TestClient.cc 51KB
TestOperations.cc 37KB
TestWatchers.cc 31KB
zkadapter.cc 28KB
ZkTreeUtil.cc 24KB
TestMulti.cc 23KB
TestReconfig.cc 22KB
TestZookeeperClose.cc 21KB
ZkAdaptor.cc 16KB
ZKMocks.cc 16KB
TestReconfigServer.cc 15KB
TestClient.cc 13KB
TestZookeeperInit.cc 11KB
LibCMocks.cc 10KB
ZkTreeUtilMain.cc 9KB
ZooKeeperQuorumServer.cc 7KB
TestDriver.cc 5KB
TestClient.cc 5KB
TestClientRetry.cc 4KB
PthreadMocks.cc 4KB
TestDriver.cc 4KB
TestDriver.cc 4KB
TestReadOnlyClient.cc 3KB
LibCSymTable.cc 2KB
ThreadingUtil.cc 2KB
Util.cc 1KB
thread.cc 1KB
log.cc 1KB
MocksBase.cc 1KB
Util.cc 1KB
Util.cc 1KB
event.cc 968B
rest.cer 595B
doxygen.cfg 50KB
services.cfg 2KB
zookeeper.cfg 1KB
defaultNodeViewers.cfg 967B
defaultConnectionSettings.cfg 963B
hostgroups.cfg 940B
zoo_sample.cfg 922B
quorum.cfg 170B
ChangeLog 4KB
Changes 1KB
zkEnv.cmd 2KB
zkServer.cmd 1KB
zkCli.cmd 1KB
zooInspector.cmd 1KB
共 1189 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
段子手-168
- 粉丝: 4156
- 资源: 2745
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 1_ROT编码 (2).zip
- IMG_7230.jpg
- python+翻译器+语音
- 一个简单的库存管理系统,使用PHP、JavaScript、Bootstrap和CSS开发
- Python(Tkinter+matplotlib)实现光斑处理系统源代码
- HC32F4A0-v2.2.0-LittleVgl-8.3-1111.zip, 基于HC32F4A0的LVGL8.3工程
- 220913201郭博宇数据结构3.docx
- 小米R3G路由器breed专属
- MATLAB实现QRLSTM长短期记忆神经网络分位数回归时间序列区间预测(含完整的程序和代码详解)
- AN-HC32F4A0系列的外部存储器控制器EXMC -Rev1.1
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功