Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To ease the interaction with the rest end point, we provided a java client for this Cluster Management Service. You will need to have geode-management.jar in your class path.


Below is a typical usage of the the CMS java client. 


Code Block
languagejava
titleJava client
public static void main(String[] args) {
  
  // use the ClusterManagementServiceBuilder to build the service client (*1)
  ClusterManagementService cms = ClusterManagementServiceBuilder.setHost("localhost").setPort(7070).build();

  // create a region, or any type that extends AbstractConfiguration (*2)
  Region regionConfig = new Region();
  regionConfig.setName(REGION_IN_SINGLE_GROUP);
  regionConfig.setGroup("group1");
  regionConfig.setType(RegionType.PARTITION);
  
  
  try {
    // feed this configuration object into the service client. You can use it to create/delete/list/get etc. (*3)
  	ClusterManagementRealizationResult result = cms.create(config);
	// use the result (*4)
   
  } catch (ClusterManagementExcpetion e) {
    // error handling (*5)
  }
  
}


*1: Build the Service

There are bunch of other connection properties you can set using the builder, like username/password, SSL context or auth tokens if the management rest api is using token based authentication. See the javadoc of `ClusterManagementServiceBuilder` for detail.

*2: Configuration Objects
*3: Cluster Operations
*4: Examine the Results
*5: Error Handling

You can use this java client when authoring server side code as well. Here is 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 = GeodeClusterManagementServiceBuilder.setCache(context.getCache()).build();
    ........
  }
}



statusCodedescription
OKoperation is successful, configuration is persisted and realized on servers
FAIL_TO_PERSISTconfiguration 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.
ERRORoperation is not successful. this includes precondition is not met (either service is 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_FOUNDentity you are trying modify/delete does not exist
ENTITY_EXISTSentity you are trying to create already exists
UNAUTHORIZEDin a secured cluster, you are not authorized to do this operation
UNAUTHENTICATEDin a secured cluster, you are not authenticated
ILLEGAL_ARGUMENTthe configuration object you passed in for this operation is not valid.