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