You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/12/05 00:59:27 UTC

[46/50] [abbrv] git commit: ACCUMULO-802 Address some issues from ReviewBoard

ACCUMULO-802 Address some issues from ReviewBoard


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

Branch: refs/heads/master
Commit: 725d82150c1933a2948822f018f8d8767ad13a11
Parents: bbba3f5
Author: Christopher Tubbs <ct...@apache.org>
Authored: Thu Nov 7 20:10:39 2013 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Dec 4 18:46:11 2013 -0500

----------------------------------------------------------------------
 .../admin/TableNamespaceOperationsImpl.java     |   5 +-
 .../client/mock/MockSecurityOperations.java     |  67 ++++++------
 .../core/client/mock/MockTableOperations.java   | 106 +++++++++----------
 3 files changed, 89 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/725d8215/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
index 35fa8ae..602110b 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
@@ -49,6 +49,7 @@ import org.apache.accumulo.core.client.impl.ServerClient;
 import org.apache.accumulo.core.client.impl.TableNamespaces;
 import org.apache.accumulo.core.client.impl.Tables;
 import org.apache.accumulo.core.client.impl.thrift.ClientService;
+import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
 import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
 import org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException;
 import org.apache.accumulo.core.constraints.Constraint;
@@ -331,8 +332,8 @@ public class TableNamespaceOperationsImpl extends TableNamespaceOperationsHelper
     String namespaceId = TableNamespaces.getNamespaceId(instance, namespace);
 
     if (namespaceId.equals(Constants.SYSTEM_TABLE_NAMESPACE_ID) || namespaceId.equals(Constants.DEFAULT_TABLE_NAMESPACE_ID)) {
-      String why = "Can't delete the system or default table namespace";
-      throw new RuntimeException(why);
+      log.debug(credentials.getPrincipal() + " attempted to delete the " + namespaceId + " table namespace");
+      throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.UNSUPPORTED_OPERATION);
     }
 
     if (TableNamespaces.getTableIds(instance, namespaceId).size() > 0) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/725d8215/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
index dd48b52..9d85f9f 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
@@ -31,42 +31,42 @@ import org.apache.accumulo.core.security.TableNamespacePermission;
 import org.apache.accumulo.core.security.TablePermission;
 
 public class MockSecurityOperations implements SecurityOperations {
-  
+
   final private MockAccumulo acu;
-  
+
   MockSecurityOperations(MockAccumulo acu) {
     this.acu = acu;
   }
-  
+
   @Deprecated
   @Override
   public void createUser(String user, byte[] password, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
     createLocalUser(user, new PasswordToken(password));
     changeUserAuthorizations(user, authorizations);
   }
-  
+
   @Override
   public void createLocalUser(String principal, PasswordToken password) throws AccumuloException, AccumuloSecurityException {
     this.acu.users.put(principal, new MockUser(principal, password, new Authorizations()));
   }
-  
+
   @Deprecated
   @Override
   public void dropUser(String user) throws AccumuloException, AccumuloSecurityException {
     dropLocalUser(user);
   }
-  
+
   @Override
   public void dropLocalUser(String principal) throws AccumuloException, AccumuloSecurityException {
     this.acu.users.remove(principal);
   }
-  
+
   @Deprecated
   @Override
   public boolean authenticateUser(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
     return authenticateUser(user, new PasswordToken(password));
   }
-  
+
   @Override
   public boolean authenticateUser(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -74,13 +74,13 @@ public class MockSecurityOperations implements SecurityOperations {
       return false;
     return user.token.equals(token);
   }
-  
+
   @Deprecated
   @Override
   public void changeUserPassword(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
     changeLocalUserPassword(user, new PasswordToken(password));
   }
-  
+
   @Override
   public void changeLocalUserPassword(String principal, PasswordToken token) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -89,7 +89,7 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
   }
-  
+
   @Override
   public void changeUserAuthorizations(String principal, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -98,7 +98,7 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
   }
-  
+
   @Override
   public Authorizations getUserAuthorizations(String principal) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -107,7 +107,7 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
   }
