use of com.hazelcast.internal.yaml.YamlSequence in project hazelcast by hazelcast.
the class AbstractYamlConfigBuilder method importDocuments.
/**
* Imports external YAML documents into the provided main YAML document.
* <p>
* Since the YAML configuration uses mappings, in order to keep the
* configuration defined in the main YAML document the imported
* document (the source) will be actually merged into the main
* document (the target). An example to it is defining one map in the
* main document, and another map in the imported document. In this
* case the documents should be merged to include both map configurations
* under the {@code root/map} node.
*
* @param imdgRoot The root of the main YAML configuration document
* @throws Exception If a YAML document to be imported can't be loaded
* @see #merge(YamlNode, YamlNode)
*/
protected void importDocuments(YamlNode imdgRoot) throws Exception {
YamlMapping rootAsMapping = asMapping(imdgRoot);
YamlSequence importSeq = rootAsMapping.childAsSequence(ConfigSections.IMPORT.getName());
if (importSeq == null || importSeq.childCount() == 0) {
return;
}
for (YamlNode importNode : importSeq.children()) {
String resource = asScalar(importNode).nodeValue();
URL url = ConfigLoader.locateConfig(resource);
if (url == null) {
throw new InvalidConfigurationException("Failed to load resource: " + resource);
}
if (!currentlyImportedFiles.add(url.getPath())) {
throw new InvalidConfigurationException("Cyclic loading of resource '" + url.getPath() + "' detected!");
}
YamlNode rootLoaded;
try (InputStream inputStream = url.openStream()) {
rootLoaded = YamlLoader.load(inputStream);
} catch (Exception ex) {
throw new InvalidConfigurationException("Loading YAML document from resource " + url.getPath() + " failed", ex);
}
YamlNode imdgRootLoaded = asMapping(rootLoaded).child(getConfigRoot());
if (imdgRootLoaded == null) {
imdgRootLoaded = rootLoaded;
}
replaceVariables(asW3cNode(imdgRootLoaded));
importDocuments(imdgRootLoaded);
// we need to merge and not just substitute with the content of the imported document
// YAML documents define mappings where the name of the nodes should be unique
merge(imdgRootLoaded, imdgRoot);
}
replaceVariables(asW3cNode(imdgRoot));
((MutableYamlMapping) rootAsMapping).removeChild(ConfigSections.IMPORT.getName());
}
use of com.hazelcast.internal.yaml.YamlSequence 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);
}
use of com.hazelcast.internal.yaml.YamlSequence 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());
}
}
}
Aggregations