From dbe55afde01edfb822301a5b56a444d95a812736 Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Sat, 11 Jan 2025 06:46:48 +0100 Subject: [PATCH] add out() and err() for easier use --- .../main/java/org/apache/hadoop/hdds/cli/GenericCli.java | 9 +++++++++ .../hdds/scm/server/StorageContainerManagerStarter.java | 4 ++-- .../java/org/apache/hadoop/ozone/conf/OzoneGetConf.java | 4 ++-- .../genconf/GenerateOzoneRequiredConfigurations.java | 4 ++-- .../main/java/org/apache/hadoop/ozone/shell/Shell.java | 2 +- .../hadoop/ozone/shell/checknative/CheckNative.java | 8 ++++---- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java index db2612bac5a..3ec9048dfcf 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java @@ -17,6 +17,7 @@ package org.apache.hadoop.hdds.cli; import java.io.IOException; +import java.io.PrintWriter; import java.util.Map; import com.google.common.base.Strings; @@ -114,4 +115,12 @@ public CommandLine getCmd() { public boolean isVerbose() { return verbose; } + + protected PrintWriter out() { + return cmd.getOut(); + } + + protected PrintWriter err() { + return cmd.getErr(); + } } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManagerStarter.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManagerStarter.java index 3753b231866..353c6c50104 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManagerStarter.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManagerStarter.java @@ -92,8 +92,8 @@ public Void call() throws Exception { versionProvider = HddsVersionProvider.class) public void generateClusterId() { commonInit(); - getCmd().getOut().println("Generating new cluster id:"); - getCmd().getOut().println(receiver.generateClusterId()); + out().println("Generating new cluster id:"); + out().println(receiver.generateClusterId()); } /** diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneGetConf.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneGetConf.java index 9e13efa3909..1ae3aa51def 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneGetConf.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneGetConf.java @@ -45,11 +45,11 @@ public class OzoneGetConf extends GenericCli { void printError(String message) { - getCmd().getErr().println(message); + err().println(message); } void printOut(String message) { - getCmd().getOut().println(message); + out().println(message); } OzoneConfiguration getConf() { diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java index fba34aa37ec..c29a90ec0d0 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java @@ -145,9 +145,9 @@ private void generateConfigurations() throws m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(generatedConfig, output); - getCmd().getOut().println("ozone-site.xml has been generated at " + path); + out().println("ozone-site.xml has been generated at " + path); } else { - getCmd().getOut().printf("ozone-site.xml already exists at %s and " + + out().printf("ozone-site.xml already exists at %s and " + "will not be overwritten%n", path); } diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/Shell.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/Shell.java index b1fa6a57150..515dcec1796 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/Shell.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/Shell.java @@ -109,7 +109,7 @@ public void printError(Throwable errorArg) { if (omException != null && !isVerbose()) { // In non-verbose mode, reformat OMExceptions as error messages to the // user. - getCmd().getErr().println(String.format("%s %s", omException.getResult().name(), + err().println(String.format("%s %s", omException.getResult().name(), omException.getMessage())); } else { // Prints the stack trace when in verbose mode. diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java index 46c27fd190d..1298811fa40 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java @@ -57,10 +57,10 @@ public Void call() throws Exception { isalLoaded = true; } } - getCmd().getOut().println("Native library checking:"); - getCmd().getOut().printf("hadoop: %b %s%n", nativeHadoopLoaded, + out().println("Native library checking:"); + out().printf("hadoop: %b %s%n", nativeHadoopLoaded, hadoopLibraryName); - getCmd().getOut().printf("ISA-L: %b %s%n", isalLoaded, isalDetail); + out().printf("ISA-L: %b %s%n", isalLoaded, isalDetail); // Attempt to load the rocks-tools lib boolean nativeRocksToolsLoaded = NativeLibraryLoader.getInstance().loadLibrary( @@ -70,7 +70,7 @@ public Void call() throws Exception { if (nativeRocksToolsLoaded) { rocksToolsDetail = NativeLibraryLoader.getJniLibraryFileName(); } - getCmd().getOut().printf("rocks-tools: %b %s%n", nativeRocksToolsLoaded, rocksToolsDetail); + out().printf("rocks-tools: %b %s%n", nativeRocksToolsLoaded, rocksToolsDetail); return null; } }