Skip to content

Commit

Permalink
HBASE-21040 Replace call to printStackTrace() with proper logger call
Browse files Browse the repository at this point in the history
Signed-off-by: tedyu <yuzhihong@gmail.com>
  • Loading branch information
subrat.mishra authored and tedyu committed Aug 15, 2018
1 parent 1114a1a commit 49ae854
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private int parseAndRun(String[] args) throws IOException {
client.restore(BackupUtils.createRestoreRequest(backupRootDir, backupId, check,
sTableArray, tTableArray, overwrite));
} catch (Exception e) {
e.printStackTrace();
LOG.error("Error while running restore backup", e);
return -5;
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ private void handleException() throws IOException {
// Rethrow the exception so the application can handle it.
while (!exceptionsQueue.isEmpty()) {
Exception first = exceptionsQueue.peek();
first.printStackTrace();
if (first instanceof IOException) {
throw (IOException) first;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ static void throwEnrichedException(ExecutionException e, int retries)
throws RetriesExhaustedException, DoNotRetryIOException {
Throwable t = e.getCause();
assert t != null; // That's what ExecutionException is about: holding an exception
t.printStackTrace();

if (t instanceof RetriesExhaustedException) {
throw (RetriesExhaustedException) t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,27 +244,28 @@ public Filter parseSimpleFilterExpression (byte [] filterStringAsByteArray)
throws CharacterCodingException {

String filterName = Bytes.toString(getFilterName(filterStringAsByteArray));
ArrayList<byte []> filterArguments = getFilterArguments(filterStringAsByteArray);
ArrayList<byte[]> filterArguments = getFilterArguments(filterStringAsByteArray);
if (!filterHashMap.containsKey(filterName)) {
throw new IllegalArgumentException("Filter Name " + filterName + " not supported");
}
filterName = filterHashMap.get(filterName);
final String methodName = "createFilterFromArguments";
try {
filterName = filterHashMap.get(filterName);
Class<?> c = Class.forName(filterName);
Class<?>[] argTypes = new Class [] {ArrayList.class};
Method m = c.getDeclaredMethod("createFilterFromArguments", argTypes);
return (Filter) m.invoke(null,filterArguments);
Class<?>[] argTypes = new Class[] { ArrayList.class };
Method m = c.getDeclaredMethod(methodName, argTypes);
return (Filter) m.invoke(null, filterArguments);
} catch (ClassNotFoundException e) {
e.printStackTrace();
LOG.error("Could not find class {}", filterName, e);
} catch (NoSuchMethodException e) {
e.printStackTrace();
LOG.error("Could not find method {} in {}", methodName, filterName, e);
} catch (IllegalAccessException e) {
e.printStackTrace();
LOG.error("Unable to access specified class {}", filterName, e);
} catch (InvocationTargetException e) {
e.printStackTrace();
LOG.error("Method {} threw an exception for {}", methodName, filterName, e);
}
throw new IllegalArgumentException("Incorrect filter string " +
new String(filterStringAsByteArray, StandardCharsets.UTF_8));
throw new IllegalArgumentException(
"Incorrect filter string " + new String(filterStringAsByteArray, StandardCharsets.UTF_8));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Sample Uploader MapReduce
Expand All @@ -60,6 +62,7 @@
*/
@InterfaceAudience.Private
public class SampleUploader extends Configured implements Tool {
private static final Logger LOG = LoggerFactory.getLogger(SampleUploader.class);

private static final String NAME = "SampleUploader";

Expand Down Expand Up @@ -100,7 +103,8 @@ public void map(LongWritable key, Text line, Context context)
try {
context.write(new ImmutableBytesWritable(row), put);
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted emitting put", e);
Thread.currentThread().interrupt();
}

// Set status every checkpoint lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* See the instructions under hbase-examples/README.txt
*/
@InterfaceAudience.Private
public class DemoClient {
private static final Logger LOG = LoggerFactory.getLogger(DemoClient.class);

static protected int port;
static protected String host;
Expand Down Expand Up @@ -110,15 +113,15 @@ private String utf8(byte[] buf) {
}
}

// Helper to translate strings to UTF8 bytes
private byte[] bytes(String s) {
try {
return s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
// Helper to translate strings to UTF8 bytes
private byte[] bytes(String s) {
try {
return s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.error("CharSetName {} not supported", s, e);
return null;
}
}

private void run() throws Exception {
TTransport transport = new TSocket(host, port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@
import org.ietf.jgss.GSSManager;
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* See the instructions under hbase-examples/README.txt
*/
@InterfaceAudience.Private
public class HttpDoAsClient {
private static final Logger LOG = LoggerFactory.getLogger(HttpDoAsClient.class);

static protected int port;
static protected String host;
Expand Down Expand Up @@ -113,7 +116,7 @@ private byte[] bytes(String s) {
try {
return s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
LOG.error("CharSetName {} not supported", s, e);
return null;
}
}
Expand Down Expand Up @@ -188,7 +191,7 @@ private Hbase.Client refresh(Hbase.Client client, THttpClient httpClient) {
try {
httpClient.setCustomHeader("Authorization", generateTicket());
} catch (GSSException e) {
e.printStackTrace();
LOG.error("Kerberos authentication failed", e);
}
}
return client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.apache.hadoop.mapred.OutputFormat;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Collection;
Expand All @@ -51,6 +53,7 @@
@InterfaceAudience.Public
@SuppressWarnings({ "rawtypes", "unchecked" })
public class TableMapReduceUtil {
private static final Logger LOG = LoggerFactory.getLogger(TableMapReduceUtil.class);

/**
* Use this before submitting a TableMap job. It will
Expand Down Expand Up @@ -110,14 +113,14 @@ public static void initTableMapJob(String table, String columns,
try {
addDependencyJars(job);
} catch (IOException e) {
e.printStackTrace();
LOG.error("IOException encountered while adding dependency jars", e);
}
}
try {
initCredentials(job);
} catch (IOException ioe) {
// just spit out the stack trace? really?
ioe.printStackTrace();
LOG.error("IOException encountered while initializing credentials", ioe);
}
}

Expand Down Expand Up @@ -310,7 +313,7 @@ public static void initCredentials(JobConf job) throws IOException {
User user = userProvider.getCurrent();
TokenUtil.addTokenForJob(conn, job, user);
} catch (InterruptedException ie) {
ie.printStackTrace();
LOG.error("Interrupted obtaining user authentication token", ie);
Thread.currentThread().interrupt();
} finally {
conn.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public void map(ImmutableBytesWritable row, Result values,
context.getCounter(Counters.CELLS).increment(cellCount);
}
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while writing cellCount", e);
Thread.currentThread().interrupt();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private boolean doCommandLine(final String[] args) {
dstTableName = tableName;
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("Failed to parse commandLine arguments", e);
printUsage("Can't start because " + e.getMessage());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ private boolean doCommandLine(final String[] args) {
}

} catch (Exception e) {
e.printStackTrace();
LOG.error("Failed to parse commandLine arguments", e);
printUsage("Can't start because " + e.getMessage());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ public void map(ImmutableBytesWritable row, Result value,
}
}
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while emitting Cell", e);
Thread.currentThread().interrupt();
}
}

Expand Down Expand Up @@ -286,7 +287,8 @@ public void map(ImmutableBytesWritable row, Result value,
}
}
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while emitting Cell", e);
Thread.currentThread().interrupt();
}
}

Expand Down Expand Up @@ -319,7 +321,8 @@ public void map(ImmutableBytesWritable row, Result value,
try {
writeResult(row, value, context);
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while writing result", e);
Thread.currentThread().interrupt();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ private boolean doCommandLine(final String[] args) {


} catch (Exception e) {
e.printStackTrace();
LOG.error("Failed to parse commandLine arguments", e);
printUsage("Can't start because " + e.getMessage());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Counter;
import org.apache.hadoop.mapreduce.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Write table content out to files in hdfs.
*/
@InterfaceAudience.Public
public class TsvImporterMapper
extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put>
{
extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
private static final Logger LOG = LoggerFactory.getLogger(TsvImporterMapper.class);

/** Timestamp for all inserted rows */
protected long ts;
Expand Down Expand Up @@ -199,7 +201,8 @@ public void map(LongWritable offset, Text value,
}
throw new IOException(badLine);
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while emitting put", e);
Thread.currentThread().interrupt();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
import org.apache.hadoop.mapreduce.Counter;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Write table content out to map output files.
*/
@InterfaceAudience.Public
public class TsvImporterTextMapper
extends Mapper<LongWritable, Text, ImmutableBytesWritable, Text>
{
extends Mapper<LongWritable, Text, ImmutableBytesWritable, Text> {
private static final Logger LOG = LoggerFactory.getLogger(TsvImporterTextMapper.class);

/** Column seperator */
private String separator;
Expand Down Expand Up @@ -121,7 +123,7 @@ public void map(LongWritable offset, Text value, Context context) throws IOExcep
}
throw new IOException(badLine);
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while emitting TSV text", e);
Thread.currentThread().interrupt();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void map(WALKey key, WALEdit value, Context context) throws IOException {
}
}
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while emitting Cell", e);
Thread.currentThread().interrupt();
}
}

Expand Down Expand Up @@ -199,7 +200,8 @@ public void map(WALKey key, WALEdit value, Context context) throws IOException {
}
}
} catch (InterruptedException e) {
e.printStackTrace();
LOG.error("Interrupted while writing results", e);
Thread.currentThread().interrupt();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public boolean doCommandLine(final String[] args) {
}

} catch (Exception e) {
e.printStackTrace();
LOG.error("Failed to parse commandLine arguments", e);
printUsage("Can't start because " + e.getMessage());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.procedure2.Procedure;
import org.apache.hadoop.hbase.procedure2.ProcedureUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureWALEntry;
Expand All @@ -51,6 +53,8 @@
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
@InterfaceStability.Evolving
public class ProcedureWALPrettyPrinter extends Configured implements Tool {
private static final Logger LOG = LoggerFactory.getLogger(ProcedureWALPrettyPrinter.class);

private final PrintStream out;

public ProcedureWALPrettyPrinter() {
Expand Down Expand Up @@ -171,7 +175,7 @@ public int run(final String[] args) throws IOException {
return(-1);
}
} catch (ParseException e) {
e.printStackTrace();
LOG.error("Failed to parse commandLine arguments", e);
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("ProcedureWALPrettyPrinter ", options, true);
return(-1);
Expand Down
Loading

0 comments on commit 49ae854

Please sign in to comment.