Search in sources :

Example 1 with DefaultDiscoveryService

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryService in project hazelcast by hazelcast.

the class AzureDiscoveryStrategyFactoryTest method createStrategy.

private static DiscoveryStrategy createStrategy(String xmlFileName) {
    final InputStream xmlResource = AzureDiscoveryStrategyFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
    DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setDiscoveryConfig(discoveryConfig);
    DefaultDiscoveryService service = new DefaultDiscoveryService(settings);
    Iterator<DiscoveryStrategy> strategies = service.getDiscoveryStrategies().iterator();
    return strategies.next();
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) InputStream(java.io.InputStream) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy)

Example 2 with DefaultDiscoveryService

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryService in project hazelcast by hazelcast.

the class SPIAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Set<MemberGroup> memberGroups = new HashSet<MemberGroup>();
    for (Member member : allMembers) {
        try {
            if (member.localMember()) {
                DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
                // If no discovery strategy is found fail-fast
                if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
                    throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
                } else {
                    for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
                        checkNotNull(discoveryStrategy.getPartitionGroupStrategy());
                        Iterable<MemberGroup> spiGroupsIterator = discoveryStrategy.getPartitionGroupStrategy().getMemberGroups();
                        for (MemberGroup group : spiGroupsIterator) {
                            memberGroups.add(group);
                        }
                        return memberGroups;
                    }
                }
            }
        } catch (Exception e) {
            if (e instanceof ValidationException) {
                throw new InvalidConfigurationException("Invalid configuration", e);
            } else {
                throw new RuntimeException("Failed to configure discovery strategies", e);
            }
        }
    }
    return memberGroups;
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.core.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) HashSet(java.util.HashSet) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 3 with DefaultDiscoveryService

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryService in project hazelcast by hazelcast.

the class SPIAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Set<MemberGroup> memberGroups = createHashSet(allMembers.size());
    for (Member member : allMembers) {
        try {
            if (member.localMember()) {
                DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
                // If no discovery strategy is found fail-fast
                if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
                    throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
                } else {
                    for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
                        PartitionGroupStrategy groupStrategy = discoveryStrategy.getPartitionGroupStrategy(allMembers);
                        if (groupStrategy == null) {
                            groupStrategy = discoveryStrategy.getPartitionGroupStrategy();
                        }
                        checkNotNull(groupStrategy);
                        for (MemberGroup group : groupStrategy.getMemberGroups()) {
                            memberGroups.add(group);
                        }
                        return memberGroups;
                    }
                }
            }
        } catch (Exception e) {
            if (e instanceof ValidationException) {
                throw new InvalidConfigurationException("Invalid configuration", e);
            } else {
                throw new RuntimeException("Failed to configure discovery strategies", e);
            }
        }
    }
    return memberGroups;
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) ValidationException(com.hazelcast.config.properties.ValidationException) PartitionGroupStrategy(com.hazelcast.spi.partitiongroup.PartitionGroupStrategy) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.cluster.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 4 with DefaultDiscoveryService

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryService in project hazelcast by hazelcast.

the class GcpDiscoveryStrategyFactoryTest method createStrategy.

private static DiscoveryStrategy createStrategy(String xmlFileName) {
    final InputStream xmlResource = GcpDiscoveryStrategyFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
    DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setDiscoveryConfig(discoveryConfig);
    DefaultDiscoveryService service = new DefaultDiscoveryService(settings);
    Iterator<DiscoveryStrategy> strategies = service.getDiscoveryStrategies().iterator();
    return strategies.next();
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) InputStream(java.io.InputStream) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy)

Example 5 with DefaultDiscoveryService

use of com.hazelcast.spi.discovery.impl.DefaultDiscoveryService in project hazelcast by hazelcast.

the class AwsDiscoveryStrategyFactoryTest method validateConfig.

private void validateConfig(final Config config) {
    final DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
    final DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setDiscoveryConfig(discoveryConfig);
    final DefaultDiscoveryService service = new DefaultDiscoveryService(settings);
    final Iterator<DiscoveryStrategy> strategies = service.getDiscoveryStrategies().iterator();
    assertTrue(strategies.hasNext());
    final DiscoveryStrategy strategy = strategies.next();
    assertTrue(strategy instanceof AwsDiscoveryStrategy);
}
Also used : DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy)

Aggregations

DiscoveryStrategy (com.hazelcast.spi.discovery.DiscoveryStrategy)5 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)5 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)3 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)3 WireMockConfiguration.wireMockConfig (com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig)2 Config (com.hazelcast.config.Config)2 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)2 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)2 ValidationException (com.hazelcast.config.properties.ValidationException)2 InputStream (java.io.InputStream)2 Member (com.hazelcast.cluster.Member)1 Member (com.hazelcast.core.Member)1 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)1 PartitionGroupStrategy (com.hazelcast.spi.partitiongroup.PartitionGroupStrategy)1 HashSet (java.util.HashSet)1