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; } }
/** * Validates the given configuration entries. A valid configuration contains only valid properties * (i.e., defined or otherwise valid) that are not prefixes and whose values are formatted * correctly for their property types. A valid configuration also contains a value for property * {@link Property#INSTANCE_ZK_TIMEOUT} within a valid range. * * @param entries iterable through configuration keys and values * @throws SanityCheckException if a fatal configuration error is found */ public static void validate(Iterable<Entry<String, String>> entries) { String instanceZkTimeoutValue = null; boolean usingVolumes = false; for (Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); Property prop = Property.getPropertyByKey(entry.getKey()); if (prop == null && Property.isValidPropertyKey(key)) continue; // unknown valid property (i.e. has proper prefix) 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() + ")"); if (key.equals(Property.INSTANCE_ZK_TIMEOUT.getKey())) { instanceZkTimeoutValue = value; } if (key.equals(Property.INSTANCE_VOLUMES.getKey())) { usingVolumes = value != null && !value.isEmpty(); } } if (instanceZkTimeoutValue != null) { checkTimeDuration( Property.INSTANCE_ZK_TIMEOUT, instanceZkTimeoutValue, new CheckTimeDurationBetween(1000, 300000)); } if (!usingVolumes) { log.warn( "Use of " + INSTANCE_DFS_URI + " and " + INSTANCE_DFS_DIR + " are deprecated. Consider using " + Property.INSTANCE_VOLUMES + " instead."); } }
public static boolean isValidTablePropertyKey(String key) { if (validTableProperties == null) { synchronized (Property.class) { if (validTableProperties == null) { HashSet<String> tmp = new HashSet<String>(); for (Property p : Property.values()) if (!p.getType().equals(PropertyType.PREFIX) && p.getKey().startsWith(Property.TABLE_PREFIX.getKey())) tmp.add(p.getKey()); validTableProperties = tmp; } } } return validTableProperties.contains(key) || key.startsWith(Property.TABLE_CONSTRAINT_PREFIX.getKey()) || key.startsWith(Property.TABLE_ITERATOR_PREFIX.getKey()) || key.startsWith(Property.TABLE_LOCALITY_GROUP_PREFIX.getKey()); }
private static void verifyPropertyTypes(PropertyType type, Property... properties) { for (Property prop : properties) if (prop.getType() != type) fatal("Unexpected property type (" + prop.getType() + " != " + type + ")"); }