@InterfaceAudience.Public public final class Constraints extends Object
TableDescriptor
is immutable now, you should use TableDescriptorBuilder
.
And when disabling or removing constraints, you could use
TableDescriptorBuilder.newBuilder(TableDescriptor)
to clone the old
TableDescriptor
and then pass it the below methods.Modifier and Type | Field and Description |
---|---|
private static Pattern |
CONSTRAINT_HTD_ATTR_KEY_PATTERN |
private static String |
CONSTRAINT_HTD_KEY_PREFIX |
private static Comparator<Constraint> |
constraintComparator |
private static String |
COUNTER_KEY |
private static int |
DEFAULT_PRIORITY |
private static String |
ENABLED_KEY |
private static org.slf4j.Logger |
LOG |
private static long |
MIN_PRIORITY |
private static String |
PRIORITY_KEY |
private static long |
UNSET_PRIORITY |
Modifier | Constructor and Description |
---|---|
private |
Constraints() |
Modifier and Type | Method and Description |
---|---|
static TableDescriptorBuilder |
add(TableDescriptorBuilder builder,
Class<? extends Constraint>... constraints)
Add configuration-less constraints to the table.
|
static TableDescriptorBuilder |
add(TableDescriptorBuilder builder,
Class<? extends Constraint> constraint,
org.apache.hadoop.conf.Configuration conf)
Add a
Constraint to the table with the given configuration
Each constraint, when added to the table, will have a specific priority, dictating the order in
which the Constraint will be run. |
static TableDescriptorBuilder |
add(TableDescriptorBuilder builder,
Pair<Class<? extends Constraint>,org.apache.hadoop.conf.Configuration>... constraints)
Add constraints and their associated configurations to the table.
|
private static TableDescriptorBuilder |
addConstraint(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz,
org.apache.hadoop.conf.Configuration conf,
long priority)
Write the raw constraint and configuration to the descriptor.
|
private static TableDescriptorBuilder |
changeConstraintEnabled(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz,
boolean enabled)
Change the whether the constraint (if it is already present) is enabled or disabled.
|
private static org.apache.hadoop.conf.Configuration |
configure(org.apache.hadoop.conf.Configuration conf,
boolean enabled,
long priority)
Setup the configuration for a constraint as to whether it is enabled and its priority
|
static TableDescriptorBuilder |
disable(TableDescriptorBuilder builder)
Turn off processing constraints for a given table, even if constraints have been turned on or
added.
|
static void |
disableConstraint(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz)
Disable the given
Constraint . |
static TableDescriptorBuilder |
enable(TableDescriptorBuilder builder)
Enable constraints on a table.
|
static void |
enableConstraint(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz)
Enable the given
Constraint . |
static boolean |
enabled(TableDescriptor desc,
Class<? extends Constraint> clazz)
Check to see if the given constraint is enabled.
|
(package private) static List<? extends Constraint> |
getConstraints(TableDescriptor desc,
ClassLoader classloader)
Get the constraints stored in the table descriptor
|
private static Pair<String,String> |
getKeyValueForClass(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz)
Get the kv
Map.Entry in the descriptor builder for the specified class |
private static Pair<String,String> |
getKeyValueForClass(TableDescriptor desc,
Class<? extends Constraint> clazz)
Get the kv
Map.Entry in the descriptor for the specified class |
private static long |
getNextPriority(TableDescriptorBuilder builder) |
static boolean |
has(TableDescriptor desc,
Class<? extends Constraint> clazz)
Check to see if the Constraint is currently set.
|
private static org.apache.hadoop.conf.Configuration |
readConfiguration(byte[] bytes)
Read the
Configuration stored in the byte stream. |
private static org.apache.hadoop.conf.Configuration |
readConfiguration(String bytes)
Read in the configuration from the String encoded configuration
|
static TableDescriptorBuilder |
remove(TableDescriptorBuilder builder)
Remove all
Constraints that have been added to the table and turn off the
constraint processing. |
static TableDescriptorBuilder |
remove(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz)
Remove the constraint (and associated information) for the table descriptor.
|
private static String |
serializeConfiguration(org.apache.hadoop.conf.Configuration conf)
Write the configuration to a String
|
private static String |
serializeConstraintClass(Class<? extends Constraint> clazz)
Just write the class to a String representation of the class as a key for the
TableDescriptor |
static TableDescriptorBuilder |
setConfiguration(TableDescriptorBuilder builder,
Class<? extends Constraint> clazz,
org.apache.hadoop.conf.Configuration configuration)
Update the configuration for the
Constraint ; does not change the order in which the
constraint is run. |
private static TableDescriptorBuilder |
updateLatestPriority(TableDescriptorBuilder builder,
long priority) |
private static TableDescriptorBuilder |
writeConstraint(TableDescriptorBuilder builder,
String key,
org.apache.hadoop.conf.Configuration conf)
Write the given key and associated configuration to the
TableDescriptorBuilder . |
private static final int DEFAULT_PRIORITY
private static final org.slf4j.Logger LOG
private static final String CONSTRAINT_HTD_KEY_PREFIX
private static final Pattern CONSTRAINT_HTD_ATTR_KEY_PATTERN
private static final String ENABLED_KEY
private static final String PRIORITY_KEY
private static final long MIN_PRIORITY
private static final long UNSET_PRIORITY
private static String COUNTER_KEY
private static final Comparator<Constraint> constraintComparator
private Constraints()
public static TableDescriptorBuilder enable(TableDescriptorBuilder builder) throws IOException
IOException
public static TableDescriptorBuilder disable(TableDescriptorBuilder builder) throws IOException
IOException
public static TableDescriptorBuilder remove(TableDescriptorBuilder builder) throws IOException
Constraints
that have been added to the table and turn off the
constraint processing.
All Configurations
and their associated Constraint
are removed.IOException
public static boolean has(TableDescriptor desc, Class<? extends Constraint> clazz)
desc
- TableDescriptor
to checkclazz
- Constraint
class to check for.Constraint
is present, even if it is disabled.
false otherwise.private static Pair<String,String> getKeyValueForClass(TableDescriptor desc, Class<? extends Constraint> clazz)
Map.Entry
in the descriptor for the specified classdesc
- TableDescriptor
to readclazz
- To search forPair
of <key, value> in the table, if that class is present.
null
otherwise.private static Pair<String,String> getKeyValueForClass(TableDescriptorBuilder builder, Class<? extends Constraint> clazz)
Map.Entry
in the descriptor builder for the specified classbuilder
- TableDescriptorBuilder
to readclazz
- To search forPair
of <key, value> in the table, if that class is present.
null
otherwise.@SafeVarargs public static TableDescriptorBuilder add(TableDescriptorBuilder builder, Class<? extends Constraint>... constraints) throws IOException
Constraint
will be run. A Constraint
earlier in the list will be run
before those later in the list. The same logic applies between two Constraints over time
(earlier added is run first on the regionserver).builder
- TableDescriptorBuilder
to add a Constraint
constraints
- Constraints
to add. All constraints are considered
automatically enabled on addIOException
- If constraint could not be serialized/added to table@SafeVarargs public static TableDescriptorBuilder add(TableDescriptorBuilder builder, Pair<Class<? extends Constraint>,org.apache.hadoop.conf.Configuration>... constraints) throws IOException
Adding the same constraint class twice will overwrite the first constraint's configuration
Each constraint, when added to the table, will have a specific priority, dictating the order in
which the Constraint
will be run. A Constraint
earlier in the list will be run
before those later in the list. The same logic applies between two Constraints over time
(earlier added is run first on the regionserver).
builder
- TableDescriptorBuilder
to add a Constraint
constraints
- Pair
of a Constraint
and its associated
Configuration
. The Constraint will be configured on load with the
specified configuration.All constraints are considered automatically enabled
on addIOException
- if any constraint could not be deserialized. Assumes if 1 constraint is not
loaded properly, something has gone terribly wrong and that all constraints
need to be enforced.public static TableDescriptorBuilder add(TableDescriptorBuilder builder, Class<? extends Constraint> constraint, org.apache.hadoop.conf.Configuration conf) throws IOException
Constraint
to the table with the given configuration
Each constraint, when added to the table, will have a specific priority, dictating the order in
which the Constraint
will be run. A Constraint
added will run on the
regionserver before those added to the TableDescriptorBuilder
later.builder
- TableDescriptorBuilder
to add a Constraint
constraint
- to be addedconf
- configuration associated with the constraintIOException
- if any constraint could not be deserialized. Assumes if 1 constraint is not
loaded properly, something has gone terribly wrong and that all constraints
need to be enforced.private static TableDescriptorBuilder addConstraint(TableDescriptorBuilder builder, Class<? extends Constraint> clazz, org.apache.hadoop.conf.Configuration conf, long priority) throws IOException
IOException
private static org.apache.hadoop.conf.Configuration configure(org.apache.hadoop.conf.Configuration conf, boolean enabled, long priority)
conf
- on which to base the new configurationenabled
- true if it should be runpriority
- relative to other constraintsTableDescriptor
private static String serializeConstraintClass(Class<? extends Constraint> clazz)
TableDescriptor
clazz
- Constraint class to convert to a TableDescriptor
keyTableDescriptor
private static TableDescriptorBuilder writeConstraint(TableDescriptorBuilder builder, String key, org.apache.hadoop.conf.Configuration conf) throws IOException
TableDescriptorBuilder
.IOException
private static String serializeConfiguration(org.apache.hadoop.conf.Configuration conf) throws IOException
conf
- to writeIOException
private static org.apache.hadoop.conf.Configuration readConfiguration(byte[] bytes) throws IOException
Configuration
stored in the byte stream.bytes
- to read fromIOException
private static org.apache.hadoop.conf.Configuration readConfiguration(String bytes) throws IOException
bytes
- to read fromIOException
- if the configuration could not be readprivate static long getNextPriority(TableDescriptorBuilder builder)
private static TableDescriptorBuilder updateLatestPriority(TableDescriptorBuilder builder, long priority)
public static TableDescriptorBuilder setConfiguration(TableDescriptorBuilder builder, Class<? extends Constraint> clazz, org.apache.hadoop.conf.Configuration configuration) throws IOException, IllegalArgumentException
Constraint
; does not change the order in which the
constraint is run.builder
- TableDescriptorBuilder
to updateclazz
- Constraint
to updateconfiguration
- to update the Constraint
with.IOException
- if the Constraint was not stored correctlyIllegalArgumentException
- if the Constraint was not present on this table.public static TableDescriptorBuilder remove(TableDescriptorBuilder builder, Class<? extends Constraint> clazz)
builder
- TableDescriptorBuilder
to modifyclazz
- Constraint
class to removepublic static void enableConstraint(TableDescriptorBuilder builder, Class<? extends Constraint> clazz) throws IOException
Constraint
. Retains all the information (e.g. Configuration) for the
Constraint
, but makes sure that it gets loaded on the table.builder
- TableDescriptorBuilder
to modifyclazz
- Constraint
to enableIOException
- If the constraint cannot be properly deserializedpublic static void disableConstraint(TableDescriptorBuilder builder, Class<? extends Constraint> clazz) throws IOException
Constraint
. Retains all the information (e.g. Configuration) for the
Constraint
, but it just doesn't load the Constraint
on the table.builder
- TableDescriptorBuilder
to modifyclazz
- Constraint
to disable.IOException
- if the constraint cannot be foundprivate static TableDescriptorBuilder changeConstraintEnabled(TableDescriptorBuilder builder, Class<? extends Constraint> clazz, boolean enabled) throws IOException
IOException
public static boolean enabled(TableDescriptor desc, Class<? extends Constraint> clazz) throws IOException
desc
- TableDescriptor
to check.clazz
- Constraint
to check forConstraint
is present and enabled. false
otherwise.IOException
- If the constraint has improperly stored in the tablestatic List<? extends Constraint> getConstraints(TableDescriptor desc, ClassLoader classloader) throws IOException
desc
- To read fromclassloader
- To use when loading classes. If a special classloader is used on a region,
for instance, then that should be the classloader used to load the
constraints. This could also apply to unit-testing situation, where want to
ensure that class is reloaded or not.Constraints
IOException
- if any part of reading/arguments failsCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.