@Override public boolean apply(@Nullable ConfigKey<?> input) { return input.getName().startsWith(prefix); } };
@Override public boolean apply(@Nullable ConfigKey<?> input) { return filter.apply(input.getName()); } };
/** as {@link #put(ConfigKey, Object)} but returning this ConfigBag for fluent-style coding */ public <T> ConfigBag configure(ConfigKey<T> key, T value) { putStringKey(key.getName(), value); return this; }
@Override public Set<String> keySet() { LinkedHashSet<String> result = Sets.newLinkedHashSet(); Set<Map.Entry<ConfigKey<?>, Object>> set = target.getAllConfig().entrySet(); for (final Map.Entry<ConfigKey<?>, Object> entry: set) { result.add(entry.getKey().getName()); } return result; }
@SuppressWarnings("unchecked") public <T> Object put(HasConfigKey<T> key, T value) { return super.put(key.getConfigKey().getName(), value); }
public PolicyConfigSummary(EntityLocal entity, Policy policy, ConfigKey<?> config) { super(config); String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); String policyUri = entityUri + "/policies/" + policy.getId(); this.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(); }
protected void putAsStringKey(Object key, Object value) { if (key instanceof HasConfigKey<?>) key = ((HasConfigKey<?>)key).getConfigKey(); if (key instanceof ConfigKey<?>) key = ((ConfigKey<?>)key).getName(); if (key instanceof String) { putStringKey((String)key, value); } else { String message = (key == null ? "Invalid key 'null'" : "Invalid key type "+key.getClass().getCanonicalName()+" ("+key+")") + "being used for configuration, ignoring"; log.debug(message, new Throwable("Source of "+message)); log.warn(message); } }
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()); }
protected Map<String,Object> obtainProvisioningFlags(MachineProvisioningLocation location) { Map<String,Object> result = Maps.newLinkedHashMap(location.getProvisioningFlags(ImmutableList.of(getClass().getName()))); result.putAll(getConfig(PROVISIONING_PROPERTIES)); if (result.get("inboundPorts") == null) { Collection<Integer> ports = getRequiredOpenPorts(); if (ports != null && ports.size() > 0) result.put("inboundPorts", ports); } result.put(LocationConfigKeys.CALLER_CONTEXT.getName(), this); return result; }
public BasicConfigKeyOverwriting(ConfigKey<T> key, T defaultValue) { super(checkNotNull(key.getTypeToken(), "type"), checkNotNull(key.getName(), "name"), key.getDescription(), defaultValue); parentKey = key; }
@Override public int execCommands(Map<String,?> props, List<String> commands, Map<String,?> env) { Map<String,Object> props2 = new MutableMap<String,Object>(); if (props!=null) props2.putAll(props); props2.put(SshTool.PROP_NO_EXTRA_OUTPUT.getName(), true); return execScript(props2, commands, env); }
/** 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; } }
/** @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 <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()); }
@Override public Map<String, Object> batchConfigRead(String application, String entityToken) { // TODO: add test EntityLocal entity = brooklyn().getEntity(application, entityToken); Map<ConfigKey<?>, Object> source = ((EntityInternal)entity).getAllConfig(); Map<String, Object> result = Maps.newLinkedHashMap(); for (Map.Entry<ConfigKey<?>, Object> ek: source.entrySet()) { result.put(ek.getKey().getName(), getValueForDisplay(entity, ek.getValue())); } return result; }
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(); } }
@Override public Map<String, Object> batchConfigRead(String application, String entityToken, String policyToken) { // TODO: add test Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); Map<ConfigKey<?>, Object> source = policy.getAllConfig(); Map<String, Object> result = Maps.newLinkedHashMap(); for (Map.Entry<ConfigKey<?>, Object> ek: source.entrySet()) { result.put(ek.getKey().getName(), getStringValueForDisplay(brooklyn(), policy, ek.getValue())); } return result; }
@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()); }
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); }
@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) {