Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: change statusCode description to be table

...

You can use this java client when authoring server side code as well. Here's how one can use CMS on a server, 

Code Block
languagejava
titleServer Side
public class MyFunction implements Function<String> {
  @Override
  public void execute(FunctionContext context) {
    //1. Get the service instance. You don't need to provide url or port or ssl information since all that information is deduced by the server automatically.
    // but you will need to provide a username/password if the cluster is secured.
    ClusterManagementService cms = ClusterManagementServiceProvider.getService();
    
    //2. Create the config object, these are just JAXB generated POJOs
    RegionConfig regionConfig = new RegionConfig(); //These are JAXB generated configuration objects
    regionConfig.setName("ACCOUNTS");
    regionConfig.setType(RegionShortcut.REPLICATE);
    
    //3. Invoke create, update, delete or get depending on what you want to do.
    ClusterManagementResult result = cms.create(regionConfig, "cluster"); 
  }
}


ClusterManagementResult

ClusterManagementResult is the result object you get when you invoke a method using cluster management service. Here is an instance of this object in json format:

Code Block
languagetext
titlejson
{
  "memberStatuses" : {
    "server-1" : {
      "success" : true,
      "message" : "success"
    }
  },
  "statusCode" : "OK",
  "statusMessage" : "successfully persisted config for cluster",
  "successful" : true
}

Here is an explanation of each of the fields in the result object:

"successful": a boolean value indicating the overall success/failure status of the service call. it will be true if and only if the "statusCode" value is "OK".

"statusCode": a enum field indicating the result status. Here is a list of possible values in this field:


statusCodedescription
OK
:
operation is successful, configuration is persisted and realized on servers
FAIL_TO_PERSIST
:
configuration is realized on servers, but some error occurred when persisting the configuration. the "statusMessage" should tell you exactly why. Normally this means some developer error. when this happened, developer needs to revert the changes or try making the same call again to try to persist it again.
ERROR
:
operation is not successful. this includes precondition is not met (either service is
not
not running or no servers available, or the configuration encountered some error when trying to be realized on one member (configuration is not fully realized on all applicable members).
ENTITY_NOT_FOUND
:
entity you are trying modify/delete does not exist
ENTITY_EXISTS
:
entity you are trying to create already exists
UNAUTHORIZED
:
in a secured cluster, you are not authorized to do this operation
UNAUTHENTICATED
:
in a secured cluster, you are not authenticated
ILLEGAL_ARGUMENT
:
the configuration object you passed in for this operation is not valid.


"StatusMessage": a detailed message about the result of the operation

"memberStatus": information about the operation status on each server.


Behind the scenes

Gliffy Diagram
size600
nameConfigElement
pagePin10

 

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. 

Pros and Cons:

Pros:

  1. A common interface to call either on the locator/server/client side
  2. A common workflow to enforce behavior consistency
  3. 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:

  1. Existing gfsh commands need to be refactored to use this API as well, otherwise we would have duplicate implementations, or have different behaviors between this API and gfsh commands.
  2. When refactoring gfsh commands, some commands' 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 options to configure the behavior of the commands. We will have to follow these steps to refactor the commands.

  1. Combine all the command options into one configuration object inside the command itself.
  2. 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.
  3. If the command can't use the common workflow, make a special method in the API for that specific configuration object. (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 so that different groups can share the workload.

Once all the commands are converted using the ClusterManagementService API, each command class can be reduced to a facade that collects the options and their values, builds the config object and calls into the API. At this point, the command objects can exist only on the gfsh client.

The end architecture would look like this:

Gliffy Diagram
namemigration
pagePin3

Project Milestones

  1. API is clearly defined
  2. All commands are converted using this API
  3. Command classes exist only on a gfsh client. The GfshHttpInvoker uses the REST API to call this ClusterConfigurationService with the configuration objects directly.