Search in sources :

Example 11 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project cas by apereo.

the class HazelcastTicketRegistryConfiguration method getConfig.

private Config getConfig(final TicketCatalog ticketCatalog) {
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    final HazelcastProperties.Cluster cluster = hz.getCluster();
    final Config config;
    if (hz.getConfigLocation() != null && hz.getConfigLocation().exists()) {
        try {
            final URL configUrl = hz.getConfigLocation().getURL();
            LOGGER.debug("Loading Hazelcast configuration from [{}]", configUrl);
            config = new XmlConfigBuilder(hz.getConfigLocation().getInputStream()).build();
            config.setConfigurationUrl(configUrl);
        } catch (final Exception e) {
            throw Throwables.propagate(e);
        }
    } else {
        // No config location, so do a default config programmatically with handful of properties exposed by CAS
        config = new Config();
        config.setProperty("hazelcast.prefer.ipv4.stack", String.valueOf(cluster.isIpv4Enabled()));
        // TCP config
        final TcpIpConfig tcpIpConfig = new TcpIpConfig().setEnabled(cluster.isTcpipEnabled()).setMembers(cluster.getMembers()).setConnectionTimeoutSeconds(cluster.getTimeout());
        LOGGER.debug("Created Hazelcast TCP/IP configuration [{}]", tcpIpConfig);
        // Multicast config
        final MulticastConfig multicastConfig = new MulticastConfig().setEnabled(cluster.isMulticastEnabled());
        if (cluster.isMulticastEnabled()) {
            multicastConfig.setMulticastGroup(cluster.getMulticastGroup());
            multicastConfig.setMulticastPort(cluster.getMulticastPort());
            final Set<String> trustedInterfaces = StringUtils.commaDelimitedListToSet(cluster.getMulticastTrustedInterfaces());
            if (!trustedInterfaces.isEmpty()) {
                multicastConfig.setTrustedInterfaces(trustedInterfaces);
            }
            multicastConfig.setMulticastTimeoutSeconds(cluster.getMulticastTimeout());
            multicastConfig.setMulticastTimeToLive(cluster.getMulticastTimeToLive());
        }
        LOGGER.debug("Created Hazelcast Multicast configuration [{}]", multicastConfig);
        // Join config
        final JoinConfig joinConfig = new JoinConfig().setMulticastConfig(multicastConfig).setTcpIpConfig(tcpIpConfig);
        LOGGER.debug("Created Hazelcast join configuration [{}]", joinConfig);
        // Network config
        final NetworkConfig networkConfig = new NetworkConfig().setPort(cluster.getPort()).setPortAutoIncrement(cluster.isPortAutoIncrement()).setJoin(joinConfig);
        LOGGER.debug("Created Hazelcast network configuration [{}]", networkConfig);
        // Finally aggregate all those config into the main Config
        config.setMapConfigs(buildHazelcastMapConfigurations(ticketCatalog)).setNetworkConfig(networkConfig);
    }
    // Add additional default config properties regardless of the configuration source
    return config.setInstanceName(cluster.getInstanceName()).setProperty(HazelcastProperties.LOGGING_TYPE_PROP, cluster.getLoggingType()).setProperty(HazelcastProperties.MAX_HEARTBEAT_SECONDS_PROP, String.valueOf(cluster.getMaxNoHeartbeatSeconds()));
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) MulticastConfig(com.hazelcast.config.MulticastConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) URL(java.net.URL)

Example 12 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project cas by apereo.

the class HazelcastSessionConfiguration method hazelcastInstance.

/**
     * Hazelcast instance that is used by the spring session
     * repository to broadcast session events. The name
     * of this bean must be left untouched.
     *
     * @return the hazelcast instance
     */
@Bean
public HazelcastInstance hazelcastInstance() {
    final Resource hzConfigResource = casProperties.getWebflow().getSession().getHzLocation();
    try {
        final URL configUrl = hzConfigResource.getURL();
        final Config config = new XmlConfigBuilder(hzConfigResource.getInputStream()).build();
        config.setConfigurationUrl(configUrl);
        config.setInstanceName(this.getClass().getSimpleName()).setProperty("hazelcast.logging.type", "slf4j").setProperty("hazelcast.max.no.heartbeat.seconds", "300");
        return Hazelcast.newHazelcastInstance(config);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) Config(com.hazelcast.config.Config) Resource(org.springframework.core.io.Resource) URL(java.net.URL) Bean(org.springframework.context.annotation.Bean)

Example 13 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.

the class DiscoverySpiTest method testParsing.

@Test
public void testParsing() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi.xml";
    InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    AwsConfig awsConfig = joinConfig.getAwsConfig();
    assertFalse(awsConfig.isEnabled());
    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    assertFalse(tcpIpConfig.isEnabled());
    MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
    assertFalse(multicastConfig.isEnabled());
    DiscoveryConfig discoveryConfig = joinConfig.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) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) InputStream(java.io.InputStream) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) JoinConfig(com.hazelcast.config.JoinConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.

the class DiscoverySpiTest method getDiscoverySPIConfig.

private static Config getDiscoverySPIConfig(String xmlFileName) {
    InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    config.getNetworkConfig().setPort(50001);
    InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
    interfaces.clear();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");
    List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
    DiscoveryStrategyFactory factory = new CollectingDiscoveryStrategyFactory(discoveryNodes);
    DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    return config;
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) InputStream(java.io.InputStream) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 15 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.

the class DiscoverySpiTest method test_metadata_discovery_on_node_startup.

@Test
public void test_metadata_discovery_on_node_startup() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
    InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(1);
    try {
        HazelcastInstance hazelcastInstance1 = instanceFactory.newHazelcastInstance(config);
        assertNotNull(hazelcastInstance1);
        Member localMember = hazelcastInstance1.getCluster().getLocalMember();
        assertEquals(Byte.MAX_VALUE, (byte) localMember.getByteAttribute("test-byte"));
        assertEquals(Short.MAX_VALUE, (short) localMember.getShortAttribute("test-short"));
        assertEquals(Integer.MAX_VALUE, (int) localMember.getIntAttribute("test-int"));
        assertEquals(Long.MAX_VALUE, (long) localMember.getLongAttribute("test-long"));
        assertEquals(Float.MAX_VALUE, localMember.getFloatAttribute("test-float"), 0);
        assertEquals(Double.MAX_VALUE, localMember.getDoubleAttribute("test-double"), 0);
        assertTrue(localMember.getBooleanAttribute("test-boolean"));
        assertEquals("TEST", localMember.getStringAttribute("test-string"));
    } finally {
        instanceFactory.shutdownAll();
    }
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InputStream(java.io.InputStream) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)25 Config (com.hazelcast.config.Config)20 Test (org.junit.Test)10 InputStream (java.io.InputStream)9 QuickTest (com.hazelcast.test.annotation.QuickTest)8 MapConfig (com.hazelcast.config.MapConfig)7 JoinConfig (com.hazelcast.config.JoinConfig)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 URL (java.net.URL)6 MapStoreConfig (com.hazelcast.config.MapStoreConfig)5 MulticastConfig (com.hazelcast.config.MulticastConfig)5 TcpIpConfig (com.hazelcast.config.TcpIpConfig)5 AwsConfig (com.hazelcast.config.AwsConfig)4 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)4 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)4 InterfacesConfig (com.hazelcast.config.InterfacesConfig)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2