accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [17/54] git commit: ACCUMULO-802 working on namespace constraints, test currently fails, doesn't update tables constraints until something else triggers a reload.
Date Fri, 01 Nov 2013 02:00:18 GMT
ACCUMULO-802 working on namespace constraints, test currently fails, doesn't update tables
constraints until something else triggers a reload.

Conflicts:
	server/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java
	test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c9ab4c97
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c9ab4c97
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c9ab4c97

Branch: refs/heads/ACCUMULO-802
Commit: c9ab4c97a27034269b31a179eb4b52f3071281f0
Parents: fa67f35
Author: Sean Hickey <tallirishllama@gmail.com>
Authored: Thu Jul 25 13:17:00 2013 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Thu Oct 31 21:25:34 2013 -0400

----------------------------------------------------------------------
 .../util/shell/commands/ConstraintCommand.java  | 62 +++++++++++++++++---
 .../server/conf/ServerConfiguration.java        | 15 +++--
 .../conf/TableNamespaceConfiguration.java       | 55 ++++++++++++-----
 .../tserver/constraints/ConstraintChecker.java  |  1 +
 .../accumulo/test/TableNamespacesTest.java      | 12 +++-
 5 files changed, 117 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9ab4c97/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
index 4280555..8be52cf 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
@@ -19,40 +19,77 @@ package org.apache.accumulo.core.util.shell.commands;
 import java.util.Map.Entry;
 
 import org.apache.accumulo.core.constraints.Constraint;
