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();
}
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;
}
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;
}
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();
}
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);
}
Aggregations