Author: billie
Date: Thu May 10 19:13:34 2012
New Revision: 1336834
URL: http://svn.apache.org/viewvc?rev=1336834&view=rev
Log:
ACCUMULO-584 added constraint methods and made other classes use them, fixed
examples functional test
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
accumulo/trunk/server/src/main/java/org/apache/accumulo/server/test/functional/ConstraintTest.java
accumulo/trunk/test/system/auto/simple/examples.py
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java?rev=1336834&r1=1336833&r2=1336834&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
Thu May 10 19:13:34 2012
@@ -529,4 +529,45 @@ public interface TableOperations {
* if the setting conflicts with any existing iterators
*/
public void checkIteratorConflicts(String tableName, IteratorSetting
setting, EnumSet<IteratorScope> scopes) throws AccumuloException,
TableNotFoundException;
+
+ /**
+ * Add a new constraint to a table.
+ *
+ * @param tableName
+ * the name of the table
+ * @param constraintClassName
+ * the full name of the constraint class
+ * @return the unique number assigned to the constraint
+ * @throws AccumuloException
+ * thrown if the constraint has already been added to the table or
if there are errors in the configuration of existing constraints
+ * @throws AccumuloSecurityException
+ * thrown if the user doesn't have permission to add the constraint
+ * @throws TableNotFoundException
+ */
+ public int addConstraint(String tableName, String constraintClassName)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException;
+
+ /**
+ * Remove a constraint from a table.
+ *
+ * @param tableName
+ * the name of the table
+ * @param number
+ * the unique number assigned to the constraint
+ * @throws AccumuloException
+ * @throws AccumuloSecurityException
+ * thrown if the user doesn't have permission to remove the
constraint
+ */
+ public void removeConstraint(String tableName, int number) throws
AccumuloException, AccumuloSecurityException;
+
+ /**
+ * List constraints on a table with their assigned numbers.
+ *
+ * @param tableName
+ * the name of the table
+ * @return a map from constraint class name to assigned number
+ * @throws AccumuloException
+ * thrown if there are errors in the configuration of existing
constraints
+ * @throws TableNotFoundException
+ */
+ public Map<String,Integer> listConstraints(String tableName) throws
AccumuloException, TableNotFoundException;
}
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java?rev=1336834&r1=1336833&r2=1336834&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
Thu May 10 19:13:34 2012
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
+import java.util.TreeSet;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -30,12 +31,12 @@ import org.apache.accumulo.core.conf.Pro
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
public abstract class TableOperationsHelper implements TableOperations {
-
+
@Override
public void attachIterator(String tableName, IteratorSetting setting) throws
AccumuloSecurityException, AccumuloException, TableNotFoundException {
attachIterator(tableName, setting, EnumSet.allOf(IteratorScope.class));
}
-
+
@Override
public void attachIterator(String tableName, IteratorSetting setting,
EnumSet<IteratorScope> scopes) throws AccumuloSecurityException,
AccumuloException,
TableNotFoundException {
@@ -148,4 +149,53 @@ public abstract class TableOperationsHel
throw new IllegalArgumentException("iterator options conflict for " +
setting.getName() + ": " + optionConflicts);
}
}
+
+ @Override
+ public int addConstraint(String tableName, String constraintClassName)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ TreeSet<Integer> constraintNumbers = new TreeSet<Integer>();
+ TreeMap<String,Integer> constraintClasses = new TreeMap<String,Integer>();
+ int i;
+ for (Entry<String,String> property : this.getProperties(tableName)) {
+ if
(property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
+ try {
+ i =
Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()));
+ } catch (NumberFormatException e) {
+ throw new AccumuloException("Bad key for existing constraint: " +
property.toString());
+ }
+ constraintNumbers.add(i);
+ constraintClasses.put(property.getValue(), i);
+ }
+ }
+ i = 1;
+ while (constraintNumbers.contains(i))
+ i++;
+ if (constraintClasses.containsKey(constraintClassName))
+ throw new AccumuloException("Constraint " + constraintClassName + "
already exists for table " + tableName + " with number "
+ + constraintClasses.get(constraintClassName));
+ this.setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() +
i, constraintClassName);
+ return i;
+ }
+
+ @Override
+ public void removeConstraint(String tableName, int number) throws
AccumuloException, AccumuloSecurityException {
+ this.removeProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString()
+ number);
+ }
+
+ @Override
+ public Map<String,Integer> listConstraints(String tableName) throws
AccumuloException, TableNotFoundException {
+ Map<String,Integer> constraints = new TreeMap<String,Integer>();
+ for (Entry<String,String> property : this.getProperties(tableName)) {
+ if
(property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
+ if (constraints.containsKey(property.getValue()))
+ throw new AccumuloException("Same constraint configured twice: " +
property.getKey() + "=" + Property.TABLE_CONSTRAINT_PREFIX
+ + constraints.get(property.getValue()) + "=" +
property.getKey());
+ try {
+ constraints.put(property.getValue(),
Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length())));
+ } catch (NumberFormatException e) {
+ throw new AccumuloException("Bad key for existing constraint: " +
property.toString());
+ }
+ }
+ }
+ return constraints;
+ }
}
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java?rev=1336834&r1=1336833&r2=1336834&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
Thu May 10 19:13:34 2012
@@ -17,10 +17,7 @@
package org.apache.accumulo.core.util.shell.commands;
import java.util.Map.Entry;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.constraints.Constraint;
import org.apache.accumulo.core.util.shell.Shell;
import org.apache.accumulo.core.util.shell.Shell.Command;
@@ -37,49 +34,24 @@ public class ConstraintCommand extends C
switch (OptUtil.configureAldOpt(cl)) {
case ADD:
- TreeSet<Integer> constraintNumbers = new TreeSet<Integer>();
- TreeMap<String,Integer> constraintClasses = new
TreeMap<String,Integer>();
- for (Entry<String,String> property :
shellState.getConnector().tableOperations().getProperties(tableName)) {
- if
(property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
- i =
Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()));
- constraintNumbers.add(i);
- constraintClasses.put(property.getValue(), i);
- }
- }
- i = 1;
- while (constraintNumbers.contains(i))
- i++;
for (String constraint : cl.getArgs()) {
- if (constraintClasses.containsKey(constraint)) {
- shellState.getReader().printString(
- "Constraint " + constraint + " already exists for table " +
tableName + " with number " + constraintClasses.get(constraint) + "\n");
- continue;
- }
if
(!shellState.getConnector().instanceOperations().testClassLoad(constraint,
Constraint.class.getName()))
throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE,
"Servers are unable to load " + constraint + " as type "
+ Constraint.class.getName());
- shellState.getConnector().tableOperations().setProperty(tableName,
Property.TABLE_CONSTRAINT_PREFIX.toString() + i, constraint);
+ i =
shellState.getConnector().tableOperations().addConstraint(tableName,
constraint);
shellState.getReader().printString("Added constraint " + constraint
+ " to table " + tableName + " with number " + i + "\n");
- i++;
- while (constraintNumbers.contains(i))
- i++;
}
break;
case DELETE:
for (String constraint : cl.getArgs()) {
i = Integer.parseInt(constraint);
-
shellState.getConnector().tableOperations().removeProperty(tableName,
Property.TABLE_CONSTRAINT_PREFIX.toString() + i);
+
shellState.getConnector().tableOperations().removeConstraint(tableName, i);
shellState.getReader().printString("Removed constraint " + i + "
from table " + tableName + "\n");
}
break;
case LIST:
- TreeMap<String,String> properties = new TreeMap<String,String>();
- for (Entry<String,String> property :
shellState.getConnector().tableOperations().getProperties(tableName)) {
- if
(property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString()))
- properties.put(property.getKey(), property.getValue());
- }
- for (Entry<String,String> property : properties.entrySet())
- shellState.getReader().printString(property.toString());
+ for (Entry<String,Integer> property :
shellState.getConnector().tableOperations().listConstraints(tableName).entrySet())
+ shellState.getReader().printString(property.toString() + "\n");
}
return 0;
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java?rev=1336834&r1=1336833&r2=1336834&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
Thu May 10 19:13:34 2012
@@ -123,23 +123,11 @@ public class CreateTableCommand extends
}
if (cl.hasOption(createTableOptEVC.getOpt())) {
- int max = 0;
- Iterable<Entry<String,String>> props =
shellState.getConnector().tableOperations().getProperties(tableName);
- boolean vcSet = false;
- for (Entry<String,String> entry : props) {
- if
(entry.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.getKey())) {
- int num =
Integer.parseInt(entry.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.getKey().length()));
- if (num > max)
- max = num;
-
- if (entry.getValue().equals(VisibilityConstraint.class.getName()))
- vcSet = true;
- }
+ try {
+ shellState.getConnector().tableOperations().addConstraint(tableName,
VisibilityConstraint.class.getName());
+ } catch (AccumuloException e) {
+ Shell.log.warn(e.getMessage() + " while setting visibility constraint,
but table was created");
}
-
- if (!vcSet)
- shellState.getConnector().tableOperations()
- .setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.getKey()
+ (max + 1), VisibilityConstraint.class.getName());
}
// Load custom formatter if set
Modified:
accumulo/trunk/server/src/main/java/org/apache/accumulo/server/test/functional/ConstraintTest.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/test/functional/ConstraintTest.java?rev=1336834&r1=1336833&r2=1336834&view=diff
==============================================================================
---
accumulo/trunk/server/src/main/java/org/apache/accumulo/server/test/functional/ConstraintTest.java
(original)
+++
accumulo/trunk/server/src/main/java/org/apache/accumulo/server/test/functional/ConstraintTest.java
Thu May 10 19:13:34 2012
@@ -139,7 +139,7 @@ public class ConstraintTest extends Func
}
// remove the numeric value constraint
- getConnector().tableOperations().removeProperty("ct",
Property.TABLE_CONSTRAINT_PREFIX + "1");
+ getConnector().tableOperations().removeConstraint("ct", 1);
UtilWaitThread.sleep(1000);
// now should be able to add a non numeric value
Modified: accumulo/trunk/test/system/auto/simple/examples.py
URL:
http://svn.apache.org/viewvc/accumulo/trunk/test/system/auto/simple/examples.py?rev=1336834&r1=1336833&r2=1336834&view=diff
==============================================================================
--- accumulo/trunk/test/system/auto/simple/examples.py (original)
+++ accumulo/trunk/test/system/auto/simple/examples.py Thu May 10 19:13:34 2012
@@ -62,9 +62,12 @@ class Examples(TestUtilsMixin, unittest.
self.comment("Testing MaxMutation constraint")
self.ashell('createtable test_ingest\n'
-'config -t test_ingest -s
table.constraint.1=org.apache.accumulo.examples.simple.constraints.MaxMutationSize\n')
- self.assert_(not self.execute(self.accumulo_sh(),
'org.apache.accumulo.server.test.TestIngest', '1', '0', '10000'))
-
+ 'constraint -a
org.apache.accumulo.examples.simple.constraints.MaxMutationSize\n')
+ handle = self.runOn('localhost', [self.accumulo_sh(),
'org.apache.accumulo.server.test.TestIngest', '1', '0', '10000'])
+ out, err = handle.communicate()
+ self.failIf(handle.returncode==0)
+ self.failUnless(err.find("MutationsRejectedException: # constraint
violations : 1") >= 0, "Was able to insert a mutation larger than max size")
+
self.ashell('createtable %s\nsetauths -u %s -s A,B\nquit\n' %(table,
ROOT))
self.comment("Testing dirlist example (a little)")
self.comment(" ingesting accumulo source")
@@ -212,7 +215,7 @@ class Examples(TestUtilsMixin, unittest.
self.wait(self.runOn(self.masterHost(), [
'hadoop', 'fs', '-copyFromLocal', ACCUMULO_HOME + "/README",
"/tmp/wc/Accumulo.README"
]))
- self.ashell('createtable wordCount -a
count=org.apache.accumulo.core.iterators.aggregation.StringSummation\nquit\n')
+ self.ashell('createtable wordCount\nsetiter -scan -majc -minc -p 10 -n
sum -class
org.apache.accumulo.core.iterators.user.SummingCombiner\n\ncount\n\nSTRING\nquit\n')
self.wait(self.runOn(self.masterHost(), [
ACCUMULO_HOME+'/bin/tool.sh',
examplesJar,
@@ -264,8 +267,8 @@ class Examples(TestUtilsMixin, unittest.
self.comment("Using some example constraints")
self.ashell('\n'.join([
'createtable testConstraints',
- 'config -t testConstraints -s
table.constraint.1=org.apache.accumulo.simple.examples.constraints.NumericValueConstraint',
- 'config -t testConstraints -s
table.constraint.2=org.apache.accumulo.simple.examples.constraints.AlphaNumKeyConstraint',
+ 'constraint -t testConstraints -a
org.apache.accumulo.examples.simple.constraints.NumericValueConstraint',
+ 'constraint -t testConstraints -a
org.apache.accumulo.examples.simple.constraints.AlphaNumKeyConstraint',
'insert r1 cf1 cq1 1111',
'insert r1 cf1 cq1 ABC',
'scan',