Search in sources :

Example 6 with MemberGroupConfig

use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method testConfigMemberGroupFactoryCreateMemberGroups.

/**
 * When there is a matching {@link MemberGroupConfig} for a {@link Member}, it will be assigned to a {@link MemberGroup}.
 * <p>
 * In this test all members will have a matching configuration, so there will be 4 groups with 2 members each.
 */
@Test
public void testConfigMemberGroupFactoryCreateMemberGroups() {
    Collection<Member> members = createMembers();
    Collection<MemberGroupConfig> groupConfigs = createMemberGroupConfigs(true);
    MemberGroupFactory groupFactory = new ConfigMemberGroupFactory(groupConfigs);
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + String.valueOf(memberGroups), 4, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
    }
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) Member(com.hazelcast.cluster.Member) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with MemberGroupConfig

use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.

the class ConfigMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> members) {
    Map<Integer, MemberGroup> memberGroups = new HashMap<Integer, MemberGroup>();
    for (Member member : members) {
        String host = ((MemberImpl) member).getAddress().getHost();
        for (Entry<Integer, MemberGroupConfig> entry : memberGroupConfigMap.entrySet()) {
            Collection<String> interfaces = entry.getValue().getInterfaces();
            boolean match;
            if (AddressUtil.isIpAddress(host)) {
                match = AddressUtil.matchAnyInterface(host, interfaces);
            } else {
                match = AddressUtil.matchAnyDomain(host, interfaces);
            }
            if (match) {
                MemberGroup group = memberGroups.get(entry.getKey());
                if (group == null) {
                    group = new DefaultMemberGroup();
                    memberGroups.put(entry.getKey(), group);
                }
                group.addMember(member);
                break;
            }
        }
    }
    return new HashSet<MemberGroup>(memberGroups.values());
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) HashSet(java.util.HashSet)

Example 8 with MemberGroupConfig

use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.

the class LocalMapStatsTest method createConfig.

private Config createConfig(String mapName, String[] firstGroup, String[] secondGroup) {
    final MemberGroupConfig firstGroupConfig = createGroupConfig(firstGroup);
    final MemberGroupConfig secondGroupConfig = createGroupConfig(secondGroup);
    Config config = getConfig();
    config.getPartitionGroupConfig().setEnabled(true).setGroupType(PartitionGroupConfig.MemberGroupType.CUSTOM);
    config.getPartitionGroupConfig().addMemberGroupConfig(firstGroupConfig);
    config.getPartitionGroupConfig().addMemberGroupConfig(secondGroupConfig);
    config.getNetworkConfig().getInterfaces().addInterface("127.0.0.*");
    config.getMapConfig(mapName).setBackupCount(2);
    return config;
}
Also used : Config(com.hazelcast.config.Config) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig)

Example 9 with MemberGroupConfig

use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.

the class MemberDomConfigProcessor method handleMemberGroup.

protected void handleMemberGroup(Node node, Config config) {
    MemberGroupConfig memberGroupConfig = new MemberGroupConfig();
    for (Node child : childElements(node)) {
        if (matches("interface", cleanNodeName(child))) {
            memberGroupConfig.addInterface(getTextContent(child));
        }
    }
    config.getPartitionGroupConfig().addMemberGroupConfig(memberGroupConfig);
}
Also used : Node(org.w3c.dom.Node) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig)

Example 10 with MemberGroupConfig

use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method testConfigCustomPartitionStateGenerator.

@Test
public void testConfigCustomPartitionStateGenerator() throws Exception {
    PartitionGroupConfig config = new PartitionGroupConfig();
    config.setEnabled(true);
    config.setGroupType(PartitionGroupConfig.MemberGroupType.CUSTOM);
    MemberGroupConfig mgCfg0 = new MemberGroupConfig();
    MemberGroupConfig mgCfg1 = new MemberGroupConfig();
    MemberGroupConfig mgCfg2 = new MemberGroupConfig();
    MemberGroupConfig mgCfg3 = new MemberGroupConfig();
    config.addMemberGroupConfig(mgCfg0);
    config.addMemberGroupConfig(mgCfg1);
    config.addMemberGroupConfig(mgCfg2);
    config.addMemberGroupConfig(mgCfg3);
    for (int k = 0; k < 3; k++) {
        for (int i = 0; i < 255; i++) {
            MemberGroupConfig mg;
            switch(i % 4) {
                case 0:
                    mg = mgCfg0;
                    break;
                case 1:
                    mg = mgCfg1;
                    break;
                case 2:
                    mg = mgCfg2;
                    break;
                case 3:
                    mg = mgCfg3;
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            mg.addInterface("10.10." + k + "." + i);
        }
    }
    test(new ConfigMemberGroupFactory(config.getMemberGroupConfigs()));
}
Also used : PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) ConfigMemberGroupFactory(com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MemberGroupConfig (com.hazelcast.config.MemberGroupConfig)12 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Member (com.hazelcast.cluster.Member)3 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)3 Config (com.hazelcast.config.Config)2 HashMap (java.util.HashMap)2 Node (org.w3c.dom.Node)2 EvictionConfig (com.hazelcast.config.EvictionConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 Member (com.hazelcast.core.Member)1 ConfigMemberGroupFactory (com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory)1 MapUtil.createLinkedHashMap (com.hazelcast.internal.util.MapUtil.createLinkedHashMap)1 YamlNode (com.hazelcast.internal.yaml.YamlNode)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 LinkedHashMap (java.util.LinkedHashMap)1