Search in sources :

Example 11 with InvalidConfigurationException

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

the class ConfigValidator method checkNearCacheConfig.

/**
 * Checks preconditions to create a map proxy with Near Cache.
 *
 * @param mapName            name of the map that Near Cache will be created for
 * @param nearCacheConfig    the {@link NearCacheConfig} to be checked
 * @param nativeMemoryConfig the {@link NativeMemoryConfig} of the Hazelcast instance
 * @param isClient           {@code true} if the config is for a Hazelcast client, {@code false} otherwise
 */
public static void checkNearCacheConfig(String mapName, NearCacheConfig nearCacheConfig, NativeMemoryConfig nativeMemoryConfig, boolean isClient) {
    checkNotNativeWhenOpenSource(nearCacheConfig.getInMemoryFormat());
    checkLocalUpdatePolicy(mapName, nearCacheConfig.getLocalUpdatePolicy());
    EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig();
    checkNearCacheEvictionConfig(evictionConfig.getEvictionPolicy(), evictionConfig.getComparatorClassName(), evictionConfig.getComparator());
    checkOnHeapNearCacheMaxSizePolicy(nearCacheConfig);
    checkNearCacheNativeMemoryConfig(nearCacheConfig.getInMemoryFormat(), nativeMemoryConfig, getBuildInfo().isEnterprise());
    if (isClient && nearCacheConfig.isCacheLocalEntries()) {
        throw new InvalidConfigurationException("The Near Cache option `cache-local-entries` is not supported in " + "client configurations.");
    }
    checkPreloaderConfig(nearCacheConfig, isClient);
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 12 with InvalidConfigurationException

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

the class ConfigValidator method checkAdvancedNetworkConfig.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:booleanexpressioncomplexity" })
public static void checkAdvancedNetworkConfig(Config config) {
    if (!config.getAdvancedNetworkConfig().isEnabled()) {
        return;
    }
    EnumMap<ProtocolType, MutableInteger> serverSocketsPerProtocolType = new EnumMap<>(ProtocolType.class);
    for (ProtocolType protocolType : ProtocolType.values()) {
        serverSocketsPerProtocolType.put(protocolType, new MutableInteger());
    }
    Map<EndpointQualifier, EndpointConfig> endpointConfigs = config.getAdvancedNetworkConfig().getEndpointConfigs();
    for (EndpointConfig endpointConfig : endpointConfigs.values()) {
        if (endpointConfig instanceof ServerSocketEndpointConfig) {
            serverSocketsPerProtocolType.get(endpointConfig.getProtocolType()).getAndInc();
        }
    }
    for (ProtocolType protocolType : ProtocolType.values()) {
        int serverSocketCount = serverSocketsPerProtocolType.get(protocolType).value;
        if (serverSocketCount > protocolType.getServerSocketCardinality()) {
            throw new InvalidConfigurationException(format("Protocol type %s allows definition " + "of up to %d server sockets but %d were configured", protocolType, protocolType.getServerSocketCardinality(), serverSocketCount));
        }
    }
    // ensure there is 1 MEMBER type server socket
    if (serverSocketsPerProtocolType.get(MEMBER).value != 1) {
        throw new InvalidConfigurationException("A member-server-socket-endpoint" + " configuration is required for the cluster to form.");
    }
    // endpoint qualifiers referenced by WAN publishers must exist
    for (WanReplicationConfig wanReplicationConfig : config.getWanReplicationConfigs().values()) {
        for (WanBatchPublisherConfig wanPublisherConfig : wanReplicationConfig.getBatchPublisherConfigs()) {
            if (wanPublisherConfig.getEndpoint() != null) {
                EndpointQualifier qualifier = EndpointQualifier.resolve(WAN, wanPublisherConfig.getEndpoint());
                if (endpointConfigs.get(qualifier) == null) {
                    throw new InvalidConfigurationException(format("WAN publisher config for cluster name '%s' requires an wan-endpoint " + "config with identifier '%s' but none was found", wanPublisherConfig.getClusterName(), wanPublisherConfig.getEndpoint()));
                }
            }
        }
    }
}
Also used : WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) ProtocolType(com.hazelcast.instance.ProtocolType) MutableInteger(com.hazelcast.internal.util.MutableInteger) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) EnumMap(java.util.EnumMap) EndpointConfig(com.hazelcast.config.EndpointConfig) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 13 with InvalidConfigurationException

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