-  
+
   @Override
   public boolean hasSystemPermission(String principal, SystemPermission perm) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -116,7 +116,7 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
   }
-  
+
   @Override
   public boolean hasTablePermission(String principal, String tableName, TablePermission perm) throws AccumuloException, AccumuloSecurityException {
     MockTable table = acu.tables.get(tableName);
@@ -127,18 +127,19 @@ public class MockSecurityOperations implements SecurityOperations {
       return false;
     return perms.contains(perm);
   }
-  
+
   @Override
-  public boolean hasTableNamespacePermission(String principal, String tableNamespace, TableNamespacePermission perm) throws AccumuloException, AccumuloSecurityException {
+  public boolean hasTableNamespacePermission(String principal, String tableNamespace, TableNamespacePermission perm) throws AccumuloException,
+      AccumuloSecurityException {
     MockTableNamespace namespace = acu.namespaces.get(tableNamespace);
     if (namespace == null)
-      throw new AccumuloSecurityException(tableNamespace, SecurityErrorCode.TABLE_DOESNT_EXIST);
+      throw new AccumuloSecurityException(tableNamespace, SecurityErrorCode.TABLE_NAMESPACE_DOESNT_EXIST);
     EnumSet<TableNamespacePermission> perms = namespace.userPermissions.get(principal);
     if (perms == null)
       return false;
     return perms.contains(perm);
   }
-  
+
   @Override
   public void grantSystemPermission(String principal, SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -147,7 +148,7 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
   }
-  
+
   @Override
   public void grantTablePermission(String principal, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
     if (acu.users.get(principal) == null)
@@ -161,21 +162,22 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       perms.add(permission);
   }
-  
+
   @Override
-  public void grantTableNamespacePermission(String principal, String tableNamespace, TableNamespacePermission permission) throws AccumuloException, AccumuloSecurityException {
+  public void grantTableNamespacePermission(String principal, String tableNamespace, TableNamespacePermission permission) throws AccumuloException,
+      AccumuloSecurityException {
     if (acu.users.get(principal) == null)
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
     MockTableNamespace namespace = acu.namespaces.get(tableNamespace);
     if (namespace == null)
-      throw new AccumuloSecurityException(tableNamespace, SecurityErrorCode.TABLE_DOESNT_EXIST);
+      throw new AccumuloSecurityException(tableNamespace, SecurityErrorCode.TABLE_NAMESPACE_DOESNT_EXIST);
     EnumSet<TableNamespacePermission> perms = namespace.userPermissions.get(principal);
     if (perms == null)
       namespace.userPermissions.put(principal, EnumSet.of(permission));
     else
       perms.add(permission);
   }
-  
+
   @Override
   public void revokeSystemPermission(String principal, SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
     MockUser user = acu.users.get(principal);
@@ -184,7 +186,7 @@ public class MockSecurityOperations implements SecurityOperations {
     else
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
   }
-  
+
   @Override
   public void revokeTablePermission(String principal, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
     if (acu.users.get(principal) == null)
@@ -195,31 +197,32 @@ public class MockSecurityOperations implements SecurityOperations {
     EnumSet<TablePermission> perms = table.userPermissions.get(principal);
     if (perms != null)
       perms.remove(permission);
-    
+
   }
-  
+
   @Override
-  public void revokeTableNamespacePermission(String principal, String tableNamespace, TableNamespacePermission permission) throws AccumuloException, AccumuloSecurityException {
+  public void revokeTableNamespacePermission(String principal, String tableNamespace, TableNamespacePermission permission) throws AccumuloException,
+      AccumuloSecurityException {
     if (acu.users.get(principal) == null)
       throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
     MockTableNamespace namespace = acu.namespaces.get(tableNamespace);
     if (namespace == null)
-      throw new AccumuloSecurityException(tableNamespace, SecurityErrorCode.TABLE_DOESNT_EXIST);
+      throw new AccumuloSecurityException(tableNamespace, SecurityErrorCode.TABLE_NAMESPACE_DOESNT_EXIST);
     EnumSet<TableNamespacePermission> perms = namespace.userPermissions.get(principal);
     if (perms != null)
       perms.remove(permission);
-    
+
   }
-  
+
   @Deprecated
   @Override
   public Set<String> listUsers() throws AccumuloException, AccumuloSecurityException {
     return listLocalUsers();
   }
-  
+
   @Override
   public Set<String> listLocalUsers() throws AccumuloException, AccumuloSecurityException {
     return acu.users.keySet();
   }
-  
+
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/725d8215/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
index 78b7826..e70a545 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
@@ -61,43 +61,39 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.Text;
 
 public class MockTableOperations extends TableOperationsHelper {
-  
+
   final private MockAccumulo acu;
   final private String username;
-  
+
   MockTableOperations(MockAccumulo acu, String username) {
     this.acu = acu;
     this.username = username;
   }
-  
+
   @Override
   public SortedSet<String> list() {
     return new TreeSet<String>(acu.tables.keySet());
   }
-  
-  /*
-   * @Override public SortedSet<String> listNamespaces() { return new TreeSet<String>(acu.namespaces.keySet()); }
-   */
-  
+
   @Override
   public boolean exists(String tableName) {
     return acu.tables.containsKey(tableName);
   }
-  
+
   private boolean namespaceExists(String namespace) {
     return acu.namespaces.containsKey(namespace);
   }
-  
+
   @Override
   public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
     create(tableName, true, TimeType.MILLIS);
   }
-  
+
   @Override
   public void create(String tableName, boolean versioningIter) throws AccumuloException, AccumuloSecurityException, TableExistsException {
     create(tableName, versioningIter, TimeType.MILLIS);
   }
-  
+
   @Override
   public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
     String namespace = Tables.extractNamespace(tableName);
@@ -106,51 +102,51 @@ public class MockTableOperations extends TableOperationsHelper {
     }
     if (exists(tableName))
       throw new TableExistsException(tableName, tableName, "");
-    
+
     if (!namespaceExists(namespace)) {
       throw new IllegalArgumentException("Table namespace (" + namespace + ") does not exist, create it first");
     }
     acu.createTable(username, tableName, versioningIter, timeType);
   }
-  
+
   @Override
   public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     acu.addSplits(tableName, partitionKeys);
   }
-  
+
   @Deprecated
   @Override
   public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
     return listSplits(tableName);
   }
-  
+
   @Deprecated
   @Override
   public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
     return listSplits(tableName);
   }
-  
+
   @Override
   public Collection<Text> listSplits(String tableName) throws TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     return acu.getSplits(tableName);
   }
-  
+
   @Override
   public Collection<Text> listSplits(String tableName, int maxSplits) throws TableNotFoundException {
     return listSplits(tableName);
   }
-  
+
   @Override
   public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     acu.tables.remove(tableName);
   }
