hadoop-ozone-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [hadoop-ozone] branch master updated: HDDS-2975. Print Freon summary to log in non-interactive mode
Date Mon, 10 Feb 2020 15:06:26 GMT
This is an automated email from the ASF dual-hosted git repository.

elek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 295d030  HDDS-2975. Print Freon summary to log in non-interactive mode
295d030 is described below

commit 295d0305a2ac11f3c0fbb6069d97ebf31b8c3133
Author: Doroszlai, Attila <adoroszlai@apache.org>
AuthorDate: Mon Feb 10 15:54:38 2020 +0100

    HDDS-2975. Print Freon summary to log in non-interactive mode
    
    Closes #522
---
 .../hadoop/ozone/freon/BaseFreonGenerator.java     | 27 +++++++++++++++++-----
 .../java/org/apache/hadoop/ozone/freon/Freon.java  |  5 ++++
 .../org/apache/hadoop/ozone/freon/ProgressBar.java | 10 ++++++--
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
index 9380970..624a658 100644
--- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
+++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
@@ -19,13 +19,18 @@ package org.apache.hadoop.ozone.freon;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import com.codahale.metrics.ScheduledReporter;
+import com.codahale.metrics.Slf4jReporter;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
 import org.apache.hadoop.hdds.scm.protocolPB.StorageContainerLocationProtocolClientSideTranslatorPB;
@@ -252,7 +257,8 @@ public class BaseFreonGenerator {
 
     executor = Executors.newFixedThreadPool(threadNo);
 
-    progressBar = new ProgressBar(System.out, testNo, successCounter::get);
+    progressBar = new ProgressBar(System.out, testNo, successCounter::get,
+        freonCommand.isInteractive());
     progressBar.start();
 
     startTime = System.currentTimeMillis();
@@ -276,12 +282,21 @@ public class BaseFreonGenerator {
    * Print out reports from the executed tests.
    */
   public void printReport() {
-    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).build();
+    ScheduledReporter reporter = freonCommand.isInteractive()
+        ? ConsoleReporter.forRegistry(metrics).build()
+        : Slf4jReporter.forRegistry(metrics).build();
     reporter.report();
-    System.out.println("Total execution time (sec): " + Math
-        .round((System.currentTimeMillis() - startTime) / 1000.0));
-    System.out.println("Failures: " + failureCounter.get());
-    System.out.println("Successful executions: " + successCounter.get());
+
+    List<String> messages = new LinkedList<>();
+    messages.add("Total execution time (sec): " +
+        Math.round((System.currentTimeMillis() - startTime) / 1000.0));
+    messages.add("Failures: " + failureCounter.get());
+    messages.add("Successful executions: " + successCounter.get());
+
+    Consumer<String> print = freonCommand.isInteractive()
+        ? System.out::println
+        : LOG::info;
+    messages.forEach(print);
   }
 
   /**
diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
index e463281..d2f30f7 100644
--- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
+++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
@@ -57,6 +57,8 @@ public class Freon extends GenericCli {
           + "and profile endpoint")
   private boolean httpServer = false;
 
+  private final boolean interactive = System.console() != null;
+
   private FreonHttpServer freonHttpServer;
   private OzoneConfiguration conf;
 
@@ -94,4 +96,7 @@ public class Freon extends GenericCli {
     new Freon().run(args);
   }
 
+  public boolean isInteractive() {
+    return interactive;
+  }
 }
diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ProgressBar.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ProgressBar.java
index e98e8fb..86c9a95 100644
--- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ProgressBar.java
+++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ProgressBar.java
@@ -123,7 +123,7 @@ public class ProgressBar {
 
   private Runnable getProgressBar(final PrintStream stream) {
     return () -> {
-      stream.println();
+      println(stream);
       while (running && currentValue.getAsLong() < maxValue) {
         print(stream, currentValue.getAsLong());
         try {
@@ -134,7 +134,7 @@ public class ProgressBar {
         }
       }
       print(stream, maxValue);
-      stream.println();
+      println(stream);
       running = false;
     };
   }
@@ -152,6 +152,12 @@ public class ProgressBar {
     }
   }
 
+  private void println(PrintStream stream) {
+    if (interactive) {
+      stream.println();
+    }
+  }
+
   private void logProgressBar(PrintStream stream, long value) {
     double percent = 100.0 * value / maxValue;
     LOG.info(String


---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-commits-help@hadoop.apache.org


Mime
View raw message