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 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 of type {@link PropertyType#BYTES} or {@link PropertyType#MEMORY}, interpreting * the value properly. * * @param property * Property to get * @return property value * @throws IllegalArgumentException * if the property is of the wrong type */ public long getAsBytes(Property property) { String memString = get(property); if (property.getType() == PropertyType.MEMORY) { return ConfigurationTypeHelper.getMemoryAsBytes(memString); } else if (property.getType() == PropertyType.BYTES) { return ConfigurationTypeHelper.getFixedMemoryAsBytes(memString); } else { throw new IllegalArgumentException(property.getKey() + " is not of BYTES or MEMORY type"); } }
public static boolean isPropertyValid(String property, String value) { Property p = Property.getPropertyByKey(property); return (p == null || p.getType().isValidFormat(value)) && Property.isValidTablePropertyKey(property); }
/** * 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; }
/** * 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); }
public static boolean isPropertyValid(String property, String value) { Property p = Property.getPropertyByKey(property); return (p == null || p.getType().isValidFormat(value)) && Property.isValidTablePropertyKey(property); }
private ClientProperty(Property prop) { this(prop.getKey(), prop.getDefaultValue(), prop.getType(), prop.getDescription()); }
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 + " |"); }
void generate() { pageHeader(); beginTable("Property"); for (Property prop : sortedProps.values()) { if (prop.getType() == PropertyType.PREFIX) { prefixSection(prop); } else { property(prop); } } beginSection("Property Types"); beginTable("Type"); propertyTypeDescriptions(); doc.close(); }
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() + ") : " + 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; } }
ConfigurationDocGen(PrintStream doc) { this.doc = doc; this.prefixes = new ArrayList<>(); this.sortedProps = new TreeMap<>(); for (Property prop : Property.values()) { if (prop.isExperimental()) continue; if (prop.getType() == PropertyType.PREFIX) this.prefixes.add(prop); else this.sortedProps.put(prop.getKey(), prop); } }
public String get(Property property) { String key = property.getKey(); String value = get(key); if (value == null || !property.getType().isValidFormat(value)) { if (value != null) log.error("Using default value for " + key + " due to improperly formatted " + property.getType() + ": " + value); value = parent.get(property); } return 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; }
public static boolean setSystemProperty(String property, String value) throws KeeperException, InterruptedException { Property p = Property.getPropertyByKey(property); if ((p != null && !p.getType().isValidFormat(value)) || !Property.isValidZooPropertyKey(property)) return false; // create the zk node for this property and set it's data to the specified value String zPath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZCONFIG + "/" + property; ZooReaderWriter.getInstance().putPersistentData(zPath, value.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); return true; }