@Override public EntityConfigMap submap(Predicate<ConfigKey<?>> filter) { EntityConfigMap m = new EntityConfigMap(entity, Maps.<ConfigKey<?>, Object>newLinkedHashMap()); for (Map.Entry<ConfigKey<?>,Object> entry: inheritedConfig.entrySet()) if (filter.apply(entry.getKey())) m.inheritedConfig.put(entry.getKey(), entry.getValue()); for (Map.Entry<ConfigKey<?>,Object> entry: ownConfig.entrySet()) if (filter.apply(entry.getKey())) m.ownConfig.put(entry.getKey(), entry.getValue()); return m; }
@Override public Map<ConfigKey<?>,Object> getAllConfig() { return configsInternal.getAllConfig(); }
@Override public <T> T getConfig(ConfigKey<T> key) { return configsInternal.getConfig(key); }
/** logs a warning if an entity has a value for a config key */ public static void warnOnIgnoringConfig(Entity entity, ConfigKey<?> key) { if (((EntityInternal)entity).getConfigMap().getRawConfig(key)!=null) log.warn("Ignoring "+key+" set on "+entity+" ("+entity.getConfig(key)+")"); }
configsInternal = new EntityConfigMap(this, managementContext.getStorage().<ConfigKey<?>, Object>getMap(id+"-config")); if (oldConfig.getLocalConfig().size() > 0) { configsInternal.setLocalConfig(oldConfig.getLocalConfig());
@Override public void refreshInheritedConfig() { if (getParent() != null) { configsInternal.setInheritedConfig(((EntityInternal)getParent()).getAllConfig()); } else { configsInternal.clearInheritedConfig(); } refreshInheritedConfigOfChildren(); }
public <T> T setConfigEvenIfOwned(ConfigKey<T> key, T val) { return (T) configsInternal.setConfig(key, val); }
builder.isTopLevelApp = (entity instanceof Application && entity.getParent() == null); Map<ConfigKey<?>, Object> localConfig = ((EntityInternal)entity).getConfigMap().getLocalConfig(); for (Map.Entry<ConfigKey<?>, Object> entry : localConfig.entrySet()) { ConfigKey<?> key = checkNotNull(entry.getKey(), localConfig);
/** sets JMR_RMI_CUSTOM_AGENT as the connection mode for the indicated apps. * <p> * TODO callers of this method have RMI dependencies in the actual app; * we should look at removing them, so that those pieces of software can run behind * forwarding public IP's and over SSL (both reasons JMXMP is preferred by us!) */ public void recommendJmxRmiCustomAgent() { // set JMX_RMI because the registry is needed (i think) Object jmx = ((EntityInternal)entity).getConfigMap().getRawConfig(UsesJmx.JMX_AGENT_MODE); if (jmx==null) { setConfig(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.JMX_RMI_CUSTOM_AGENT); } else if (jmx!=JmxAgentModes.JMX_RMI_CUSTOM_AGENT) { log.warn("Entity "+entity+" may not function unless running JMX_RMI_CUSTOM_AGENT mode (asked to use "+jmx+")"); } }
@SuppressWarnings("unchecked") private <T> T setConfigInternal(ConfigKey<T> key, Object val) { if (!inConstruction && getManagementSupport().isDeployed()) { // previously we threw, then warned, but it is still quite common; // so long as callers don't expect miracles, it should be fine. // i (Alex) think the way to be stricter about this (if that becomes needed) // would be to introduce a 'mutable' field on config keys LOG.debug("configuration being made to {} after deployment: {} = {}; change may not be visible in other contexts", new Object[] { this, key, val }); } return (T) configsInternal.setConfig(key, val); }
@GET @Path("/{config}") @ApiOperation(value = "Fetch config value", responseClass = "Object") @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application, entity or config key") }) public String get( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") String entityToken, @ApiParam(value = "Config key ID", required = true) @PathParam("config") String configKeyName ) { EntityLocal entity = brooklyn().getEntity(application, entityToken); ConfigKey<?> ck = entity.getEntityType().getConfigKey(configKeyName); if (ck==null) ck = new BasicConfigKey<Object>(Object.class, configKeyName); return getValueForDisplay(entity, ((AbstractEntity)entity).getConfigMap().getRawConfig(ck)); }
@Override public <T> T getConfig(HasConfigKey<T> key) { return configsInternal.getConfig(key); }
Object v = ((EntityInternal)e).getConfigMap().getRawConfig(it); if (!isTrivial(v)) { out.append(currentIndentation+tab+tab+it.getName());
@Override public <T> T getConfig(ConfigKey<T> key, T defaultValue) { return configsInternal.getConfig(key, defaultValue); }
@Override public String get(String application, String entityToken, String configKeyName) { EntityLocal entity = brooklyn().getEntity(application, entityToken); ConfigKey<?> ck = entity.getEntityType().getConfigKey(configKeyName); if (ck==null) ck = new BasicConfigKey<Object>(Object.class, configKeyName); return getValueForDisplay(entity, ((AbstractEntity)entity).getConfigMap().getRawConfig(ck)); }
public <T> T getConfig(ConfigKey<T> key) { return getConfig(key, null); }
/** extracts the values for the main brooklyn.ssh.config.* config keys (i.e. those declared in ConfigKeys) * as declared on the entity, and inserts them in a map using the unprefixed state, for ssh. */ /* currently this is computed for each call, which may be wasteful, but it is reliable in the face of config changes. * we could cache the Map. note that we do _not_ cache (or even own) the SshTool; * the SshTool is created or re-used by the SshMachineLocation making use of these properties */ protected Map<String, Object> getSshFlags() { Map<String, Object> result = Maps.newLinkedHashMap(); StringConfigMap globalConfig = ((EntityInternal)getEntity()).getManagementContext().getConfig(); Map<ConfigKey<?>, Object> mgmtConfig = globalConfig.getAllConfig(); Map<ConfigKey<?>, Object> entityConfig = ((EntityInternal)getEntity()).getAllConfig(); Map<ConfigKey<?>, Object> allConfig = MutableMap.<ConfigKey<?>, Object>builder().putAll(mgmtConfig).putAll(entityConfig).build(); for (ConfigKey<?> key : allConfig.keySet()) { if (key.getName().startsWith(SshTool.BROOKLYN_CONFIG_KEY_PREFIX)) { // have to use raw config to test whether the config is set Object val = ((EntityInternal)getEntity()).getConfigMap().getRawConfig(key); if (val!=null) { val = getEntity().getConfig(key); } else { val = globalConfig.getRawConfig(key); if (val!=null) val = globalConfig.getConfig(key); } if (val!=null) { result.put(ConfigUtils.unprefixedKey(SshTool.BROOKLYN_CONFIG_KEY_PREFIX, key).getName(), val); } } } return result; }
@Override public <T> T getConfig(HasConfigKey<T> key, T defaultValue) { return configsInternal.getConfig(key, defaultValue); }
public <T> T getConfig(HasConfigKey<T> key) { return getConfig(key.getConfigKey(), null); }
@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()); }