public Collection<MemberGroup> createMemberGroups(Collection<MemberImpl> members) { final Map<Integer, MemberGroup> memberGroups = new HashMap<Integer, MemberGroup>(); for (MemberImpl member : members) { if (member.isLiteMember()) { continue; } for (Entry<Integer, MemberGroupConfig> groupConfigEntry : memberGroupConfigMap.entrySet()) { if (AddressPicker.matchAddress(member.getAddress().getHost(), groupConfigEntry.getValue().getInterfaces())) { MemberGroup group = memberGroups.get(groupConfigEntry.getKey()); if (group == null) { group = new DefaultMemberGroup(); memberGroups.put(groupConfigEntry.getKey(), group); } group.addMember(member); break; } } } return memberGroups.values(); }
protected Set<MemberGroup> createInternalMemberGroups(Collection<MemberImpl> members) { final Map<Integer, MemberGroup> memberGroups = new HashMap<Integer, MemberGroup>(); for (MemberImpl member : members) { if (member.isLiteMember()) { continue; } for (Entry<Integer, MemberGroupConfig> groupConfigEntry : memberGroupConfigMap.entrySet()) { if (AddressUtil.matchAnyInterface(member.getAddress().getHost(), groupConfigEntry.getValue().getInterfaces())) { MemberGroup group = memberGroups.get(groupConfigEntry.getKey()); if (group == null) { group = new DefaultMemberGroup(); memberGroups.put(groupConfigEntry.getKey(), group); } group.addMember(member); break; } } } return new HashSet<MemberGroup>(memberGroups.values()); }
private void setPartitionGroup(PartitionGroupConfig partitionGroup) { partitionGroup.setEnabled(false); partitionGroup.setGroupType(MemberGroupType.CUSTOM); MemberGroupConfig memberGroupConfig = new MemberGroupConfig(); memberGroupConfig.addInterface("10.10.0.*").addInterface("10.10.3.*").addInterface("10.10.5.*"); partitionGroup.addMemberGroupConfig(memberGroupConfig); }
private PartitionGroupConfig partitionConfig(final com.typesafe.config.Config c) { final PartitionGroupConfig partitionGroupConfig = new PartitionGroupConfig(); partitionGroupConfig.setEnabled(true); partitionGroupConfig.setGroupType(ConfigUtils.getString(c, "group-type").map(MemberGroupType::valueOf).orElseThrow(new ConfigurationExceptionSupplier("name is required"))); if (partitionGroupConfig.getGroupType().equals(CUSTOM)) { ConfigUtils.getConfigList(c, "member-group-configs").ifPresent(memberGroupConfigs -> { memberGroupConfigs.stream().forEach(memberGroupConfig -> { final MemberGroupConfig _memberGroupConfig = new MemberGroupConfig(); _memberGroupConfig.setInterfaces(ConfigUtils.getStringList(memberGroupConfig, "interfaces").orElseThrow(new ConfigurationExceptionSupplier("no interfaces were defined for the MemberGroupConfig"))); partitionGroupConfig.addMemberGroupConfig(_memberGroupConfig); }); }); } return partitionGroupConfig; }
public ConfigMemberGroupFactory(Collection<MemberGroupConfig> memberGroupConfigs) { super(); this.memberGroupConfigMap = new LinkedHashMap<Integer, MemberGroupConfig>(); int key = 0; for (MemberGroupConfig groupConfig : memberGroupConfigs) { memberGroupConfigMap.put(key++, groupConfig); } }
@Test public void testConfigCustomPartitionStateGenerator() throws Exception { PartitionGroupConfig config = new PartitionGroupConfig(); config.setEnabled(true); config.setGroupType(MemberGroupType.CUSTOM); config.addMemberGroupConfig(new MemberGroupConfig().addInterface("10.10.0.0").addInterface("10.10.0.2")) .addMemberGroupConfig(new MemberGroupConfig().addInterface("10.10.0.3-5")) .addMemberGroupConfig(new MemberGroupConfig().addInterface("10.10.0.6").addInterface("10.10.0.7").addInterface("10.10.0.8")) .addMemberGroupConfig(new MemberGroupConfig().addInterface("10.10.0.9-100")); PartitionStateGenerator generator = PartitionStateGeneratorFactory.newConfigPartitionStateGenerator(config); test(generator, new ConfigMemberGroupFactory(config.getMemberGroupConfigs())); }