Search in sources :

Example 1 with HazelcastProperties

use of org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties in project cas by apereo.

the class HazelcastMonitor method getStatistics.

@Override
protected CacheStatistics[] getStatistics() {
    final List<CacheStatistics> statsList = new ArrayList<>();
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    LOGGER.debug("Locating hazelcast instance [{}]...", hz.getCluster().getInstanceName());
    final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(hz.getCluster().getInstanceName());
    instance.getConfig().getMapConfigs().keySet().forEach(key -> {
        final IMap map = instance.getMap(key);
        LOGGER.debug("Starting to collect hazelcast statistics for map [{}] identified by key [{}]...", map, key);
        statsList.add(new HazelcastStatistics(map, hz.getCluster().getMembers().size()));
    });
    return statsList.toArray(new CacheStatistics[statsList.size()]);
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList)

Example 2 with HazelcastProperties

use of org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties in project cas by apereo.

the class HazelcastTicketRegistryConfiguration method ticketRegistry.

@Autowired
@Bean
public TicketRegistry ticketRegistry(@Qualifier("ticketCatalog") final TicketCatalog ticketCatalog) {
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    final HazelcastTicketRegistry r = new HazelcastTicketRegistry(hazelcast(ticketCatalog), ticketCatalog, hz.getPageSize());
    r.setCipherExecutor(Beans.newTicketRegistryCipherExecutor(hz.getCrypto()));
    return r;
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) HazelcastTicketRegistry(org.apereo.cas.ticket.registry.HazelcastTicketRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) Bean(org.springframework.context.annotation.Bean)

Example 3 with HazelcastProperties

use of org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties 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 4 with HazelcastProperties

use of org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties in project cas by apereo.

the class HazelcastTicketRegistryConfiguration method createMapConfig.

private MapConfig createMapConfig(final TicketDefinition definition) {
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    final HazelcastProperties.Cluster cluster = hz.getCluster();
    final EvictionPolicy evictionPolicy = EvictionPolicy.valueOf(cluster.getEvictionPolicy());
    LOGGER.debug("Creating Hazelcast map configuration for [{}] with idle timeout [{}] second(s)", definition.getProperties().getStorageName(), definition.getProperties().getStorageTimeout());
    return new MapConfig().setName(definition.getProperties().getStorageName()).setMaxIdleSeconds((int) definition.getProperties().getStorageTimeout()).setBackupCount(cluster.getBackupCount()).setAsyncBackupCount(cluster.getAsyncBackupCount()).setEvictionPolicy(evictionPolicy).setMaxSizeConfig(new MaxSizeConfig().setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(cluster.getMaxSizePolicy())).setSize(cluster.getMaxHeapSizePercentage()));
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) EvictionPolicy(com.hazelcast.config.EvictionPolicy) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

HazelcastProperties (org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties)4 MapConfig (com.hazelcast.config.MapConfig)2 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)2 Config (com.hazelcast.config.Config)1 EvictionPolicy (com.hazelcast.config.EvictionPolicy)1 JoinConfig (com.hazelcast.config.JoinConfig)1 MulticastConfig (com.hazelcast.config.MulticastConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1 TcpIpConfig (com.hazelcast.config.TcpIpConfig)1 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HazelcastTicketRegistry (org.apereo.cas.ticket.registry.HazelcastTicketRegistry)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Bean (org.springframework.context.annotation.Bean)1