Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java (revision 1158848) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java (working copy) @@ -20,8 +20,11 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; @@ -36,9 +39,7 @@ import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.regionserver.wal.HLog.Reader; import org.apache.hadoop.hbase.util.Bytes; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; +import org.codehaus.jackson.map.ObjectMapper; /** * HLogPrettyPrinter prints the contents of a given HLog with a variety of @@ -65,6 +66,8 @@ private boolean firstTxn; // useful for programatic capture of JSON output private PrintStream out; + // for JSON encoding + private ObjectMapper mapper; /** * Basic constructor that simply initializes values to reasonable defaults. @@ -78,6 +81,7 @@ persistentOutput = false; firstTxn = true; out = System.out; + mapper = new ObjectMapper(); } /** @@ -239,23 +243,25 @@ HLogKey key = entry.getKey(); WALEdit edit = entry.getEdit(); // begin building a transaction structure - JSONObject txn = new JSONObject(key.toStringMap()); + Map txn = key.toStringMap(); // check output filters if (sequence >= 0 && ((Long) txn.get("sequence")) != sequence) continue; if (region != null && !((String) txn.get("region")).equals(region)) continue; // initialize list into which we will store atomic actions - JSONArray actions = new JSONArray(); + List actions = new ArrayList(); for (KeyValue kv : edit.getKeyValues()) { // add atomic operation to txn - JSONObject op = new JSONObject(kv.toStringMap()); + Map op = + new HashMap(kv.toStringMap()); if (outputValues) op.put("value", Bytes.toStringBinary(kv.getValue())); + // check row output filter if (row == null || ((String) op.get("row")).equals(row)) - actions.put(op); + actions.add(op); } - if (actions.length() == 0) + if (actions.size() == 0) continue; txn.put("actions", actions); if (outputJSON) { @@ -264,27 +270,26 @@ firstTxn = false; else out.print(","); - out.print(txn); + // encode and print JSON + out.print(mapper.writeValueAsString(txn)); } else { // Pretty output, complete with indentation by atomic action - out.println("Sequence " + txn.getLong("sequence") + " " - + "from region " + txn.getString("region") + " " + "in table " - + txn.getString("table")); - for (int i = 0; i < actions.length(); i++) { - JSONObject op = actions.getJSONObject(i); + out.println("Sequence " + txn.get("sequence") + " " + + "from region " + txn.get("region") + " " + "in table " + + txn.get("table")); + for (int i = 0; i < actions.size(); i++) { + Map op = actions.get(i); out.println(" Action:"); - out.println(" row: " + op.getString("row")); - out.println(" column: " + op.getString("family") + ":" - + op.getString("qualifier")); + out.println(" row: " + op.get("row")); + out.println(" column: " + op.get("family") + ":" + + op.get("qualifier")); out.println(" at time: " - + (new Date(op.getLong("timestamp")))); + + (new Date((Long) op.get("timestamp")))); if (outputValues) out.println(" value: " + op.get("value")); } } } - } catch (JSONException e) { - e.printStackTrace(); } finally { log.close(); } Index: pom.xml =================================================================== --- pom.xml (revision 1158848) +++ pom.xml (working copy) @@ -638,6 +638,7 @@ https://issues.apache.org/jira/secure/attachment/12459473/hdfs-895-branch-20-append.txt --> 0.20-append-r1057313 + 1.5.5 5.5.23 2.1 6.1.26 @@ -677,9 +678,6 @@ implementation of the same, because Hadoop also uses this version * javax.servlet:jsp-api in favour of org.mortbay.jetty:jsp-api-2.1 * javax.xml.stream:stax-api in favour of stax:stax-api - - Note: Both org.apache.avro:avro and com.sun.jersey:jersey-json depend on Jackson so the version - is chosen which comes first in the list of dependencies (jersey in this case) --> @@ -829,7 +827,30 @@ servlet-api-2.5 ${jetty.jspapi.version} + + org.codehaus.jackson + jackson-core-asl + ${jackson.version} + + + org.codehaus.jackson + jackson-mapper-asl + ${jackson.version} + + + org.codehaus.jackson + jackson-jaxrs + ${jackson.version} + + + org.codehaus.jackson + jackson-xc + ${jackson.version} + + org.slf4j slf4j-api ${slf4j.version}