You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ec...@apache.org on 2013/08/02 22:33:45 UTC

[3/5] git commit: ACCUMULO-1620 limit the number of objects logged

ACCUMULO-1620 limit the number of objects logged


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9291beeb
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9291beeb
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9291beeb

Branch: refs/heads/master
Commit: 9291beebf7f6ef323a2f7a211edf121251e5741f
Parents: 9d50657
Author: Eric Newton <er...@gmail.com>
Authored: Fri Aug 2 16:26:46 2013 -0400
Committer: Eric Newton <er...@gmail.com>
Committed: Fri Aug 2 16:26:46 2013 -0400

----------------------------------------------------------------------
 .../security/AuditedSecurityOperation.java      | 24 +++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/9291beeb/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
index 7944ee3..ee337a5 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/AuditedSecurityOperation.java
@@ -17,8 +17,12 @@
 package org.apache.accumulo.server.security;
 
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.client.impl.Tables;
@@ -120,13 +124,27 @@ public class AuditedSecurityOperation extends SecurityOperation {
   }
   
   public static final String CAN_SCAN_AUDIT_TEMPLATE = "action: scan; targetTable: %s; authorizations: %s; range: %s; columns: %s; iterators: %s; iteratorOptions: %s;";
+  private static final int MAX_ELEMENTS_TO_LOG = 10;
+  
+  private static List<String> truncate(Collection<? extends Object> list) {
+    List<String> result = new ArrayList<String>();
+    int i = 0;
+    for (Object obj : list) {
+      if (i > MAX_ELEMENTS_TO_LOG) {
+        result.add(" and " + (list.size() - MAX_ELEMENTS_TO_LOG) + " more ");
+        break;
+      }
+      result.add(obj.toString());
+    }
+    return result;
+  }
   
   @Override
   public boolean canScan(TCredentials credentials, String tableId, TRange range, List<TColumn> columns, List<IterInfo> ssiList,
       Map<String,Map<String,String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
     if (shouldAudit(credentials, tableId)) {
       Range convertedRange = new Range(range);
-      List<Column> convertedColumns = Translator.translate(columns, new Translator.TColumnTranslator());
+      List<String> convertedColumns = truncate(Translator.translate(columns, new Translator.TColumnTranslator()));
       String tableName = getTableName(tableId);
       
       try {
@@ -152,6 +170,10 @@ public class AuditedSecurityOperation extends SecurityOperation {
       @SuppressWarnings({"unchecked", "rawtypes"})
       Map<KeyExtent,List<Range>> convertedBatch = Translator.translate(tbatch, new Translator.TKeyExtentTranslator(), new Translator.ListTranslator(
           new Translator.TRangeTranslator()));
+      Map<KeyExtent, List<String>> truncated = new HashMap<KeyExtent, List<String>>();
+      for (Entry<KeyExtent,List<Range>> entry : convertedBatch.entrySet()) {
+          truncated.put(entry.getKey(), truncate(entry.getValue()));
+      }
       List<Column> convertedColumns = Translator.translate(tcolumns, new Translator.TColumnTranslator());
       String tableName = getTableName(tableId);