ctubbsii commented on a change in pull request #2238:
URL: https://github.com/apache/accumulo/pull/2238#discussion_r717202807



##########
File path: 
core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths 
provided by test")
+public class ClusterConfigParserTest {
+
+  @Rule
+  public TemporaryFolder tmp = new TemporaryFolder();
+
+  @Test
+  public void testParse() throws Exception {
+    URL configFile = ClusterConfigParserTest.class
+        .getResource("/org/apache/accumulo/core/conf/cluster/cluster.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+    assertEquals(5, contents.size());
+    assertTrue(contents.containsKey("manager"));
+    assertEquals("localhost1 localhost2", contents.get("manager"));
+    assertTrue(contents.containsKey("monitor"));
+    assertEquals("localhost1 localhost2", contents.get("monitor"));
+    assertTrue(contents.containsKey("tracer"));
+    assertEquals("localhost", contents.get("tracer"));
+    assertTrue(contents.containsKey("gc"));
+    assertEquals("localhost", contents.get("gc"));
+    assertTrue(contents.containsKey("tserver"));
+    assertEquals("localhost1 localhost2 localhost3 localhost4", 
contents.get("tserver"));
+    assertFalse(contents.containsKey("compaction"));
+    assertFalse(contents.containsKey("compaction.coordinator"));
+    assertFalse(contents.containsKey("compaction.compactor"));
+    assertFalse(contents.containsKey("compaction.compactor.queue"));
+    assertFalse(contents.containsKey("compaction.compactor.q1"));
+    assertFalse(contents.containsKey("compaction.compactor.q2"));
+  }
+
+  @Test
+  public void testParseWithExternalCompactions() throws Exception {
+    URL configFile = ClusterConfigParserTest.class.getResource(
+        
"/org/apache/accumulo/core/conf/cluster/cluster-with-external-compactions.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+    assertEquals(9, contents.size());
+    assertTrue(contents.containsKey("manager"));
+    assertEquals("localhost1 localhost2", contents.get("manager"));
+    assertTrue(contents.containsKey("monitor"));
+    assertEquals("localhost1 localhost2", contents.get("monitor"));
+    assertTrue(contents.containsKey("tracer"));
+    assertEquals("localhost", contents.get("tracer"));
+    assertTrue(contents.containsKey("gc"));
+    assertEquals("localhost", contents.get("gc"));
+    assertTrue(contents.containsKey("tserver"));
+    assertEquals("localhost1 localhost2 localhost3 localhost4", 
contents.get("tserver"));
+    assertFalse(contents.containsKey("compaction"));
+    assertTrue(contents.containsKey("compaction.coordinator"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.coordinator"));
+    assertFalse(contents.containsKey("compaction.compactor"));
+    assertTrue(contents.containsKey("compaction.compactor.queue"));
+    assertEquals("q1 q2", contents.get("compaction.compactor.queue"));
+    assertTrue(contents.containsKey("compaction.compactor.q1"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.compactor.q1"));
+    assertTrue(contents.containsKey("compaction.compactor.q2"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.compactor.q2"));
+  }
+
+  @Test
+  public void testShellOutput() throws Exception {
+
+    File f = tmp.newFile();
+    f.deleteOnExit();
+
+    PrintStream ps = new PrintStream(f);
+
+    URL configFile = ClusterConfigParserTest.class.getResource(
+        
"/org/apache/accumulo/core/conf/cluster/cluster-with-external-compactions.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+
+    ClusterConfigParser.outputShellVariables(contents, ps);
+    ps.close();
+
+    Map<String,String> expected = new HashMap<>();
+    expected.put("MANAGER_HOSTS", "\"localhost1 localhost2\"");
+    expected.put("MONITOR_HOSTS", "\"localhost1 localhost2\"");
+    expected.put("TRACER_HOSTS", "\"localhost\"");
+    expected.put("GC_HOSTS", "\"localhost\"");
+    expected.put("TSERVER_HOSTS", "\"localhost1 localhost2 localhost3 
localhost4\"");
+    expected.put("COORDINATOR_HOSTS", "\"localhost1 localhost2\"");
+    expected.put("COMPACTION_QUEUES", "\"q1 q2\"");
+    expected.put("COMPACTOR_HOSTS_q1", "\"localhost1 localhost2\"");
+    expected.put("COMPACTOR_HOSTS_q2", "\"localhost1 localhost2\"");
+
+    Map<String,String> actual = new HashMap<>();
+    try (BufferedReader rdr = Files.newBufferedReader(Paths.get(f.toURI()))) {
+      rdr.lines().forEach(l -> {
+        String[] props = l.split("=");
+        actual.put(props[0], props[1]);

Review comment:
       You already have a stream from `lines()`. Instead of calling `forEach` 
and splitting them, just use `Collector.toMap` to create a Map and assign it to 
`actual` directly from the stream.

##########
File path: 
core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths 
provided by test")
+public class ClusterConfigParserTest {
+
+  @Rule
+  public TemporaryFolder tmp = new TemporaryFolder();
+
+  @Test
+  public void testParse() throws Exception {
+    URL configFile = ClusterConfigParserTest.class
+        .getResource("/org/apache/accumulo/core/conf/cluster/cluster.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+    assertEquals(5, contents.size());
+    assertTrue(contents.containsKey("manager"));
+    assertEquals("localhost1 localhost2", contents.get("manager"));
+    assertTrue(contents.containsKey("monitor"));
+    assertEquals("localhost1 localhost2", contents.get("monitor"));
+    assertTrue(contents.containsKey("tracer"));
+    assertEquals("localhost", contents.get("tracer"));
+    assertTrue(contents.containsKey("gc"));
+    assertEquals("localhost", contents.get("gc"));
+    assertTrue(contents.containsKey("tserver"));
+    assertEquals("localhost1 localhost2 localhost3 localhost4", 
contents.get("tserver"));
+    assertFalse(contents.containsKey("compaction"));
+    assertFalse(contents.containsKey("compaction.coordinator"));
+    assertFalse(contents.containsKey("compaction.compactor"));
+    assertFalse(contents.containsKey("compaction.compactor.queue"));
+    assertFalse(contents.containsKey("compaction.compactor.q1"));
+    assertFalse(contents.containsKey("compaction.compactor.q2"));
+  }
+
+  @Test
+  public void testParseWithExternalCompactions() throws Exception {
+    URL configFile = ClusterConfigParserTest.class.getResource(
+        
"/org/apache/accumulo/core/conf/cluster/cluster-with-external-compactions.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+    assertEquals(9, contents.size());
+    assertTrue(contents.containsKey("manager"));
+    assertEquals("localhost1 localhost2", contents.get("manager"));
+    assertTrue(contents.containsKey("monitor"));
+    assertEquals("localhost1 localhost2", contents.get("monitor"));
+    assertTrue(contents.containsKey("tracer"));
+    assertEquals("localhost", contents.get("tracer"));
+    assertTrue(contents.containsKey("gc"));
+    assertEquals("localhost", contents.get("gc"));
+    assertTrue(contents.containsKey("tserver"));
+    assertEquals("localhost1 localhost2 localhost3 localhost4", 
contents.get("tserver"));
+    assertFalse(contents.containsKey("compaction"));
+    assertTrue(contents.containsKey("compaction.coordinator"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.coordinator"));
+    assertFalse(contents.containsKey("compaction.compactor"));
+    assertTrue(contents.containsKey("compaction.compactor.queue"));
+    assertEquals("q1 q2", contents.get("compaction.compactor.queue"));
+    assertTrue(contents.containsKey("compaction.compactor.q1"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.compactor.q1"));
+    assertTrue(contents.containsKey("compaction.compactor.q2"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.compactor.q2"));
+  }
+
+  @Test
+  public void testShellOutput() throws Exception {
+
+    File f = tmp.newFile();
+    f.deleteOnExit();
+
+    PrintStream ps = new PrintStream(f);
+
+    URL configFile = ClusterConfigParserTest.class.getResource(
+        
"/org/apache/accumulo/core/conf/cluster/cluster-with-external-compactions.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+
+    ClusterConfigParser.outputShellVariables(contents, ps);
+    ps.close();
+
+    Map<String,String> expected = new HashMap<>();
+    expected.put("MANAGER_HOSTS", "\"localhost1 localhost2\"");
+    expected.put("MONITOR_HOSTS", "\"localhost1 localhost2\"");
+    expected.put("TRACER_HOSTS", "\"localhost\"");
+    expected.put("GC_HOSTS", "\"localhost\"");
+    expected.put("TSERVER_HOSTS", "\"localhost1 localhost2 localhost3 
localhost4\"");
+    expected.put("COORDINATOR_HOSTS", "\"localhost1 localhost2\"");
+    expected.put("COMPACTION_QUEUES", "\"q1 q2\"");
+    expected.put("COMPACTOR_HOSTS_q1", "\"localhost1 localhost2\"");
+    expected.put("COMPACTOR_HOSTS_q2", "\"localhost1 localhost2\"");
+
+    Map<String,String> actual = new HashMap<>();
+    try (BufferedReader rdr = Files.newBufferedReader(Paths.get(f.toURI()))) {
+      rdr.lines().forEach(l -> {

Review comment:
       You could probably just do `Files.lines` instead of bothering with a 
buffered reader for these files.

##########
File path: 
core/src/test/resources/org/apache/accumulo/core/conf/cluster/cluster.yml
##########
@@ -0,0 +1,53 @@
+#

Review comment:
       Please rename these config files with a `.yaml` extension. `.yml` may be 
common, but it is discouraged by the YAML community. See 
https://yaml.org/faq.html for the official recommendation.

##########
File path: assemble/bin/accumulo-cluster
##########
@@ -43,52 +43,68 @@ function invalid_args {
   exit 1
 }
 
-function verify_config {
+function parse_fail {
+  echo "Failed to parse ${conf}/cluster.yml"
+  exit 1
+}
+
+function parse_config {
   if [[ -f ${conf}/slaves ]]; then
     echo "ERROR: A 'slaves' file was found in ${conf}/"
-    echo "Accumulo now reads tablet server hosts from 'tservers' and requires 
that the 'slaves' file not be present to reduce confusion."
+    echo "Accumulo now uses cluster host configuration information from 
'cluster.yml' and requires that the 'slaves' file not be present to reduce 
confusion."
     echo "Please rename the 'slaves' file to 'tservers' or remove it if both 
exist."
     exit 1
   fi
 
-  if [[ ! -f ${conf}/tservers ]]; then
-    echo "ERROR: A 'tservers' file was not found at ${conf}/tservers"
-    echo "Please make sure it exists and is configured with tablet server 
hosts."
+  if [[ ! -f ${conf}/cluster.yml ]]; then
+    echo "ERROR: A 'cluster.yml' file was not found at ${conf}/cluster.yml"
+    echo "Please make sure it exists and is configured with the host 
information. Run 'create-config' to create an example configuration."
     exit 1
   fi
 
-  unset manager1
-  if [[ -f "${conf}/$manager_file" ]]; then
-    manager1=$(grep -Ev '(^#|^\s*$)' "${conf}/$manager_file" | head -1)
+  trap 'rm -f "$CONFIG_FILE"' EXIT
+  CONFIG_FILE=$(mktemp) || exit 1
+  ${accumulo_cmd} org.apache.accumulo.core.conf.cluster.ClusterConfigParser 
${conf}/cluster.yml > $CONFIG_FILE || parse_fail

Review comment:
       I think you're going to want to double-quote the bash variables. Note 
that the braces aren't necessary... they may help with readability, but there's 
no ambiguity they are resolving in the above, so they aren't strictly 
necessary. The double quotes are, though, so that spaces in the value of the 
variables don't  mess up the parameters. For example, if a parent directory for 
`$conf` was `/home/user1/my config files/accumulo/`, those spaces would mess 
things up. Same in the `$accumulo_cmd` variable throughout. Use ShellCheck to 
check the script.

##########
File path: 
core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths 
provided by test")
+public class ClusterConfigParserTest {
+
+  @Rule
+  public TemporaryFolder tmp = new TemporaryFolder();
+
+  @Test
+  public void testParse() throws Exception {
+    URL configFile = ClusterConfigParserTest.class
+        .getResource("/org/apache/accumulo/core/conf/cluster/cluster.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+    assertEquals(5, contents.size());
+    assertTrue(contents.containsKey("manager"));
+    assertEquals("localhost1 localhost2", contents.get("manager"));
+    assertTrue(contents.containsKey("monitor"));
+    assertEquals("localhost1 localhost2", contents.get("monitor"));
+    assertTrue(contents.containsKey("tracer"));
+    assertEquals("localhost", contents.get("tracer"));
+    assertTrue(contents.containsKey("gc"));
+    assertEquals("localhost", contents.get("gc"));
+    assertTrue(contents.containsKey("tserver"));
+    assertEquals("localhost1 localhost2 localhost3 localhost4", 
contents.get("tserver"));
+    assertFalse(contents.containsKey("compaction"));
+    assertFalse(contents.containsKey("compaction.coordinator"));
+    assertFalse(contents.containsKey("compaction.compactor"));
+    assertFalse(contents.containsKey("compaction.compactor.queue"));
+    assertFalse(contents.containsKey("compaction.compactor.q1"));
+    assertFalse(contents.containsKey("compaction.compactor.q2"));
+  }
+
+  @Test
+  public void testParseWithExternalCompactions() throws Exception {
+    URL configFile = ClusterConfigParserTest.class.getResource(
+        
"/org/apache/accumulo/core/conf/cluster/cluster-with-external-compactions.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+    assertEquals(9, contents.size());
+    assertTrue(contents.containsKey("manager"));
+    assertEquals("localhost1 localhost2", contents.get("manager"));
+    assertTrue(contents.containsKey("monitor"));
+    assertEquals("localhost1 localhost2", contents.get("monitor"));
+    assertTrue(contents.containsKey("tracer"));
+    assertEquals("localhost", contents.get("tracer"));
+    assertTrue(contents.containsKey("gc"));
+    assertEquals("localhost", contents.get("gc"));
+    assertTrue(contents.containsKey("tserver"));
+    assertEquals("localhost1 localhost2 localhost3 localhost4", 
contents.get("tserver"));
+    assertFalse(contents.containsKey("compaction"));
+    assertTrue(contents.containsKey("compaction.coordinator"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.coordinator"));
+    assertFalse(contents.containsKey("compaction.compactor"));
+    assertTrue(contents.containsKey("compaction.compactor.queue"));
+    assertEquals("q1 q2", contents.get("compaction.compactor.queue"));
+    assertTrue(contents.containsKey("compaction.compactor.q1"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.compactor.q1"));
+    assertTrue(contents.containsKey("compaction.compactor.q2"));
+    assertEquals("localhost1 localhost2", 
contents.get("compaction.compactor.q2"));
+  }
+
+  @Test
+  public void testShellOutput() throws Exception {
+
+    File f = tmp.newFile();
+    f.deleteOnExit();
+
+    PrintStream ps = new PrintStream(f);
+
+    URL configFile = ClusterConfigParserTest.class.getResource(
+        
"/org/apache/accumulo/core/conf/cluster/cluster-with-external-compactions.yml");
+    assertNotNull(configFile);
+
+    Map<String,String> contents =
+        ClusterConfigParser.parseConfiguration(new 
File(configFile.toURI()).getAbsolutePath());
+
+    ClusterConfigParser.outputShellVariables(contents, ps);
+    ps.close();
+
+    Map<String,String> expected = new HashMap<>();

Review comment:
       Try `Map.of(k1, v1, k2, v2, ....)` for creating the expected map as an 
immutable map.

##########
File path: 
core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.yaml.snakeyaml.Yaml;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+public class ClusterConfigParser {
+
+  private static final String PROPERTY_FORMAT = "%s=\"%s\"";
+  private static final String[] SECTIONS =
+      new String[] {"manager", "monitor", "gc", "tracer", "tserver"};
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not 
set by user input")
+  public static Map<String,String> parseConfiguration(String configFile) 
throws IOException {
+    Map<String,String> results = new HashMap<>();
+    try (InputStream fis = Files.newInputStream(Paths.get(configFile), 
StandardOpenOption.READ)) {
+      Yaml y = new Yaml();
+      Map<String,Object> config = y.load(fis);
+      config.forEach((k, v) -> flatten("", k, v, results));
+    }
+    return results;
+  }
+
+  private static String addTheDot(String key) {
+    return (key.endsWith(".")) ? "" : ".";
+  }
+
+  @SuppressWarnings("unchecked")

Review comment:
       Can we narrow this warnings suppression down, or does it have to cover 
the entire method? Covering the entire method can mask untriaged problems.

##########
File path: 
core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths 
provided by test")
+public class ClusterConfigParserTest {
+
+  @Rule
+  public TemporaryFolder tmp = new TemporaryFolder();

Review comment:
       Please create temporary folders as a subdirectory of 
`${user.dir}/target` (`System.getProperty("user.dir") + "/target"`), so as to 
keep Maven build artifacts, even intermediate ones, in the project directories, 
and not in `/tmp`.

##########
File path: 
core/src/test/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParserTest.java
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.PrintStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths 
provided by test")
+public class ClusterConfigParserTest {
+
+  @Rule
+  public TemporaryFolder tmp = new TemporaryFolder();

Review comment:
       I saw the change. It's fine, but I think a simpler change would have 
been to keep the `@Rule`. Other ITs, such as `TokenFileIT` do:
   
   ```java
     @Rule
     public TemporaryFolder folder =
         new TemporaryFolder(new File(System.getProperty("user.dir") + 
"/target"));
   ```

##########
File path: 
core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.conf.cluster;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.yaml.snakeyaml.Yaml;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+public class ClusterConfigParser {
+
+  private static final String PROPERTY_FORMAT = "%s=\"%s\"";
+  private static final String[] SECTIONS =
+      new String[] {"manager", "monitor", "gc", "tracer", "tserver"};
+
+  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not 
set by user input")
+  public static Map<String,String> parseConfiguration(String configFile) 
throws IOException {
+    Map<String,String> results = new HashMap<>();
+    try (InputStream fis = Files.newInputStream(Paths.get(configFile), 
StandardOpenOption.READ)) {
+      Yaml y = new Yaml();
+      Map<String,Object> config = y.load(fis);
+      config.forEach((k, v) -> flatten("", k, v, results));
+    }
+    return results;
+  }
+
+  private static String addTheDot(String key) {
+    return (key.endsWith(".")) ? "" : ".";
+  }
+
+  @SuppressWarnings("unchecked")

Review comment:
       You can by assigning the map to a local variable:
   
   ```java
       } else if (value instanceof Map) {
         @SuppressWarnings("unchecked")
         var map = (Map<String,Object>) value;
         map.forEach((k, v) -> flatten(parent + key, k, v, results));
       } else {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to