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 4B27CF3BE for ; Fri, 25 Apr 2014 17:16:26 +0000 (UTC) Received: (qmail 68483 invoked by uid 500); 25 Apr 2014 17:16:20 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 68435 invoked by uid 500); 25 Apr 2014 17:16:19 -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 68423 invoked by uid 99); 25 Apr 2014 17:16:19 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2014 17:16:19 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C828B951CD6; Fri, 25 Apr 2014 17:16:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: busbey@apache.org To: commits@accumulo.apache.org Date: Fri, 25 Apr 2014 17:16:18 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/5] ACCUMULO-2726 Adds back missing methods for binary backwards compat with non-Deprecated methods from 1.5.0. Marks things that we're for sure removing with @Deprecated; mostly things that shouldn't have been in public to begin with. Repository: accumulo Updated Branches: refs/heads/1.6.0-SNAPSHOT e450d74ae -> f4454a065 http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java new file mode 100644 index 0000000..f97069a --- /dev/null +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java @@ -0,0 +1,225 @@ +/* + * 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.mock; + +import java.util.EnumSet; +import java.util.Set; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.admin.SecurityOperations; +import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode; +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.security.NamespacePermission; +import org.apache.accumulo.core.security.SystemPermission; +import org.apache.accumulo.core.security.TablePermission; + +class MockSecurityOperationsImpl implements SecurityOperations { + + final private MockAccumulo acu; + + MockSecurityOperationsImpl(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); + if (user == null) + 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); + if (user != null) + user.token = token.clone(); + 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); + if (user != null) + user.authorizations = authorizations; + else + throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); + } + + @Override + public Authorizations getUserAuthorizations(String principal) throws AccumuloException, AccumuloSecurityException { + MockUser user = acu.users.get(principal); + if (user != null) + return user.authorizations; + 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); + if (user != null) + return user.permissions.contains(perm); + 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); + if (table == null) + throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST); + EnumSet perms = table.userPermissions.get(principal); + if (perms == null) + return false; + return perms.contains(perm); + } + + @Override + public boolean hasNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException { + MockNamespace mockNamespace = acu.namespaces.get(namespace); + if (mockNamespace == null) + throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST); + EnumSet perms = mockNamespace.userPermissions.get(principal); + if (perms == null) + return false; + return perms.contains(permission); + } + + @Override + public void grantSystemPermission(String principal, SystemPermission permission) throws AccumuloException, AccumuloSecurityException { + MockUser user = acu.users.get(principal); + if (user != null) + user.permissions.add(permission); + 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) + throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); + MockTable table = acu.tables.get(tableName); + if (table == null) + throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST); + EnumSet perms = table.userPermissions.get(principal); + if (perms == null) + table.userPermissions.put(principal, EnumSet.of(permission)); + else + perms.add(permission); + } + + @Override + public void grantNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException { + if (acu.users.get(principal) == null) + throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); + MockNamespace mockNamespace = acu.namespaces.get(namespace); + if (mockNamespace == null) + throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST); + EnumSet perms = mockNamespace.userPermissions.get(principal); + if (perms == null) + mockNamespace.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); + if (user != null) + user.permissions.remove(permission); + 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) + throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); + MockTable table = acu.tables.get(tableName); + if (table == null) + throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST); + EnumSet perms = table.userPermissions.get(principal); + if (perms != null) + perms.remove(permission); + + } + + @Override + public void revokeNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException { + if (acu.users.get(principal) == null) + throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST); + MockNamespace mockNamespace = acu.namespaces.get(namespace); + if (mockNamespace == null) + throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST); + EnumSet perms = mockNamespace.userPermissions.get(principal); + if (perms != null) + perms.remove(permission); + + } + + @Deprecated + @Override + public Set listUsers() throws AccumuloException, AccumuloSecurityException { + return listLocalUsers(); + } + + @Override + public Set listLocalUsers() throws AccumuloException, AccumuloSecurityException { + return acu.users.keySet(); + } + +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java index 2bc9436..0d3aca2 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java @@ -20,7 +20,11 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Writer; +import org.apache.commons.io.output.WriterOutputStream; + +import org.apache.commons.cli.CommandLine; import jline.console.ConsoleReader; import org.apache.accumulo.core.Constants; @@ -35,11 +39,28 @@ public class MockShell extends Shell { protected InputStream in; protected OutputStream out; - + + /** + * Will only be set if you use either the Writer constructor or the setWriter(Writer) method + * @deprecated since 1.6.0; use out + */ + @Deprecated + protected Writer writer = null; + public MockShell(InputStream in, OutputStream out) throws IOException { super(); this.in = in; this.out = out; + // we presume they don't use the writer field unless they use the other constructor. + } + + /** + * @deprecated since 1.6.0; use OutputStream version + */ + @Deprecated + public MockShell(InputStream in, Writer out) throws IOException { + this(in, new WriterOutputStream(out, Constants.UTF8.name())); + this.writer = out; } public boolean config(String... args) { @@ -67,6 +88,15 @@ public class MockShell extends Shell { // We always want a MockInstance for this test instance = new MockInstance(); } + + /** + * @deprecated since 1.6.0; use ShellOptionsJC version + */ + @Deprecated + protected void setInstance(CommandLine cl) { + // same result as in previous version + setInstance((ShellOptionsJC)null); + } public int start() throws IOException { if (configError) @@ -122,6 +152,15 @@ public class MockShell extends Shell { public void setConsoleWriter(OutputStream out) { this.out = out; } + + /** + * @deprecated since 1.6.0; use the OutputStream version + */ + @Deprecated + public void setConsoleWriter(Writer out) { + setConsoleWriter(new WriterOutputStream(out, Constants.UTF8.name())); + this.writer = out; + } /** * Convenience method to create the byte-array to hand to the console http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/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 d3b1571..ee8880c 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 @@ -16,432 +16,13 @@ */ package org.apache.accumulo.core.client.mock; -import java.io.DataInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -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 org.apache.accumulo.core.client.AccumuloException; -import org.apache.accumulo.core.client.AccumuloSecurityException; -import org.apache.accumulo.core.client.IteratorSetting; -import org.apache.accumulo.core.client.NamespaceNotFoundException; -import org.apache.accumulo.core.client.TableExistsException; -import org.apache.accumulo.core.client.TableNotFoundException; -import org.apache.accumulo.core.client.admin.DiskUsage; -import org.apache.accumulo.core.client.admin.FindMax; -import org.apache.accumulo.core.client.admin.TableOperationsHelper; -import org.apache.accumulo.core.client.admin.TimeType; -import org.apache.accumulo.core.client.impl.Tables; -import org.apache.accumulo.core.conf.AccumuloConfiguration; -import org.apache.accumulo.core.data.Key; -import org.apache.accumulo.core.data.Mutation; -import org.apache.accumulo.core.data.Range; -import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.file.FileOperations; -import org.apache.accumulo.core.file.FileSKVIterator; -import org.apache.accumulo.core.metadata.MetadataTable; -import org.apache.accumulo.core.metadata.RootTable; -import org.apache.accumulo.core.security.Authorizations; -import org.apache.accumulo.core.security.ColumnVisibility; -import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader; -import org.apache.commons.lang.NotImplementedException; -import org.apache.hadoop.fs.FSDataOutputStream; -import org.apache.hadoop.fs.FileStatus; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.io.Text; - -public class MockTableOperations extends TableOperationsHelper { - private static final byte[] ZERO = {0}; - private final MockAccumulo acu; - private final String username; +/** + * @deprecated since 1.6.0; not intended for public api and you should not use it. + */ +@Deprecated +public class MockTableOperations extends MockTableOperationsImpl { MockTableOperations(MockAccumulo acu, String username) { - this.acu = acu; - this.username = username; - } - - @Override - public SortedSet list() { - return new TreeSet(acu.tables.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.qualify(tableName).getFirst(); - if (!tableName.matches(Tables.VALID_NAME_REGEX)) { - throw new IllegalArgumentException(); - } - if (exists(tableName)) - throw new TableExistsException(tableName, tableName, ""); - - if (!namespaceExists(namespace)) { - throw new IllegalArgumentException("Namespace (" + namespace + ") does not exist, create it first"); - } - acu.createTable(username, tableName, versioningIter, timeType); - } - - @Override - public void addSplits(String tableName, SortedSet partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException { - if (!exists(tableName)) - throw new TableNotFoundException(tableName, tableName, ""); - acu.addSplits(tableName, partitionKeys); - } - - @Deprecated - @Override - public Collection getSplits(String tableName) throws TableNotFoundException { - return listSplits(tableName); - } - - @Deprecated - @Override - public Collection getSplits(String tableName, int maxSplits) throws TableNotFoundException { - return listSplits(tableName); - } - - @Override - public Collection listSplits(String tableName) throws TableNotFoundException { - if (!exists(tableName)) - throw new TableNotFoundException(tableName, tableName, ""); - return acu.getSplits(tableName); - } - - @Override - public Collection 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 { - if (!exists(oldTableName)) - throw new TableNotFoundException(oldTableName, oldTableName, ""); - if (exists(newTableName)) - throw new TableExistsException(newTableName, newTableName, ""); - MockTable t = acu.tables.remove(oldTableName); - String namespace = Tables.qualify(newTableName).getFirst(); - MockNamespace n = acu.namespaces.get(namespace); - if (n == null) { - n = new MockNamespace(); - } - t.setNamespaceName(namespace); - t.setNamespace(n); - 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> getProperties(String tableName) throws TableNotFoundException { - String namespace = Tables.qualify(tableName).getFirst(); - if (!exists(tableName)) { - if (!namespaceExists(namespace)) - throw new TableNotFoundException(tableName, new NamespaceNotFoundException(null, namespace, null)); - throw new TableNotFoundException(null, tableName, null); - } - - Set> props = new HashSet>(acu.namespaces.get(namespace).settings.entrySet()); - - Set> tableProps = acu.tables.get(tableName).settings.entrySet(); - for (Entry e : tableProps) { - if (props.contains(e)) { - props.remove(e); - } - props.add(e); - } - return props; - } - - @Override - public void setLocalityGroups(String tableName, Map> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - if (!exists(tableName)) - throw new TableNotFoundException(tableName, tableName, ""); - acu.tables.get(tableName).setLocalityGroups(groups); - } - - @Override - public Map> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException { - if (!exists(tableName)) - throw new TableNotFoundException(tableName, tableName, ""); - return acu.tables.get(tableName).getLocalityGroups(); - } - - @Override - public Set splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException, - TableNotFoundException { - if (!exists(tableName)) - 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 { - long time = System.currentTimeMillis(); - MockTable table = acu.tables.get(tableName); - if (table == null) { - throw new TableNotFoundException(null, tableName, "The table was not found"); - } - Path importPath = new Path(dir); - Path failurePath = new Path(failureDir); - - FileSystem fs = acu.getFileSystem(); - /* - * check preconditions - */ - // directories are directories - if (fs.isFile(importPath)) { - throw new IOException("Import path must be a directory."); - } - if (fs.isFile(failurePath)) { - throw new IOException("Failure path must be a directory."); - } - // failures are writable - Path createPath = failurePath.suffix("/.createFile"); - FSDataOutputStream createStream = null; - try { - createStream = fs.create(createPath); - } catch (IOException e) { - throw new IOException("Error path is not writable."); - } finally { - if (createStream != null) { - createStream.close(); - } - } - fs.delete(createPath, false); - // failures are empty - FileStatus[] failureChildStats = fs.listStatus(failurePath); - if (failureChildStats.length > 0) { - throw new IOException("Error path must be empty."); - } - /* - * Begin the import - iterate the files in the path - */ - for (FileStatus importStatus : fs.listStatus(importPath)) { - try { - FileSKVIterator importIterator = FileOperations.getInstance().openReader(importStatus.getPath().toString(), true, fs, fs.getConf(), - AccumuloConfiguration.getDefaultConfiguration()); - while (importIterator.hasTop()) { - Key key = importIterator.getTopKey(); - Value value = importIterator.getTopValue(); - if (setTime) { - key.setTimestamp(time); - } - Mutation mutation = new Mutation(key.getRow()); - if (!key.isDeleted()) { - mutation.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), key.getTimestamp(), - value); - } else { - mutation.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), - key.getTimestamp()); - } - table.addMutation(mutation); - importIterator.next(); - } - } catch (Exception e) { - FSDataOutputStream failureWriter = null; - DataInputStream failureReader = null; - try { - failureWriter = fs.create(failurePath.suffix("/" + importStatus.getPath().getName())); - failureReader = fs.open(importStatus.getPath()); - int read = 0; - byte[] buffer = new byte[1024]; - while (-1 != (read = failureReader.read(buffer))) { - failureWriter.write(buffer, 0, read); - } - } finally { - if (failureReader != null) - failureReader.close(); - if (failureWriter != null) - failureWriter.close(); - } - } - 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 tableIdMap() { - Map result = new HashMap(); - for (String table : acu.tables.keySet()) { - if (RootTable.NAME.equals(table)) - result.put(table, RootTable.ID); - else if (MetadataTable.NAME.equals(table)) - result.put(table, MetadataTable.ID); - else - result.put(table, table); - } - return result; - } - - @Override - public List getDiskUsage(Set tables) throws AccumuloException, AccumuloSecurityException { - - List diskUsages = new ArrayList(); - diskUsages.add(new DiskUsage(new TreeSet(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)) - throw new TableNotFoundException(tableName, tableName, ""); - MockTable t = acu.tables.get(tableName); - Text startText = new Text(start); - Text endText = new Text(end); - startText.append(ZERO, 0, 1); - endText.append(ZERO, 0, 1); - Set keep = new TreeSet(t.table.subMap(new Key(startText), new Key(endText)).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 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 propertiesToSet, Set 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) { - e.printStackTrace(); - return false; - } - return true; + super(acu,username); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java new file mode 100644 index 0000000..fea9568 --- /dev/null +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java @@ -0,0 +1,447 @@ +/* + * 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.mock; + +import java.io.DataInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +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 org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.NamespaceNotFoundException; +import org.apache.accumulo.core.client.TableExistsException; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.admin.DiskUsage; +import org.apache.accumulo.core.client.admin.FindMax; +import org.apache.accumulo.core.client.impl.TableOperationsHelper; +import org.apache.accumulo.core.client.admin.TimeType; +import org.apache.accumulo.core.client.impl.Tables; +import org.apache.accumulo.core.conf.AccumuloConfiguration; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.file.FileOperations; +import org.apache.accumulo.core.file.FileSKVIterator; +import org.apache.accumulo.core.metadata.MetadataTable; +import org.apache.accumulo.core.metadata.RootTable; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.security.ColumnVisibility; +import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader; +import org.apache.commons.lang.NotImplementedException; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.Text; + +class MockTableOperationsImpl extends TableOperationsHelper { + private static final byte[] ZERO = {0}; + private final MockAccumulo acu; + private final String username; + + MockTableOperationsImpl(MockAccumulo acu, String username) { + this.acu = acu; + this.username = username; + } + + @Override + public SortedSet list() { + return new TreeSet(acu.tables.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.qualify(tableName).getFirst(); + if (!tableName.matches(Tables.VALID_NAME_REGEX)) { + throw new IllegalArgumentException(); + } + if (exists(tableName)) + throw new TableExistsException(tableName, tableName, ""); + + if (!namespaceExists(namespace)) { + throw new IllegalArgumentException("Namespace (" + namespace + ") does not exist, create it first"); + } + acu.createTable(username, tableName, versioningIter, timeType); + } + + @Override + public void addSplits(String tableName, SortedSet partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException { + if (!exists(tableName)) + throw new TableNotFoundException(tableName, tableName, ""); + acu.addSplits(tableName, partitionKeys); + } + + @Deprecated + @Override + public Collection getSplits(String tableName) throws TableNotFoundException { + return listSplits(tableName); + } + + @Deprecated + @Override + public Collection getSplits(String tableName, int maxSplits) throws TableNotFoundException { + return listSplits(tableName); + } + + @Override + public Collection listSplits(String tableName) throws TableNotFoundException { + if (!exists(tableName)) + throw new TableNotFoundException(tableName, tableName, ""); + return acu.getSplits(tableName); + } + + @Override + public Collection 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 { + if (!exists(oldTableName)) + throw new TableNotFoundException(oldTableName, oldTableName, ""); + if (exists(newTableName)) + throw new TableExistsException(newTableName, newTableName, ""); + MockTable t = acu.tables.remove(oldTableName); + String namespace = Tables.qualify(newTableName).getFirst(); + MockNamespace n = acu.namespaces.get(namespace); + if (n == null) { + n = new MockNamespace(); + } + t.setNamespaceName(namespace); + t.setNamespace(n); + 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> getProperties(String tableName) throws TableNotFoundException { + String namespace = Tables.qualify(tableName).getFirst(); + if (!exists(tableName)) { + if (!namespaceExists(namespace)) + throw new TableNotFoundException(tableName, new NamespaceNotFoundException(null, namespace, null)); + throw new TableNotFoundException(null, tableName, null); + } + + Set> props = new HashSet>(acu.namespaces.get(namespace).settings.entrySet()); + + Set> tableProps = acu.tables.get(tableName).settings.entrySet(); + for (Entry e : tableProps) { + if (props.contains(e)) { + props.remove(e); + } + props.add(e); + } + return props; + } + + @Override + public void setLocalityGroups(String tableName, Map> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { + if (!exists(tableName)) + throw new TableNotFoundException(tableName, tableName, ""); + acu.tables.get(tableName).setLocalityGroups(groups); + } + + @Override + public Map> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException { + if (!exists(tableName)) + throw new TableNotFoundException(tableName, tableName, ""); + return acu.tables.get(tableName).getLocalityGroups(); + } + + @Override + public Set splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException, + TableNotFoundException { + if (!exists(tableName)) + 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 { + long time = System.currentTimeMillis(); + MockTable table = acu.tables.get(tableName); + if (table == null) { + throw new TableNotFoundException(null, tableName, "The table was not found"); + } + Path importPath = new Path(dir); + Path failurePath = new Path(failureDir); + + FileSystem fs = acu.getFileSystem(); + /* + * check preconditions + */ + // directories are directories + if (fs.isFile(importPath)) { + throw new IOException("Import path must be a directory."); + } + if (fs.isFile(failurePath)) { + throw new IOException("Failure path must be a directory."); + } + // failures are writable + Path createPath = failurePath.suffix("/.createFile"); + FSDataOutputStream createStream = null; + try { + createStream = fs.create(createPath); + } catch (IOException e) { + throw new IOException("Error path is not writable."); + } finally { + if (createStream != null) { + createStream.close(); + } + } + fs.delete(createPath, false); + // failures are empty + FileStatus[] failureChildStats = fs.listStatus(failurePath); + if (failureChildStats.length > 0) { + throw new IOException("Error path must be empty."); + } + /* + * Begin the import - iterate the files in the path + */ + for (FileStatus importStatus : fs.listStatus(importPath)) { + try { + FileSKVIterator importIterator = FileOperations.getInstance().openReader(importStatus.getPath().toString(), true, fs, fs.getConf(), + AccumuloConfiguration.getDefaultConfiguration()); + while (importIterator.hasTop()) { + Key key = importIterator.getTopKey(); + Value value = importIterator.getTopValue(); + if (setTime) { + key.setTimestamp(time); + } + Mutation mutation = new Mutation(key.getRow()); + if (!key.isDeleted()) { + mutation.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), key.getTimestamp(), + value); + } else { + mutation.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), + key.getTimestamp()); + } + table.addMutation(mutation); + importIterator.next(); + } + } catch (Exception e) { + FSDataOutputStream failureWriter = null; + DataInputStream failureReader = null; + try { + failureWriter = fs.create(failurePath.suffix("/" + importStatus.getPath().getName())); + failureReader = fs.open(importStatus.getPath()); + int read = 0; + byte[] buffer = new byte[1024]; + while (-1 != (read = failureReader.read(buffer))) { + failureWriter.write(buffer, 0, read); + } + } finally { + if (failureReader != null) + failureReader.close(); + if (failureWriter != null) + failureWriter.close(); + } + } + 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 tableIdMap() { + Map result = new HashMap(); + for (String table : acu.tables.keySet()) { + if (RootTable.NAME.equals(table)) + result.put(table, RootTable.ID); + else if (MetadataTable.NAME.equals(table)) + result.put(table, MetadataTable.ID); + else + result.put(table, table); + } + return result; + } + + @Override + public List getDiskUsage(Set tables) throws AccumuloException, AccumuloSecurityException { + + List diskUsages = new ArrayList(); + diskUsages.add(new DiskUsage(new TreeSet(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)) + throw new TableNotFoundException(tableName, tableName, ""); + MockTable t = acu.tables.get(tableName); + Text startText = new Text(start); + Text endText = new Text(end); + startText.append(ZERO, 0, 1); + endText.append(ZERO, 0, 1); + Set keep = new TreeSet(t.table.subMap(new Key(startText), new Key(endText)).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 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 propertiesToSet, Set 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) { + e.printStackTrace(); + return false; + } + return true; + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java index 6bd01a9..ac6a6e9 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java @@ -16,55 +16,38 @@ */ package org.apache.accumulo.core.client.mock; -import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.TableNotFoundException; -import org.apache.accumulo.core.client.impl.TabletLocator; import org.apache.accumulo.core.data.KeyExtent; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.security.Credentials; +import org.apache.accumulo.core.security.thrift.TCredentials; import org.apache.hadoop.io.Text; -public class MockTabletLocator extends TabletLocator { +/** + * @deprecated since 1.6.0; not intended for public api and you should not use it. + */ +@Deprecated +public class MockTabletLocator extends org.apache.accumulo.core.client.mock.impl.MockTabletLocator { public MockTabletLocator() {} - - @Override - public TabletLocation locateTablet(Credentials credentials, Text row, boolean skipRow, boolean retry) throws AccumuloException, AccumuloSecurityException, + + public TabletLocation locateTablet(Text row, boolean skipRow, boolean retry, TCredentials credentials) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - throw new UnsupportedOperationException(); + return locateTablet(Credentials.fromThrift(credentials), row, skipRow, retry); } - @Override - public void binMutations(Credentials credentials, List mutations, Map> binnedMutations, List failures) + public void binMutations(List mutations, Map> binnedMutations, List failures, TCredentials credentials) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - TabletServerMutations tsm = new TabletServerMutations("5"); - for (T m : mutations) - tsm.addMutation(new KeyExtent(), m); - binnedMutations.put("", tsm); + binMutations(Credentials.fromThrift(credentials), mutations, binnedMutations, failures); } - - @Override - public List binRanges(Credentials credentials, List ranges, Map>> binnedRanges) throws AccumuloException, + + public List binRanges(List ranges, Map>> binnedRanges, TCredentials credentials) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - binnedRanges.put("", Collections.singletonMap(new KeyExtent(new Text(), null, null), ranges)); - return Collections.emptyList(); + return binRanges(Credentials.fromThrift(credentials), ranges, binnedRanges); } - - @Override - public void invalidateCache(KeyExtent failedExtent) {} - - @Override - public void invalidateCache(Collection keySet) {} - - @Override - public void invalidateCache() {} - - @Override - public void invalidateCache(String server) {} } http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java new file mode 100644 index 0000000..35f160f --- /dev/null +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java @@ -0,0 +1,70 @@ +/* + * 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.mock.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.impl.TabletLocator; +import org.apache.accumulo.core.data.KeyExtent; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.security.Credentials; +import org.apache.hadoop.io.Text; + +public class MockTabletLocator extends TabletLocator { + public MockTabletLocator() {} + + @Override + public TabletLocation locateTablet(Credentials credentials, Text row, boolean skipRow, boolean retry) throws AccumuloException, AccumuloSecurityException, + TableNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public void binMutations(Credentials credentials, List mutations, Map> binnedMutations, List failures) + throws AccumuloException, AccumuloSecurityException, TableNotFoundException { + TabletServerMutations tsm = new TabletServerMutations("5"); + for (T m : mutations) + tsm.addMutation(new KeyExtent(), m); + binnedMutations.put("", tsm); + } + + @Override + public List binRanges(Credentials credentials, List ranges, Map>> binnedRanges) throws AccumuloException, + AccumuloSecurityException, TableNotFoundException { + binnedRanges.put("", Collections.singletonMap(new KeyExtent(new Text(), null, null), ranges)); + return Collections.emptyList(); + } + + @Override + public void invalidateCache(KeyExtent failedExtent) {} + + @Override + public void invalidateCache(Collection keySet) {} + + @Override + public void invalidateCache() {} + + @Override + public void invalidateCache(String server) {} +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java b/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java index 32136a8..1d91574 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java @@ -19,7 +19,6 @@ package org.apache.accumulo.core.client.admin; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,14 +33,15 @@ import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.TableExistsException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.data.Range; -import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; import org.apache.accumulo.core.security.Authorizations; import org.apache.hadoop.io.Text; -import org.junit.Assert; -import org.junit.Test; -public class TableOperationsHelperTest { +/** + * This class is left in place specifically to test for regressions against the published version of TableOperationsHelper. + */ +public class TableOperationsHelperTest extends org.apache.accumulo.core.client.impl.TableOperationsHelperTest { + @SuppressWarnings("deprecation") static class Tester extends TableOperationsHelper { Map> settings = new HashMap>(); @@ -200,15 +200,6 @@ public class TableOperationsHelperTest { return null; } - void check(String tablename, String[] values) { - Map expected = new TreeMap(); - for (String value : values) { - String parts[] = value.split("=", 2); - expected.put(parts[0], parts[1]); - } - Assert.assertEquals(expected, settings.get(tablename)); - } - @Override public void importTable(String tableName, String exportDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {} @@ -224,72 +215,9 @@ public class TableOperationsHelperTest { return false; } } - - @Test - public void testAttachIterator() throws Exception { - Tester t = new Tester(); - Map empty = Collections.emptyMap(); - t.attachIterator("table", new IteratorSetting(10, "someName", "foo.bar", empty), EnumSet.of(IteratorScope.scan)); - t.check("table", new String[] {"table.iterator.scan.someName=10,foo.bar",}); - t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan)); - t.check("table", new String[] {}); - - IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar"); - setting.addOptions(Collections.singletonMap("key", "value")); - t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc)); - setting = new IteratorSetting(10, "someName", "foo.bar"); - t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan)); - t.check("table", new String[] {"table.iterator.majc.someName=10,foo.bar", "table.iterator.majc.someName.opt.key=value", - "table.iterator.scan.someName=10,foo.bar",}); - - t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan)); - setting = new IteratorSetting(20, "otherName", "some.classname"); - setting.addOptions(Collections.singletonMap("key", "value")); - t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc)); - setting = new IteratorSetting(20, "otherName", "some.classname"); - t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan)); - Map> two = t.listIterators("table"); - Assert.assertEquals(2, two.size()); - Assert.assertTrue(two.containsKey("otherName")); - Assert.assertTrue(two.get("otherName").size() == 2); - Assert.assertTrue(two.get("otherName").contains(IteratorScope.majc)); - Assert.assertTrue(two.get("otherName").contains(IteratorScope.scan)); - Assert.assertTrue(two.containsKey("someName")); - Assert.assertTrue(two.get("someName").size() == 1); - Assert.assertTrue(two.get("someName").contains(IteratorScope.majc)); - t.removeIterator("table", "someName", EnumSet.allOf(IteratorScope.class)); - t.check("table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", - "table.iterator.scan.otherName=20,some.classname",}); - - setting = t.getIteratorSetting("table", "otherName", IteratorScope.scan); - Assert.assertEquals(20, setting.getPriority()); - Assert.assertEquals("some.classname", setting.getIteratorClass()); - Assert.assertTrue(setting.getOptions().isEmpty()); - setting = t.getIteratorSetting("table", "otherName", IteratorScope.majc); - Assert.assertEquals(20, setting.getPriority()); - Assert.assertEquals("some.classname", setting.getIteratorClass()); - Assert.assertFalse(setting.getOptions().isEmpty()); - Assert.assertEquals(Collections.singletonMap("key", "value"), setting.getOptions()); - t.attachIterator("table", setting, EnumSet.of(IteratorScope.minc)); - t.check("table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", - "table.iterator.minc.otherName=20,some.classname", "table.iterator.minc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname",}); - - try { - t.attachIterator("table", setting); - Assert.fail(); - } catch (AccumuloException e) {} - setting.setName("thirdName"); - try { - t.attachIterator("table", setting); - Assert.fail(); - } catch (AccumuloException e) {} - setting.setPriority(10); - t.setProperty("table", "table.iterator.minc.thirdName.opt.key", "value"); - try { - t.attachIterator("table", setting); - Assert.fail(); - } catch (AccumuloException e) {} - t.removeProperty("table", "table.iterator.minc.thirdName.opt.key"); - t.attachIterator("table", setting); + + @Override + protected org.apache.accumulo.core.client.impl.TableOperationsHelper getHelper() { + return new Tester(); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java new file mode 100644 index 0000000..02838ed --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java @@ -0,0 +1,305 @@ +/* + * 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.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.TableExistsException; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.admin.DiskUsage; +import org.apache.accumulo.core.client.admin.TimeType; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.hadoop.io.Text; +import org.junit.Assert; +import org.junit.Test; + +public class TableOperationsHelperTest { + + static class Tester extends TableOperationsHelper { + Map> settings = new HashMap>(); + + @Override + public SortedSet list() { + return null; + } + + @Override + public boolean exists(String tableName) { + return true; + } + + @Override + public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {} + + @Override + public void create(String tableName, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableExistsException { + create(tableName, limitVersion, TimeType.MILLIS); + } + + @Override + public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {} + + @Override + public void addSplits(String tableName, SortedSet partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {} + + @Deprecated + @Override + public Collection getSplits(String tableName) throws TableNotFoundException { + return null; + } + + @Deprecated + @Override + public Collection getSplits(String tableName, int maxSplits) throws TableNotFoundException { + return null; + } + + @Override + public Collection listSplits(String tableName) throws TableNotFoundException { + return null; + } + + @Override + public Collection listSplits(String tableName, int maxSplits) throws TableNotFoundException { + return null; + } + + @Override + public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive) + throws TableNotFoundException, AccumuloException, AccumuloSecurityException { + return null; + } + + @Override + public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { + + } + + @Override + public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {} + + @Override + public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException, + AccumuloException {} + + @Override + public void compact(String tableName, Text start, Text end, List iterators, boolean flush, boolean wait) throws AccumuloSecurityException, + TableNotFoundException, AccumuloException {} + + @Override + public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {} + + @Override + public void clone(String srcTableName, String newTableName, boolean flush, Map propertiesToSet, Set propertiesToExclude) + throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {} + + @Override + public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException, + TableExistsException {} + + @Deprecated + @Override + public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {} + + @Override + public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {} + + @Override + public void setProperty(String tableName, String property, String value) throws AccumuloException, AccumuloSecurityException { + if (!settings.containsKey(tableName)) + settings.put(tableName, new TreeMap()); + settings.get(tableName).put(property, value); + } + + @Override + public void removeProperty(String tableName, String property) throws AccumuloException, AccumuloSecurityException { + if (!settings.containsKey(tableName)) + return; + settings.get(tableName).remove(property); + } + + @Override + public Iterable> getProperties(String tableName) throws AccumuloException, TableNotFoundException { + Map empty = Collections.emptyMap(); + if (!settings.containsKey(tableName)) + return empty.entrySet(); + return settings.get(tableName).entrySet(); + } + + @Override + public void setLocalityGroups(String tableName, Map> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {} + + @Override + public Map> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException { + return null; + } + + @Override + public Set splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException, + TableNotFoundException { + return null; + } + + @Override + public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws TableNotFoundException, IOException, + AccumuloException, AccumuloSecurityException {} + + @Override + public void offline(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { + + } + + @Override + public void online(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {} + + @Override + public void offline(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { + + } + + @Override + public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {} + + @Override + public void clearLocatorCache(String tableName) throws TableNotFoundException {} + + @Override + public Map tableIdMap() { + return null; + } + + @Override + public List getDiskUsage(Set tables) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { + return null; + } + + @Override + public void importTable(String tableName, String exportDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {} + + @Override + public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {} + + @Override + public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {} + + @Override + public boolean testClassLoad(String tableName, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException, + TableNotFoundException { + return false; + } + } + + protected TableOperationsHelper getHelper() { + return new Tester(); + } + + void check(TableOperationsHelper t, String tablename, String[] values) throws Exception { + Map expected = new TreeMap(); + for (String value : values) { + String parts[] = value.split("=", 2); + expected.put(parts[0], parts[1]); + } + Map actual = new TreeMap(); + for (Entry entry : t.getProperties(tablename)) { + actual.put(entry.getKey(), entry.getValue()); + } + Assert.assertEquals(expected, actual); + } + + @Test + public void testAttachIterator() throws Exception { + TableOperationsHelper t = getHelper(); + Map empty = Collections.emptyMap(); + t.attachIterator("table", new IteratorSetting(10, "someName", "foo.bar", empty), EnumSet.of(IteratorScope.scan)); + check(t, "table", new String[] {"table.iterator.scan.someName=10,foo.bar",}); + t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan)); + check(t, "table", new String[] {}); + + IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar"); + setting.addOptions(Collections.singletonMap("key", "value")); + t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc)); + setting = new IteratorSetting(10, "someName", "foo.bar"); + t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan)); + check(t, "table", new String[] {"table.iterator.majc.someName=10,foo.bar", "table.iterator.majc.someName.opt.key=value", + "table.iterator.scan.someName=10,foo.bar",}); + + t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan)); + setting = new IteratorSetting(20, "otherName", "some.classname"); + setting.addOptions(Collections.singletonMap("key", "value")); + t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc)); + setting = new IteratorSetting(20, "otherName", "some.classname"); + t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan)); + Map> two = t.listIterators("table"); + Assert.assertEquals(2, two.size()); + Assert.assertTrue(two.containsKey("otherName")); + Assert.assertTrue(two.get("otherName").size() == 2); + Assert.assertTrue(two.get("otherName").contains(IteratorScope.majc)); + Assert.assertTrue(two.get("otherName").contains(IteratorScope.scan)); + Assert.assertTrue(two.containsKey("someName")); + Assert.assertTrue(two.get("someName").size() == 1); + Assert.assertTrue(two.get("someName").contains(IteratorScope.majc)); + t.removeIterator("table", "someName", EnumSet.allOf(IteratorScope.class)); + check(t, "table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", + "table.iterator.scan.otherName=20,some.classname",}); + + setting = t.getIteratorSetting("table", "otherName", IteratorScope.scan); + Assert.assertEquals(20, setting.getPriority()); + Assert.assertEquals("some.classname", setting.getIteratorClass()); + Assert.assertTrue(setting.getOptions().isEmpty()); + setting = t.getIteratorSetting("table", "otherName", IteratorScope.majc); + Assert.assertEquals(20, setting.getPriority()); + Assert.assertEquals("some.classname", setting.getIteratorClass()); + Assert.assertFalse(setting.getOptions().isEmpty()); + Assert.assertEquals(Collections.singletonMap("key", "value"), setting.getOptions()); + t.attachIterator("table", setting, EnumSet.of(IteratorScope.minc)); + check(t, "table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", + "table.iterator.minc.otherName=20,some.classname", "table.iterator.minc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname",}); + + try { + t.attachIterator("table", setting); + Assert.fail(); + } catch (AccumuloException e) {} + setting.setName("thirdName"); + try { + t.attachIterator("table", setting); + Assert.fail(); + } catch (AccumuloException e) {} + setting.setPriority(10); + t.setProperty("table", "table.iterator.minc.thirdName.opt.key", "value"); + try { + t.attachIterator("table", setting); + Assert.fail(); + } catch (AccumuloException e) {} + t.removeProperty("table", "table.iterator.minc.thirdName.opt.key"); + t.attachIterator("table", setting); + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java b/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java index 2f9e4d3..d61dd30 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java +++ b/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java @@ -25,7 +25,7 @@ import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.NamespaceNotFoundException; import org.apache.accumulo.core.client.TableNotFoundException; -import org.apache.accumulo.core.client.admin.SecurityOperationsImpl; +import org.apache.accumulo.core.client.impl.SecurityOperationsImpl; import org.apache.accumulo.core.client.impl.Namespaces; import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode; import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException; http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java ---------------------------------------------------------------------- diff --git a/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java b/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java index d63a63e..cd522f5 100644 --- a/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java +++ b/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java @@ -26,7 +26,7 @@ import java.util.Set; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.NamespaceNotFoundException; -import org.apache.accumulo.core.client.admin.TableOperationsImpl; +import org.apache.accumulo.core.client.impl.TableOperationsImpl; import org.apache.accumulo.core.client.admin.TimeType; import org.apache.accumulo.core.client.impl.Namespaces; import org.apache.accumulo.core.client.impl.Tables; http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java ---------------------------------------------------------------------- diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java b/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java index cd59b78..031ba9c 100644 --- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java +++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/ImportTable.java @@ -34,7 +34,7 @@ import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.BatchWriter; import org.apache.accumulo.core.client.BatchWriterConfig; import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.admin.TableOperationsImpl; +import org.apache.accumulo.core.client.impl.TableOperationsImpl; import org.apache.accumulo.core.client.impl.Namespaces; import org.apache.accumulo.core.client.impl.Tables; import org.apache.accumulo.core.client.impl.thrift.TableOperation; http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/test/compat/japi-compliance/japi-accumulo-1.5.xml ---------------------------------------------------------------------- diff --git a/test/compat/japi-compliance/japi-accumulo-1.5.xml b/test/compat/japi-compliance/japi-accumulo-1.5.xml index 9e6f47f..f49dbb5 100644 --- a/test/compat/japi-compliance/japi-accumulo-1.5.xml +++ b/test/compat/japi-compliance/japi-accumulo-1.5.xml @@ -25,7 +25,6 @@ org.apache.accumulo.core.client.impl - org.apache.accumulo.core.client.mock org.apache.accumulo.core.data.thrift http://git-wip-us.apache.org/repos/asf/accumulo/blob/f4454a06/test/compat/japi-compliance/japi-accumulo-1.6.xml ---------------------------------------------------------------------- diff --git a/test/compat/japi-compliance/japi-accumulo-1.6.xml b/test/compat/japi-compliance/japi-accumulo-1.6.xml index 36553b8..0403a96 100644 --- a/test/compat/japi-compliance/japi-accumulo-1.6.xml +++ b/test/compat/japi-compliance/japi-accumulo-1.6.xml @@ -25,7 +25,8 @@ org.apache.accumulo.core.client.impl - org.apache.accumulo.core.client.mock + org.apache.accumulo.core.client.lexicoders.impl + org.apache.accumulo.core.client.mapreduce.lib.impl org.apache.accumulo.core.data.thrift org.apache.accumulo.minicluster.impl