Provides a RESTful JSON interface to a property based zookeeper data model.
This project adds a HTTP based RESTful interface on top of the project ZooKeeper Properties
The purpose is to allow for easy access to view/change properties using non-programmatic tools such as wget and curl
The above figure depicts a setup where there are a number of micro services, in an essence stand-alone processes performing some task. A typical problem in a micro services architecture is to configure each individual service. Not only are the services potentially distributed over a number of hosts, there's most likley going to be multiple instances of each service. The common pattern is to use a centralized database for storage, of which ZooKeeper is very popular.
The project ZooKeeper Properties provides the API the application/service needs to read property/configuration data.
For details on data model and usage of the persistence layer refer to the above referred project.
This project focuses on adding a simple way to manage the properties/configuration.
That is without needing to perform programmatic tasks.
Quite often the administrator needing to setup/maintain the system is not a programmer, rather a script hacker.
This person only wants to be able to set/read/delete property data using scripting tools or possible a web browser.
Therefore this project provides a simple RESTful interface allowing for easy manipulation of the property data using tools such as curl.
There's four basic uses cases which are described in the sections to come.
Performing a GET on the URL:
[uri]/properties
Will yield a json formated list with all the names of the existing property sets.
E.g.
["system"]
Performing a GET on the URL:
[uri]/properties/set-name
Will yield a json formated list with all the name/value pairs of the properties for the set with the name set-name.
E.g.
{port: "6969",host: "127.0.0.1"}
If no such property set exists NOT_FOUND 404 is returned.
Performing a PUT on the URL:
[uri]/properties/set-name
With the data such as :
{port: "6969",host: "127.0.0.1"}
Will set the properties for the set with the name set-name.
Note any existing set with the same name will be overwritten.
It's also important that the Content-Type is set to application/json
A successful operation results in CREATED 201
Performing a DELETE on the URL:
[uri]/properties/set-name
Will delete the set with the name set-name.
There project includes two way to try out the software.
Both are described below.
Using the StartServiceManually class found in the source tree.
It will both start a in-memory ZooKeeper instance as well as a HTTP server exposing the REST interface.
Use any IDE of your choice to start the class.
The project also provides an example web-app that you can build to a war file and deploy into a servlet engine of your choice.
The web-app has been tested and verified with Tomcat.
This expects there to be a ZooKeeper server running on the localhost on port 2181.
Curl is a popular Linux utility for sending HTTP operations from a bash shell.
The examples below is using the StartServiceManually class started in Eclipse.
%>curl localhost:9998/properties
Will produce
["example-set"]
%>curl -H "Content-Type: application/json" -d '{user.name:"Peter",host:"127.0.0.1"}' -X PUT localhost:9998/properties/my-properties
Note the Content-Type it's important to provide.
%>curl localhost:9998/properties/example-set
Will produce
{port:"6969",host:"127.0.0.1"}
%>curl -X DELETE localhost:9998/properties/example-set
Copyright 2016 Peter Nerg.
Licensed 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.