Search in sources :

Example 36 with InvalidConfigurationException

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

the class YamlClientFailoverDomConfigProcessor method handleClients.

@Override
protected void handleClients(Node node) {
    boolean clientConfigDefined = false;
    for (Node child : childElements(node)) {
        String clientPath = getTextContent(child);
        try {
            ClientConfig config = new YamlClientConfigBuilder(clientPath).build();
            clientFailoverConfig.addClientConfig(config);
            clientConfigDefined = true;
        } catch (IOException e) {
            throw new InvalidConfigurationException("Could not create the config from given path : " + clientPath, e);
        }
    }
    if (!clientConfigDefined) {
        String path = ((YamlElementAdapter) node).getYamlNode().path();
        throw new InvalidConfigurationException(String.format("At least one client configuration must be defined " + "under '%s'", path));
    }
}
Also used : YamlClientConfigBuilder(com.hazelcast.client.config.YamlClientConfigBuilder) Node(org.w3c.dom.Node) IOException(java.io.IOException) ClientConfig(com.hazelcast.client.config.ClientConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 37 with InvalidConfigurationException

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

the class ConfigFactory method newEvictionConfig.

public static EvictionConfig newEvictionConfig(Integer maxSize, MaxSizePolicy maxSizePolicy, EvictionPolicy evictionPolicy, boolean isNearCache, boolean isIMap, String comparatorClassName, EvictionPolicyComparator<?, ?, ?> comparator) {
    int finalSize = maxSize(maxSize, isIMap);
    MaxSizePolicy finalMaxSizePolicy = maxSizePolicy(maxSizePolicy, isIMap);
    EvictionPolicy finalEvictionPolicy = evictionPolicy(evictionPolicy, isIMap);
    try {
        doEvictionConfigChecks(finalMaxSizePolicy, finalEvictionPolicy, comparatorClassName, comparator, isIMap, isNearCache);
    } catch (IllegalArgumentException e) {
        throw new InvalidConfigurationException(e.getMessage());
    }
    EvictionConfig evictionConfig = new EvictionConfig().setSize(finalSize).setMaxSizePolicy(finalMaxSizePolicy).setEvictionPolicy(finalEvictionPolicy);
    if (comparatorClassName != null) {
        evictionConfig.setComparatorClassName(comparatorClassName);
    }
    if (comparator != null) {
        evictionConfig.setComparator(comparator);
    }
    return evictionConfig;
}
Also used : MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) EvictionPolicy(com.hazelcast.config.EvictionPolicy) ConfigValidator.checkNearCacheEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkNearCacheEvictionConfig) ConfigValidator.checkEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkEvictionConfig) ConfigValidator.checkMapEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkMapEvictionConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 38 with InvalidConfigurationException

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

the class DefaultDiscoveryService method loadDiscoveryStrategies.

