Search in sources :

Example 21 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class MemberDomConfigProcessor method getEvictionConfig.

private EvictionConfig getEvictionConfig(Node node, boolean isNearCache, boolean isIMap) {
    EvictionConfig evictionConfig = new EvictionConfig();
    if (isIMap) {
        // Set IMap defaults
        evictionConfig.setEvictionPolicy(MapConfig.DEFAULT_EVICTION_POLICY).setMaxSizePolicy(MapConfig.DEFAULT_MAX_SIZE_POLICY).setSize(MapConfig.DEFAULT_MAX_SIZE);
    }
    Node size = getNamedItemNode(node, "size");
    Node maxSizePolicy = getNamedItemNode(node, "max-size-policy");
    Node evictionPolicy = getNamedItemNode(node, "eviction-policy");
    Node comparatorClassName = getNamedItemNode(node, "comparator-class-name");
    if (size != null) {
        evictionConfig.setSize(parseInt(getTextContent(size)));
        if (isIMap && evictionConfig.getSize() == 0) {
            evictionConfig.setSize(MapConfig.DEFAULT_MAX_SIZE);
        }
    }
    if (maxSizePolicy != null) {
        evictionConfig.setMaxSizePolicy(MaxSizePolicy.valueOf(upperCaseInternal(getTextContent(maxSizePolicy))));
    }
    if (evictionPolicy != null) {
        evictionConfig.setEvictionPolicy(EvictionPolicy.valueOf(upperCaseInternal(getTextContent(evictionPolicy))));
    }
    if (comparatorClassName != null) {
        String className = getTextContent(comparatorClassName);
        if (!StringUtil.isNullOrEmptyAfterTrim(className)) {
            evictionConfig.setComparatorClassName(className);
        }
    }
    try {
        doEvictionConfigChecks(evictionConfig, isIMap, isNearCache);
    } catch (IllegalArgumentException e) {
        throw new InvalidConfigurationException(e.getMessage());
    }
    return evictionConfig;
}
Also used : ConfigValidator.checkNearCacheEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkNearCacheEvictionConfig) ConfigValidator.checkCacheEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheEvictionConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) ConfigValidator.checkMapEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkMapEvictionConfig) Node(org.w3c.dom.Node) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 22 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class XmlClientConfigBuilder method handleConfig.

private void handleConfig(Element docElement) throws Exception {
    for (Node node : childElements(docElement)) {
        String nodeName = cleanNodeName(node);
        if (occurrenceSet.contains(nodeName)) {
            throw new InvalidConfigurationException("Duplicate '" + nodeName + "' definition found in XML configuration. ");
        }
        handleXmlNode(node, nodeName);
        if (!canOccurMultipleTimes(nodeName)) {
            occurrenceSet.add(nodeName);
        }
    }
}
Also used : Node(org.w3c.dom.Node) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 23 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 = 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;
}
Also used : ValidationException(com.hazelcast.config.properties.ValidationException) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) Member(com.hazelcast.core.Member) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) ValidationException(com.hazelcast.config.properties.ValidationException) HashSet(java.util.HashSet) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 24 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast-jet by hazelcast.

the class XmlJetConfigBuilder method parse.

@Override
protected Document parse(InputStream inputStream) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    DocumentBuilder builder = dbf.newDocumentBuilder();
    try {
        return builder.parse(inputStream);
    } catch (Exception e) {
        String msg = "Failed to parse config" + LINE_SEPARATOR + "Exception: " + e.getMessage() + LINE_SEPARATOR + "Hazelcast Jet startup interrupted.";
        LOGGER.severe(msg);
        throw new InvalidConfigurationException(e.getMessage(), e);
    } finally {
        IOUtil.closeResource(inputStream);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 25 with InvalidConfigurationException

use of com.hazelcast.config.InvalidConfigurationException in project hazelcast by hazelcast.

the class MemberDomConfigProcessor method getTimedExpiryPolicyFactoryConfig.

private CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig getTimedExpiryPolicyFactoryConfig(Node node) {
    String expiryPolicyTypeStr = getAttribute(node, "expiry-policy-type");
    String durationAmountStr = getAttribute(node, "duration-amount");
    String timeUnitStr = getAttribute(node, "time-unit");
    ExpiryPolicyType expiryPolicyType = ExpiryPolicyType.valueOf(upperCaseInternal(expiryPolicyTypeStr));
    if (expiryPolicyType != ExpiryPolicyType.ETERNAL && (isNullOrEmpty(durationAmountStr) || isNullOrEmpty(timeUnitStr))) {
        throw new InvalidConfigurationException("Both of the \"duration-amount\" or \"time-unit\" attributes " + "are required for expiry policy factory configuration " + "(except \"ETERNAL\" expiry policy type)");
    }
    CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig durationConfig = null;
    if (expiryPolicyType != ExpiryPolicyType.ETERNAL) {
        long durationAmount;
        try {
            durationAmount = parseLong(durationAmountStr);
        } catch (NumberFormatException e) {
            throw new InvalidConfigurationException("Invalid value for duration amount: " + durationAmountStr, e);
        }
        if (durationAmount <= 0) {
            throw new InvalidConfigurationException("Duration amount must be positive: " + durationAmount);
        }
        TimeUnit timeUnit;
        try {
            timeUnit = TimeUnit.valueOf(upperCaseInternal(timeUnitStr));
        } catch (IllegalArgumentException e) {
            throw new InvalidConfigurationException("Invalid value for time unit: " + timeUnitStr, e);
        }
        durationConfig = new CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig(durationAmount, timeUnit);
    }
    return new CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig(expiryPolicyType, durationConfig);
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) TimeUnit(java.util.concurrent.TimeUnit) ExpiryPolicyType(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig.ExpiryPolicyType) 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