the class ConfigValidator method checkOnHeapNearCacheMaxSizePolicy.

private static void checkOnHeapNearCacheMaxSizePolicy(NearCacheConfig nearCacheConfig) {
    InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat();
    if (inMemoryFormat == NATIVE) {
        return;
    }
    MaxSizePolicy maxSizePolicy = nearCacheConfig.getEvictionConfig().getMaxSizePolicy();
    if (!NEAR_CACHE_SUPPORTED_ON_HEAP_MAX_SIZE_POLICIES.contains(maxSizePolicy)) {
        throw new InvalidConfigurationException(format("Near Cache maximum size policy %s cannot be used with %s storage." + " Supported maximum size policies are: %s", maxSizePolicy, inMemoryFormat, NEAR_CACHE_SUPPORTED_ON_HEAP_MAX_SIZE_POLICIES));
    }
}
Also used : MaxSizePolicy(com.hazelcast.config.MaxSizePolicy) InMemoryFormat(com.hazelcast.config.InMemoryFormat) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 14 with InvalidConfigurationException

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

the class AbstractDomConfigProcessor method handlePersistentMemoryConfig.

private void handlePersistentMemoryConfig(PersistentMemoryConfig persistentMemoryConfig, Node node) {
    Node enabledNode = getNamedItemNode(node, "enabled");
    if (enabledNode != null) {
        boolean enabled = getBooleanValue(getTextContent(enabledNode));
        persistentMemoryConfig.setEnabled(enabled);
    }
    final Node modeNode = getNamedItemNode(node, "mode");
    final String modeStr = getTextContent(modeNode);
    PersistentMemoryMode mode = PersistentMemoryMode.MOUNTED;
    if (!StringUtil.isNullOrEmptyAfterTrim(modeStr)) {
        try {
            mode = PersistentMemoryMode.valueOf(modeStr);
            persistentMemoryConfig.setMode(mode);
        } catch (Exception ex) {
            throw new InvalidConfigurationException("Invalid 'mode' for 'persistent-memory': " + modeStr);
        }
    }
    for (Node parent : childElements(node)) {
        final String nodeName = cleanNodeName(parent);
        if (matches("directories", nodeName)) {
            if (PersistentMemoryMode.SYSTEM_MEMORY == mode) {
                throw new InvalidConfigurationException("Directories for 'persistent-memory' should only be" + " defined if the 'mode' is set to '" + PersistentMemoryMode.MOUNTED.name() + "'");
            }
            for (Node dirNode : childElements(parent)) {
                handlePersistentMemoryDirectory(persistentMemoryConfig, dirNode);
            }
        }
    }
}
Also used : PersistentMemoryMode(com.hazelcast.config.PersistentMemoryMode) Node(org.w3c.dom.Node) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 15 with InvalidConfigurationException

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

the class DefaultNodeContext method newMemberAddressProviderInstance.

@SuppressWarnings("checkstyle:npathcomplexity")
private static // would make it harder to read
MemberAddressProvider newMemberAddressProviderInstance(Class<? extends MemberAddressProvider> clazz, ILogger logger, Properties properties) {
    Properties nonNullProps = properties == null ? new Properties() : properties;
    MemberAddressProvider provider = InstantiationUtils.newInstanceOrNull(clazz, nonNullProps, logger);
    if (provider == null) {
        provider = InstantiationUtils.newInstanceOrNull(clazz, logger, nonNullProps);
    }
    if (provider == null) {
        provider = InstantiationUtils.newInstanceOrNull(clazz, nonNullProps);
    }
    if (provider == null) {
        if (properties != null && !properties.isEmpty()) {
            throw new InvalidConfigurationException("Cannot find a matching constructor for MemberAddressProvider.  " + "The member address provider has properties configured, but the class " + "'" + clazz.getName() + "' does not have a public constructor accepting properties.");
        }
        provider = InstantiationUtils.newInstanceOrNull(clazz, logger);
    }
    if (provider == null) {
        provider = InstantiationUtils.newInstanceOrNull(clazz);
    }
    if (provider == null) {
        throw new InvalidConfigurationException("Cannot find a matching constructor for MemberAddressProvider " + "implementation '" + clazz.getName() + "'.");
    }
    return provider;
}
Also used : MemberAddressProvider(com.hazelcast.spi.MemberAddressProvider) Properties(java.util.Properties) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) 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