Search in sources :

Example 1 with YamlConfigSchemaValidator

use of com.hazelcast.internal.config.YamlConfigSchemaValidator in project hazelcast by hazelcast.

the class YamlClientConfigBuilder method parseAndBuildConfig.

private void parseAndBuildConfig(ClientConfig config) throws Exception {
    YamlMapping yamlRootNode;
    try {
        yamlRootNode = ((YamlMapping) YamlLoader.load(in));
    } catch (Exception ex) {
        throw new InvalidConfigurationException("Invalid YAML configuration", ex);
    }
    YamlNode clientRoot = yamlRootNode.childAsMapping(ClientConfigSections.HAZELCAST_CLIENT.getName());
    if (clientRoot == null) {
        clientRoot = yamlRootNode;
    }
    YamlDomChecker.check(clientRoot);
    Node w3cRootNode = asW3cNode(clientRoot);
    replaceVariables(w3cRootNode);
    importDocuments(clientRoot);
    if (shouldValidateTheSchema()) {
        new YamlConfigSchemaValidator().validate((YamlMapping) clientRoot.parent());
    }
    new YamlClientDomConfigProcessor(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) YamlMapping(com.hazelcast.internal.yaml.YamlMapping) YamlClientDomConfigProcessor(com.hazelcast.client.config.impl.YamlClientDomConfigProcessor) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) IOException(java.io.IOException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 2 with YamlConfigSchemaValidator

use of com.hazelcast.internal.config.YamlConfigSchemaValidator in project hazelcast by hazelcast.

the class YamlConfigBuilder method parseAndBuildConfig.

private void parseAndBuildConfig(Config config) throws Exception {
    YamlMapping yamlRootNode;
    try {
        yamlRootNode = ((YamlMapping) YamlLoader.load(in));
    } catch (Exception ex) {
        throw new InvalidConfigurationException("Invalid YAML configuration", ex);
    }
    YamlNode imdgRoot = yamlRootNode.childAsMapping(ConfigSections.HAZELCAST.getName());
    if (imdgRoot == null) {
        imdgRoot = yamlRootNode;
    }
    YamlDomChecker.check(imdgRoot);
    Node w3cRootNode = asW3cNode(imdgRoot);
    replaceVariables(w3cRootNode);
    importDocuments(imdgRoot);
    if (shouldValidateTheSchema()) {
        new YamlConfigSchemaValidator().validate((YamlMapping) imdgRoot.parent());
    }
    new YamlMemberDomConfigProcessor(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) YamlMemberDomConfigProcessor(com.hazelcast.internal.config.YamlMemberDomConfigProcessor) YamlMapping(com.hazelcast.internal.yaml.YamlMapping) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with YamlConfigSchemaValidator

use of com.hazelcast.internal.config.YamlConfigSchemaValidator 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 4 with YamlConfigSchemaValidator

use of com.hazelcast.internal.config.YamlConfigSchemaValidator 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

YamlConfigSchemaValidator (com.hazelcast.internal.config.YamlConfigSchemaValidator)4 YamlMapping (com.hazelcast.internal.yaml.YamlMapping)4 W3cDomUtil.asW3cNode (com.hazelcast.internal.config.yaml.W3cDomUtil.asW3cNode)3 YamlNode (com.hazelcast.internal.yaml.YamlNode)3 IOException (java.io.IOException)3 Node (org.w3c.dom.Node)3 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)2 YamlClientDomConfigProcessor (com.hazelcast.client.config.impl.YamlClientDomConfigProcessor)1 YamlClientFailoverDomConfigProcessor (com.hazelcast.client.config.impl.YamlClientFailoverDomConfigProcessor)1 HazelcastException (com.hazelcast.core.HazelcastException)1 SchemaViolationConfigurationException (com.hazelcast.internal.config.SchemaViolationConfigurationException)1 YamlMemberDomConfigProcessor (com.hazelcast.internal.config.YamlMemberDomConfigProcessor)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1