Skip to content

Commit

Permalink
[FLINK-5637] Avoid warning while parsing YAML configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
rmetzger committed Jan 25, 2017
1 parent b9ea4cf commit 54d3e26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,20 @@ private static Configuration loadYAMLResource(File file) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)))){

String line;
int lineNo = 0;
while ((line = reader.readLine()) != null) {

lineNo++;
// 1. check for comments
String[] comments = line.split("#", 2);
String conf = comments[0];
String conf = comments[0].trim();

// 2. get key and value
if (conf.length() > 0) {
String[] kv = conf.split(": ", 2);

// skip line with no valid key-value pair
if (kv.length == 1) {
LOG.warn("Error while trying to split key and value in configuration file " + file + ": " + line);
LOG.warn("Error while trying to split key and value in configuration file " + file + ":" + lineNo + ": \"" + line + "\"");
continue;
}

Expand All @@ -165,7 +166,7 @@ private static Configuration loadYAMLResource(File file) {

// sanity check
if (key.length() == 0 || value.length() == 0) {
LOG.warn("Error after splitting key and value in configuration file " + file + ": " + line);
LOG.warn("Error after splitting key and value in configuration file " + file + ":" + lineNo + ": \"" + line + "\"");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void testConfigurationYAML() {
pw.println("mykey3:myvalue3"); // SKIP, missing white space after colon
pw.println(" some nonsense without colon and whitespace separator"); // SKIP
pw.println(" : "); // SKIP
pw.println(" "); // SKIP
pw.println(" "); // SKIP (silently)
pw.println(" "); // SKIP (silently)
pw.println("mykey4: myvalue4# some comments"); // OK, skip comments only
pw.println(" mykey5 : myvalue5 "); // OK, trim unnecessary whitespace
pw.println("mykey6: my: value6"); // OK, only use first ': ' as separator
Expand Down
2 changes: 1 addition & 1 deletion flink-dist/src/main/resources/flink-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ parallelism.default: 1
#==============================================================================
# Web Frontend
#==============================================================================

# The address under which the web-based runtime monitor listens.
#
#jobmanager.web.address: 0.0.0.0
Expand Down

0 comments on commit 54d3e26

Please sign in to comment.