private static Object findConfigValue(Entity entity, String configKeyName) { Map<ConfigKey<?>, Object> config = ((EntityInternal)entity).getAllConfig(); for (Entry<ConfigKey<?>, Object> entry : config.entrySet()) { if (configKeyName.equals(entry.getKey().getName())) return entry.getValue(); } return null; }
@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; }
@GET @Path("/current-state") @ApiOperation(value = "Fetch config key values in batch", notes="Returns a map of config name to value") public Map<String, Object> batchConfigRead( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") 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; }
@Override public void refreshInheritedConfig() { if (getParent() != null) { configsInternal.setInheritedConfig(((EntityInternal)getParent()).getAllConfig()); } else { configsInternal.clearInheritedConfig(); } refreshInheritedConfigOfChildren(); }
/** 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; }