/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<Bytes> keys = new ArrayList<>(); // loop through all the key, values looking for constraints for (Map.Entry<Bytes, Bytes> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (Bytes key : keys) { desc.remove(key); } }
Constraints.disable(desc);
/** * Test that Constraints are properly enabled, disabled, and removed * * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testEnableDisableRemove() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); // check general enabling/disabling of constraints // first add a constraint Constraints.add(desc, AllPassConstraint.class); // make sure everything is enabled assertTrue(Constraints.enabled(desc, AllPassConstraint.class)); assertTrue(desc.hasCoprocessor(ConstraintProcessor.class.getName())); // check disabling Constraints.disable(desc); assertFalse(desc.hasCoprocessor(ConstraintProcessor.class.getName())); // make sure the added constraints are still present assertTrue(Constraints.enabled(desc, AllPassConstraint.class)); // check just removing the single constraint Constraints.remove(desc, AllPassConstraint.class); assertFalse(Constraints.has(desc, AllPassConstraint.class)); // Add back the single constraint Constraints.add(desc, AllPassConstraint.class); // and now check that when we remove constraints, all are gone Constraints.remove(desc); assertFalse(desc.hasCoprocessor(ConstraintProcessor.class.getName())); assertFalse(Constraints.has(desc, AllPassConstraint.class)); }
/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<ImmutableBytesWritable> keys = new ArrayList<ImmutableBytesWritable>(); // loop through all the key, values looking for constraints for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (ImmutableBytesWritable key : keys) { desc.remove(key); } }
/** * Remove all {@link Constraint Constraints} that have been added to the table * and turn off the constraint processing. * <p> * All {@link Configuration Configurations} and their associated * {@link Constraint} are removed. * * @param desc * {@link HTableDescriptor} to remove {@link Constraint Constraints} * from. */ public static void remove(HTableDescriptor desc) { // disable constraints disable(desc); // remove all the constraint settings List<ImmutableBytesWritable> keys = new ArrayList<ImmutableBytesWritable>(); // loop through all the key, values looking for constraints for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : desc .getValues().entrySet()) { String key = Bytes.toString((e.getKey().get())); String[] className = CONSTRAINT_HTD_ATTR_KEY_PATTERN.split(key); if (className.length == 2) { keys.add(e.getKey()); } } // now remove all the keys we found for (ImmutableBytesWritable key : keys) { desc.remove(key.get()); } }
Constraints.disable(desc);
/** * Test that Constraints are properly enabled, disabled, and removed * * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testEnableDisableRemove() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); // check general enabling/disabling of constraints // first add a constraint Constraints.add(desc, AllPassConstraint.class); // make sure everything is enabled assertTrue(Constraints.enabled(desc, AllPassConstraint.class)); assertTrue(desc.hasCoprocessor(ConstraintProcessor.class.getName())); // check disabling Constraints.disable(desc); assertFalse(desc.hasCoprocessor(ConstraintProcessor.class.getName())); // make sure the added constraints are still present assertTrue(Constraints.enabled(desc, AllPassConstraint.class)); // check just removing the single constraint Constraints.remove(desc, AllPassConstraint.class); assertFalse(Constraints.has(desc, AllPassConstraint.class)); // Add back the single constraint Constraints.add(desc, AllPassConstraint.class); // and now check that when we remove constraints, all are gone Constraints.remove(desc); assertFalse(desc.hasCoprocessor(ConstraintProcessor.class.getName())); assertFalse(Constraints.has(desc, AllPassConstraint.class)); }