Search in sources :

Example 31 with InvalidConfigurationException

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());
        }
    }
}
Also used : YamlSequence(com.hazelcast.internal.yaml.YamlSequence) YamlNode(com.hazelcast.internal.yaml.YamlNode) YamlScalar(com.hazelcast.internal.yaml.YamlScalar) YamlMapping(com.hazelcast.internal.yaml.YamlMapping) YamlNameNodePair(com.hazelcast.internal.yaml.YamlNameNodePair) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 32 with InvalidConfigurationException

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;
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) ValidationException(com.hazelcast.config.properties.ValidationException) PartitionGroupStrategy(com.hazelcast.spi.partitiongroup.PartitionGroupStrategy) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.cluster.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 33 with InvalidConfigurationException

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) HazelcastClient(com.hazelcast.client.HazelcastClient) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 34 with InvalidConfigurationException

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);
}
Also used : YamlConfigSchemaValidator(com.hazelcast.internal.config.YamlConfigSchemaValidator) YamlNode(com.hazelcast.internal.yaml.YamlNode) W3cDomUtil.asW3cNode(com.hazelcast.internal.config.yaml.W3cDomUtil.asW3cNode) Node(org.w3c.dom.Node) YamlNode(com.hazelcast.internal.yaml.YamlNode) YamlClientFailoverDomConfigProcessor(com.hazelcast.client.config.impl.YamlClientFailoverDomConfigProcessor) YamlMapping(com.hazelcast.internal.yaml.YamlMapping) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 35 with InvalidConfigurationException

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);
}
Also used : PredicateConfig(com.hazelcast.config.PredicateConfig) Node(org.w3c.dom.Node) 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