Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6E753E3B5 for ; Thu, 7 Mar 2013 22:11:29 +0000 (UTC) Received: (qmail 62137 invoked by uid 500); 7 Mar 2013 22:11:29 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 62111 invoked by uid 500); 7 Mar 2013 22:11:29 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 62083 invoked by uid 99); 7 Mar 2013 22:11:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Mar 2013 22:11:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Mar 2013 22:10:57 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 430372388993; Thu, 7 Mar 2013 22:10:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1454126 - in /accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client: ./ admin/ impl/ Date: Thu, 07 Mar 2013 22:10:33 -0000 To: commits@accumulo.apache.org From: kturner@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130307221034.430372388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kturner Date: Thu Mar 7 22:10:33 2013 New Revision: 1454126 URL: http://svn.apache.org/r1454126 Log: ACCUMULO-1018 applied patch from Kevin Faro that adds table info to security exception messages Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java Thu Mar 7 22:10:33 2013 @@ -18,6 +18,7 @@ package org.apache.accumulo.core.client; import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode; import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException; +import org.apache.commons.lang.StringUtils; /** * An Accumulo Exception for security violations, authentication failures, authorization failures, etc. @@ -61,6 +62,7 @@ public class AccumuloSecurityException e } private String user; + private String tableInfo; private SecurityErrorCode errorCode; /** @@ -89,6 +91,23 @@ public class AccumuloSecurityException e * the relevant user for the security violation * @param errorcode * the specific reason for this exception + * @param tableInfo + * the relevant tableInfo for the security violation + * @param cause + * the exception that caused this violation + */ + public AccumuloSecurityException(final String user, final SecurityErrorCode errorcode, final String tableInfo, final Throwable cause) { + super(getDefaultErrorMessage(errorcode), cause); + this.user = user; + this.errorCode = errorcode == null ? SecurityErrorCode.DEFAULT_SECURITY_ERROR : errorcode; + this.tableInfo = tableInfo; + } + + /** + * @param user + * the relevant user for the security violation + * @param errorcode + * the specific reason for this exception */ public AccumuloSecurityException(final String user, final SecurityErrorCode errorcode) { super(getDefaultErrorMessage(errorcode)); @@ -97,6 +116,21 @@ public class AccumuloSecurityException e } /** + * @param user + * the relevant user for the security violation + * @param errorcode + * the specific reason for this exception + * @param tableInfo + * the relevant tableInfo for the security violation + */ + public AccumuloSecurityException(final String user, final SecurityErrorCode errorcode, final String tableInfo) { + super(getDefaultErrorMessage(errorcode)); + this.user = user; + this.errorCode = errorcode == null ? SecurityErrorCode.DEFAULT_SECURITY_ERROR : errorcode; + this.tableInfo = tableInfo; + } + + /** * @return the relevant user for the security violation */ public String getUser() { @@ -108,6 +142,17 @@ public class AccumuloSecurityException e } /** + * @return the relevant tableInfo for the security violation + */ + public String getTableInfo() { + return tableInfo; + } + + public void setTableInfo(String tableInfo) { + this.tableInfo = tableInfo; + } + + /** * @return the specific reason for this exception */ public SecurityErrorCode getErrorCode() { @@ -115,6 +160,13 @@ public class AccumuloSecurityException e } public String getMessage() { - return "Error " + errorCode + " for user " + user + " - " + super.getMessage(); + StringBuilder message = new StringBuilder(); + message.append("Error ").append(errorCode); + message.append(" for user ").append(user); + if(!StringUtils.isEmpty(tableInfo)) { + message.append(" on table ").append(tableInfo); + } + message.append(" - ").append(super.getMessage()); + return message.toString(); } } Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java Thu Mar 7 22:10:33 2013 @@ -19,10 +19,12 @@ package org.apache.accumulo.core.client; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.accumulo.core.client.impl.Tables; import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode; import org.apache.accumulo.core.data.ConstraintViolationSummary; import org.apache.accumulo.core.data.KeyExtent; @@ -33,7 +35,7 @@ import org.apache.accumulo.core.data.Key */ public class MutationsRejectedException extends AccumuloException { private static final long serialVersionUID = 1L; - + private List cvsl; private Map> af; private Collection es; @@ -49,9 +51,9 @@ public class MutationsRejectedException * @param unknownErrors * number of unknown errors */ - public MutationsRejectedException(List cvsList, HashMap> hashMap, + public MutationsRejectedException(Instance instance, List cvsList, HashMap> hashMap, Collection serverSideErrors, int unknownErrors, Throwable cause) { - super("# constraint violations : " + cvsList.size() + " security codes: " + hashMap.values() + " # server errors " + serverSideErrors.size() + super("# constraint violations : " + cvsList.size() + " security codes: " + format(hashMap, instance) + " # server errors " + serverSideErrors.size() + " # exceptions " + unknownErrors, cause); this.cvsl = cvsList; this.af = hashMap; @@ -59,6 +61,22 @@ public class MutationsRejectedException this.unknownErrors = unknownErrors; } + private static String format(HashMap> hashMap, Instance instance) { + Map> errorMap = new HashMap>(); + + for(KeyExtent ke : hashMap.keySet()) { + String tableInfo = Tables.getPrintableTableInfoFromId(instance, ke.getTableId().toString()); + + if(!errorMap.containsKey(tableInfo)) { + errorMap.put(tableInfo, new HashSet()); + } + + errorMap.get(tableInfo).addAll(hashMap.get(ke)); + } + + return errorMap.toString(); + } + /** * @return the internal list of constraint violations */ Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java Thu Mar 7 22:10:33 2013 @@ -80,6 +80,7 @@ import org.apache.accumulo.core.security import org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException; import org.apache.accumulo.core.tabletserver.thrift.TabletClientService; import org.apache.accumulo.core.util.ArgumentChecker; +import org.apache.accumulo.core.util.ByteBufferUtil; import org.apache.accumulo.core.util.CachedConfiguration; import org.apache.accumulo.core.util.LocalityGroupUtil; import org.apache.accumulo.core.util.MetadataTable; @@ -289,7 +290,9 @@ public class TableOperationsImpl extends Tables.clearCache(instance); return ret; } catch (ThriftSecurityException e) { - throw new AccumuloSecurityException(e.user, e.code, e); + String tableName = ByteBufferUtil.toString(args.get(0)); + String tableInfo = Tables.getPrintableTableInfoFromName(instance, tableName); + throw new AccumuloSecurityException(e.user, e.code, tableInfo, e); } catch (ThriftTableOperationException e) { switch (e.getType()) { case EXISTS: Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java Thu Mar 7 22:10:33 2013 @@ -102,6 +102,26 @@ public class Tables { return tableId == null ? "(NAME:" + tableName + ")" : tableId; } + public static String getPrintableTableInfoFromId(Instance instance, String tableId) { + String tableName = null; + try { + tableName = getTableName(instance, tableId); + } catch (TableNotFoundException e) { + //handled in the string formatting + } + return tableName == null ? String.format("?(ID:%s)", tableId) : String.format("%s(ID:%s)", tableName, tableId); + } + + public static String getPrintableTableInfoFromName(Instance instance, String tableName) { + String tableId = null; + try { + tableId = getTableId(instance, tableName); + } catch (TableNotFoundException e) { + //handled in the string formatting + } + return tableId == null ? String.format("%s(?)", tableName) : String.format("%s(ID:%s)", tableName, tableId); + } + public static TableState getTableState(Instance instance, String tableId) { String statePath = ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_STATE; ZooCache zc = getZooCache(instance); Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java Thu Mar 7 22:10:33 2013 @@ -323,6 +323,10 @@ public class TabletServerBatchReaderIter doLookups(binnedRanges, receiver, columns); } + private String getTableInfo() { + return Tables.getPrintableTableInfoFromId(instance, table); + } + private class QueryTask implements Runnable { private String tsLocation; @@ -376,6 +380,7 @@ public class TabletServerBatchReaderIter locator.invalidateCache(tsLocation); log.debug(e.getMessage(), e); } catch (AccumuloSecurityException e) { + e.setTableInfo(getTableInfo()); log.debug(e.getMessage(), e); Tables.clearCache(instance); @@ -405,6 +410,7 @@ public class TabletServerBatchReaderIter log.debug(e.getMessage(), e); fatalException = e; } catch (AccumuloSecurityException e) { + e.setTableInfo(getTableInfo()); log.debug(e.getMessage(), e); fatalException = e; } catch (Throwable t) { Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java Thu Mar 7 22:10:33 2013 @@ -522,7 +522,7 @@ public class TabletServerBatchWriter { private void checkForFailures() throws MutationsRejectedException { if (somethingFailed) { List cvsList = violations.asList(); - throw new MutationsRejectedException(cvsList, new HashMap>(authorizationFailures), serverSideErrors, unknownErrors, lastUnknownError); + throw new MutationsRejectedException(instance, cvsList, new HashMap>(authorizationFailures), serverSideErrors, unknownErrors, lastUnknownError); } } Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java?rev=1454126&r1=1454125&r2=1454126&view=diff ============================================================================== --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java (original) +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java Thu Mar 7 22:10:33 2013 @@ -300,6 +300,7 @@ public class ThriftScanner { Tables.clearCache(instance); if (!Tables.exists(instance, scanState.tableName.toString())) throw new TableDeletedException(scanState.tableName.toString()); + e.setTableInfo(Tables.getPrintableTableInfoFromId(instance, scanState.tableName.toString())); throw e; } catch (TApplicationException tae) { throw new AccumuloServerException(loc.tablet_location, tae);