protected ConfigSummary(ConfigKey<?> config) { this.name = config.getName(); this.type = config.getTypeName(); this.description = config.getDescription(); this.reconfigurable = config.isReconfigurable(); /* Use String, to guarantee it is serializable; otherwise get: * No serializer found for class brooklyn.policy.autoscaling.AutoScalerPolicy$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[9]->brooklyn.rest.domain.PolicyConfigSummary["defaultValue"]) * at org.codehaus.jackson.map.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:52) */ this.defaultValue = (config.getDefaultValue() == null) ? null : config.getDefaultValue().toString(); this.label = null; this.priority = null; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public <V> EffectorBuilder<T> parameter(ConfigKey<V> key) { return parameter(new BasicParameterType<V>(key.getName(), (Class)key.getType(), key.getDescription(), key.getDefaultValue())); } public EffectorBuilder<T> parameter(ParameterType<?> p) {
public BasicConfigKeyOverwriting(ConfigKey<T> key, T defaultValue) { super(checkNotNull(key.getTypeToken(), "type"), checkNotNull(key.getName(), "name"), key.getDescription(), defaultValue); parentKey = key; }
/** @deprecated since 0.6.0; use {@link ConfigKeys#newConfigKeyWithDefault(ConfigKey, Object)} */ public BasicConfigKey(ConfigKey<T> key, T defaultValue) { log.warn("deprecated use of BasicConfigKey(exendedKey) constructor, for "+key+" ("+defaultValue+")"); this.description = key.getDescription(); this.name = checkNotNull(key.getName(), "name"); this.typeToken = checkNotNull(key.getTypeToken(), "type"); this.type = checkNotNull(key.getType(), "type"); this.defaultValue = defaultValue; this.reconfigurable = false; }
protected static <T> T getOptionalVal(Map<String,?> map, ConfigKey<T> keyC) { if (keyC==null) return null; String key = keyC.getName(); if (map!=null && map.containsKey(key)) { return TypeCoercions.coerce(map.get(key), keyC.getTypeToken()); } else { return keyC.getDefaultValue(); } }
/** removes the given prefix from the key for configuration purposes; logs warning and does nothing if there is no such prefix. * prefix will typically end with a ".". * this is useful for configuration purposes when a subsystem uses a short-name config (e.g. "user") * but in entity config or at the root (brooklyn.properties) there are longer names (e.g. "brooklyn.ssh.config.user"), * and we wish to convert from the longer names to the short-name. */ public static <T> ConfigKey<T> unprefixedKey(String prefix, ConfigKey<T> key) { String newName = key.getName(); if (newName.startsWith(prefix)) newName = newName.substring(prefix.length()); else log.warn("Cannot remove prefix "+prefix+" from key "+key+" (ignoring)"); return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue()); }
LOG.warn("no value defined for config key field (skipping): "+f); } else { configKeysAll.put(k.getName(), new FieldAndValue<ConfigKey<?>>(f, k)); "from {} and {}, preferring {}", new Object[] { best.value.getName(), optionalEntity!=null ? optionalEntity : clazz, best.value.getDefaultValue(), k.field, best.field, lower}); best = new FieldAndValue<ConfigKey<?>>(lower!=null ? lower : best.field, best.value); "from {} and {}, preferring lower {}, value {}", new Object[] { best.value.getName(), optionalEntity!=null ? optionalEntity : clazz, k.field, best.field, lower, lowerV.getDefaultValue() }); best = new FieldAndValue<ConfigKey<?>>(lower, lowerV); } else { "keeping latter (arbitrarily)", new Object[] { best.value.getName(), optionalEntity!=null ? optionalEntity : clazz, k.field, best.field, k.value.getDefaultValue(), best.value.getDefaultValue() }); continue; } else { configKeys.put(best.value.getName(), best);
protected static <T> T getMandatoryVal(Map<String,?> map, ConfigKey<T> keyC) { String key = keyC.getName(); checkArgument(map.containsKey(key), "must contain key '"+keyC+"'"); return TypeCoercions.coerce(map.get(key), keyC.getTypeToken()); }
public static <T> ConfigKey<T> newConfigKeyRenamed(String newName, ConfigKey<T> key) { return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue()); }
public Object setConfig(ConfigKey<?> key, Object v) { Object val; if ((v instanceof Future) || (v instanceof DeferredSupplier)) { // no coercion for these (coerce on exit) val = v; } else if (key instanceof StructuredConfigKey) { // no coercion for these structures (they decide what to do) val = v; } else { try { val = TypeCoercions.coerce(v, key.getType()); } catch (Exception e) { throw new IllegalArgumentException("Cannot coerce or set "+v+" to "+key, e); } } Object oldVal; if (key instanceof StructuredConfigKey) { oldVal = ((StructuredConfigKey)key).applyValueToMap(val, ownConfig); } else { oldVal = ownConfig.put(key, val); } return oldVal; }
ConfigKey key = entry.getKey(); Object value = entry.getValue(); Class<?> type = (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName()); if (memento.getEntityReferenceConfigs().contains(entry.getKey())) { value = MementoTransformer.transformIdsToEntities(rebindContext, value, type, true);
return deprecatedResult; } else { return currentKeysInOrderOfPreference[0].getDefaultValue();
protected <T> T get(ConfigKey<T> key, boolean remove) { // TODO for now, no evaluation -- closure content / smart (self-extracting) keys are NOT supported // (need a clean way to inject that behaviour, as well as desired TypeCoercions) Object value; if (config.containsKey(key.getName())) value = getStringKey(key.getName(), remove); else value = key.getDefaultValue(); return TypeCoercions.coerce(value, key.getTypeToken()); }
/** returns the value of the key if specified, otherwise defaultValue */ protected static <T> T getOptionalVal(Map<String,?> map, ConfigKey<T> keyC, T defaultValue) { String key = keyC.getName(); if (map.containsKey(key)) { return TypeCoercions.coerce(map.get(key), keyC.getTypeToken()); } else { return defaultValue; } }
protected Collection<Integer> getRequiredOpenPorts(Entity entity) { Set<Integer> ports = MutableSet.of(22); for (ConfigKey k: entity.getEntityType().getConfigKeys()) { if (PortRange.class.isAssignableFrom(k.getType())) { PortRange p = (PortRange) entity.getConfig(k); if (p != null && !p.isEmpty()) ports.add(p.iterator().next()); } } log.debug("getRequiredOpenPorts detected default {} for {}", ports, entity); return ports; }
@Override public <T> T getConfig(ConfigKey<T> key) { if (hasConfig(key, false)) return getConfigBag().get(key); if (getParent()!=null) return getParent().getConfig(key); return key.getDefaultValue(); } @Override
@SuppressWarnings("unchecked") public <T> Object put(ConfigKey<T> key, T value) { return super.put(key.getName(), value); }
protected EntityConfigSummary(ConfigKey<?> config, String label, Double priority, Map<String, URI> links) { super(config.getName(), config.getTypeName(), config.getDescription(), JsonUtils.toJsonable(config.getDefaultValue()), config.isReconfigurable(), label, priority); this.links = links==null ? null : ImmutableMap.copyOf(links); }
@Override public <T> T getConfig(ConfigKey<T> key, T defaultValue) { if (!containsKey(key.getName())) { if (defaultValue!=null) return defaultValue; return key.getDefaultValue(); } Object value = get(key.getName()); if (value==null) return null; // no evaluation / key extraction here return TypeCoercions.coerce(value, key.getTypeToken()); }