accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [35/61] [abbrv] [partial] accumulo git commit: ACCUMULO-722 put trunk in my sandbox
Date Thu, 03 Mar 2016 22:00:00 GMT
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java
new file mode 100644
index 0000000..75addbf
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java
@@ -0,0 +1,117 @@
+/**
+ * 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.ArrayList;
+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.admin.ActiveScan;
+import org.apache.accumulo.core.client.admin.InstanceOperations;
+import org.apache.accumulo.start.classloader.AccumuloClassLoader;
+
+/**
+ * 
+ */
+public class MockInstanceOperations implements InstanceOperations {
+  MockAccumulo acu;
+  
+  /**
+   * @param acu
+   */
+  public MockInstanceOperations(MockAccumulo acu) {
+    this.acu = acu;
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#setProperty(java.lang.String, java.lang.String)
+   */
+  @Override
+  public void setProperty(String property, String value) throws AccumuloException, AccumuloSecurityException {
+    acu.setProperty(property, value);
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#removeProperty(java.lang.String)
+   */
+  @Override
+  public void removeProperty(String property) throws AccumuloException, AccumuloSecurityException {
+    acu.removeProperty(property);
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#getSystemConfiguration()
+   */
+  @Override
+  public Map<String,String> getSystemConfiguration() throws AccumuloException, AccumuloSecurityException {
+    return acu.systemProperties;
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#getSiteConfiguration()
+   */
+  @Override
+  public Map<String,String> getSiteConfiguration() throws AccumuloException, AccumuloSecurityException {
+    return acu.systemProperties;
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#getTabletServers()
+   */
+  @Override
+  public List<String> getTabletServers() {
+    return new ArrayList<String>();
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#getActiveScans(java.lang.String)
+   */
+  @Override
+  public List<ActiveScan> getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException {
+    return new ArrayList<ActiveScan>();
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.accumulo.core.client.admin.InstanceOperations#testClassLoad(java.lang.String, java.lang.String)
+   */
+  @Override
+  public boolean testClassLoad(String className, String asTypeName) throws AccumuloException, AccumuloSecurityException {
+    try {
+      AccumuloClassLoader.loadClass(className, Class.forName(asTypeName));
+    } catch (ClassNotFoundException e) {
+      e.printStackTrace();
+      return false;
+    }
+    return true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java
new file mode 100644
index 0000000..b4a7068
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java
@@ -0,0 +1,56 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.MultiTableBatchWriter;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+
+public class MockMultiTableBatchWriter implements MultiTableBatchWriter {
+  MockAccumulo acu = null;
+  Map<String,MockBatchWriter> bws = null;
+  
+  public MockMultiTableBatchWriter(MockAccumulo acu) {
+    this.acu = acu;
+    bws = new HashMap<String,MockBatchWriter>();
+  }
+  
+  @Override
+  public BatchWriter getBatchWriter(String table) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+    if (!bws.containsKey(table)) {
+      bws.put(table, new MockBatchWriter(acu, table));
+    }
+    return bws.get(table);
+  }
+  
+  @Override
+  public void flush() throws MutationsRejectedException {}
+  
+  @Override
+  public void close() throws MutationsRejectedException {}
+  
+  @Override
+  public boolean isClosed() {
+    throw new UnsupportedOperationException();
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java
new file mode 100644
index 0000000..41c5e50
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java
@@ -0,0 +1,105 @@
+/*
+ * 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.IOException;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.Filter;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.SortedMapIterator;
+import org.apache.accumulo.core.security.Authorizations;
+
+public class MockScanner extends MockScannerBase implements Scanner {
+  
+  int timeOut = 0;
+  int batchSize = 0;
+  Range range = new Range();
+  
+  MockScanner(MockTable table, Authorizations auths) {
+    super(table, auths);
+  }
+  
+  @Override
+  public void setTimeOut(int timeOut) {
+    this.timeOut = timeOut;
+  }
+  
+  @Override
+  public int getTimeOut() {
+    return timeOut;
+  }
+  
+  @Override
+  public void setRange(Range range) {
+    this.range = range;
+  }
+  
+  @Override
+  public Range getRange() {
+    return this.range;
+  }
+  
+  @Override
+  public void setBatchSize(int size) {
+    this.batchSize = size;
+  }
+  
+  @Override
+  public int getBatchSize() {
+    return this.batchSize;
+  }
+  
+  @Override
+  public void enableIsolation() {}
+  
+  @Override
+  public void disableIsolation() {}
+  
+  static class RangeFilter extends Filter {
+    Range range;
+    
+    RangeFilter(SortedKeyValueIterator<Key,Value> i, Range range) {
+      setSource(i);
+      this.range = range;
+    }
+    
+    @Override
+    public boolean accept(Key k, Value v) {
+      return range.contains(k);
+    }
+  }
+  
+  @Override
+  public Iterator<Entry<Key,Value>> iterator() {
+    SortedKeyValueIterator<Key,Value> i = new SortedMapIterator(table.table);
+    try {
+      i = new RangeFilter(createFilter(i), range);
+      i.seek(range, createColumnBSS(fetchedColumns), !fetchedColumns.isEmpty());
+      return new IteratorAdapter(i);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java
new file mode 100644
index 0000000..72cb863
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java
@@ -0,0 +1,117 @@
+/*
+ * 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.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.impl.ScannerOptions;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.data.ArrayByteSequence;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Column;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+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.iterators.system.ColumnFamilySkippingIterator;
+import org.apache.accumulo.core.iterators.system.ColumnQualifierFilter;
+import org.apache.accumulo.core.iterators.system.DeletingIterator;
+import org.apache.accumulo.core.iterators.system.MultiIterator;
+import org.apache.accumulo.core.iterators.system.VisibilityFilter;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.commons.lang.NotImplementedException;
+
+public class MockScannerBase extends ScannerOptions implements ScannerBase {
+  
+  protected final MockTable table;
+  protected final Authorizations auths;
+  
+  MockScannerBase(MockTable mockTable, Authorizations authorizations) {
+    this.table = mockTable;
+    this.auths = authorizations;
+  }
+  
+  static HashSet<ByteSequence> createColumnBSS(Collection<Column> columns) {
+    HashSet<ByteSequence> columnSet = new HashSet<ByteSequence>();
+    for (Column c : columns) {
+      columnSet.add(new ArrayByteSequence(c.getColumnFamily()));
+    }
+    return columnSet;
+  }
+  
+  static class MockIteratorEnvironment implements IteratorEnvironment {
+    @Override
+    public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName) throws IOException {
+      throw new NotImplementedException();
+    }
+    
+    @Override
+    public AccumuloConfiguration getConfig() {
+      return AccumuloConfiguration.getDefaultConfiguration();
+    }
+    
+    @Override
+    public IteratorScope getIteratorScope() {
+      return IteratorScope.scan;
+    }
+    
+    @Override
+    public boolean isFullMajorCompaction() {
+      return false;
+    }
+    
+    private ArrayList<SortedKeyValueIterator<Key,Value>> topLevelIterators = new ArrayList<SortedKeyValueIterator<Key,Value>>();
+    
+    @Override
+    public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
+      topLevelIterators.add(iter);
+    }
+    
+    SortedKeyValueIterator<Key,Value> getTopLevelIterator(SortedKeyValueIterator<Key,Value> iter) {
+      if (topLevelIterators.isEmpty())
+        return iter;
+      ArrayList<SortedKeyValueIterator<Key,Value>> allIters = new ArrayList<SortedKeyValueIterator<Key,Value>>(topLevelIterators);
+      allIters.add(iter);
+      return new MultiIterator(allIters, false);
+    }
+  }
+  
+  public SortedKeyValueIterator<Key,Value> createFilter(SortedKeyValueIterator<Key,Value> inner) throws IOException {
+    byte[] defaultLabels = {};
+    inner = new ColumnFamilySkippingIterator(new DeletingIterator(inner, false));
+    ColumnQualifierFilter cqf = new ColumnQualifierFilter(inner, new HashSet<Column>(fetchedColumns));
+    VisibilityFilter vf = new VisibilityFilter(cqf, auths, defaultLabels);
+    AccumuloConfiguration conf = new MockConfiguration(table.settings);
+    MockIteratorEnvironment iterEnv = new MockIteratorEnvironment();
+    SortedKeyValueIterator<Key,Value> result = iterEnv.getTopLevelIterator(IteratorUtil.loadIterators(IteratorScope.scan, vf, null, conf,
+        serverSideIteratorList, serverSideIteratorOptions, iterEnv, false));
+    return result;
+  }
+  
+  @Override
+  public Iterator<Entry<Key,Value>> iterator() {
+    throw new UnsupportedOperationException();
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
new file mode 100644
index 0000000..e1db951
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
@@ -0,0 +1,154 @@
+/*
+ * 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.Arrays;
+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.security.Authorizations;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.security.thrift.SecurityErrorCode;
+
+public class MockSecurityOperations implements SecurityOperations {
+  
+  final private MockAccumulo acu;
+  
+  MockSecurityOperations(MockAccumulo acu) {
+    this.acu = acu;
+  }
+  
+  @Override
+  public void createUser(String user, byte[] password, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
+    this.acu.users.put(user, new MockUser(user, password, authorizations));
+  }
+  
+  @Override
+  public void dropUser(String user) throws AccumuloException, AccumuloSecurityException {
+    this.acu.users.remove(user);
+  }
+  
+  @Override
+  public boolean authenticateUser(String name, byte[] password) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user == null)
+      return false;
+    return Arrays.equals(user.password, password);
+  }
+  
+  @Override
+  public void changeUserPassword(String name, byte[] password) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user != null)
+      user.password = Arrays.copyOf(password, password.length);
+    else
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+  }
+  
+  @Override
+  public void changeUserAuthorizations(String name, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user != null)
+      user.authorizations = authorizations;
+    else
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+  }
+  
+  @Override
+  public Authorizations getUserAuthorizations(String name) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user != null)
+      return user.authorizations;
+    else
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+  }
+  
+  @Override
+  public boolean hasSystemPermission(String name, SystemPermission perm) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user != null)
+      return user.permissions.contains(perm);
+    else
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+  }
+  
+  @Override
+  public boolean hasTablePermission(String name, 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<TablePermission> perms = table.userPermissions.get(name);
+    if (perms == null)
+      return false;
+    return perms.contains(perm);
+  }
+  
+  @Override
+  public void grantSystemPermission(String name, SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user != null)
+      user.permissions.add(permission);
+    else
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+  }
+  
+  @Override
+  public void grantTablePermission(String name, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
+    if (acu.users.get(name) == null)
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+    MockTable table = acu.tables.get(tableName);
+    if (table == null)
+      throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
+    EnumSet<TablePermission> perms = table.userPermissions.get(name);
+    if (perms == null)
+      table.userPermissions.put(name, EnumSet.of(permission));
+    else
+      perms.add(permission);
+  }
+  
+  @Override
+  public void revokeSystemPermission(String name, SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
+    MockUser user = acu.users.get(name);
+    if (user != null)
+      user.permissions.remove(permission);
+    else
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+  }
+  
+  @Override
+  public void revokeTablePermission(String name, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
+    if (acu.users.get(name) == null)
+      throw new AccumuloSecurityException(name, SecurityErrorCode.USER_DOESNT_EXIST);
+    MockTable table = acu.tables.get(tableName);
+    if (table == null)
+      throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
+    EnumSet<TablePermission> perms = table.userPermissions.get(name);
+    if (perms != null)
+      perms.remove(permission);
+    
+  }
+  
+  @Override
+  public Set<String> listUsers() throws AccumuloException, AccumuloSecurityException {
+    return acu.users.keySet();
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
new file mode 100644
index 0000000..27f9cff
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
@@ -0,0 +1,137 @@
+/**
+ * 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.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+
+import jline.ConsoleReader;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.commons.cli.CommandLine;
+
+/**
+ * An Accumulo Shell implementation that allows a developer to attach an InputStream and Writer to the Shell for testing purposes.
+ */
+public class MockShell extends Shell {
+  private static final String NEWLINE = "\n";
+  
+  protected InputStream in;
+  protected Writer writer;
+  
+  public MockShell(InputStream in, Writer writer) throws IOException {
+    super();
+    this.in = in;
+    this.writer = writer;
+  }
+  
+  public boolean config(String... args) {
+    configError = super.config(args);
+    
+    // Update the ConsoleReader with the input and output "redirected"
+    try {
+      this.reader = new ConsoleReader(in, writer);
+    } catch (Exception e) {
+      printException(e);
+      configError = true;
+    }
+    
+    // Don't need this for testing purposes
+    this.reader.setUseHistory(false);
+    this.reader.setUsePagination(false);
+    
+    // Make the parsing from the client easier;
+    this.verbose = false;
+    return configError;
+  }
+  
+  @Override
+  protected void setInstance(CommandLine cl) {
+    // We always want a MockInstance for this test
+    instance = new MockInstance();
+  }
+  
+  public int start() throws IOException {
+    if (configError)
+      return 1;
+    
+    String input;
+    if (isVerbose())
+      printInfo();
+    
+    if (execFile != null) {
+      java.util.Scanner scanner = new java.util.Scanner(new File(execFile));
+      while (scanner.hasNextLine())
+        execCommand(scanner.nextLine(), true, isVerbose());
+    } else if (execCommand != null) {
+      for (String command : execCommand.split("\n")) {
+        execCommand(command, true, isVerbose());
+      }
+      return exitCode;
+    }
+    
+    while (true) {
+      if (hasExited())
+        return exitCode;
+      
+      reader.setDefaultPrompt(getDefaultPrompt());
+      input = reader.readLine();
+      if (input == null) {
+        reader.printNewline();
+        return exitCode;
+      } // user canceled
+      
+      execCommand(input, false, false);
+    }
+  }
+  
+  /**
+   * @param in
+   *          the in to set
+   */
+  public void setConsoleInputStream(InputStream in) {
+    this.in = in;
+  }
+  
+  /**
+   * @param writer
+   *          the writer to set
+   */
+  public void setConsoleWriter(Writer writer) {
+    this.writer = writer;
+  }
+  
+  /**
+   * Convenience method to create the byte-array to hand to the console
+   * 
+   * @param commands
+   *          An array of commands to run
+   * @return A byte[] input stream which can be handed to the console.
+   */
+  public static ByteArrayInputStream makeCommands(String... commands) {
+    StringBuilder sb = new StringBuilder(commands.length * 8);
+    
+    for (String command : commands) {
+      sb.append(command).append(NEWLINE);
+    }
+    
+    return new ByteArrayInputStream(sb.toString().getBytes());
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
new file mode 100644
index 0000000..f558822
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
@@ -0,0 +1,126 @@
+/*
+ * 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.Collection;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ColumnUpdate;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.hadoop.io.Text;
+
+public class MockTable {
+  
+  static class MockMemKey extends Key {
+    private int count;
+    
+    MockMemKey(Key key, int count) {
+      super(key);
+      this.count = count;
+    }
+    
+    @Override
+    public int hashCode() {
+      return super.hashCode() + count;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+      MockMemKey other = (MockMemKey) obj;
+      return super.equals(other) && count == other.count;
+    }
+    
+    @Override
+    public String toString() {
+      return super.toString() + " count=" + count;
+    }
+    
+    @Override
+    public int compareTo(Key o) {
+      int compare = super.compareTo(o);
+      if (compare != 0)
+        return compare;
+      if (o instanceof MockMemKey) {
+        MockMemKey other = (MockMemKey) o;
+        if (count < other.count)
+          return 1;
+        if (count > other.count)
+          return -1;
+      } else {
+        return 1;
+      }
+      return 0;
+    }
+  };
+  
+  final SortedMap<Key,Value> table = new ConcurrentSkipListMap<Key,Value>();
+  int mutationCount = 0;
+  final Map<String,String> settings;
+  Map<String,EnumSet<TablePermission>> userPermissions = new HashMap<String,EnumSet<TablePermission>>();
+  private TimeType timeType;
+  SortedSet<Text> splits = new TreeSet<Text>();
+  
+  MockTable(boolean useVersions, TimeType timeType) {
+    this.timeType = timeType;
+    settings = IteratorUtil.generateInitialTableProperties();
+    for (Entry<String,String> entry : AccumuloConfiguration.getDefaultConfiguration()) {
+      String key = entry.getKey();
+      if (key.startsWith(Property.TABLE_PREFIX.getKey()))
+        settings.put(key, entry.getValue());
+    }
+  }
+  
+  synchronized void addMutation(Mutation m) {
+    long now = System.currentTimeMillis();
+    mutationCount++;
+    for (ColumnUpdate u : m.getUpdates()) {
+      Key key = new Key(m.getRow(), 0, m.getRow().length, u.getColumnFamily(), 0, u.getColumnFamily().length, u.getColumnQualifier(), 0,
+          u.getColumnQualifier().length, u.getColumnVisibility(), 0, u.getColumnVisibility().length, u.getTimestamp());
+      if (u.isDeleted())
+        key.setDeleted(true);
+      if (!u.hasTimestamp())
+        if (timeType.equals(TimeType.LOGICAL))
+          key.setTimestamp(mutationCount);
+        else
+          key.setTimestamp(now);
+      
+      table.put(new MockMemKey(key, mutationCount), new Value(u.getValue()));
+    }
+  }
+  
+  public void addSplits(SortedSet<Text> partitionKeys) {
+    splits.addAll(partitionKeys);
+  }
+  
+  public Collection<Text> getSplits() {
+    return splits;
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
new file mode 100644
index 0000000..55c175c
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
@@ -0,0 +1,240 @@
+/*
+ * 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.IOException;
+import java.util.Collection;
+import java.util.Collections;
+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.TreeSet;
+
+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.IteratorSetting;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+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.data.Range;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.hadoop.io.Text;
+
+public class MockTableOperations extends TableOperationsHelper {
+  
+  final private MockAccumulo acu;
+  final private String username;
+  
+  MockTableOperations(MockAccumulo acu, String username) {
+    this.acu = acu;
+    this.username = username;
+  }
+  
+  @Override
+  public SortedSet<String> list() {
+    return new TreeSet<String>(acu.tables.keySet());
+  }
+  
+  @Override
+  public boolean exists(String tableName) {
+    return acu.tables.containsKey(tableName);
+  }
+  
+  @Override
+  public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+    if (!tableName.matches(Constants.VALID_TABLE_NAME_REGEX)) {
+      throw new IllegalArgumentException();
+    }
+    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 {
+    if (!tableName.matches(Constants.VALID_TABLE_NAME_REGEX)) {
+      throw new IllegalArgumentException();
+    }
+    if (exists(tableName))
+      throw new TableExistsException(tableName, tableName, "");
+    acu.createTable(username, tableName, versioningIter, timeType);
+  }
+  
+  @Override
+  public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+    acu.addSplits(tableName, partitionKeys);
+  }
+  
+  @Override
+  public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+    return acu.getSplits(tableName);
+  }
+  
+  @Override
+  public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
+    return getSplits(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);
+    acu.tables.put(newTableName, t);
+  }
+  
+  @Override
+  public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {}
+  
+  @Override
+  public void setProperty(String tableName, String property, String value) throws AccumuloException, AccumuloSecurityException {
+    acu.tables.get(tableName).settings.put(property, value);
+  }
+  
+  @Override
+  public void removeProperty(String tableName, String property) throws AccumuloException, AccumuloSecurityException {
+    acu.tables.get(tableName).settings.remove(property);
+  }
+  
+  @Override
+  public Iterable<Entry<String,String>> getProperties(String tableName) throws TableNotFoundException {
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+    return acu.tables.get(tableName).settings.entrySet();
+  }
+  
+  @Override
+  public void setLocalityGroups(String tableName, Map<String,Set<Text>> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public Set<Range> splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException,
+      TableNotFoundException {
+    return Collections.singleton(range);
+  }
+  
+  @Override
+  public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloException,
+      AccumuloSecurityException, TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void offline(String tableName) throws AccumuloSecurityException, AccumuloException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void online(String tableName) throws AccumuloSecurityException, AccumuloException {}
+  
+  @Override
+  public void clearLocatorCache(String tableName) throws TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public Map<String,String> tableIdMap() {
+    Map<String,String> result = new HashMap<String,String>();
+    for (String table : acu.tables.keySet()) {
+      result.put(table, table);
+    }
+    return result;
+  }
+  
+  @Override
+  public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException,
+      AccumuloException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
+      TableNotFoundException, AccumuloException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
+      throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
+    throw new NotImplementedException();
+  }
+  
+  @Override
+  public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+    throw new NotImplementedException();
+  }
+  
+  @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();
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java
new file mode 100644
index 0000000..a63a86e
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java
@@ -0,0 +1,68 @@
+/*
+ * 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.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.hadoop.io.Text;
+
+public class MockTabletLocator extends TabletLocator {
+  public MockTabletLocator() {}
+  
+  @Override
+  public TabletLocation locateTablet(Text row, boolean skipRow, boolean retry) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+    throw new UnsupportedOperationException();
+  }
+  
+  @Override
+  public void binMutations(List<Mutation> mutations, Map<String,TabletServerMutations> binnedMutations, List<Mutation> failures) throws AccumuloException,
+      AccumuloSecurityException, TableNotFoundException {
+    TabletServerMutations tsm = new TabletServerMutations();
+    for (Mutation m : mutations)
+      tsm.addMutation(new KeyExtent(), m);
+    binnedMutations.put("", tsm);
+  }
+  
+  @Override
+  public List<Range> binRanges(List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> 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<KeyExtent> keySet) {}
+  
+  @Override
+  public void invalidateCache() {}
+  
+  @Override
+  public void invalidateCache(String server) {}
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java
new file mode 100644
index 0000000..d784d7a
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java
@@ -0,0 +1,37 @@
+/*
+ * 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.Arrays;
+import java.util.EnumSet;
+
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.SystemPermission;
+
+public class MockUser {
+  final EnumSet<SystemPermission> permissions;
+  final String name;
+  byte[] password;
+  Authorizations authorizations;
+  
+  MockUser(String username, byte[] password, Authorizations auths) {
+    this.name = username;
+    this.password = Arrays.copyOf(password, password.length);
+    this.authorizations = auths;
+    this.permissions = EnumSet.noneOf(SystemPermission.class);
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java b/1.5/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
new file mode 100644
index 0000000..07c8864
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
@@ -0,0 +1,158 @@
+/*
+ * 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.conf;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.log4j.Logger;
+
+public abstract class AccumuloConfiguration implements Iterable<Entry<String,String>> {
+  private static final Logger log = Logger.getLogger(AccumuloConfiguration.class);
+  
+  public abstract String get(Property property);
+  
+  public abstract Iterator<Entry<String,String>> iterator();
+  
+  private void checkType(Property property, PropertyType type) {
+    if (!property.getType().equals(type)) {
+      String msg = "Configuration method intended for type " + type + " called with a " + property.getType() + " argument (" + property.getKey() + ")";
+      IllegalArgumentException err = new IllegalArgumentException(msg);
+      log.error(msg, err);
+      throw err;
+    }
+  }
+  
+  public long getMemoryInBytes(Property property) {
+    checkType(property, PropertyType.MEMORY);
+    
+    String memString = get(property);
+    return getMemoryInBytes(memString);
+  }
+  
+  static public long getMemoryInBytes(String str) {
+    int multiplier = 0;
+    switch (str.charAt(str.length() - 1)) {
+      case 'G':
+        multiplier += 10;
+      case 'M':
+        multiplier += 10;
+      case 'K':
+        multiplier += 10;
+      case 'B':
+        return Long.parseLong(str.substring(0, str.length() - 1)) << multiplier;
+      default:
+        return Long.parseLong(str);
+    }
+  }
+  
+  public long getTimeInMillis(Property property) {
+    checkType(property, PropertyType.TIMEDURATION);
+    
+    return getTimeInMillis(get(property));
+  }
+  
+  static public long getTimeInMillis(String str) {
+    int multiplier = 1;
+    switch (str.charAt(str.length() - 1)) {
+      case 'd':
+        multiplier *= 24;
+      case 'h':
+        multiplier *= 60;
+      case 'm':
+        multiplier *= 60;
+      case 's':
+        multiplier *= 1000;
+        if (str.length() > 1 && str.endsWith("ms")) // millis
+          // case
+          return Long.parseLong(str.substring(0, str.length() - 2));
+        return Long.parseLong(str.substring(0, str.length() - 1)) * multiplier;
+      default:
+        return Long.parseLong(str) * 1000;
+    }
+  }
+  
+  public boolean getBoolean(Property property) {
+    checkType(property, PropertyType.BOOLEAN);
+    return Boolean.parseBoolean(get(property));
+  }
+  
+  public double getFraction(Property property) {
+    checkType(property, PropertyType.FRACTION);
+    
+    return getFraction(get(property));
+  }
+  
+  public double getFraction(String str) {
+    if (str.charAt(str.length() - 1) == '%')
+      return Double.parseDouble(str.substring(0, str.length() - 1)) / 100.0;
+    return Double.parseDouble(str);
+  }
+  
+  public int getPort(Property property) {
+    checkType(property, PropertyType.PORT);
+    
+    String portString = get(property);
+    int port = Integer.parseInt(portString);
+    if (port != 0) {
+      if (port < 1024 || port > 65535) {
+        log.error("Invalid port number " + port + "; Using default " + property.getDefaultValue());
+        port = Integer.parseInt(property.getDefaultValue());
+      }
+    }
+    return port;
+  }
+  
+  public int getCount(Property property) {
+    checkType(property, PropertyType.COUNT);
+    
+    String countString = get(property);
+    return Integer.parseInt(countString);
+  }
+  
+  public static synchronized DefaultConfiguration getDefaultConfiguration() {
+    return DefaultConfiguration.getInstance();
+  }
+  
+  // Only here for Shell option-free start-up
+  /**
+   * 
+   * @deprecated not for client use
+   */
+  public static synchronized AccumuloConfiguration getSiteConfiguration() {
+    return SiteConfiguration.getInstance(getDefaultConfiguration());
+  }
+  
+  public static AccumuloConfiguration getTableConfiguration(Connector conn, String tableId) throws TableNotFoundException, AccumuloException {
+    String tableName = Tables.getTableName(conn.getInstance(), tableId);
+    return new ConfigurationCopy(conn.tableOperations().getProperties(tableName));
+  }
+  
+  public int getMaxFilesPerTablet() {
+    int maxFilesPerTablet = getCount(Property.TABLE_FILE_MAX);
+    if (maxFilesPerTablet <= 0) {
+      maxFilesPerTablet = getCount(Property.TSERV_SCAN_MAX_OPENFILES) - 1;
+      log.debug("Max files per tablet " + maxFilesPerTablet);
+    }
+    
+    return maxFilesPerTablet;
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigSanityCheck.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigSanityCheck.java b/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigSanityCheck.java
new file mode 100644
index 0000000..3314914
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigSanityCheck.java
@@ -0,0 +1,87 @@
+/*
+ * 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.conf;
+
+import java.util.Map.Entry;
+
+import org.apache.log4j.Logger;
+
+public class ConfigSanityCheck {
+  
+  private static final Logger log = Logger.getLogger(ConfigSanityCheck.class);
+  private static final String PREFIX = "BAD CONFIG ";
+  
+  public static void validate(AccumuloConfiguration acuconf) {
+    for (Entry<String,String> entry : acuconf) {
+      String key = entry.getKey();
+      String value = entry.getValue();
+      Property prop = Property.getPropertyByKey(entry.getKey());
+      if (prop == null && Property.isValidTablePropertyKey(key))
+        continue; // unknown valid per-table property
+      else if (prop == null)
+        log.warn(PREFIX + "unrecognized property key (" + key + ")");
+      else if (prop.getType() == PropertyType.PREFIX)
+        fatal(PREFIX + "incomplete property key (" + key + ")");
+      else if (!prop.getType().isValidFormat(value))
+        fatal(PREFIX + "improperly formatted value for key (" + key + ", type=" + prop.getType() + ")");
+    }
+    
+    checkTimeDuration(acuconf, Property.INSTANCE_ZK_TIMEOUT, new CheckTimeDurationBetween(1000, 300000));
+  }
+  
+  private static interface CheckTimeDuration {
+    boolean check(long propVal);
+    
+    String getDescription(Property prop);
+  }
+  
+  private static class CheckTimeDurationBetween implements CheckTimeDuration {
+    long min, max;
+    
+    CheckTimeDurationBetween(long x, long y) {
+      min = Math.min(x, y);
+      max = Math.max(x, y);
+    }
+    
+    @Override
+    public boolean check(long propVal) {
+      return propVal >= min && propVal <= max;
+    }
+    
+    @Override
+    public String getDescription(Property prop) {
+      return "ensure " + min + " <= " + prop + " <= " + max;
+    }
+  }
+  
+  private static void checkTimeDuration(AccumuloConfiguration acuconf, Property prop, CheckTimeDuration chk) {
+    verifyPropertyTypes(PropertyType.TIMEDURATION, prop);
+    if (!chk.check(acuconf.getTimeInMillis(prop)))
+      fatal(PREFIX + chk.getDescription(prop));
+  }
+  
+  private static void verifyPropertyTypes(PropertyType type, Property... properties) {
+    for (Property prop : properties)
+      if (prop.getType() != type)
+        fatal("Unexpected property type (" + prop.getType() + " != " + type + ")");
+  }
+  
+  private static void fatal(String msg) {
+    log.fatal(msg);
+    throw new RuntimeException(msg);
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java b/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java
new file mode 100644
index 0000000..4755ce1
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java
@@ -0,0 +1,60 @@
+/*
+ * 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.conf;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class ConfigurationCopy extends AccumuloConfiguration {
+  final Map<String,String> copy = Collections.synchronizedMap(new HashMap<String,String>());
+  
+  public ConfigurationCopy(Map<String,String> config) {
+    this(config.entrySet());
+  }
+  
+  public ConfigurationCopy(Iterable<Entry<String,String>> config) {
+    for (Entry<String,String> entry : config) {
+      copy.put(entry.getKey(), entry.getValue());
+    }
+  }
+  
+  public ConfigurationCopy() {
+    this(new HashMap<String,String>());
+  }
+  
+  @Override
+  public String get(Property property) {
+    return copy.get(property.getKey());
+  }
+  
+  @Override
+  public Iterator<Entry<String,String>> iterator() {
+    return copy.entrySet().iterator();
+  }
+  
+  public void set(Property prop, String value) {
+    copy.put(prop.getKey(), value);
+  }
+  
+  public void set(String key, String value) {
+    copy.put(key, value);
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationObserver.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationObserver.java b/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationObserver.java
new file mode 100644
index 0000000..46f8692
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationObserver.java
@@ -0,0 +1,25 @@
+/*
+ * 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.conf;
+
+public interface ConfigurationObserver {
+  void propertyChanged(String key);
+  
+  void propertiesChanged();
+  
+  void sessionExpired();
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java b/1.5/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java
new file mode 100644
index 0000000..005ff97
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java
@@ -0,0 +1,152 @@
+/*
+ * 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.conf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import org.apache.log4j.Logger;
+
+public class DefaultConfiguration extends AccumuloConfiguration {
+  private static DefaultConfiguration instance = null;
+  private static Logger log = Logger.getLogger(DefaultConfiguration.class);
+  
+  public static DefaultConfiguration getInstance() {
+    if (instance == null) {
+      instance = new DefaultConfiguration();
+      ConfigSanityCheck.validate(instance);
+    }
+    return instance;
+  }
+  
+  @Override
+  public String get(Property property) {
+    return property.getDefaultValue();
+  }
+  
+  @Override
+  public Iterator<Entry<String,String>> iterator() {
+    TreeMap<String,String> entries = new TreeMap<String,String>();
+    for (Property prop : Property.values())
+      if (!prop.getType().equals(PropertyType.PREFIX))
+        entries.put(prop.getKey(), prop.getDefaultValue());
+    
+    return entries.entrySet().iterator();
+  }
+  
+  private static void generateDocumentation(PrintStream doc) {
+    // read static content from resources and output
+    InputStream data = DefaultConfiguration.class.getClassLoader().getResourceAsStream("config.html");
+    if (data != null) {
+      byte[] buffer = new byte[1024];
+      int n;
+      try {
+        while ((n = data.read(buffer)) > 0)
+          doc.print(new String(buffer, 0, n));
+      } catch (IOException e) {
+        e.printStackTrace();
+        return;
+      } finally {
+    	  try { 
+    		  data.close();
+    	  } catch (IOException ex) {
+    		  log .error(ex, ex);
+    	  }
+      }
+    }
+    doc.println();
+    
+    ArrayList<Property> prefixes = new ArrayList<Property>();
+    TreeMap<String,Property> sortedProps = new TreeMap<String,Property>();
+    for (Property prop : Property.values()) {
+      if (prop.getType().equals(PropertyType.PREFIX))
+        prefixes.add(prop);
+      else
+        sortedProps.put(prop.getKey(), prop);
+    }
+    
+    doc.println("  <p>Jump to: ");
+    String delimiter = "";
+    for (Property prefix : prefixes) {
+      doc.print(delimiter + "<a href='#" + prefix.name() + "'>" + prefix.getKey() + "*</a>");
+      delimiter = "&nbsp;|&nbsp;";
+    }
+    doc.println("  </p>");
+    
+    doc.println("  <table>");
+    for (Property prefix : prefixes) {
+      doc.println("   <tr><td colspan='5'><a name='" + prefix.name() + "' class='large'>" + prefix.getKey() + "*</a></td></tr>");
+      doc.println("   <tr><td colspan='5'><i>" + prefix.getDescription() + "</i></td></tr>");
+      if (!prefix.equals(Property.TABLE_CONSTRAINT_PREFIX) && !prefix.equals(Property.TABLE_ITERATOR_PREFIX)
+          && !prefix.equals(Property.TABLE_LOCALITY_GROUP_PREFIX))
+        doc.println("   <tr><th>Property</th><th>Type</th><th>Zookeeper Mutable</th><th>Default Value</th><th>Description</th></tr>");
+      
+      boolean highlight = true;
+      for (Property prop : sortedProps.values()) {
+        if (prop.getKey().startsWith(prefix.getKey())) {
+          doc.println("   <tr " + (highlight ? "class='highlight'" : "") + ">");
+          highlight = !highlight;
+          doc.println("    <td>" + prop.getKey() + "</td>");
+          doc.println("    <td><b><a href='#" + prop.getType().name() + "'>" + prop.getType().toString().replaceAll(" ", "&nbsp;") + "</a></b></td>");
+          String zoo = "no";
+          if (Property.isValidZooPropertyKey(prop.getKey())) {
+            zoo = "yes";
+            if (Property.isFixedZooPropertyKey(prop)) {
+              zoo = "yes but requires restart of the " + prop.getKey().split("[.]")[0];
+            }
+          }
+          doc.println("    <td>" + zoo + "</td>");
+          doc.println("    <td><pre>" + (prop.getDefaultValue().isEmpty() ? "&nbsp;" : prop.getDefaultValue().replaceAll(" ", "&nbsp;")) + "</pre></td>");
+          doc.println("    <td>" + prop.getDescription() + "</td>");
+          doc.println("   </tr>");
+        }
+      }
+    }
+    doc.println("  </table>");
+    
+    doc.println("  <h1>Property Type Descriptions</h1>");
+    doc.println("  <table>");
+    doc.println("   <tr><th>Property Type</th><th>Description</th></tr>");
+    boolean highlight = true;
+    for (PropertyType type : PropertyType.values()) {
+      if (type.equals(PropertyType.PREFIX))
+        continue;
+      doc.println("   <tr " + (highlight ? "class='highlight'" : "") + ">");
+      highlight = !highlight;
+      doc.println("     <td><h3><a name='" + type.name() + "'>" + type + "</a></td>");
+      doc.println("     <td>" + type.getFormatDescription() + "</td>");
+      doc.println("    </tr>");
+    }
+    doc.println("  </table>");
+    doc.println(" </body>");
+    doc.println("</html>");
+    doc.close();
+  }
+  
+  /*
+   * Generate documentation for conf/accumulo-site.xml file usage
+   */
+  public static void main(String[] args) {
+    if (args.length == 1 && args[0].equals("--generate-doc"))
+      generateDocumentation(System.out);
+  }
+}


Mime
View raw message