LocatorClusterManagementService implements ClusterManagementService { @Override public <T extends AbstractConfiguration<R>, R extends RuntimeInfo> ClusterManagementListResult<T, R> list( T filter) { ClusterManagementListResult<T, R> result = new ClusterManagementListResult<>(); if (persistenceService == null) { return assertSuccessful(new ClusterManagementListResult<>(StatusCode.ERROR, "Cluster configuration service needs to be enabled.")); } List<T> resultList = new ArrayList<>(); if (filter instanceof Member) { resultList.add(filter); } else { ConfigurationManager<T> manager = getConfigurationManager(filter); Set<String> groups; if (StringUtils.isNotBlank(filter.getGroup())) { groups = Collections.singleton(filter.getGroup()); } else { groups = persistenceService.getGroups(); } for (String group : groups) { List<T> list = manager.list(filter, group); if (!AbstractConfiguration.isCluster(group)) { list.forEach(t -> { if (t instanceof GroupableConfiguration) { ((GroupableConfiguration<?>) t).setGroup(group); } }); } list.stream().filter(t -> !resultList.contains(t)) .forEach(resultList::add); } } List<EntityGroupInfo<T, R>> responses = new ArrayList<>(); boolean hasRuntimeInfo = hasRuntimeInfo(filter.getClass()); for (T element : resultList) { EntityGroupInfo<T, R> response = new EntityGroupInfo<>(element); responses.add(response); if (!hasRuntimeInfo) { continue; } Set<DistributedMember> members; if (filter instanceof Member) { members = memberValidator.findMembers(filter.getId(), filter.getGroup()); } else { members = memberValidator.findServers(element); } if (members.size() == 0) { continue; } if (element.isGlobalRuntime()) { members = Collections.singleton(members.iterator().next()); } List<R> runtimeInfos = executeCacheRealizationFunction( element, CacheElementOperation.GET, members); response.setRuntimeInfo(runtimeInfos); } if (filter instanceof Member) { List<R> members = responses.get(0).getRuntimeInfo(); for (R memberInfo : members) { Member member = new Member(); member.setId(memberInfo.getMemberName()); EntityInfo<T, R> entityInfo = new EntityInfo<>(memberInfo.getMemberName(), Collections.singletonList( new EntityGroupInfo<>((T) member, Collections.singletonList(memberInfo)))); result.addEntityInfo(entityInfo); } } else { result.setEntityGroupInfo(responses); } return assertSuccessful(result); } LocatorClusterManagementService(InternalCache cache,
      InternalConfigurationPersistenceService persistenceService); @VisibleForTesting  LocatorClusterManagementService(
      InternalCache cache,
      InternalConfigurationPersistenceService persistenceService,
      Map<Class, ConfigurationManager> managers,
      Map<Class, ConfigurationValidator> validators,
      MemberValidator memberValidator,
      CommonConfigurationValidator commonValidator,
      OperationManager operationManager); @Override ClusterManagementRealizationResult create(T config); @Override ClusterManagementRealizationResult delete(
      T config); @Override ClusterManagementRealizationResult update(
      T config); @Override ClusterManagementListResult<T, R> list(
      T filter); @Override ClusterManagementGetResult<T, R> get(
      T config); @Override ClusterManagementOperationResult<A, V> start(
      A op); @Override ClusterManagementListOperationsResult<A, V> list(
      A opType); @Override ClusterManagementOperationResult<A, V> get(
      A opType, String opId); @Override CompletableFuture<ClusterManagementOperationResult<A, V>> getFuture(
      A opType, String opId); boolean isConnected(); @Override void close(); @VisibleForTesting
  // the dlock service name used by the CMS
  static final String CMS_DLOCK_SERVICE_NAME; }
@Test public void list_oneGroup() { regionConfig.setGroup("cluster"); doReturn(Sets.newHashSet("cluster", "group1")).when(persistenceService).getGroups(); service.list(regionConfig); verify(persistenceService).getCacheConfig("cluster", true); verify(regionManager).list(any(Region.class), any(CacheConfig.class)); }
@Test public void list_oneGroupCaseInsensitive() { regionConfig.setGroup("CLUSTER"); doReturn(Sets.newHashSet("cluster", "group1")).when(persistenceService).getGroups(); service.list(regionConfig); verify(persistenceService).getCacheConfig("cluster", true); verify(regionManager).list(any(Region.class), any(CacheConfig.class)); }