-  
+
   @Override
   public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
       TableExistsException {
@@ -169,35 +165,35 @@ public class MockTableOperations extends TableOperationsHelper {
     acu.namespaces.put(namespace, n);
     acu.tables.put(newTableName, t);
   }
-  
+
   @Deprecated
   @Override
   public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {}
-  
+
   @Override
   public void setProperty(String tableName, String property, String value) throws AccumuloException, AccumuloSecurityException {
     acu.tables.get(tableName).settings.put(property, value);
   }
-  
+
   @Override
   public void removeProperty(String tableName, String property) throws AccumuloException, AccumuloSecurityException {
     acu.tables.get(tableName).settings.remove(property);
   }
-  
+
   @Override
   public Iterable<Entry<String,String>> getProperties(String tableName) throws TableNotFoundException {
     String namespace = Tables.extractNamespace(tableName);
-    
+
     if (!namespaceExists(namespace)) {
       throw new IllegalArgumentException("Table namespace (" + namespace + ") does not exist");
     }
-    
+
     Set<Entry<String,String>> props = new HashSet<Entry<String,String>>(acu.namespaces.get(namespace).settings.entrySet());
-    
+
     if (!exists(tableName)) {
       throw new TableNotFoundException(tableName, tableName, "");
     }
-    
+
     Set<Entry<String,String>> tableProps = acu.tables.get(tableName).settings.entrySet();
     for (Entry<String,String> e : tableProps) {
       if (props.contains(e)) {
@@ -207,21 +203,21 @@ public class MockTableOperations extends TableOperationsHelper {
     }
     return props;
   }
-  
+
   @Override
   public void setLocalityGroups(String tableName, Map<String,Set<Text>> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     acu.tables.get(tableName).setLocalityGroups(groups);
   }
-  
+
   @Override
   public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     return acu.tables.get(tableName).getLocalityGroups();
   }
-  
+
   @Override
   public Set<Range> splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException,
       TableNotFoundException {
@@ -229,7 +225,7 @@ public class MockTableOperations extends TableOperationsHelper {
       throw new TableNotFoundException(tableName, tableName, "");
     return Collections.singleton(range);
   }
-  
+
   @Override
   public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloException,
       AccumuloSecurityException, TableNotFoundException {
@@ -240,7 +236,7 @@ public class MockTableOperations extends TableOperationsHelper {
     }
     Path importPath = new Path(dir);
     Path failurePath = new Path(failureDir);
-    
+
     FileSystem fs = acu.getFileSystem();
     /*
      * check preconditions
@@ -315,35 +311,35 @@ public class MockTableOperations extends TableOperationsHelper {
       fs.delete(importStatus.getPath(), true);
     }
   }
-  
+
   @Override
   public void offline(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
     offline(tableName, false);
   }
-  
+
   @Override
   public void offline(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public void online(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
     online(tableName, false);
   }
-  
+
   @Override
   public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public void clearLocatorCache(String tableName) throws TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public Map<String,String> tableIdMap() {
     Map<String,String> result = new HashMap<String,String>();
@@ -357,23 +353,23 @@ public class MockTableOperations extends TableOperationsHelper {
     }
     return result;
   }
-  
+
   @Override
   public List<DiskUsage> getDiskUsage(Set<String> tables) throws AccumuloException, AccumuloSecurityException {
-    
+
     List<DiskUsage> diskUsages = new ArrayList<DiskUsage>();
     diskUsages.add(new DiskUsage(new TreeSet<String>(tables), 0l));
-    
+
     return diskUsages;
   }
-  
+
   @Override
   public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     acu.merge(tableName, start, end);
   }
-  
+
   @Override
   public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
     if (!exists(tableName))
@@ -382,63 +378,63 @@ public class MockTableOperations extends TableOperationsHelper {
     Set<Key> keep = new TreeSet<Key>(t.table.tailMap(new Key(start)).headMap(new Key(end)).keySet());
     t.table.keySet().removeAll(keep);
   }
-  
+
   @Override
   public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException,
       AccumuloException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
       TableNotFoundException, AccumuloException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
       throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
     throw new NotImplementedException();
   }
-  
+
   @Override
   public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
   }
-  
+
   @Override
   public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive)
       throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
     MockTable table = acu.tables.get(tableName);
     if (table == null)
       throw new TableNotFoundException(tableName, tableName, "no such table");
-    
+
     return FindMax.findMax(new MockScanner(table, auths), startRow, startInclusive, endRow, endInclusive);
   }
-  
+
   @Override
   public void importTable(String tableName, String exportDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {
     throw new NotImplementedException();
   }
-  
+
   @Override
   public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
     throw new NotImplementedException();
   }
-  
+
   @Override
   public boolean testClassLoad(String tableName, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException,
       TableNotFoundException {
-    
+
     try {
       AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
     } catch (ClassNotFoundException e) {