public String getValue(Properties properties) { Objects.requireNonNull(properties); String value = properties.getProperty(getKey()); if (value == null || value.isEmpty()) { value = getDefaultValue(); } Objects.requireNonNull(value); if (isRequired() && value.isEmpty()) { throw new IllegalArgumentException(getKey() + " must be set!"); } if (!type.isValidFormat(value)) { throw new IllegalArgumentException( "Invalid format for type \"" + type + "\" for provided value: " + value); } return value; }
private void checkType(ClientProperty property, PropertyType type) { if (!property.getType().equals(type)) { String msg = "Configuration method intended for type " + type + " called with a " + property.getType() + " argument (" + property.getKey() + ")"; throw new IllegalArgumentException(msg); } }
void propertyTypeDescriptions() { for (PropertyType type : PropertyType.values()) { if (type == PropertyType.PREFIX) continue; doc.println( "| " + sanitize(type.toString()) + " | " + sanitize(type.getFormatDescription()) + " |"); } }
@Override void propertyTypeDescriptions() { columnNames("Property Type", "Description"); for (PropertyType type : PropertyType.values()) { if (type == PropertyType.PREFIX) continue; beginRow(); cellData("<h3 id='" + type.name() + "'>" + type + "</h3>", null); cellData(type.getFormatDescription(), null); endRow(); } }
@Override void property(Property prefix, Property prop) { boolean isDeprecated = prefix.isDeprecated() || prop.isDeprecated(); if (prop.getKey().startsWith(prefix.getKey())) { beginRow(); cellData(prop.getKey(), isDeprecated ? "class='deprecated'" : null); cellData( "<b><a href='#" + prop.getType().name() + "'>" + prop.getType().toString().replaceAll(" ", " ") + "</a></b>", isDeprecated ? "class='deprecated'" : null); cellData(isZooKeeperMutable(prop), isDeprecated ? "class='deprecated'" : null); cellData( "<pre>" + (prop.getRawDefaultValue().isEmpty() ? " " : sanitize(prop.getRawDefaultValue().replaceAll(" ", " "))) + "</pre>", isDeprecated ? "class='deprecated'" : null); cellData( (isDeprecated ? "<b><i>Deprecated.</i></b> " : "") + sanitize(prop.getDescription()), isDeprecated ? "class='deprecated'" : null); endRow(); } }
void property(Property prop) { boolean depr = prop.isDeprecated(); doc.print("| <a name=\"" + prop.getKey().replace(".", "_") + "\" class=\"prop\"></a> " + prop.getKey() + " | "); doc.print(prop.isExperimental() ? "**Experimental.** " : ""); doc.print( (depr ? "**Deprecated.** " : "") + strike(sanitize(prop.getDescription()), depr) + "<br>"); doc.print(strike("**type:** " + prop.getType().name(), depr) + ", "); doc.print(strike("**zk mutable:** " + isZooKeeperMutable(prop), depr) + ", "); String defaultValue = sanitize(prop.getRawDefaultValue()).trim(); if (defaultValue.length() == 0) { defaultValue = strike("**default value:** empty", depr); } else if (defaultValue.contains("\n")) { // deal with multi-line values, skip strikethrough of value defaultValue = strike("**default value:** ", depr) + "\n```\n" + defaultValue + "\n```\n"; } else { if (prop.getType() == PropertyType.CLASSNAME && defaultValue.startsWith("org.apache.accumulo")) { defaultValue = strike("**default value:** " + "{% jlink -f " + defaultValue + " %}", depr); } else { defaultValue = strike("**default value:** " + "`" + defaultValue + "`", depr); } } doc.println(defaultValue + " |"); }
@Override void property(Property prefix, Property prop) { boolean depr = prefix.isDeprecated() || prop.isDeprecated(); if (prop.getKey().startsWith(prefix.getKey())) { doc.println("===== " + prop.getKey()); doc.println(strike((depr ? "_Deprecated._ " : "") + sanitize(prop.getDescription()), depr)); doc.println(); doc.println(strike("_Type:_ " + prop.getType().name(), depr) + " +"); doc.println(strike("_Zookeeper Mutable:_ " + isZooKeeperMutable(prop), depr) + " +"); String defaultValue = sanitize(prop.getRawDefaultValue()).trim(); if (defaultValue.length() == 0) { // need a placeholder or the asciidoc line break won't work defaultValue = strike("_Default Value:_ _empty_", depr); } else if (defaultValue.contains("\n")) { // deal with multi-line values, skip strikethrough of value defaultValue = strike("_Default Value:_ ", depr) + "\n----\n" + defaultValue + "\n----\n"; } else { defaultValue = strike("_Default Value:_ " + "`" + defaultValue + "`", depr); } doc.println(defaultValue); doc.println(); } }
public static boolean isPropertyValid(String property, String value) { Property p = Property.getPropertyByKey(property); return (p == null || p.getType().isValidFormat(value)) && Property.isValidTablePropertyKey(property); }
@Override void propertyTypeDescriptions() { for (PropertyType type : PropertyType.values()) { if (type == PropertyType.PREFIX) continue; doc.println("==== " + sanitize(type.toString())); doc.println(sanitize(type.getFormatDescription())); doc.println(); } }
private static 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; } }
@Override public String get(Property property) { String value = config.get(property.getKey()); if (value == null || !property.getType().isValidFormat(value)) { if (value != null) { log.error("Using default value for {} due to improperly formatted {}: {}", property.getKey(), property.getType(), value); } value = parent.get(property); } return value; }
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; } }
public static boolean isPropertyValid(String property, String value) { Property p = Property.getPropertyByKey(property); return (p == null || p.getType().isValidFormat(value)) && Property.isValidTablePropertyKey(property); }
private void checkType(ClientProperty property, PropertyType type) { if (!property.getType().equals(type)) { String msg = "Configuration method intended for type " + type + " called with a " + property.getType() + " argument (" + property.getKey() + ")"; throw new IllegalArgumentException(msg); } }
/** * Helper for transforming Accumulo configuration properties into something that can be stored * safely inside the Hadoop Job configuration. * * @param implementingClass * the class whose name will be used as a prefix for the property configuration key * @param conf * the Hadoop configuration object to configure * @param property * the supported Accumulo property * @param value * the value of the property to set * @since 1.6.0 */ private static <T> void setAccumuloProperty(Class<?> implementingClass, Configuration conf, Property property, T value) { if (isSupportedAccumuloProperty(property)) { String val = String.valueOf(value); if (property.getType().isValidFormat(val)) conf.set( enumToConfKey(implementingClass, Opts.ACCUMULO_PROPERTIES) + "." + property.getKey(), val); else throw new IllegalArgumentException( "Value is not appropriate for property type '" + property.getType() + "'"); } else throw new IllegalArgumentException("Unsupported configuration property " + property.getKey()); }
public static boolean setSystemProperty(ServerContext context, String property, String value) throws KeeperException, InterruptedException { if (!Property.isValidZooPropertyKey(property)) { IllegalArgumentException iae = new IllegalArgumentException( "Zookeeper property is not mutable: " + property); log.debug("Attempted to set zookeeper property. It is not mutable", iae); throw iae; } // Find the property taking prefix into account Property foundProp = null; for (Property prop : Property.values()) { if (prop.getType() == PropertyType.PREFIX && property.startsWith(prop.getKey()) || prop.getKey().equals(property)) { foundProp = prop; break; } } if ((foundProp == null || (foundProp.getType() != PropertyType.PREFIX && !foundProp.getType().isValidFormat(value)))) { IllegalArgumentException iae = new IllegalArgumentException( "Ignoring property " + property + " it is either null or in an invalid format"); log.debug("Attempted to set zookeeper property. Value is either null or invalid", iae); throw iae; } // create the zk node for this property and set it's data to the specified value String zPath = context.getZooKeeperRoot() + Constants.ZCONFIG + "/" + property; return context.getZooReaderWriter().putPersistentData(zPath, value.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); }
private String _get(Property property) { String key = property.getKey(); String value = null; if (Property.isValidZooPropertyKey(key)) { value = getRaw(key); } if (value == null || !property.getType().isValidFormat(value)) { if (value != null) log.error("Using parent value for {} due to improperly formatted {}: {}", key, property.getType(), value); value = parent.get(property); } return value; }
/** * Gets a property. If the property is not in ZooKeeper or is present but an invalid format for * the property type, the parent configuration is consulted (if provided). * * @param property * property to get * @param path * ZooKeeper path where properties lie * @param parent * parent configuration (optional) * @return property value, or null if not found */ String get(Property property, String path, AccumuloConfiguration parent) { String key = property.getKey(); String value = get(path + "/" + key); if (value == null || !property.getType().isValidFormat(value)) { if (value != null) { log.error("Using default value for {} due to improperly formatted {}: {}", key, property.getType(), value); } if (parent != null) { value = parent.get(property); } } return value; }
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() + ") : " + value);
public static boolean isPropertyValid(String property, String value) { Property p = Property.getPropertyByKey(property); if ((p != null && !p.getType().isValidFormat(value)) || !Property.isValidTablePropertyKey(property)) return false; return true; }