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