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; }
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()); }
if (config.getType().isEnum()) { this.type = Enum.class.getName(); this.defaultValue = (config.getDefaultValue() == null) ? null : ((Enum)config.getDefaultValue()).name(); this.possibleValues = FluentIterable .from(Arrays.asList((Enum[])(config.getType().getEnumConstants()))) } else { this.type = config.getTypeName(); this.defaultValue = (config.getDefaultValue() == null) ? null : JsonUtils.toJsonable(config.getDefaultValue()); this.possibleValues = null;
public static PolicyConfigSummary policyConfigSummary(BrooklynRestResourceUtils utils, EntityLocal entity, Policy policy, ConfigKey<?> config) { String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); String policyUri = entityUri + "/policies/" + policy.getId(); Map<String, URI> links = ImmutableMap.<String, URI>builder() .put("self", URI.create(policyUri + "/config/" + config.getName())) .put("application", URI.create(applicationUri)) .put("entity", URI.create(entityUri)) .put("policy", URI.create(policyUri)) .build(); return new PolicyConfigSummary(config.getName(), config.getTypeName(), config.getDescription(), PolicyConfigResource.getStringValueForDisplay(utils, policy, config.getDefaultValue()), config.isReconfigurable(), links); }
public static <T> ConfigKey<T> newConfigKeyRenamed(String newName, ConfigKey<T> key) { return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.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()); }
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); }
return deprecatedResult; } else { return currentKeysInOrderOfPreference[0].getDefaultValue();
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); best.value.getName(), optionalEntity!=null ? optionalEntity : clazz, k.field, best.field, lower, lowerV.getDefaultValue() }); best = new FieldAndValue<ConfigKey<?>>(lower, lowerV); } else { best.value.getName(), optionalEntity!=null ? optionalEntity : clazz, k.field, best.field, k.value.getDefaultValue(), best.value.getDefaultValue() });
@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) {
@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()); }
@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
} catch (Exception e) { /* normal if 'true'; just fall back to default */ } if (delayMs<0) delayMs = Time.parseTimeString(WAIT_FOR_SSHABLE.getDefaultValue());
@SuppressWarnings("unchecked") @Override public <T> T getConfig(ConfigKey<T> key, T defaultValue) { // FIXME What about inherited task in config?! // alex says: think that should work, no? // FIXME What if someone calls getConfig on a task, before setting parent app? // alex says: not supported (throw exception, or return the task) // In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key // TODO If ask for a config value that's not in our configKeys, should we really continue with rest of method and return key.getDefaultValue? // e.g. SshBasedJavaAppSetup calls setAttribute(JMX_USER), which calls getConfig(JMX_USER) // but that example doesn't have a default... ConfigKey<T> ownKey = adjunct!=null ? (ConfigKey<T>)elvis(adjunct.getAdjunctType().getConfigKey(key.getName()), key) : key; // Don't use groovy truth: if the set value is e.g. 0, then would ignore set value and return default! if (ownKey instanceof ConfigKeySelfExtracting) { if (((ConfigKeySelfExtracting<T>)ownKey).isSet(ownConfig)) { // FIXME Should we support config from futures? How to get execution context before setEntity? EntityLocal entity = adjunct.entity; ExecutionContext exec = (entity != null) ? ((EntityInternal)entity).getExecutionContext() : null; return ((ConfigKeySelfExtracting<T>)ownKey).extractValue(ownConfig, exec); } } else { LOG.warn("Config key {} of {} is not a ConfigKeySelfExtracting; cannot retrieve value; returning default", ownKey, this); } return TypeCoercions.coerce((defaultValue != null) ? defaultValue : ownKey.getDefaultValue(), key.getTypeToken()); }
@SuppressWarnings("unchecked") public <T> T getConfig(ConfigKey<T> key, T defaultValue) { // FIXME What about inherited task in config?! // alex says: think that should work, no? // FIXME What if someone calls getConfig on a task, before setting parent app? // alex says: not supported (throw exception, or return the task) // In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key // TODO If ask for a config value that's not in our configKeys, should we really continue with rest of method and return key.getDefaultValue? // e.g. SshBasedJavaAppSetup calls setAttribute(JMX_USER), which calls getConfig(JMX_USER) // but that example doesn't have a default... ConfigKey<T> ownKey = entity!=null ? (ConfigKey<T>)elvis(entity.getEntityType().getConfigKey(key.getName()), key) : key; ExecutionContext exec = entity.getExecutionContext(); // Don't use groovy truth: if the set value is e.g. 0, then would ignore set value and return default! if (ownKey instanceof ConfigKeySelfExtracting) { if (((ConfigKeySelfExtracting<T>)ownKey).isSet(ownConfig)) { return ((ConfigKeySelfExtracting<T>)ownKey).extractValue(ownConfig, exec); } else if (((ConfigKeySelfExtracting<T>)ownKey).isSet(inheritedConfig)) { return ((ConfigKeySelfExtracting<T>)ownKey).extractValue(inheritedConfig, exec); } } else { LOG.warn("Config key {} of {} is not a ConfigKeySelfExtracting; cannot retrieve value; returning default", ownKey, this); } return TypeCoercions.coerce((defaultValue != null) ? defaultValue : ownKey.getDefaultValue(), key.getTypeToken()); }