+import org.apache.accumulo.core.metadata.MetadataTable;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
 import org.apache.accumulo.core.util.shell.ShellCommandException;
 import org.apache.accumulo.core.util.shell.ShellCommandException.ErrorCode;
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
 
 public class ConstraintCommand extends Command {
+  protected Option tableNamespaceOpt;
+  
   @Override
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
-    final String tableName = OptUtil.getTableOpt(cl, shellState);
+    final String tableName;
+    final String namespace;
+    
+    if (cl.hasOption(tableNamespaceOpt.getOpt())) {
+      namespace = cl.getOptionValue(tableNamespaceOpt.getOpt());
+    } else {
+      namespace = null;
+    }
+    
+    tableName = OptUtil.getTableOpt(cl, shellState);
+    
     int i;
     
     switch (OptUtil.getAldOpt(cl)) {
       case ADD:
         for (String constraint : cl.getArgs()) {
-          if (!shellState.getConnector().tableOperations().testClassLoad(tableName, constraint,
Constraint.class.getName())) {
+          if (!shellState.getConnector().tableOperations().testClassLoad(MetadataTable.NAME,
constraint, Constraint.class.getName())) {
             throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are
unable to load " + constraint + " as type "
                 + Constraint.class.getName());
           }
-          i = shellState.getConnector().tableOperations().addConstraint(tableName, constraint);
-          shellState.getReader().println("Added constraint " + constraint + " to table "
+ tableName + " with number " + i);
+          if (namespace != null) {
+            i = shellState.getConnector().tableNamespaceOperations().addConstraint(namespace,
constraint);
+            shellState.getReader().println("Added constraint " + constraint + " to table
namespace " + namespace + " with number " + i);
+          } else if (tableName != null){
+            i = shellState.getConnector().tableOperations().addConstraint(tableName, constraint);
+            shellState.getReader().println("Added constraint " + constraint + " to table
" + tableName + " with number " + i);
+          } else {
+            throw new IllegalArgumentException("Please specify either a table or a table
namespace");
+          }
         }
         break;
       case DELETE:
         for (String constraint : cl.getArgs()) {
           i = Integer.parseInt(constraint);
-          shellState.getConnector().tableOperations().removeConstraint(tableName, i);
-          shellState.getReader().println("Removed constraint " + i + " from table " + tableName);
+          if (namespace != null) {
+            shellState.getConnector().tableNamespaceOperations().removeConstraint(namespace,
i);
+            shellState.getReader().println("Removed constraint " + i + " from table namespace
" + namespace);
+          } else if (tableName != null){
+            shellState.getConnector().tableOperations().removeConstraint(tableName, i);
+            shellState.getReader().println("Removed constraint " + i + " from table " + tableName);
+          } else {
+            throw new IllegalArgumentException("Please specify either a table or a table
namespace");
+          }
         }
         break;
       case LIST:
-        for (Entry<String,Integer> property : shellState.getConnector().tableOperations().listConstraints(tableName).entrySet())
{
-          shellState.getReader().println(property.toString());
+        if (namespace != null) {
+          for (Entry<String,Integer> property : shellState.getConnector().tableNamespaceOperations().listConstraints(namespace).entrySet())
{
+            shellState.getReader().println(property.toString());
+          }
+        } else if (tableName != null){
+          for (Entry<String,Integer> property : shellState.getConnector().tableOperations().listConstraints(tableName).entrySet())
{
+            shellState.getReader().println(property.toString());
+          }
+        } else {
+          throw new IllegalArgumentException("Please specify either a table or a table namespace");
         }
     }
     
@@ -78,7 +115,14 @@ public class ConstraintCommand extends Command {
   public Options getOptions() {
     final Options o = new Options();
     o.addOptionGroup(OptUtil.addListDeleteGroup("constraint"));
-    o.addOption(OptUtil.tableOpt("table to add, delete, or list constraints for"));
+    
+    OptionGroup grp = new OptionGroup();
+    grp.addOption(OptUtil.tableOpt("table to add, delete, or list constraints for"));
+    tableNamespaceOpt = new Option(Shell.tableNamespaceOption, "table-namespace", true, "name
of a table namespace to operate on");
+    tableNamespaceOpt.setArgName("tableNamespace");
+    grp.addOption(tableNamespaceOpt);
+    
+    o.addOptionGroup(grp);
     return o;
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9ab4c97/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java
b/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java
index f3421cc..fe78ca4 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfiguration.java
@@ -63,12 +63,13 @@ public class ServerConfiguration {
 
   public static TableNamespaceConfiguration getTableNamespaceConfigurationForTable(Instance
instance, String tableId) {
     checkPermissions();
+    String namespaceId = Tables.getNamespace(instance, tableId);
     synchronized (tableNamespaceInstances) {
-      TableNamespaceConfiguration conf = tableNamespaceInstances.get(tableId);
+      TableNamespaceConfiguration conf = tableNamespaceInstances.get(namespaceId);
       if (conf == null) {
-        conf = new TableNamespaceConfiguration(tableId, getSystemConfiguration(instance));
+        conf = new TableNamespaceConfiguration(namespaceId, getSystemConfiguration(instance));
         ConfigSanityCheck.validate(conf);
-        tableNamespaceInstances.put(tableId, conf);
+        tableNamespaceInstances.put(namespaceId, conf);
       }
       return conf;
     }
@@ -79,7 +80,7 @@ public class ServerConfiguration {
     synchronized (tableNamespaceInstances) {
       TableNamespaceConfiguration conf = tableNamespaceInstances.get(namespaceId);
       if (conf == null) {
-        conf = new TableNamespaceConfiguration(namespaceId, getSystemConfiguration(instance),
true);
+        conf = new TableNamespaceConfiguration(namespaceId, getSystemConfiguration(instance));
         ConfigSanityCheck.validate(conf);
         tableNamespaceInstances.put(namespaceId, conf);
       }
@@ -106,6 +107,12 @@ public class ServerConfiguration {
     }
   }
 
+  static void removeNamespaceIdInstance(String namespaceId) {
+    synchronized (tableNamespaceInstances) {
+      tableNamespaceInstances.remove(namespaceId);
+    }
+  }
+
   static void expireAllTableObservers() {
     synchronized (tableInstances) {
       for (Entry<String,TableConfiguration> entry : tableInstances.entrySet()) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9ab4c97/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java
b/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java
index 0454c29..2334ce7 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java
@@ -23,7 +23,6 @@ import java.util.TreeMap;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.impl.Tables;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.zookeeper.ZooUtil;
@@ -36,22 +35,16 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration
{
   
   private final AccumuloConfiguration parent;
   private static ZooCache propCache = null;
-  private String tableId = null;
   private String namespaceId = null;
   private Instance inst = null;
-  
-  public TableNamespaceConfiguration(String tableId, AccumuloConfiguration parent) {
-    inst = HdfsZooInstance.getInstance();
-    propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut());
-    this.parent = parent;
-    this.tableId = tableId;
-  }
-  
-  public TableNamespaceConfiguration(String namespaceId, AccumuloConfiguration parent, boolean
notForSpecificTable) {
+  private Set<ConfigurationObserver> observers;
+
+  public TableNamespaceConfiguration(String namespaceId, AccumuloConfiguration parent) {
     inst = HdfsZooInstance.getInstance();
     propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut());
     this.parent = parent;
     this.namespaceId = namespaceId;
+    this.observers = Collections.synchronizedSet(new HashSet<ConfigurationObserver>());
   }
   
   @Override
@@ -114,9 +107,43 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration
{
   }
   
   private String getNamespaceId() {
-    if (tableId != null) {
-      return Tables.getNamespace(inst, tableId);
-    }
     return namespaceId;
   }
+  
+  public void addObserver(ConfigurationObserver co) {
+    if (namespaceId == null) {
+      String err = "Attempt to add observer for non-table-namespace configuration";
+      log.error(err);
+      throw new RuntimeException(err);
+    }
+    iterator();
+    observers.add(co);
+  }
+  
+  public void removeObserver(ConfigurationObserver configObserver) {
+    if (namespaceId == null) {
+      String err = "Attempt to remove observer for non-table-namespace configuration";
+      log.error(err);
+      throw new RuntimeException(err);
+    }
+    observers.remove(configObserver);
+  }
+  
+  public void expireAllObservers() {
+    Collection<ConfigurationObserver> copy = Collections.unmodifiableCollection(observers);
+    for (ConfigurationObserver co : copy)
+      co.sessionExpired();
+  }
+  
+  public void propertyChanged(String key) {
+    Collection<ConfigurationObserver> copy = Collections.unmodifiableCollection(observers);
+    for (ConfigurationObserver co : copy)
+      co.propertyChanged(key);
+  }
+  
+  public void propertiesChanged(String key) {
+    Collection<ConfigurationObserver> copy = Collections.unmodifiableCollection(observers);
+    for (ConfigurationObserver co : copy)
+      co.propertiesChanged();
+  }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9ab4c97/server/tserver/src/main/java/org/apache/accumulo/tserver/constraints/ConstraintChecker.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/constraints/ConstraintChecker.java
b/server/tserver/src/main/java/org/apache/accumulo/tserver/constraints/ConstraintChecker.java
index 6f52485..902f12b 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/constraints/ConstraintChecker.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/constraints/ConstraintChecker.java
@@ -59,6 +59,7 @@ public class ConstraintChecker {
       
       for (Entry<String,String> entry : conf) {
         if (entry.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.getKey())) {
+          System.err.println("FOUND A CONSTRAINT: " + entry.toString() + " for table " +
conf.getTableId());
           String className = entry.getValue();
           Class<? extends Constraint> clazz = loader.loadClass(className).asSubclass(Constraint.class);
           log.debug("Loaded constraint " + clazz.getName() + " for " + conf.getTableId());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/c9ab4c97/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java b/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java
index cfd8000..e3455fb 100644
--- a/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java
@@ -48,6 +48,8 @@ import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.iterators.Filter;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
 import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.UtilWaitThread;
+import org.apache.accumulo.examples.simple.constraints.AlphaNumKeyConstraint;
 import org.apache.accumulo.examples.simple.constraints.NumericValueConstraint;
 import org.apache.accumulo.minicluster.MiniAccumuloCluster;
 import org.junit.AfterClass;
@@ -65,6 +67,7 @@ public class TableNamespacesTest {
   @BeforeClass
   static public void setUp() throws Exception {
     folder.create();
+    System.out.println(folder.getRoot());
     accumulo = new MiniAccumuloCluster(folder.getRoot(), secret);
     accumulo.start();
   }
@@ -72,7 +75,7 @@ public class TableNamespacesTest {
   @AfterClass
   static public void tearDown() throws Exception {
     accumulo.stop();
-    folder.delete();
+    // folder.delete();
   }
   
   /**
@@ -387,6 +390,13 @@ public class TableNamespacesTest {
     c.tableNamespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
     
     c.tableNamespaceOperations().addConstraint(namespace, NumericValueConstraint.class.getName());
+    c.tableOperations().addConstraint(tableName, AlphaNumKeyConstraint.class.getName());
+    
+    for (Entry<String,Integer> e : c.tableOperations().listConstraints(tableName).entrySet())
{
+      System.out.println(e.toString());
+    }
+    //UtilWaitThread.sleep(10000);
+    
     m = new Mutation("rowy");
     m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
     try {


Mime
View raw message