ACCUMULO-802 Lookup namespace config dynamically per table
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/77a3aa46 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/77a3aa46 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/77a3aa46 Branch: refs/heads/ACCUMULO-802 Commit: 77a3aa461f81d55c19b463d5d8d24a398c6753e4 Parents: a9ede22 Author: Christopher Tubbs <[email protected]> Authored: Fri Jul 12 12:11:34 2013 -0400 Committer: Christopher Tubbs <[email protected]> Committed: Thu Oct 31 21:22:25 2013 -0400 ---------------------------------------------------------------------- .../server/client/ClientServiceHandler.java | 88 ++++++++++---------- .../server/conf/ServerConfiguration.java | 14 ++-- .../conf/TableNamespaceConfiguration.java | 26 +++--- 3 files changed, 64 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/77a3aa46/server/base/src/main/java/org/apache/accumulo/server/client/ClientServiceHandler.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/client/ClientServiceHandler.java b/server/base/src/main/java/org/apache/accumulo/server/client/ClientServiceHandler.java index e061f99..d0d83cb 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/client/ClientServiceHandler.java +++ b/server/base/src/main/java/org/apache/accumulo/server/client/ClientServiceHandler.java @@ -71,13 +71,13 @@ public class ClientServiceHandler implements ClientService.Iface { protected final TransactionWatcher transactionWatcher; private final Instance instance; private final VolumeManager fs; - + public ClientServiceHandler(Instance instance, TransactionWatcher transactionWatcher, VolumeManager fs) { this.instance = instance; this.transactionWatcher = transactionWatcher; this.fs = fs; } - + protected String checkTableId(String tableName, TableOperation operation) throws ThriftTableOperationException { String tableId = Tables.getNameToIdMap(instance).get(tableName); if (tableId == null) { @@ -89,28 +89,28 @@ public class ClientServiceHandler implements ClientService.Iface { } return tableId; } - + @Override public String getInstanceId() { return instance.getInstanceID(); } - + @Override public String getRootTabletLocation() { return instance.getRootTabletLocation(); } - + @Override public String getZooKeepers() { return instance.getZooKeepers(); } - + @Override public void ping(TCredentials credentials) { // anybody can call this; no authentication check log.info("Master reports: I just got pinged!"); } - + @Override public boolean authenticate(TInfo tinfo, TCredentials credentials) throws ThriftSecurityException { try { @@ -120,7 +120,7 @@ public class ClientServiceHandler implements ClientService.Iface { throw e; } } - + @Override public boolean authenticateUser(TInfo tinfo, TCredentials credentials, TCredentials toAuth) throws ThriftSecurityException { try { @@ -130,81 +130,81 @@ public class ClientServiceHandler implements ClientService.Iface { throw e; } } - + @Override public void changeAuthorizations(TInfo tinfo, TCredentials credentials, String user, List<ByteBuffer> authorizations) throws ThriftSecurityException { security.changeAuthorizations(credentials, user, new Authorizations(authorizations)); } - + @Override public void changeLocalUserPassword(TInfo tinfo, TCredentials credentials, String principal, ByteBuffer password) throws ThriftSecurityException { PasswordToken token = new PasswordToken(password); Credentials toChange = new Credentials(principal, token); security.changePassword(credentials, toChange); } - + @Override public void createLocalUser(TInfo tinfo, TCredentials credentials, String principal, ByteBuffer password) throws ThriftSecurityException { PasswordToken token = new PasswordToken(password); Credentials newUser = new Credentials(principal, token); security.createUser(credentials, newUser, new Authorizations()); } - + @Override public void dropLocalUser(TInfo tinfo, TCredentials credentials, String user) throws ThriftSecurityException { security.dropUser(credentials, user); } - + @Override public List<ByteBuffer> getUserAuthorizations(TInfo tinfo, TCredentials credentials, String user) throws ThriftSecurityException { return security.getUserAuthorizations(credentials, user).getAuthorizationsBB(); } - + @Override public void grantSystemPermission(TInfo tinfo, TCredentials credentials, String user, byte permission) throws ThriftSecurityException { security.grantSystemPermission(credentials, user, SystemPermission.getPermissionById(permission)); } - + @Override public void grantTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(tableName, TableOperation.PERMISSION); security.grantTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission)); } - + @Override public void revokeSystemPermission(TInfo tinfo, TCredentials credentials, String user, byte permission) throws ThriftSecurityException { security.revokeSystemPermission(credentials, user, SystemPermission.getPermissionById(permission)); } - + @Override public void revokeTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(tableName, TableOperation.PERMISSION); security.revokeTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission)); } - + @Override public boolean hasSystemPermission(TInfo tinfo, TCredentials credentials, String user, byte sysPerm) throws ThriftSecurityException { return security.hasSystemPermission(credentials, user, SystemPermission.getPermissionById(sysPerm)); } - + @Override public boolean hasTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte tblPerm) throws ThriftSecurityException, ThriftTableOperationException { String tableId = checkTableId(tableName, TableOperation.PERMISSION); return security.hasTablePermission(credentials, user, tableId, TablePermission.getPermissionById(tblPerm)); } - + @Override public Set<String> listLocalUsers(TInfo tinfo, TCredentials credentials) throws ThriftSecurityException { return security.listUsers(credentials); } - + private static Map<String,String> conf(TCredentials credentials, AccumuloConfiguration conf) throws TException { security.authenticateUser(credentials, credentials); conf.invalidateCache(); - + Map<String,String> result = new HashMap<String,String>(); for (Entry<String,String> entry : conf) { String key = entry.getKey(); @@ -213,7 +213,7 @@ public class ClientServiceHandler implements ClientService.Iface { } return result; } - + @Override public Map<String,String> getConfiguration(TInfo tinfo, TCredentials credentials, ConfigurationType type) throws TException { switch (type) { @@ -226,14 +226,14 @@ public class ClientServiceHandler implements ClientService.Iface { } throw new RuntimeException("Unexpected configuration type " + type); } - + @Override public Map<String,String> getTableConfiguration(TInfo tinfo, TCredentials credentials, String tableName) throws TException, ThriftTableOperationException { String tableId = checkTableId(tableName, null); AccumuloConfiguration config = new ServerConfiguration(instance).getTableConfiguration(tableId); return conf(credentials, config); } - + @Override public List<String> bulkImportFiles(TInfo tinfo, final TCredentials credentials, final long tid, final String tableId, final List<String> files, final String errorDir, final boolean setTime) throws ThriftSecurityException, ThriftTableOperationException, TException { @@ -253,17 +253,17 @@ public class ClientServiceHandler implements ClientService.Iface { throw new TException(ex); } } - + @Override public boolean isActive(TInfo tinfo, long tid) throws TException { return transactionWatcher.isActive(tid); } - + @SuppressWarnings({"rawtypes", "unchecked"}) @Override public boolean checkClass(TInfo tinfo, TCredentials credentials, String className, String interfaceMatch) throws TException { security.authenticateUser(credentials, credentials); - + ClassLoader loader = getClass().getClassLoader(); Class shouldMatch; try { @@ -285,32 +285,32 @@ public class ClientServiceHandler implements ClientService.Iface { return false; } } - + @Override public boolean checkTableClass(TInfo tinfo, TCredentials credentials, String tableName, String className, String interfaceMatch) throws TException, ThriftTableOperationException, ThriftSecurityException { - + security.authenticateUser(credentials, credentials); - + String tableId = checkTableId(tableName, null); - + ClassLoader loader = getClass().getClassLoader(); Class<?> shouldMatch; try { shouldMatch = loader.loadClass(interfaceMatch); - + new ServerConfiguration(instance).getTableConfiguration(tableId); - + String context = new ServerConfiguration(instance).getTableConfiguration(tableId).get(Property.TABLE_CLASSPATH); - + ClassLoader currentLoader; - + if (context != null && !context.equals("")) { currentLoader = AccumuloVFSClassLoader.getContextManager().getClassLoader(context); } else { currentLoader = AccumuloVFSClassLoader.getClassLoader(); } - + Class<?> test = currentLoader.loadClass(className).asSubclass(shouldMatch); test.newInstance(); return true; @@ -319,15 +319,15 @@ public class ClientServiceHandler implements ClientService.Iface { return false; } } - + @Override public List<TDiskUsage> getDiskUsage(Set<String> tables, TCredentials credentials) throws ThriftTableOperationException, ThriftSecurityException, TException { try { AuthenticationToken token = AuthenticationTokenSerializer.deserialize(credentials.getTokenClassName(), credentials.getToken()); Connector conn = instance.getConnector(credentials.getPrincipal(), token); - + HashSet<String> tableIds = new HashSet<String>(); - + for (String table : tables) { // ensure that table table exists String tableId = checkTableId(table, null); @@ -335,7 +335,7 @@ public class ClientServiceHandler implements ClientService.Iface { if (!security.canScan(credentials, tableId)) throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED); } - + // use the same set of tableIds that were validated above to avoid race conditions Map<TreeSet<String>,Long> diskUsage = TableDiskUsage.getDiskUsage(new ServerConfiguration(instance).getConfiguration(), tableIds, fs, conn); List<TDiskUsage> retUsages = new ArrayList<TDiskUsage>(); @@ -343,7 +343,7 @@ public class ClientServiceHandler implements ClientService.Iface { retUsages.add(new TDiskUsage(new ArrayList<String>(usageItem.getKey()), usageItem.getValue())); } return retUsages; - + } catch (AccumuloSecurityException e) { throw e.asThriftException(); } catch (AccumuloException e) { @@ -352,7 +352,7 @@ public class ClientServiceHandler implements ClientService.Iface { throw new TException(e); } } - + @Override public Map<String,String> getTableNamespaceConfiguration(TInfo tinfo, TCredentials credentials, String ns) throws ThriftTableOperationException, TException { String namespaceId; @@ -362,7 +362,7 @@ public class ClientServiceHandler implements ClientService.Iface { String why = "Could not find table namespace while getting configuration."; throw new ThriftTableOperationException(null, ns, null, null, why); } - AccumuloConfiguration config = new ServerConfiguration(instance).getTableNamespaceConfiguration(namespaceId); + AccumuloConfiguration config = ServerConfiguration.getTableNamespaceConfiguration(instance, namespaceId); return conf(credentials, config); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/77a3aa46/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java index 7897093..f1bd8e7 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java @@ -61,14 +61,14 @@ public class ServerConfiguration { return getZooConfiguration(instance); } - public static TableNamespaceConfiguration getTableNamespaceConfiguration(Instance instance, String namespaceId) { + public static TableNamespaceConfiguration getTableNamespaceConfiguration(Instance instance, String tableId) { checkPermissions(); synchronized (tableNamespaceInstances) { - TableNamespaceConfiguration conf = tableNamespaceInstances.get(namespaceId); + TableNamespaceConfiguration conf = tableNamespaceInstances.get(tableId); if (conf == null) { - conf = new TableNamespaceConfiguration(instance, namespaceId, getSystemConfiguration(instance)); + conf = new TableNamespaceConfiguration(tableId, getSystemConfiguration(instance)); ConfigSanityCheck.validate(conf); - tableNamespaceInstances.put(namespaceId, conf); + tableNamespaceInstances.put(tableId, conf); } return conf; } @@ -79,7 +79,7 @@ public class ServerConfiguration { synchronized (tableInstances) { TableConfiguration conf = tableInstances.get(tableId); if (conf == null && Tables.exists(instance, tableId)) { - conf = new TableConfiguration(instance.getInstanceID(), tableId, getTableNamespaceConfiguration(instance, Tables.getNamespace(instance, tableId))); + conf = new TableConfiguration(instance.getInstanceID(), tableId, getTableNamespaceConfiguration(instance, tableId)); ConfigSanityCheck.validate(conf); tableInstances.put(tableId, conf); } @@ -115,10 +115,6 @@ public class ServerConfiguration { return getTableConfiguration(extent.getTableId().toString()); } - public TableNamespaceConfiguration getTableNamespaceConfiguration(String namespaceId) { - return getTableNamespaceConfiguration(instance, namespaceId); - } - public synchronized AccumuloConfiguration getConfiguration() { return getZooConfiguration(instance); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/77a3aa46/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java index a5c3437..c8498a1 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java @@ -23,6 +23,7 @@ import java.util.TreeMap; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.impl.Tables; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.zookeeper.ZooUtil; @@ -34,17 +35,18 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration { private static final Logger log = Logger.getLogger(TableNamespaceConfiguration.class); private final AccumuloConfiguration parent; - private final String instanceId; private static ZooCache propCache = null; - private String namespaceId = null; + private String tableId = null; + private Instance inst = null; - public TableNamespaceConfiguration (Instance inst, String namespaceId, AccumuloConfiguration parent) { - propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut()); - this.instanceId = inst.getInstanceID(); - this.parent = parent; - this.namespaceId = namespaceId; + public TableNamespaceConfiguration(String tableId, AccumuloConfiguration parent) { + inst = HdfsZooInstance.getInstance(); + propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut()); + this.parent = parent; + this.tableId = tableId; } - + + @Override public void invalidateCache() { if (propCache != null) propCache.clear(); @@ -64,11 +66,12 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration { } private String get(String key) { - String zPath = ZooUtil.getRoot(instanceId) + Constants.ZNAMESPACES + "/" + namespaceId + Constants.ZNAMESPACE_CONF + "/" + key; + String zPath = ZooUtil.getRoot(inst.getInstanceID()) + Constants.ZNAMESPACES + "/" + Tables.getNamespace(inst, tableId) + Constants.ZNAMESPACE_CONF + "/" + + key; byte[] v = getPropCache().get(zPath); String value = null; if (v != null) - value = new String(v); + value = new String(v, Constants.UTF8); return value; } @@ -89,7 +92,8 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration { for (Entry<String,String> parentEntry : parent) entries.put(parentEntry.getKey(), parentEntry.getValue()); - List<String> children = getPropCache().getChildren(ZooUtil.getRoot(instanceId) + Constants.ZNAMESPACES + "/" + namespaceId + Constants.ZNAMESPACE_CONF); + List<String> children = getPropCache().getChildren( + ZooUtil.getRoot(inst.getInstanceID()) + Constants.ZNAMESPACES + "/" + Tables.getNamespace(inst, tableId) + Constants.ZNAMESPACE_CONF); if (children != null) { for (String child : children) { String value = get(child);
