Search in sources :

Example 11 with DiscoveryConfig

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"));
}
Also used : AwsConfig(com.hazelcast.config.AwsConfig) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) InputStream(java.io.InputStream) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with DiscoveryConfig

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);
}
Also used : DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) List(java.util.List) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with DiscoveryConfig

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"));
}
Also used : AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) Iterator(java.util.Iterator) List(java.util.List) IList(com.hazelcast.core.IList) TcpIpConfig(com.hazelcast.config.TcpIpConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 14 with DiscoveryConfig

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;
}
Also used : DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) ILogger(com.hazelcast.logging.ILogger) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 15 with DiscoveryConfig

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);
        }
    }
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ArrayList(java.util.ArrayList) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) HazelcastException(com.hazelcast.core.HazelcastException) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig)

Aggregations

DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)15 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)9 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)7 AwsConfig (com.hazelcast.config.AwsConfig)7 InputStream (java.io.InputStream)7 ClientConfig (com.hazelcast.client.config.ClientConfig)6 JoinConfig (com.hazelcast.config.JoinConfig)6 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)6 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)6 Config (com.hazelcast.config.Config)5 InterfacesConfig (com.hazelcast.config.InterfacesConfig)5 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)5 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)4 TcpIpConfig (com.hazelcast.config.TcpIpConfig)4 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)4 MulticastConfig (com.hazelcast.config.MulticastConfig)3 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)3 Address (com.hazelcast.nio.Address)3