swagle commented on a change in pull request #199: HDDS-2502. Close ScmClient 
in RatisInsight.
URL: https://github.com/apache/hadoop-ozone/pull/199#discussion_r347059169
 
 

 ##########
 File path: 
hadoop-ozone/insight/src/main/java/org/apache/hadoop/ozone/insight/datanode/RatisInsight.java
 ##########
 @@ -47,22 +48,24 @@ public RatisInsight(OzoneConfiguration conf) {
   public List<LoggerSource> getRelatedLoggers(boolean verbose) {
     List<LoggerSource> result = new ArrayList<>();
     try {
-      ScmClient scmClient = createScmClient(conf);
-      Pipeline pipeline = scmClient.listPipelines()
-          .stream()
-          .filter(d -> d.getNodes().size() > 1)
-          .findFirst()
-          .get();
-      for (DatanodeDetails datanode : pipeline.getNodes()) {
-        Component dn =
-            new Component(Type.DATANODE, datanode.getUuid().toString(),
-                datanode.getHostName(), 9882);
-        result
-            .add(new LoggerSource(dn, "org.apache.ratis.server.impl",
-                defaultLevel(verbose)));
+      Optional<Pipeline> pipeline;
+      try (ScmClient scmClient = createScmClient(conf)) {
+        pipeline = scmClient.listPipelines()
+            .stream()
+            .filter(d -> d.getNodes().size() > 1)
+            .findFirst();
+      }
+      if (pipeline.isPresent()) {
+        for (DatanodeDetails datanode : pipeline.get().getNodes()) {
+          Component dn = new Component(
+              Type.DATANODE, datanode.getUuid().toString(),
+              datanode.getHostName(), 9882);
+          result.add(new LoggerSource(dn, "org.apache.ratis.server.impl",
+              defaultLevel(verbose)));
+        }
       }
     } catch (IOException e) {
-      throw new RuntimeException("Can't enumerate required logs", e);
+      throw new ExceptionInInitializerError(e);
 
 Review comment:
   @adoroszlai Agree, much better exception to throw.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to