use of com.hazelcast.config.DiscoveryConfig in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testParsing.
@Test
public void testParsing() throws Exception {
String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
AwsConfig awsConfig = networkConfig.getAwsConfig();
assertNull(awsConfig);
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
assertTrue(discoveryConfig.isEnabled());
assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());
DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
assertEquals(3, providerConfig.getProperties().size());
assertEquals("foo", providerConfig.getProperties().get("key-string"));
assertEquals("123", providerConfig.getProperties().get("key-int"));
assertEquals("true", providerConfig.getProperties().get("key-boolean"));
}
use of com.hazelcast.config.DiscoveryConfig 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.DiscoveryConfig 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.DiscoveryConfig in project hazelcast by hazelcast.
the class HazelcastClientInstanceImpl method initDiscoveryService.
private DiscoveryService initDiscoveryService(ClientConfig config) {
// and strategies are resolved but the AddressProvider is never registered
if (!properties.getBoolean(ClientProperty.DISCOVERY_SPI_ENABLED)) {
return null;
}
ILogger logger = loggingService.getLogger(DiscoveryService.class);
ClientNetworkConfig networkConfig = config.getNetworkConfig();
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig().getAsReadOnly();
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(config.getClassLoader()).setLogger(logger).setDiscoveryMode(DiscoveryMode.Client).setDiscoveryConfig(discoveryConfig);
DiscoveryService discoveryService = factory.newDiscoveryService(settings);
discoveryService.start();
return discoveryService;
}
use of com.hazelcast.config.DiscoveryConfig 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);
}
}
}
Aggregations