use of com.hazelcast.config.DiscoveryStrategyConfig in project hazelcast by hazelcast.
the class TestClientNetworkConfig method smokeDiscoverySpiConfig.
@Test
public void smokeDiscoverySpiConfig() {
DiscoveryConfig discoveryConfig = client.getClientConfig().getNetworkConfig().getDiscoveryConfig();
assertNull(discoveryConfig.getDiscoveryServiceProvider());
assertTrue(discoveryConfig.getNodeFilter() instanceof DummyNodeFilter);
List<DiscoveryStrategyConfig> discoveryStrategyConfigs = (List<DiscoveryStrategyConfig>) discoveryConfig.getDiscoveryStrategyConfigs();
assertEquals(4, discoveryStrategyConfigs.size());
DiscoveryStrategyConfig discoveryStrategyConfig = discoveryStrategyConfigs.get(0);
assertTrue(discoveryStrategyConfig.getDiscoveryStrategyFactory() instanceof DummyDiscoveryStrategyFactory);
assertEquals(3, discoveryStrategyConfig.getProperties().size());
assertEquals("foo", discoveryStrategyConfig.getProperties().get("key-string"));
assertEquals("123", discoveryStrategyConfig.getProperties().get("key-int"));
assertEquals("true", discoveryStrategyConfig.getProperties().get("key-boolean"));
DiscoveryStrategyConfig discoveryStrategyConfig2 = discoveryStrategyConfigs.get(1);
assertEquals(DummyDiscoveryStrategy.class.getName(), discoveryStrategyConfig2.getClassName());
assertEquals(1, discoveryStrategyConfig2.getProperties().size());
assertEquals("foo2", discoveryStrategyConfig2.getProperties().get("key-string"));
DiscoveryStrategyConfig discoveryStrategyConfig3 = discoveryStrategyConfigs.get(2);
assertEquals(DummyDiscoveryStrategy.class.getName(), discoveryStrategyConfig3.getClassName());
DiscoveryStrategyConfig discoveryStrategyConfig4 = discoveryStrategyConfigs.get(3);
assertTrue(discoveryStrategyConfig4.getDiscoveryStrategyFactory() instanceof DummyDiscoveryStrategyFactory);
}
use of com.hazelcast.config.DiscoveryStrategyConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testNetworkConfig.
@Test
public void testNetworkConfig() {
NetworkConfig networkConfig = config.getNetworkConfig();
assertNotNull(networkConfig);
assertEquals(5700, networkConfig.getPort());
assertFalse(networkConfig.isPortAutoIncrement());
Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
assertEquals(2, allowedPorts.size());
Iterator portIter = allowedPorts.iterator();
assertEquals("35000-35100", portIter.next());
assertEquals("36000,36100", portIter.next());
assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
assertEquals(false, networkConfig.getJoin().getMulticastConfig().isLoopbackModeEnabled());
Set<String> tis = networkConfig.getJoin().getMulticastConfig().getTrustedInterfaces();
assertEquals(1, tis.size());
assertEquals("10.10.10.*", tis.iterator().next());
assertFalse(networkConfig.getInterfaces().isEnabled());
assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
assertNotNull(tcp);
assertTrue(tcp.isEnabled());
assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
List<String> members = tcp.getMembers();
assertEquals(members.toString(), 2, members.size());
assertEquals("127.0.0.1:5700", members.get(0));
assertEquals("127.0.0.1:5701", members.get(1));
assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
AwsConfig aws = networkConfig.getJoin().getAwsConfig();
assertFalse(aws.isEnabled());
assertEquals("sample-access-key", aws.getAccessKey());
assertEquals("sample-secret-key", aws.getSecretKey());
assertEquals("sample-region", aws.getRegion());
assertEquals("sample-group", aws.getSecurityGroupName());
assertEquals("sample-tag-key", aws.getTagKey());
assertEquals("sample-tag-value", aws.getTagValue());
assertEquals("sample-role", aws.getIamRole());
assertTrue("reuse-address", networkConfig.isReuseAddress());
DiscoveryConfig discoveryConfig = networkConfig.getJoin().getDiscoveryConfig();
assertTrue(discoveryConfig.getDiscoveryServiceProvider() instanceof DummyDiscoveryServiceProvider);
assertTrue(discoveryConfig.getNodeFilter() instanceof DummyNodeFilter);
List<DiscoveryStrategyConfig> discoveryStrategyConfigs = (List<DiscoveryStrategyConfig>) discoveryConfig.getDiscoveryStrategyConfigs();
assertEquals(2, discoveryStrategyConfigs.size());
DiscoveryStrategyConfig discoveryStrategyConfig = discoveryStrategyConfigs.get(0);
assertTrue(discoveryStrategyConfig.getDiscoveryStrategyFactory() instanceof DummyDiscoveryStrategyFactory);
assertEquals(3, discoveryStrategyConfig.getProperties().size());
assertEquals("foo", discoveryStrategyConfig.getProperties().get("key-string"));
assertEquals("123", discoveryStrategyConfig.getProperties().get("key-int"));
assertEquals("true", discoveryStrategyConfig.getProperties().get("key-boolean"));
DiscoveryStrategyConfig discoveryStrategyConfig2 = discoveryStrategyConfigs.get(1);
assertEquals(DummyDiscoveryStrategy.class.getName(), discoveryStrategyConfig2.getClassName());
assertEquals(1, discoveryStrategyConfig2.getProperties().size());
assertEquals("foo2", discoveryStrategyConfig2.getProperties().get("key-string"));
}
use of com.hazelcast.config.DiscoveryStrategyConfig in project hazelcast by hazelcast.
the class XmlClientConfigBuilder method handleDiscoveryStrategy.
private void handleDiscoveryStrategy(Node node, DiscoveryConfig discoveryConfig) {
NamedNodeMap atts = node.getAttributes();
boolean enabled = false;
String clazz = null;
for (int a = 0; a < atts.getLength(); a++) {
Node att = atts.item(a);
String value = getTextContent(att).trim();
if ("enabled".equalsIgnoreCase(att.getNodeName())) {
enabled = getBooleanValue(value);
} else if ("class".equals(att.getNodeName())) {
clazz = value;
}
}
if (!enabled || clazz == null) {
return;
}
Map<String, Comparable> properties = new HashMap<String, Comparable>();
for (Node child : childElements(node)) {
String name = cleanNodeName(child);
if ("properties".equals(name)) {
fillProperties(child, properties);
}
}
discoveryConfig.addDiscoveryStrategyConfig(new DiscoveryStrategyConfig(clazz, properties));
}
use of com.hazelcast.config.DiscoveryStrategyConfig in project hazelcast by hazelcast.
the class DefaultDiscoveryService method loadDiscoveryStrategies.
private Iterable<DiscoveryStrategy> loadDiscoveryStrategies(DiscoveryServiceSettings settings) {
DiscoveryConfig discoveryConfig = settings.getDiscoveryConfig();
ClassLoader configClassLoader = settings.getConfigClassLoader();
try {
Collection<DiscoveryStrategyConfig> discoveryStrategyConfigs = new ArrayList<DiscoveryStrategyConfig>(discoveryConfig.getDiscoveryStrategyConfigs());
Iterator<DiscoveryStrategyFactory> iterator = ServiceLoader.iterator(DiscoveryStrategyFactory.class, SERVICE_LOADER_TAG, configClassLoader);
// Collect possible factories
List<DiscoveryStrategyFactory> factories = new ArrayList<DiscoveryStrategyFactory>();
while (iterator.hasNext()) {
factories.add(iterator.next());
}
for (DiscoveryStrategyConfig config : discoveryStrategyConfigs) {
DiscoveryStrategyFactory factory = config.getDiscoveryStrategyFactory();
if (factory != null) {
factories.add(factory);
}
}
List<DiscoveryStrategy> discoveryStrategies = new ArrayList<DiscoveryStrategy>();
for (DiscoveryStrategyFactory factory : factories) {
DiscoveryStrategy discoveryStrategy = buildDiscoveryStrategy(factory, discoveryStrategyConfigs);
if (discoveryStrategy != null) {
discoveryStrategies.add(discoveryStrategy);
}
}
return discoveryStrategies;
} catch (Exception e) {
if (e instanceof ValidationException) {
throw new InvalidConfigurationException("Invalid configuration", e);
} else {
throw new RuntimeException("Failed to configure discovery strategies", e);
}
}
}
use of com.hazelcast.config.DiscoveryStrategyConfig in project hazelcast by hazelcast.
the class DefaultDiscoveryService method buildDiscoveryStrategy.
private DiscoveryStrategy buildDiscoveryStrategy(DiscoveryStrategyFactory factory, Collection<DiscoveryStrategyConfig> discoveryStrategyConfigs) {
Class<? extends DiscoveryStrategy> discoveryStrategyType = factory.getDiscoveryStrategyType();
String className = discoveryStrategyType.getName();
for (DiscoveryStrategyConfig config : discoveryStrategyConfigs) {
String factoryClassName = getFactoryClassName(config);
if (className.equals(factoryClassName)) {
Map<String, Comparable> properties = buildProperties(factory, config, className);
return factory.newDiscoveryStrategy(discoveryNode, logger, properties);
}
}
return null;
}
Aggregations