use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class YamlDomChecker method check.
/**
* Performs {code @null} checks on the provided YAML node recursively.
*
* @param node The YAML node to check for {@code null}s
*/
public static void check(YamlNode node) {
if (node instanceof YamlMapping) {
for (YamlNameNodePair nodePair : ((YamlMapping) node).childrenPairs()) {
YamlNode child = nodePair.childNode();
if (child == null) {
String path = YamlUtil.constructPath(node, nodePair.nodeName());
reportNullEntryOnConcretePath(path);
}
check(nodePair.childNode());
}
} else if (node instanceof YamlSequence) {
for (YamlNode child : ((YamlSequence) node).children()) {
if (child == null) {
throw new InvalidConfigurationException("There is a null configuration entry under sequence " + node.path() + ". Please check if the provided YAML configuration is well-indented and no blocks started without " + "sub-nodes.");
}
check(child);
}
} else {
if (((YamlScalar) node).nodeValue() == null) {
reportNullEntryOnConcretePath(node.path());
}
}
}
use of com.hazelcast.config.InvalidConfigurationException 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.InvalidConfigurationException in project hazelcast by hazelcast.
the class TestHazelcastFactory method newHazelcastClient.
public HazelcastInstance newHazelcastClient(ClientConfig config, String sourceIp) {
if (!mockNetwork) {
HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
registerJvmNameAndPidMetric(((HazelcastClientProxy) client).client);
return client;
}
if (config == null) {
config = new XmlClientConfigBuilder().build();
}
Thread currentThread = Thread.currentThread();
ClassLoader tccl = currentThread.getContextClassLoader();
try {
if (tccl == ClassLoader.getSystemClassLoader()) {
currentThread.setContextClassLoader(HazelcastClient.class.getClassLoader());
}
HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(getInstanceName(config), config, null, clientRegistry.createClientServiceFactory(sourceIp), createAddressProvider(config));
registerJvmNameAndPidMetric(client);
client.start();
if (clients.putIfAbsent(client.getName(), client) != null) {
throw new InvalidConfigurationException("HazelcastClientInstance with name '" + client.getName() + "' already exists!");
}
OutOfMemoryErrorDispatcher.registerClient(client);
return new HazelcastClientProxy(client);
} finally {
currentThread.setContextClassLoader(tccl);
}
}
use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class YamlClientFailoverConfigBuilder method parseAndBuildConfig.
private void parseAndBuildConfig(ClientFailoverConfig config) throws Exception {
YamlMapping yamlRootNode;
try {
yamlRootNode = ((YamlMapping) YamlLoader.load(in));
} catch (Exception ex) {
throw new InvalidConfigurationException("Invalid YAML configuration", ex);
}
String configRoot = getConfigRoot();
YamlNode clientFailoverRoot = yamlRootNode.childAsMapping(configRoot);
if (clientFailoverRoot == null) {
clientFailoverRoot = yamlRootNode;
}
YamlDomChecker.check(clientFailoverRoot);
Node w3cRootNode = asW3cNode(clientFailoverRoot);
replaceVariables(w3cRootNode);
importDocuments(clientFailoverRoot);
if (shouldValidateTheSchema()) {
new YamlConfigSchemaValidator().validate(yamlRootNode);
}
new YamlClientFailoverDomConfigProcessor(true, config).buildConfig(w3cRootNode);
}
use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.
the class QueryCacheYamlConfigBuilderHelper method queryCachePredicateHandler.
@Override
protected void queryCachePredicateHandler(Node childNode, QueryCacheConfig queryCacheConfig) {
Node classNameNode = getNamedItemNode(childNode, "class-name");
Node sqlNode = getNamedItemNode(childNode, "sql");
if (classNameNode != null && sqlNode != null) {
throw new InvalidConfigurationException("Both class-name and sql is defined for the predicate of map " + childNode.getParentNode().getParentNode().getNodeName());
}
if (classNameNode == null && sqlNode == null) {
throw new InvalidConfigurationException("Either class-name and sql must be defined for the predicate of map " + childNode.getParentNode().getParentNode().getNodeName());
}
PredicateConfig predicateConfig = new PredicateConfig();
if (classNameNode != null) {
predicateConfig.setClassName(getTextContent(classNameNode));
} else if (sqlNode != null) {
predicateConfig.setSql(getTextContent(sqlNode));
}
queryCacheConfig.setPredicateConfig(predicateConfig);
}
Aggregations