Search in sources :

Example 6 with YamlNode

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

the class YamlMemberDomConfigProcessor method handleTrustedInterfaces.

@Override
protected void handleTrustedInterfaces(TrustedInterfacesConfigurable<?> tiConfig, Node n) {
    YamlSequence yamlNode = getWrappedYamlSequence(n);
    for (YamlNode interfaceNode : yamlNode.children()) {
        String trustedInterface = asScalar(interfaceNode).nodeValue();
        tiConfig.addTrustedInterface(trustedInterface);
    }
    super.handleTrustedInterfaces(tiConfig, n);
}
Also used : YamlSequence(com.hazelcast.internal.yaml.YamlSequence) W3cDomUtil.getWrappedYamlSequence(com.hazelcast.internal.config.yaml.W3cDomUtil.getWrappedYamlSequence) YamlNode(com.hazelcast.internal.yaml.YamlNode)

Example 7 with YamlNode

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

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

the class W3cDomTest method testW3cDomAdapter.

@Test
public void testW3cDomAdapter() {
    InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map-extended.yaml");
    YamlNode yamlRoot = YamlLoader.load(inputStream, "root-map");
    Node domRoot = W3cDomUtil.asW3cNode(yamlRoot);
    NamedNodeMap rootAttributes = domRoot.getAttributes();
    Node embeddedMap = rootAttributes.getNamedItem("embedded-map");
    NamedNodeMap embeddedMapAttributes = embeddedMap.getAttributes();
    String scalarString = embeddedMapAttributes.getNamedItem("scalar-str").getTextContent();
    int scalarInt = Integer.parseInt(embeddedMapAttributes.getNamedItem("scalar-int").getTextContent());
    double scalarDouble = Double.parseDouble(embeddedMapAttributes.getNamedItem("scalar-double").getTextContent());
    boolean scalarBool = Boolean.parseBoolean(embeddedMapAttributes.getNamedItem("scalar-bool").getTextContent());
    Node embeddedListNode = embeddedMapAttributes.getNamedItem("embedded-list");
    NodeList embeddedList = embeddedListNode.getChildNodes();
    String elItem0 = embeddedList.item(0).getTextContent();
    Node elItem0AsNode = embeddedList.item(0);
    int elItem1 = Integer.parseInt(embeddedList.item(1).getTextContent());
    double elItem2 = Double.parseDouble(embeddedList.item(2).getTextContent());
    boolean elItem3 = Boolean.parseBoolean(embeddedList.item(3).getTextContent());
    NodeList embeddedList2 = embeddedMapAttributes.getNamedItem("embedded-list2").getChildNodes();
    String el2Item0 = embeddedList2.item(0).getTextContent();
    double el2Item1 = Double.parseDouble(embeddedList2.item(1).getTextContent());
    String keysValue = embeddedList.item(4).getAttributes().getNamedItem("key").getTextContent();
    String multilineStr = domRoot.getAttributes().getNamedItem("multiline-str").getTextContent();
    assertEquals("embedded-map", embeddedMap.getNodeName());
    assertEquals("scalar-str", embeddedMap.getChildNodes().item(0).getNodeName());
    assertNull(embeddedMap.getChildNodes().item(NOT_EXISTING));
    assertNull(embeddedMap.getTextContent());
    assertEquals("embedded-list", embeddedMapAttributes.item(4).getNodeName());
    assertEquals("embedded-list", embeddedListNode.getNodeName());
    assertEquals("embedded-map", embeddedListNode.getParentNode().getNodeName());
    assertSame(emptyNamedNodeMap(), embeddedListNode.getAttributes());
    assertEquals(6, embeddedMap.getAttributes().getLength());
    // root-map/embedded-map/scalars
    assertEquals(6, embeddedMap.getChildNodes().getLength());
    assertEquals("h4z3lc4st", scalarString);
    assertEquals(123, scalarInt);
    assertEquals(123.12312D, scalarDouble, 10E-5);
    assertTrue(scalarBool);
    // root-map/embedded-map/embedded-list
    assertEquals("value1", elItem0);
    assertEquals(NOT_EXISTING, elItem1);
    assertEquals(42.42D, elItem2, 10E-2);
    assertFalse(elItem3);
    NodeList elItem0ChildNodes = elItem0AsNode.getChildNodes();
    assertEquals(1, elItem0ChildNodes.getLength());
    assertEquals("value1", elItem0ChildNodes.item(0).getNodeValue());
    assertEquals("value1", elItem0AsNode.getNodeValue());
    // root-map/embedded-map/embedded-list2
    assertEquals(2, embeddedList2.getLength());
    assertEquals("value2", el2Item0);
    assertEquals(1D, el2Item1, 10E-1);
    assertEquals("value", keysValue);
    assertEquals("Hazelcast IMDG\n" + "The Leading Open Source In-Memory Data Grid:\n" + "Distributed Computing, Simplified.\n", multilineStr);
    Element embeddedMapAsElement = (Element) embeddedMap;
    String scalarStrAttr = embeddedMapAsElement.getAttribute("scalar-str");
    assertEquals("h4z3lc4st", scalarStrAttr);
    assertEquals("embedded-map", embeddedMapAsElement.getTagName());
    assertTrue(embeddedMapAsElement.hasAttribute("scalar-str"));
    assertEquals("", embeddedMapAsElement.getAttribute("non-existing"));
    NodeList nodesByTagName = embeddedMapAsElement.getElementsByTagName("scalar-str");
    assertEquals(1, nodesByTagName.getLength());
    assertEquals("h4z3lc4st", nodesByTagName.item(0).getNodeValue());
}
Also used : EmptyNamedNodeMap.emptyNamedNodeMap(com.hazelcast.internal.config.yaml.EmptyNamedNodeMap.emptyNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) YamlNode(com.hazelcast.internal.yaml.YamlNode) InputStream(java.io.InputStream) YamlTest(com.hazelcast.internal.yaml.YamlTest) Node(org.w3c.dom.Node) YamlNode(com.hazelcast.internal.yaml.YamlNode) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) YamlTest(com.hazelcast.internal.yaml.YamlTest)

