# 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
没有合适的资源?快使用搜索试试~ 我知道了~
zookeeper-3.4.14.zip

共1466个文件
java:592个
html:256个
xml:45个

需积分: 46 24 下载量 118 浏览量
2019-05-15
20:39:59
上传
评论
收藏 110.49MB ZIP 举报
温馨提示
zookeeper-3.4.14,包含添加系统服务插件及添加bat. 1. zookeeper-3.4.14源包 2. commons-daemon-1.1.0-bin-windows.zip 插件 3. 配置好插件的zookeeper-3.4.14包,右键管理员权限执行zk-server-install.bat
资源推荐
资源详情
资源评论













收起资源包目录





































































































共 1466 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论


hicome
- 粉丝: 33
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于树莓派的自动驾驶小车制作项目
- 陶粒混凝土砌体信息化施工技术研究.docx
- acp-admin-cloud-Kotlin资源
- 基于单片机一氧化碳报警器方案设计书.doc
- 中职《计算机组装与维修》课程中课岗融合教学的应用.docx
- mcp-gitee-ent-AI人工智能资源
- 互联网+背景下职业院校教师信息素养提升有效策略.docx
- 计算机系统在自动化仪器仪表中的运用.docx
- 深信服国产虚拟化平台介绍.docx
- rust-ruoyi-Rust资源
- PLC在电镀生产线上的应用(大学本科方案设计书).doc
- 电气工程中电气自动化技术探析.docx
- 网络环境下企业财会管理工作探析1.docx
- 三全育人理念下高校网络思政育人路径思考.docx
- 财务共享服务下管理会计信息化有效实施对策探讨.docx
- 运营商大数据安全管理策略研究.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
