Search in sources :

Example 6 with YamlMapping

use of com.hazelcast.internal.yaml.YamlMapping 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 7 with YamlMapping

use of com.hazelcast.internal.yaml.YamlMapping 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 8 with YamlMapping

use of com.hazelcast.internal.yaml.YamlMapping in project hazelcast by hazelcast.

the class YamlMemberDomConfigProcessorTest method toNode.

private static Node toNode(String yaml) {
    YamlMapping yamlRootNode = ((YamlMapping) YamlLoader.load(yaml));
    YamlNode imdgRoot = yamlRootNode.childAsMapping(ConfigSections.HAZELCAST.getName());
    if (imdgRoot == null) {
        imdgRoot = yamlRootNode;
    }
    return asW3cNode(imdgRoot);
}
Also used : YamlNode(com.hazelcast.internal.yaml.YamlNode) YamlMapping(com.hazelcast.internal.yaml.YamlMapping)

Example 9 with YamlMapping

use of com.hazelcast.internal.yaml.YamlMapping in project hazelcast by hazelcast.

the class YamlConfigSchemaValidatorTest method validationExceptionIsWrapped.

@Test
public void validationExceptionIsWrapped() {
    YamlMapping config = (YamlMapping) YamlDomBuilder.build(new HashMap<>());
    YamlConfigSchemaValidator validator = new YamlConfigSchemaValidator();
    try {
        validator.validate(config);
        fail("did not throw exception for invalid config");
    } catch (SchemaViolationConfigurationException e) {
        assertEquals("#", e.getKeywordLocation());
        assertEquals("#", e.getInstanceLocation());
        assertEquals("exactly one of [hazelcast], [hazelcast-client] and [hazelcast-client-failover] should be present in the" + " root schema document, 0 are present", e.getMessage());
    }
}
Also used : YamlConfigSchemaValidator(com.hazelcast.internal.config.YamlConfigSchemaValidator) HashMap(java.util.HashMap) SchemaViolationConfigurationException(com.hazelcast.internal.config.SchemaViolationConfigurationException) YamlMapping(com.hazelcast.internal.yaml.YamlMapping) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

YamlMapping (com.hazelcast.internal.yaml.YamlMapping)9 YamlNode (com.hazelcast.internal.yaml.YamlNode)7 YamlConfigSchemaValidator (com.hazelcast.internal.config.YamlConfigSchemaValidator)4 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)3 W3cDomUtil.asW3cNode (com.hazelcast.internal.config.yaml.W3cDomUtil.asW3cNode)3 IOException (java.io.IOException)3 Node (org.w3c.dom.Node)3 MutableYamlMapping (com.hazelcast.internal.yaml.MutableYamlMapping)2 YamlNameNodePair (com.hazelcast.internal.yaml.YamlNameNodePair)2 YamlSequence (com.hazelcast.internal.yaml.YamlSequence)2 YamlClientDomConfigProcessor (com.hazelcast.client.config.impl.YamlClientDomConfigProcessor)1 YamlClientFailoverDomConfigProcessor (com.hazelcast.client.config.impl.YamlClientFailoverDomConfigProcessor)1 HazelcastException (com.hazelcast.core.HazelcastException)1 Versions (com.hazelcast.internal.cluster.Versions)1 SchemaViolationConfigurationException (com.hazelcast.internal.config.SchemaViolationConfigurationException)1 YamlMemberDomConfigProcessor (com.hazelcast.internal.config.YamlMemberDomConfigProcessor)1 MutableYamlSequence (com.hazelcast.internal.yaml.MutableYamlSequence)1 YamlScalar (com.hazelcast.internal.yaml.YamlScalar)1 YamlToJsonConverter (com.hazelcast.internal.yaml.YamlToJsonConverter)1 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)1