private Iterable<DiscoveryStrategy> loadDiscoveryStrategies(DiscoveryServiceSettings settings) {
    ClassLoader configClassLoader = settings.getConfigClassLoader();
    try {
        Collection<DiscoveryStrategyConfig> discoveryStrategyConfigs = new ArrayList<DiscoveryStrategyConfig>(settings.getAllDiscoveryConfigs());
        List<DiscoveryStrategyFactory> factories = collectFactories(discoveryStrategyConfigs, configClassLoader);
        List<DiscoveryStrategy> discoveryStrategies = new ArrayList<DiscoveryStrategy>();
        for (DiscoveryStrategyConfig config : discoveryStrategyConfigs) {
            DiscoveryStrategy discoveryStrategy = buildDiscoveryStrategy(config, factories);
            discoveryStrategies.add(discoveryStrategy);
        }
        if (discoveryStrategies.isEmpty() && settings.isAutoDetectionEnabled()) {
            logger.fine("Discovery auto-detection enabled, looking for available discovery strategies");
            DiscoveryStrategyFactory autoDetectedFactory = detectDiscoveryStrategyFactory(factories);
            if (autoDetectedFactory != null) {
                logger.info(String.format("Auto-detection selected discovery strategy: %s", autoDetectedFactory.getClass()));
                discoveryStrategies.add(autoDetectedFactory.newDiscoveryStrategy(discoveryNode, logger, Collections.emptyMap()));
            } else {
                logger.fine("No discovery strategy is applicable for auto-detection");
            }
        }
        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 : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ArrayList(java.util.ArrayList) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 39 with InvalidConfigurationException

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

the class DiscoveryServicePropertiesUtil method prepareProperties.

/**
 * Validates, verifies, and maps {@code properties} with the given {@code propertyDefinitions}.
 *
 * @param properties          properties from the Hazelcast node configuration (from the service-discovery section)
 * @param propertyDefinitions property definitions specific for the given
 *                            {@link com.hazelcast.spi.discovery.DiscoveryStrategy}
 * @return mapped properties
 * @throws InvalidConfigurationException if the the required properties are not satisfied or any property is not not
 *                                       applicable to the given definitions
 * @throws ValidationException           if any property is invalid
 */
static Map<String, Comparable> prepareProperties(Map<String, Comparable> properties, Collection<PropertyDefinition> propertyDefinitions) {
    Map<String, Comparable> mappedProperties = createHashMap(propertyDefinitions.size());
    for (PropertyDefinition propertyDefinition : propertyDefinitions) {
        String propertyKey = propertyDefinition.key();
        if (properties.containsKey(propertyKey.replace("-", ""))) {
            properties.put(propertyKey, properties.remove(propertyKey.replace("-", "")));
        }
        if (!properties.containsKey(propertyKey)) {
            if (!propertyDefinition.optional()) {
                throw new InvalidConfigurationException(String.format("Missing property '%s' on discovery strategy", propertyKey));
            }
            continue;
        }
        Comparable value = properties.get(propertyKey);
        TypeConverter typeConverter = propertyDefinition.typeConverter();
        Comparable mappedValue = typeConverter.convert(value);
        ValueValidator validator = propertyDefinition.validator();
        if (validator != null) {
            validator.validate(mappedValue);
        }
        mappedProperties.put(propertyKey, mappedValue);
    }
    verifyNoUnknownProperties(mappedProperties, properties);
    return mappedProperties;
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) ValueValidator(com.hazelcast.config.properties.ValueValidator) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 40 with InvalidConfigurationException

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

the class WanReplicationServiceImpl method createPublishers.

private ConcurrentMap<String, WanPublisher> createPublishers(WanReplicationConfig wanReplicationConfig) {
    List<WanCustomPublisherConfig> customPublisherConfigs = wanReplicationConfig.getCustomPublisherConfigs();
    int publisherCount = customPublisherConfigs.size();
    if (publisherCount == 0) {
        return createConcurrentHashMap(1);
    }
    ConcurrentMap<String, WanPublisher> publishers = createConcurrentHashMap(publisherCount);
    Map<String, AbstractWanPublisherConfig> publisherConfigs = createHashMap(publisherCount);
    customPublisherConfigs.forEach(publisherConfig -> {
        String publisherId = getWanPublisherId(publisherConfig);
        if (publishers.containsKey(publisherId)) {
            throw new InvalidConfigurationException("Detected duplicate publisher ID '" + publisherId + "' for a single WAN replication config");
        }
        WanPublisher publisher = createPublisher(publisherConfig);
        publishers.put(publisherId, publisher);
        publisherConfigs.put(publisherId, publisherConfig);
    });
    for (Entry<String, WanPublisher> publisherEntry : publishers.entrySet()) {
        String publisherId = publisherEntry.getKey();
        WanPublisher publisher = publisherEntry.getValue();
        ManagedContext managedContext = node.getSerializationService().getManagedContext();
        publisher = (WanPublisher) managedContext.initialize(publisher);
        publisher.init(wanReplicationConfig, publisherConfigs.get(publisherId));
    }
    return publishers;
}
Also used : WanPublisher(com.hazelcast.wan.WanPublisher) WanCustomPublisherConfig(com.hazelcast.config.WanCustomPublisherConfig) AbstractWanPublisherConfig(com.hazelcast.config.AbstractWanPublisherConfig) ManagedContext(com.hazelcast.core.ManagedContext) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)43 Node (org.w3c.dom.Node)19 YamlNode (com.hazelcast.internal.yaml.YamlNode)5 IOException (java.io.IOException)5 EvictionConfig (com.hazelcast.config.EvictionConfig)3 ValidationException (com.hazelcast.config.properties.ValidationException)3 YamlMapping (com.hazelcast.internal.yaml.YamlMapping)3 DiscoveryStrategy (com.hazelcast.spi.discovery.DiscoveryStrategy)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)2 Member (com.hazelcast.cluster.Member)2 EventJournalConfig (com.hazelcast.config.EventJournalConfig)2 EvictionPolicy (com.hazelcast.config.EvictionPolicy)2 MaxSizePolicy (com.hazelcast.config.MaxSizePolicy)2 OnJoinPermissionOperationName (com.hazelcast.config.OnJoinPermissionOperationName)2 PermissionType (com.hazelcast.config.PermissionConfig.PermissionType)2 PredicateConfig (com.hazelcast.config.PredicateConfig)2 WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)2 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)2 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)2