Search in sources :

Example 6 with DiscoveryStrategyConfig

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);
}
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 7 with DiscoveryStrategyConfig

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"));
}
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 8 with DiscoveryStrategyConfig

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));
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) HashMap(java.util.HashMap) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) Node(org.w3c.dom.Node)

Example 9 with DiscoveryStrategyConfig

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

Example 10 with DiscoveryStrategyConfig

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;
}
Also used : DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig)

Aggregations

DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)10 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)8 AwsConfig (com.hazelcast.config.AwsConfig)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Config (com.hazelcast.config.Config)4 InterfacesConfig (com.hazelcast.config.InterfacesConfig)4 JoinConfig (com.hazelcast.config.JoinConfig)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)3 TcpIpConfig (com.hazelcast.config.TcpIpConfig)3 DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)3 InputStream (java.io.InputStream)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 MulticastConfig (com.hazelcast.config.MulticastConfig)2 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)2 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)2 List (java.util.List)2