http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/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 deleted file mode 100644 index a7d0c34..0000000 --- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java +++ /dev/null @@ -1,590 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.accumulo.core.client.admin; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import jline.internal.Log; - -import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.client.AccumuloException; -import org.apache.accumulo.core.client.AccumuloSecurityException; -import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.IteratorSetting; -import org.apache.accumulo.core.client.TableNamespaceExistsException; -import org.apache.accumulo.core.client.TableNamespaceNotEmptyException; -import org.apache.accumulo.core.client.TableNamespaceNotFoundException; -import org.apache.accumulo.core.client.TableNotFoundException; -import org.apache.accumulo.core.client.TableOfflineException; -import org.apache.accumulo.core.client.impl.ClientExec; -import org.apache.accumulo.core.client.impl.ClientExecReturn; -import org.apache.accumulo.core.client.impl.MasterClient; -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; -import org.apache.accumulo.core.iterators.IteratorUtil; -import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; -import org.apache.accumulo.core.iterators.SortedKeyValueIterator; -import org.apache.accumulo.core.master.thrift.MasterClientService; -import org.apache.accumulo.core.master.thrift.TableOperation; -import org.apache.accumulo.core.security.Credentials; -import org.apache.accumulo.core.util.ArgumentChecker; -import org.apache.accumulo.core.util.ByteBufferUtil; -import org.apache.accumulo.core.util.OpTimer; -import org.apache.accumulo.core.util.UtilWaitThread; -import org.apache.accumulo.trace.instrument.Tracer; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.thrift.TException; -import org.apache.thrift.transport.TTransportException; - -/** - * Provides a class for administering table namespaces - * - */ -public class TableNamespaceOperationsImpl extends TableNamespaceOperationsHelper { - private Instance instance; - private Credentials credentials; - - private static final Logger log = Logger.getLogger(TableOperations.class); - - /** - * @param instance - * the connection information for this instance - * @param credentials - * the username/password for this connection - */ - public TableNamespaceOperationsImpl(Instance instance, Credentials credentials) { - ArgumentChecker.notNull(instance, credentials); - this.instance = instance; - this.credentials = credentials; - } - - /** - * Retrieve a list of table namespaces in Accumulo. - * - * @return List of table namespaces in accumulo - */ - @Override - public SortedSet<String> list() { - OpTimer opTimer = new OpTimer(log, Level.TRACE).start("Fetching list of table namespaces..."); - TreeSet<String> namespaces = new TreeSet<String>(TableNamespaces.getNameToIdMap(instance).keySet()); - opTimer.stop("Fetched " + namespaces.size() + " table namespaces in %DURATION%"); - return namespaces; - } - - /** - * A method to check if a table namespace exists in Accumulo. - * - * @param namespace - * the name of the table namespace - * @return true if the table namespace exists - */ - @Override - public boolean exists(String namespace) { - ArgumentChecker.notNull(namespace); - - OpTimer opTimer = new OpTimer(log, Level.TRACE).start("Checking if table namespace " + namespace + " exists..."); - boolean exists = TableNamespaces.getNameToIdMap(instance).containsKey(namespace); - opTimer.stop("Checked existance of " + exists + " in %DURATION%"); - return exists; - } - - /** - * Create a table namespace with no special configuration - * - * @param namespace - * the name of the table namespace - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission - * @throws TableNamespaceExistsException - * if the table namespace already exists - */ - @Override - public void create(String namespace) throws AccumuloException, AccumuloSecurityException, TableNamespaceExistsException { - create(namespace, true, TimeType.MILLIS); - } - - /** - * @param namespace - * the name of the table namespace - * @param limitVersion - * Enables/disables the versioning iterator, which will limit the number of Key versions kept. - */ - @Override - public void create(String namespace, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableNamespaceExistsException { - create(namespace, limitVersion, TimeType.MILLIS); - } - - /** - * @param namespace - * the name of the table namespace - * @param timeType - * specifies logical or real-time based time recording for entries in the table - * @param limitVersion - * Enables/disables the versioning iterator, which will limit the number of Key versions kept. - */ - @Override - public void create(String namespace, boolean limitVersion, TimeType timeType) throws AccumuloException, AccumuloSecurityException, - TableNamespaceExistsException { - ArgumentChecker.notNull(namespace, timeType); - - List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(namespace.getBytes()), ByteBuffer.wrap(timeType.name().getBytes())); - - Map<String,String> opts = IteratorUtil.generateInitialTableProperties(limitVersion); - - try { - doTableNamespaceOperation(TableOperation.CREATE, args, opts); - } catch (TableNamespaceNotFoundException e1) { - // should not happen - throw new RuntimeException(e1); - } - } - - private long beginTableNamespaceOperation() throws ThriftSecurityException, TException { - while (true) { - MasterClientService.Iface client = null; - try { - client = MasterClient.getConnectionWithRetry(instance); - return client.beginTableNamespaceOperation(Tracer.traceInfo(), credentials.toThrift(instance)); - } catch (TTransportException tte) { - log.debug("Failed to call beginTableOperation(), retrying ... ", tte); - UtilWaitThread.sleep(100); - } finally { - MasterClient.close(client); - } - } - } - - private void executeTableNamespaceOperation(long opid, TableOperation op, List<ByteBuffer> args, Map<String,String> opts, boolean autoCleanUp) - throws ThriftSecurityException, TException, ThriftTableOperationException { - while (true) { - MasterClientService.Iface client = null; - try { - client = MasterClient.getConnectionWithRetry(instance); - client.executeTableNamespaceOperation(Tracer.traceInfo(), credentials.toThrift(instance), opid, op, args, opts, autoCleanUp); - break; - } catch (TTransportException tte) { - log.debug("Failed to call executeTableOperation(), retrying ... ", tte); - UtilWaitThread.sleep(100); - } finally { - MasterClient.close(client); - } - } - } - - private String waitForTableNamespaceOperation(long opid) throws ThriftSecurityException, TException, ThriftTableOperationException { - while (true) { - MasterClientService.Iface client = null; - try { - client = MasterClient.getConnectionWithRetry(instance); - return client.waitForTableNamespaceOperation(Tracer.traceInfo(), credentials.toThrift(instance), opid); - } catch (TTransportException tte) { - log.debug("Failed to call waitForTableOperation(), retrying ... ", tte); - UtilWaitThread.sleep(100); - } finally { - MasterClient.close(client); - } - } - } - - private void finishTableNamespaceOperation(long opid) throws ThriftSecurityException, TException { - while (true) { - MasterClientService.Iface client = null; - try { - client = MasterClient.getConnectionWithRetry(instance); - client.finishTableNamespaceOperation(Tracer.traceInfo(), credentials.toThrift(instance), opid); - break; - } catch (TTransportException tte) { - log.debug("Failed to call finishTableOperation(), retrying ... ", tte); - UtilWaitThread.sleep(100); - } finally { - MasterClient.close(client); - } - } - } - - private String doTableNamespaceOperation(TableOperation op, List<ByteBuffer> args, Map<String,String> opts) throws AccumuloSecurityException, - TableNamespaceExistsException, TableNamespaceNotFoundException, AccumuloException { - return doTableNamespaceOperation(op, args, opts, true); - } - - private String doTableNamespaceOperation(TableOperation op, List<ByteBuffer> args, Map<String,String> opts, boolean wait) throws AccumuloSecurityException, - TableNamespaceExistsException, TableNamespaceNotFoundException, AccumuloException { - Long opid = null; - - try { - opid = beginTableNamespaceOperation(); - executeTableNamespaceOperation(opid, op, args, opts, !wait); - if (!wait) { - opid = null; - return null; - } - String ret = waitForTableNamespaceOperation(opid); - Tables.clearCache(instance); - return ret; - } catch (ThriftSecurityException 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: - throw new TableNamespaceExistsException(e); - case NOTFOUND: - throw new TableNamespaceNotFoundException(e); - case OFFLINE: - throw new TableOfflineException(instance, null); - case OTHER: - default: - throw new AccumuloException(e.description, e); - } - } catch (Exception e) { - throw new AccumuloException(e.getMessage(), e); - } finally { - // always finish table op, even when exception - if (opid != null) - try { - finishTableNamespaceOperation(opid); - } catch (Exception e) { - log.warn(e.getMessage(), e); - } - } - } - - /** - * Delete a table namespace if empty - * - * @param namespace - * the name of the table namespace - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission - * @throws TableNamespaceNotFoundException - * if the table namespace does not exist - * @throws TableNamespaceNotEmptyException - * if the table namespaces still contains tables - * @throws TableNotFoundException - * if table not found while deleting - */ - @Override - public void delete(String namespace) throws AccumuloException, AccumuloSecurityException, TableNamespaceNotFoundException, TableNamespaceNotEmptyException, - TableNotFoundException { - delete(namespace, false); - } - - /** - * Delete a table namespace - * - * @param namespace - * the name of the table namespace - * @param deleteTables - * boolean, if true deletes all the tables in the namespace in addition to deleting the namespace. - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission - * @throws TableNamespaceNotFoundException - * if the table namespace does not exist - * @throws TableNamespaceNotEmptyException - * if the table namespaces still contains tables - * @throws TableNotFoundException - * if table not found while deleting - */ - @Override - public void delete(String namespace, boolean deleteTables) throws AccumuloException, AccumuloSecurityException, TableNamespaceNotFoundException, - TableNamespaceNotEmptyException, TableNotFoundException { - ArgumentChecker.notNull(namespace); - String namespaceId = TableNamespaces.getNamespaceId(instance, namespace); - - if (namespaceId.equals(Constants.SYSTEM_TABLE_NAMESPACE_ID) || namespaceId.equals(Constants.DEFAULT_TABLE_NAMESPACE_ID)) { - 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) { - if (!deleteTables) { - throw new TableNamespaceNotEmptyException(namespaceId, namespace, null); - } - for (String table : TableNamespaces.getTableNames(instance, namespaceId)) { - try { - getTableOperations().delete(table); - } catch (TableNotFoundException e) { - log.debug("Table (" + table + ") not found while deleting namespace, probably deleted while we were deleting the rest of the tables"); - } - } - } - - List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(namespace.getBytes())); - Map<String,String> opts = new HashMap<String,String>(); - - try { - doTableNamespaceOperation(TableOperation.DELETE, args, opts); - } catch (TableNamespaceExistsException e) { - // should not happen - throw new RuntimeException(e); - } - - } - - /** - * Rename a table namespace - * - * @param oldNamespaceName - * the old table namespace - * @param newNamespaceName - * the new table namespace - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission - * @throws TableNamespaceNotFoundException - * if the old table namespace name does not exist - * @throws TableNamespaceExistsException - * if the new table namespace name already exists - */ - @Override - public void rename(String oldNamespaceName, String newNamespaceName) throws AccumuloSecurityException, TableNamespaceNotFoundException, AccumuloException, - TableNamespaceExistsException { - - List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(oldNamespaceName.getBytes()), ByteBuffer.wrap(newNamespaceName.getBytes())); - Map<String,String> opts = new HashMap<String,String>(); - doTableNamespaceOperation(TableOperation.RENAME, args, opts); - } - - /** - * Sets a property on a table namespace which will apply to all tables in the namespace - * - * @param namespace - * the name of the table namespace - * @param property - * the name of a per-table property - * @param value - * the value to set a per-table property to - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission - */ - @Override - public void setProperty(final String namespace, final String property, final String value) throws AccumuloException, AccumuloSecurityException { - ArgumentChecker.notNull(namespace, property, value); - - MasterClient.execute(instance, new ClientExec<MasterClientService.Client>() { - @Override - public void execute(MasterClientService.Client client) throws Exception { - client.setTableNamespaceProperty(Tracer.traceInfo(), credentials.toThrift(instance), namespace, property, value); - } - }); - } - - /** - * Removes a property from a table namespace - * - * @param namespace - * the name of the table namespace - * @param property - * the name of a per-table property - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission - */ - @Override - public void removeProperty(final String namespace, final String property) throws AccumuloException, AccumuloSecurityException { - ArgumentChecker.notNull(namespace, property); - - MasterClient.execute(instance, new ClientExec<MasterClientService.Client>() { - @Override - public void execute(MasterClientService.Client client) throws Exception { - client.removeTableNamespaceProperty(Tracer.traceInfo(), credentials.toThrift(instance), namespace, property); - } - }); - } - - /** - * Gets properties of a table namespace - * - * @param namespace - * the name of the table namespace - * @return all properties visible by this table namespace (system and per-namespace properties) - * @throws TableNamespaceNotFoundException - * if the table namespace does not exist - */ - @Override - public Iterable<Entry<String,String>> getProperties(final String namespace) throws AccumuloException, TableNamespaceNotFoundException { - ArgumentChecker.notNull(namespace); - try { - return ServerClient.executeRaw(instance, new ClientExecReturn<Map<String,String>,ClientService.Client>() { - @Override - public Map<String,String> execute(ClientService.Client client) throws Exception { - return client.getTableNamespaceConfiguration(Tracer.traceInfo(), credentials.toThrift(instance), namespace); - } - }).entrySet(); - } catch (ThriftTableOperationException e) { - switch (e.getType()) { - case NOTFOUND: - throw new TableNamespaceNotFoundException(e); - case OTHER: - default: - throw new AccumuloException(e.description, e); - } - } catch (AccumuloException e) { - throw e; - } catch (Exception e) { - throw new AccumuloException(e); - } - - } - - /** - * - * @param namespace - * the table namespace to take offline - * @throws AccumuloException - * when there is a general accumulo error - * @throws AccumuloSecurityException - * when the user does not have the proper permissions - * @throws TableNamespaceNotFoundException - * if the table namespace does not exist - */ - @Override - public void offline(String namespace) throws AccumuloSecurityException, AccumuloException, TableNamespaceNotFoundException { - - ArgumentChecker.notNull(namespace); - String namespaceId = TableNamespaces.getNamespaceId(instance, namespace); - try { - for (String table : TableNamespaces.getTableNames(instance, namespaceId)) { - getTableOperations().offline(table); - } - } catch (TableNotFoundException e) { - Log.error("Table namespace (" + namespaceId + ") contains reference to table that doesn't exist"); - } - } - - /** - * - * @param namespace - * the table namespace to take online - * @throws AccumuloException - * when there is a general accumulo error - * @throws AccumuloSecurityException - * when the user does not have the proper permissions - * @throws TableNamespaceNotFoundException - * if the table namespace does not exist - */ - @Override - public void online(String namespace) throws AccumuloSecurityException, AccumuloException, TableNamespaceNotFoundException { - ArgumentChecker.notNull(namespace); - String namespaceId = TableNamespaces.getNamespaceId(instance, namespace); - try { - for (String table : TableNamespaces.getTableNames(instance, namespaceId)) { - getTableOperations().online(table); - } - } catch (TableNotFoundException e) { - Log.warn("Table namespace (" + namespaceId + ") contains a reference to a table that doesn't exist"); - } - } - - /** - * Get a mapping of table namespace name to internal table namespace id. - * - * @return the map from table namespace name to internal table namespace id - */ - @Override - public Map<String,String> namespaceIdMap() { - return TableNamespaces.getNameToIdMap(instance); - } - - @Override - public List<DiskUsage> getDiskUsage(String namespace) throws AccumuloException, AccumuloSecurityException, TableNamespaceNotFoundException { - Set<String> tables = new HashSet<String>(); - String namespaceId = TableNamespaces.getNamespaceId(instance, namespace); - tables.addAll(TableNamespaces.getTableNames(instance, namespaceId)); - List<DiskUsage> du = null; - try { - du = getTableOperations().getDiskUsage(tables); - } catch (TableNotFoundException e) { - log.warn("Could not find table (" + e.getTableName() + ") reference in namespace (" + namespace + ")"); - } - return du; - } - - private TableOperations getTableOperations() throws AccumuloException, AccumuloSecurityException { - return new TableOperationsImpl(instance, credentials); - } - - @Override - public void attachIterator(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException, - TableNamespaceNotFoundException { - testClassLoad(namespace, setting.getIteratorClass(), SortedKeyValueIterator.class.getName()); - super.attachIterator(namespace, setting, scopes); - } - - @Override - public int addConstraint(String namespace, String constraintClassName) throws AccumuloException, AccumuloSecurityException, TableNamespaceNotFoundException { - testClassLoad(namespace, constraintClassName, Constraint.class.getName()); - return super.addConstraint(namespace, constraintClassName); - } - - @Override - public boolean testClassLoad(final String namespace, final String className, final String asTypeName) throws TableNamespaceNotFoundException, - AccumuloException, AccumuloSecurityException { - ArgumentChecker.notNull(namespace, className, asTypeName); - - try { - return ServerClient.executeRaw(instance, new ClientExecReturn<Boolean,ClientService.Client>() { - @Override - public Boolean execute(ClientService.Client client) throws Exception { - return client.checkTableNamespaceClass(Tracer.traceInfo(), credentials.toThrift(instance), namespace, className, asTypeName); - } - }); - } catch (ThriftTableOperationException e) { - switch (e.getType()) { - case NOTFOUND: - throw new TableNamespaceNotFoundException(e); - case OTHER: - default: - throw new AccumuloException(e.description, e); - } - } catch (ThriftSecurityException e) { - throw new AccumuloSecurityException(e.user, e.code, e); - } catch (AccumuloException e) { - throw e; - } catch (Exception e) { - throw new AccumuloException(e); - } - } -}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java index aa4c83e..c398e6e 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java @@ -50,20 +50,20 @@ import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Instance; import org.apache.accumulo.core.client.IsolatedScanner; import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.NamespaceNotFoundException; import org.apache.accumulo.core.client.RowIterator; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.TableDeletedException; import org.apache.accumulo.core.client.TableExistsException; -import org.apache.accumulo.core.client.TableNamespaceNotFoundException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TableOfflineException; import org.apache.accumulo.core.client.impl.AccumuloServerException; import org.apache.accumulo.core.client.impl.ClientExec; import org.apache.accumulo.core.client.impl.ClientExecReturn; import org.apache.accumulo.core.client.impl.MasterClient; +import org.apache.accumulo.core.client.impl.Namespaces; import org.apache.accumulo.core.client.impl.ServerClient; import org.apache.accumulo.core.client.impl.ServerConfigurationUtil; -import org.apache.accumulo.core.client.impl.TableNamespaces; import org.apache.accumulo.core.client.impl.Tables; import org.apache.accumulo.core.client.impl.TabletLocator; import org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation; @@ -129,7 +129,7 @@ public class TableOperationsImpl extends TableOperationsHelper { private Credentials credentials; public static final String CLONE_EXCLUDE_PREFIX = "!"; - + private static final Logger log = Logger.getLogger(TableOperations.class); /** @@ -222,9 +222,9 @@ public class TableOperationsImpl extends TableOperationsHelper { String namespace = Tables.extractNamespace(tableName); if (!namespaceExists(namespace)) { - String info = "Table namespace not found while trying to create table"; - throw new IllegalArgumentException(new TableNamespaceNotFoundException(null, namespace, info)); - } else if (namespace.equals(Constants.SYSTEM_TABLE_NAMESPACE)) { + String info = "Namespace not found while trying to create table"; + throw new IllegalArgumentException(new NamespaceNotFoundException(null, namespace, info)); + } else if (namespace.equals(Constants.SYSTEM_NAMESPACE)) { String info = "Can't create tables in the system namespace"; throw new IllegalArgumentException(info); } @@ -687,8 +687,8 @@ public class TableOperationsImpl extends TableOperationsHelper { String namespace = Tables.extractNamespace(newTableName); if (!namespaceExists(namespace)) { - String info = "Table namespace not found while cloning table"; - throw new IllegalArgumentException(new TableNamespaceNotFoundException(null, namespace, info)); + String info = "Namespace not found while cloning table"; + throw new IllegalArgumentException(new NamespaceNotFoundException(null, namespace, info)); } String srcTableId = Tables.getTableId(instance, srcTableName); @@ -725,13 +725,13 @@ public class TableOperationsImpl extends TableOperationsHelper { doTableOperation(TableOperation.CLONE, args, opts); } - // get the properties that are only in the table namespace so that we can exclude them when copying table properties. + // get the properties that are only in the namespace so that we can exclude them when copying table properties. // also, don't exclude properties that are going to be explicitly set. private HashSet<String> getUniqueNamespaceProperties(String namespace, String table, Map<String,String> propsToSet) throws TableNotFoundException, AccumuloException { HashSet<String> props = new HashSet<String>(); try { - Iterable<Entry<String,String>> n = new TableNamespaceOperationsImpl(instance, credentials).getProperties(namespace); + Iterable<Entry<String,String>> n = new NamespaceOperationsImpl(instance, credentials).getProperties(namespace); Iterable<Entry<String,String>> t = getProperties(table); Map<String,String> tmap = new HashMap<String,String>(); for (Entry<String,String> e : t) { @@ -743,8 +743,8 @@ public class TableOperationsImpl extends TableOperationsHelper { props.add(e.getKey()); } } - } catch (TableNamespaceNotFoundException e) { - throw new IllegalStateException(new TableNamespaceNotFoundException(null, namespace, null)); + } catch (NamespaceNotFoundException e) { + throw new IllegalStateException(new NamespaceNotFoundException(null, namespace, null)); } for (Entry<String,String> e : propsToSet.entrySet()) { @@ -775,8 +775,8 @@ public class TableOperationsImpl extends TableOperationsHelper { String namespace = Tables.extractNamespace(newTableName); if (!namespaceExists(namespace)) { - String info = "Table namespace not found while renaming table"; - throw new IllegalArgumentException(new TableNamespaceNotFoundException(null, namespace, info)); + String info = "Namespace not found while renaming table"; + throw new IllegalArgumentException(new NamespaceNotFoundException(null, namespace, info)); } List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(oldTableName.getBytes()), ByteBuffer.wrap(newTableName.getBytes())); @@ -1523,8 +1523,8 @@ public class TableOperationsImpl extends TableOperationsHelper { String namespace = Tables.extractNamespace(tableName); if (!namespaceExists(namespace)) { - String info = "Table namespace not found while importing to table"; - throw new RuntimeException(new TableNamespaceNotFoundException(null, namespace, info)); + String info = "Namespace not found while importing to table"; + throw new RuntimeException(new NamespaceNotFoundException(null, namespace, info)); } List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(importDir.getBytes())); @@ -1599,6 +1599,6 @@ public class TableOperationsImpl extends TableOperationsHelper { } private boolean namespaceExists(String namespace) { - return TableNamespaces.getNameToIdMap(instance).containsKey(namespace); + return Namespaces.getNameToIdMap(instance).containsKey(namespace); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java index bc3f39a..fcecb3a 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java @@ -36,8 +36,8 @@ import org.apache.accumulo.core.client.admin.InstanceOperations; import org.apache.accumulo.core.client.admin.InstanceOperationsImpl; import org.apache.accumulo.core.client.admin.SecurityOperations; import org.apache.accumulo.core.client.admin.SecurityOperationsImpl; -import org.apache.accumulo.core.client.admin.TableNamespaceOperations; -import org.apache.accumulo.core.client.admin.TableNamespaceOperationsImpl; +import org.apache.accumulo.core.client.admin.NamespaceOperations; +import org.apache.accumulo.core.client.admin.NamespaceOperationsImpl; import org.apache.accumulo.core.client.admin.TableOperations; import org.apache.accumulo.core.client.admin.TableOperationsImpl; import org.apache.accumulo.core.client.impl.thrift.ClientService; @@ -53,7 +53,7 @@ public class ConnectorImpl extends Connector { private final Credentials credentials; private SecurityOperations secops = null; private TableOperations tableops = null; - private TableNamespaceOperations namespaceops = null; + private NamespaceOperations namespaceops = null; private InstanceOperations instanceops = null; public ConnectorImpl(final Instance instance, Credentials cred) throws AccumuloException, AccumuloSecurityException { @@ -161,9 +161,9 @@ public class ConnectorImpl extends Connector { } @Override - public synchronized TableNamespaceOperations tableNamespaceOperations() { + public synchronized NamespaceOperations namespaceOperations() { if (namespaceops == null) - namespaceops = new TableNamespaceOperationsImpl(instance, credentials); + namespaceops = new NamespaceOperationsImpl(instance, credentials); return namespaceops; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java new file mode 100644 index 0000000..0b5fff6 --- /dev/null +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.core.client.impl; + +import java.security.SecurityPermission; +import java.util.LinkedList; +import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.NamespaceNotFoundException; +import org.apache.accumulo.core.zookeeper.ZooUtil; +import org.apache.accumulo.fate.zookeeper.ZooCache; + +public class Namespaces { + private static SecurityPermission TABLES_PERMISSION = new SecurityPermission("tablesPermission"); + + private static ZooCache getZooCache(Instance instance) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(TABLES_PERMISSION); + } + return ZooCache.getInstance(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()); + } + + private static SortedMap<String,String> getMap(Instance instance, boolean nameAsKey) { + ZooCache zc = getZooCache(instance); + + List<String> namespaceIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES); + + TreeMap<String,String> namespaceMap = new TreeMap<String,String>(); + + for (String id : namespaceIds) { + byte[] path = zc.get(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + id + Constants.ZNAMESPACE_NAME); + if (path != null) { + if (nameAsKey) + namespaceMap.put(new String(path, Constants.UTF8), id); + else + namespaceMap.put(id, new String(path, Constants.UTF8)); + } + } + return namespaceMap; + } + + public static String getNamespaceId(Instance instance, String namespace) throws NamespaceNotFoundException { + String id = getNameToIdMap(instance).get(namespace); + if (id == null) + throw new NamespaceNotFoundException(null, namespace, "getNamespaceId() failed to find namespace"); + return id; + } + + public static String getNamespaceName(Instance instance, String namespaceId) throws NamespaceNotFoundException { + String namespaceName = getIdToNameMap(instance).get(namespaceId); + if (namespaceName == null) + throw new NamespaceNotFoundException(namespaceId, null, "getNamespaceName() failed to find namespace"); + return namespaceName; + } + + public static SortedMap<String,String> getNameToIdMap(Instance instance) { + return getMap(instance, true); + } + + public static SortedMap<String,String> getIdToNameMap(Instance instance) { + return getMap(instance, false); + } + + public static List<String> getTableIds(Instance instance, String namespaceId) throws NamespaceNotFoundException { + List<String> l = new LinkedList<String>(); + for (String id : Tables.getIdToNameMap(instance).keySet()) { + if (Tables.getNamespace(instance, id).equals(namespaceId)) { + l.add(id); + } + } + return l; + } + + public static List<String> getTableNames(Instance instance, String namespaceId) throws NamespaceNotFoundException { + ZooCache zc = getZooCache(instance); + List<String> ids = getTableIds(instance, namespaceId); + List<String> names = new LinkedList<String>(); + String namespace = getNamespaceName(instance, namespaceId) + "."; + if (namespaceId.equals(Constants.DEFAULT_NAMESPACE_ID) || namespaceId.equals(Constants.SYSTEM_NAMESPACE_ID)) { + // default and system namespaces aren't displayed for backwards compatibility + namespace = ""; + } + for (String id : ids) { + names.add(namespace + new String(zc.get(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + id + Constants.ZTABLE_NAME), Constants.UTF8)); + } + return names; + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/core/src/main/java/org/apache/accumulo/core/client/impl/TableNamespaces.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/TableNamespaces.java b/core/src/main/java/org/apache/accumulo/core/client/impl/TableNamespaces.java deleted file mode 100644 index 935cf16..0000000 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/TableNamespaces.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.accumulo.core.client.impl; - -import java.security.SecurityPermission; -import java.util.LinkedList; -import java.util.List; -import java.util.SortedMap; -import java.util.TreeMap; - -import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.TableNamespaceNotFoundException; -import org.apache.accumulo.core.zookeeper.ZooUtil; -import org.apache.accumulo.fate.zookeeper.ZooCache; - -public class TableNamespaces { - private static SecurityPermission TABLES_PERMISSION = new SecurityPermission("tablesPermission"); - - private static ZooCache getZooCache(Instance instance) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(TABLES_PERMISSION); - } - return ZooCache.getInstance(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()); - } - - private static SortedMap<String,String> getMap(Instance instance, boolean nameAsKey) { - ZooCache zc = getZooCache(instance); - - List<String> namespaceIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES); - - TreeMap<String,String> namespaceMap = new TreeMap<String,String>(); - - for (String id : namespaceIds) { - byte[] path = zc.get(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + id + Constants.ZNAMESPACE_NAME); - if (path != null) { - if (nameAsKey) - namespaceMap.put(new String(path, Constants.UTF8), id); - else - namespaceMap.put(id, new String(path, Constants.UTF8)); - } - } - return namespaceMap; - } - - public static String getNamespaceId(Instance instance, String namespace) throws TableNamespaceNotFoundException { - String id = getNameToIdMap(instance).get(namespace); - if (id == null) - throw new TableNamespaceNotFoundException(null, namespace, "getNamespaceId() failed to find namespace"); - return id; - } - - public static String getNamespaceName(Instance instance, String namespaceId) throws TableNamespaceNotFoundException { - String namespaceName = getIdToNameMap(instance).get(namespaceId); - if (namespaceName == null) - throw new TableNamespaceNotFoundException(namespaceId, null, "getNamespaceName() failed to find namespace"); - return namespaceName; - } - - public static SortedMap<String,String> getNameToIdMap(Instance instance) { - return getMap(instance, true); - } - - public static SortedMap<String,String> getIdToNameMap(Instance instance) { - return getMap(instance, false); - } - - public static List<String> getTableIds(Instance instance, String namespaceId) throws TableNamespaceNotFoundException { - List<String> l = new LinkedList<String>(); - for (String id : Tables.getIdToNameMap(instance).keySet()) { - if (Tables.getNamespace(instance, id).equals(namespaceId)) { - l.add(id); - } - } - return l; - } - - public static List<String> getTableNames(Instance instance, String namespaceId) throws TableNamespaceNotFoundException { - ZooCache zc = getZooCache(instance); - List<String> ids = getTableIds(instance, namespaceId); - List<String> names = new LinkedList<String>(); - String namespace = getNamespaceName(instance, namespaceId) + "."; - if (namespaceId.equals(Constants.DEFAULT_TABLE_NAMESPACE_ID) || namespaceId.equals(Constants.SYSTEM_TABLE_NAMESPACE_ID)) { - // default and system namespaces aren't displayed for backwards compatibility - namespace = ""; - } - for (String id : ids) { - names.add(namespace + new String(zc.get(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + id + Constants.ZTABLE_NAME), Constants.UTF8)); - } - return names; - } -} http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java index f80f506..f017df4 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java @@ -27,7 +27,7 @@ import jline.internal.Log; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.TableNamespaceNotFoundException; +import org.apache.accumulo.core.client.NamespaceNotFoundException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.master.state.tables.TableState; import org.apache.accumulo.core.metadata.MetadataTable; @@ -61,10 +61,10 @@ public class Tables { // create fully qualified table name if it's in a namespace other than default or system. if (nId != null) { String namespaceId = new String(nId, Constants.UTF8); - if (!namespaceId.equals(Constants.DEFAULT_TABLE_NAMESPACE_ID) && !namespaceId.equals(Constants.SYSTEM_TABLE_NAMESPACE_ID)) { + if (!namespaceId.equals(Constants.DEFAULT_NAMESPACE_ID) && !namespaceId.equals(Constants.SYSTEM_NAMESPACE_ID)) { try { - name += TableNamespaces.getNamespaceName(instance, namespaceId) + "."; - } catch (TableNamespaceNotFoundException e) { + name += Namespaces.getNamespaceName(instance, namespaceId) + "."; + } catch (NamespaceNotFoundException e) { Log.error("Table (" + tableId + ") contains reference to namespace (" + namespaceId + ") that doesn't exist"); continue; } @@ -163,11 +163,11 @@ public class Tables { public static String extractNamespace(String tableName) { String[] s = tableName.split("\\."); if (tableName.equals(MetadataTable.NAME) || tableName.equals(RootTable.NAME)) { - return Constants.SYSTEM_TABLE_NAMESPACE; + return Constants.SYSTEM_NAMESPACE; } else if (s.length == 2 && !s[0].isEmpty()) { return s[0]; } else { - return Constants.DEFAULT_TABLE_NAMESPACE; + return Constants.DEFAULT_NAMESPACE; } }