Example 9 with YamlNode

use of com.hazelcast.internal.yaml.YamlNode 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)

Aggregations

YamlNode (com.hazelcast.internal.yaml.YamlNode)9 YamlMapping (com.hazelcast.internal.yaml.YamlMapping)7 Node (org.w3c.dom.Node)4 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)3 YamlConfigSchemaValidator (com.hazelcast.internal.config.YamlConfigSchemaValidator)3 W3cDomUtil.asW3cNode (com.hazelcast.internal.config.yaml.W3cDomUtil.asW3cNode)3 YamlSequence (com.hazelcast.internal.yaml.YamlSequence)3 IOException (java.io.IOException)3 MutableYamlMapping (com.hazelcast.internal.yaml.MutableYamlMapping)2 YamlNameNodePair (com.hazelcast.internal.yaml.YamlNameNodePair)2 InputStream (java.io.InputStream)2 YamlClientDomConfigProcessor (com.hazelcast.client.config.impl.YamlClientDomConfigProcessor)1 YamlClientFailoverDomConfigProcessor (com.hazelcast.client.config.impl.YamlClientFailoverDomConfigProcessor)1 HazelcastException (com.hazelcast.core.HazelcastException)1 YamlMemberDomConfigProcessor (com.hazelcast.internal.config.YamlMemberDomConfigProcessor)1 EmptyNamedNodeMap.emptyNamedNodeMap (com.hazelcast.internal.config.yaml.EmptyNamedNodeMap.emptyNamedNodeMap)1 W3cDomUtil.getWrappedYamlSequence (com.hazelcast.internal.config.yaml.W3cDomUtil.getWrappedYamlSequence)1 MutableYamlSequence (com.hazelcast.internal.yaml.MutableYamlSequence)1 YamlScalar (com.hazelcast.internal.yaml.YamlScalar)1 YamlTest (com.hazelcast.internal.yaml.YamlTest)1