Skip to content

Commit

Permalink
add out() and err() for easier use
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai committed Jan 11, 2025
1 parent e1bec22 commit dbe55af
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,4 +115,12 @@ public CommandLine getCmd() {
public boolean isVerbose() {
return verbose;
}

protected PrintWriter out() {
return cmd.getOut();
}

protected PrintWriter err() {
return cmd.getErr();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
}

0 comments on commit dbe55af

Please sign in to comment.