diff --git a/peel-core/src/main/scala/org/peelframework/core/config/Model.scala b/peel-core/src/main/scala/org/peelframework/core/config/Model.scala index f4409169..e52c0fcb 100644 --- a/peel-core/src/main/scala/org/peelframework/core/config/Model.scala +++ b/peel-core/src/main/scala/org/peelframework/core/config/Model.scala @@ -76,6 +76,39 @@ object Model { } } + class INI(val c: Config, val prefix: String) extends Model { + + val sections = { + val sectionBuffer = ListBuffer[Section]() + + def sanitize(s: String) = + s.stripPrefix(s"$prefix.") // remove prefix + + def fixRoot(s: String) = if (s == "_root_") null else s + + def collectPairs(c: Config, name: String): Unit = { + val buffer = ListBuffer[Pair]() + + for (e <- c.entrySet().asScala) { + val key = sanitize(e.getKey) + .replace("\"_root_\"", "_root_") + .stripPrefix(s"$name.") + buffer += Pair(key, c.getString(e.getKey)) + } + + sectionBuffer += Section(fixRoot(name), buffer.toList.asJava) + } + + for (e <- c.getObject(prefix).entrySet().asScala) { + val name = sanitize(e.getKey) + collectPairs(c.withOnlyPath(s"$prefix.$name"), name) + } + + sectionBuffer.toList.asJava + } + + } + /** A model for environment files (e.g., etc/hadoop/hadoop-env.sh). * * The children of the specified `prefix` path in the given `c` config are converted as (key, value) pairs in a diff --git a/peel-extensions/src/main/resources/templates/hadoop-3/conf/ini.mustache b/peel-extensions/src/main/resources/templates/hadoop-3/conf/ini.mustache new file mode 100644 index 00000000..9119b7b6 --- /dev/null +++ b/peel-extensions/src/main/resources/templates/hadoop-3/conf/ini.mustache @@ -0,0 +1,7 @@ +{{#sections}}{{#name}}[{{name}}] +{{/name}} +{{#entries}} +{{name}}={{value}} +{{/entries}} + +{{/sections}} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 657c3f07..66b7c2bc 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ 1.3.2 3.4 - 1.9 + 1.15 0.6.0