Versions Compared

Key

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

...

No Format
public interface ClusterConfigurationService {
  /**
  * @param group The group to which the cluster configuration applies. default is "cluster"
  * @param additionalBindClass custom element classes created by other modules if present.
  * @return The cluster configuration for the specified group.
  */
  CacheConfig getCacheConfig(String group, Class<? extends CacheElement>... additionalBindClass);
 
  /**
  * @param group The group to which the cluster configuration applies. default is "cluster"
  * @param mutator Specification of how the cluster configuration should be altered.
  * @param additionalBindClass custom element classes created by other modules if present.
  */
  void updateCacheConfig(String group, UnaryOperator<CacheConfig> mutator, Class<? extends CacheElement>... additionalBindClass);
}


Intended Use:

Given an interface as the above, we would be able to implement, for instance, the CreateIndexCommand instead as

No Format
public class CreateIndexCommand implements GfshCommandSingleGfshCommand {
  private static final CreateIndexFunction createIndexFunction = new CreateIndexFunction();

  @CliCommand(value = CliStrings.CREATE_INDEX, help = CliStrings.CREATE_INDEX__HELP)
  @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA})
  @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
      operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.QUERY)
  public Result createIndex(...){
 
  Result result;
  final Set<DistributedMember> targetMembers = findMembers(group, memberNameOrID);

  if (targetMembers.isEmpty()) {
    return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
  }

  // Objective: create this Index object.
  // This class was generated by JAXB
  RegionConfig.Index index = new RegionConfig.Index();
  index.setName(indexName);
  index.setExpression(indexedExpression);
  index.setTypesetFromClause(regionPath);
  if (indexType.name()); == IndexType.PRIMARY_KEY) {
    index.setFromClausesetKeyIndex(regionPathtrue);

  // invoke the function on each member, where the index will be created} else {
    index.setKeyIndex(false);
    index.setType(indexType.getName());
  }

  List<CliFunctionResult> functionResults =
      executeAndGetFunctionResult(createIndexFunction, index, targetMembers);
  result = ResultBuilder.buildResult(functionResults);

  ClusterConfigurationService service = getSharedConfiguration(result.setConfigObject(index);
  ifreturn (result.getStatus().equals(Result.Status.OK) && service != nullresult;
}
 
@Override
public void updateClusterConfig(String group, CacheConfig config, Object element) {
  RegionConfig.Index index // If the function executes successfully and the ClusterConfigurationService exists then update the cluster config.
	service.updateCacheConfig("cluster", cc -> {
	= (RegionConfig.Index) element;
  String regionPath = getValidRegionName(index.getFromClause(), config);

  RegionConfig regionConfig = findRegionConfig(cc, config.findRegionConfiguration(regionPath);
  if    if(regionConfig == null) {
    throw new EntityNotFoundException("region isRegion " + index.getFromClause() + " not found.");
   }
   regionConfig.getIndex().add(index);
      return cc;
    });
  
  }
  return result;
}

 

Here, we declaratively build the RegionConfig.Index object we would like to add to the configuration.
On successfull creation, we search for the RegionConfig object to which the index configuration should belong and add this index to that array.
With the mutator defined, we execute (a concurrency-safe) update to the cluster configuration.

...