Table of Contents |
---|
Problem Statement
Top-Level Goal
The top-level goal is a single API for managing cluster configuration.
The beneficiaries of this work are those who want Currently, when a developer wants to change the configuration of a the cluster , say, create a region (or destroy an index, or update an async event queue) and have the change persisted in the cluster configuration for incoming servers, there is no public API for him to do so. He will have to replicate the effort of the equivalent gfsh command to achieve the same effect. It would be nice if we can expose what these commands do to a public API.
Product Goals
(create/destroy regions, indices or gateway receivers/senders etc), and have these changes replicated on all the applicable servers and persisted in the cluster configuration service. In addition to developers building Geode-based applications, the target user group includes developers working on different parts of the Geode code such as Spring Data for Apache, queries for Lucene index, or storage for the JDBC connector.
Problem Statement
In the current implementation:
- Most cluster configuration tasks are possible, but only by coordinating XML file-based configuration files, properties files, and gfsh commands.
- Many of the desired outcomes are achievable through multiple paths.
- Establishing a consistent configuration and persisting it across the cluster is difficult, sometimes impossible.
Product Goals
The developer should be able to:
Create regions/indices on the fly.
Persist the configuration and apply it to the cluster (when a new node joins, it has the config; when the server restarts, it has the config)
Obtain a consistent view of the current configuration
Apply the same change to the cluster in the same way
Be able to change the configuration in one place
Obtain this configuration without being on the cluster
Proposed Solution
The proposed solution includes:
- Address the multiple path issue by presenting a single public API for configuring the cluster, including such tasks as creating a region destroying an index, or update an async event queue.
- Provide a means to persist the change in the cluster configuration.
- Save a
- configuration to the Cluster Management Service without having to restart the servers
- Obtain the cluster management service from a cache when calling from a client or a server
- Pass a config object to the cluster management service
- Use CRUD operations
- to manage config objects
User Goals
Create a more modular product to allow for easy extension and integration. The beneficiaries of this work are the developers working on different parts of the code such as Spring Data for Apache, Queries for Lucene index, storage for the JDBC connector, other Geode developers and anyone who wants to change the configuration of the cluster (create/destroy regions, indices or gateway receivers/senders etc), have these changes replicated on all the applicable servers and persisted in the configuration persistence service for new joining servers.
This solution should meet the following requirements:
The user needs to be authenticated and authorized for each API call based on the resource he/she is trying to access.
- Enable Security Manager with Finer Grained Security
User can call the API from either the client side or the server side.
The outcome (behavior) is the same on both client and server:
affects cluster wide
idempotent
What We Have Now
What We Have Now:Our admin rest API "sort of" already serves this purpose, but it has these shortcomings:
- It's not a public API
- the APIincludesagfshcommandstringThe API is restricted to the operations implemented as gfsh commands, as the argument to the API is a gfsh command string.
- Each command does similar things, yet commands may not be consistent with each other.
Below is a diagram of the current state of things:
Gliffy Diagram | ||||
---|---|---|---|---|
|
From the current state of commands, It's not easy to extract a common interface for all the commands. And developers do not wanttousegfshcommandstringsas want to use gfsh command strings as a "makeshift" API to call into the command. We are in need of a unified interface and a unified workflow for all the commands as well.
Proposal
A We propose a new Cluster Management Service (CMS) which has two responsibilities:
- Update runtime configuration of servers (if any running)
- Persist configuration (if enabled)has to be enabled to use CMS)
Note that in order to use this API, Cluster Configuration needs to be enabled.
Gliffy Diagram | ||||||
---|---|---|---|---|---|---|
|
The CMS API is exposed as a REST API new endpoint as part of "Admin REST APIs", accepting configuration objects (JSON) that needs need to be applied to the cluster. CMS adheres to the standard REST semantics, so users can use POST, PUTPATCH, DELETE & and GET to create, update, delete or read, respectively. The API returns a JSON body that contains a message describing the result along with returning standard HTTP status codes.
Create API
API | Status Code | Response Body | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Endpoint: http://locator:8080/configure Method: POST Headers: security-username: user1 security-password: password1 Body:
| 201 |
| ||||||||||||||
400 |
| |||||||||||||||
400 |
| |||||||||||||||
401 |
| |||||||||||||||
403 |
|
Update/Delete/Get API
Endpoint: http://locator:8080/configure
Method: DELETE
Headers:
security-username: user1
security-password: password1
Body:
Code Block | ||||
---|---|---|---|---|
| ||||
{
"regionConfig": {
"name" : "Foo",
"refId" : "REPLICATE"
}
} |
PS: Only DELETE is illustrated.
For PUT/GET respective
request/responses are assumed.
200
Code Block | ||||
---|---|---|---|---|
| ||||
{
"message": "Region '/Foo' destroyed on Server1, Server2, Server3"
} |
Code Block | ||||
---|---|---|---|---|
| ||||
{
"message": "missing authorization parameters"
} |
Code Block | ||||
---|---|---|---|---|
| ||||
{
"message": "user1 not authorized for DATA:MANAGE"
} |
Code Block | ||||
---|---|---|---|---|
| ||||
{
"message": "Region with name '/Foo' does not exist"
} |
Let's look at some code to see how users can use this service. The below example shows how to create a region using CMS.
Curl (any standard REST client)
Code Block | ||||
---|---|---|---|---|
| ||||
curl http://locator.host:8080/configure?ifNotExists=true -XPOST -d '
{
"regionConfig": {
"name" : "Foo",
"refId" : "REPLICATE"
}
}' |
On Client
Code Block | ||||
---|---|---|---|---|
| ||||
ClusterManagementService cms = ClientCache.getClusterManagementService();
RegionConfig regionConfig = new RegionConfig(); //These are JAXB generated configuration objects
regionConfig.setName("Foo");
regionConfig.setrefId("REPLICATE");
ConfigResult result = cms.create(regionConfig, null, true); //create(config, memberOrGroup, ifNotExists) returns a ConfigResult or throws an exception
|
On Server
Here's how one can use CMS on serverside.
Code Block | ||||
---|---|---|---|---|
| ||||
public class MyFunction implements Function<String> {
@Override
public void execute(FunctionContext context) {
//1. Get the service from cache
Cache cache = context.getCache();
ClusterConfigurationService cms = Cache.getClusterManagementService();
//2. Create the config object, these are just JAXB generated POJOs
RegionConfig regionConfig = new RegionConfig(); //These are JAXB generated configuration objects
regionConfig.setName("Foo");
regionConfig.setrefId("REPLICATE");
//3. Invoke create, update, delete or get dependening on what you want to do.
ConfigResult result = cms.create(regionConfig, null, true); //create(config, memberOrGroup, ifNotExists) returns a ConfigResult or throws an exception
}
} |
Behind the scenes
Following the effort here, Configuration Persistence Service, we already have a set of configuration objects derived from the cache XML schema. This would serve a common object that developers would use to configure the config instance first and then ask the cluster management service to persist it, either on the cache(create the real thing on an existing cache) or on the configuration persistence service (persist the configuration itself).
On the locator side, the configuration service framework will just handle the workflow. It's up to each individual ClusterConfigElement to implement how it needs to be persisted and applied.
How does it work
On the locator side, the configuration service framework will just handle the workflow. It's up to each individual ClusterConfigElement to implement how it needs to be persisted and applied.
Gliffy Diagram | ||||
---|---|---|---|---|
|
This is what happens inside the LocatorClusterManagementService for a create operation:
Gliffy Diagram | ||||
---|---|---|---|---|
|
This is what happens inside the LocatorClusterManagementService for a list operation:
Gliffy Diagram | ||||
---|---|---|---|---|
|
Pros and Cons:
Pros:
- a A common interface to call either on the locator/server/client side.
- a A common workflow to enforce behavior consistency.
- Modularized implementation. The configuration object needs to implement the additional interfaces in order to be used in this API. This allows us to add functionality gradually and per function groups.
Cons:
- Existing gfsh commands need to be refactored to use this API as well, otherwise we would have duplicate implementations, or have different behaviors between using this API and using gfsh commands.
- When refactoring gfsh commands, some commands' behavior behaviors will change if they want to strictly follow this workflow, unless we add additional APIs for specific configuration objects.
Migration Strategy:
Our current commands uses numerous command options to configure the behavior of the commands. We will have to follow these steps to refactor the commands.
- combine Combine all the command options into one configuration objects object inside the command itself.
- have Have the command execution call the public API if the command conforms to the new workflow. In this step, the config objects needs to implement the ClusterConfigElement.
- If the command can't use the common workflow, make a special method in the api API for that specific configuration object. (we We need to evaluate carefully . - we don't want to make too many exceptions to the common workflow.)
The above work can be divided into functional groups and have the different group so that different groups can share the workload.
Once all the commands are converted using the ClusterManagementService API, All the command classes are just a facade of collecting the options values, build each command class can be reduced to a facade that collects the options and their values, builds the config object and call calls into the API. At this point, the command objects can exist only exist on the gfsh client.
The end architecture would look like this: Gliffy Diagram
Project Milestones
- API is clearly defined
- All commands are converted using this API
- Command classes exist only exist on Gfsh a gfsh client. The GfshHttpInvoker uses the rest REST API to call this ClusterConfigurationService with the configuration objects directly.