use of com.hazelcast.config.properties.ValidationException in project hazelcast by hazelcast.
the class DefaultDiscoveryService method buildDiscoveryStrategy.
private DiscoveryStrategy buildDiscoveryStrategy(DiscoveryStrategyConfig config, List<DiscoveryStrategyFactory> candidateFactories) {
for (DiscoveryStrategyFactory factory : candidateFactories) {
Class<? extends DiscoveryStrategy> discoveryStrategyType = factory.getDiscoveryStrategyType();
String className = discoveryStrategyType.getName();
String factoryClassName = getFactoryClassName(config);
if (className.equals(factoryClassName)) {
Map<String, Comparable> properties = DiscoveryServicePropertiesUtil.prepareProperties(config.getProperties(), nullToEmpty(factory.getConfigurationProperties()));
return factory.newDiscoveryStrategy(discoveryNode, logger, properties);
}
}
throw new ValidationException("There is no discovery strategy factory to create '" + config + "' Is it a typo in a strategy classname? " + "Perhaps you forgot to include implementation on a classpath?");
}
use of com.hazelcast.config.properties.ValidationException in project hazelcast by hazelcast.
the class SPIAwareMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
Set<MemberGroup> memberGroups = new HashSet<MemberGroup>();
for (Member member : allMembers) {
try {
if (member.localMember()) {
DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
// If no discovery strategy is found fail-fast
if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
} else {
for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
checkNotNull(discoveryStrategy.getPartitionGroupStrategy());
Iterable<MemberGroup> spiGroupsIterator = discoveryStrategy.getPartitionGroupStrategy().getMemberGroups();
for (MemberGroup group : spiGroupsIterator) {
memberGroups.add(group);
}
return memberGroups;
}
}
}
} catch (Exception e) {
if (e instanceof ValidationException) {
throw new InvalidConfigurationException("Invalid configuration", e);
} else {
throw new RuntimeException("Failed to configure discovery strategies", e);
}
}
}
return memberGroups;
}
use of com.hazelcast.config.properties.ValidationException 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.properties.ValidationException in project hazelcast by hazelcast.
the class SPIAwareMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
Set<MemberGroup> memberGroups = createHashSet(allMembers.size());
for (Member member : allMembers) {
try {
if (member.localMember()) {
DefaultDiscoveryService defaultDiscoveryService = (DefaultDiscoveryService) discoveryService;
// If no discovery strategy is found fail-fast
if (!defaultDiscoveryService.getDiscoveryStrategies().iterator().hasNext()) {
throw new RuntimeException("Could not load any Discovery Strategy, please " + "check service definitions under META_INF.services folder. ");
} else {
for (DiscoveryStrategy discoveryStrategy : defaultDiscoveryService.getDiscoveryStrategies()) {
PartitionGroupStrategy groupStrategy = discoveryStrategy.getPartitionGroupStrategy(allMembers);
if (groupStrategy == null) {
groupStrategy = discoveryStrategy.getPartitionGroupStrategy();
}
checkNotNull(groupStrategy);
for (MemberGroup group : groupStrategy.getMemberGroups()) {
memberGroups.add(group);
}
return memberGroups;
}
}
}
} catch (Exception e) {
if (e instanceof ValidationException) {
throw new InvalidConfigurationException("Invalid configuration", e);
} else {
throw new RuntimeException("Failed to configure discovery strategies", e);
}
}
}
return memberGroups;
}
use of com.hazelcast.config.properties.ValidationException in project hazelcast by hazelcast.
the class DiscoveryServicePropertiesUtilTest method invalidProperty.
@Test(expected = ValidationException.class)
public void invalidProperty() {
// given
Map<String, Comparable> properties = new HashMap<>(singletonMap(PROPERTY_KEY_1, (Comparable) PROPERTY_VALUE_1));
ValueValidator<String> valueValidator = mock(ValueValidator.class);
willThrow(new ValidationException("Invalid property")).given(valueValidator).validate(PROPERTY_VALUE_1);
Collection<PropertyDefinition> propertyDefinitions = singletonList((PropertyDefinition) new SimplePropertyDefinition(PROPERTY_KEY_1, false, STRING, new DummyValidator()));
// when
prepareProperties(properties, propertyDefinitions);
// then
// throw exception
}
Aggregations