use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class VespaModel method getConfig.
/**
* Resolve config for a given key and config definition
*
* @param configKey The key to resolve.
* @param targetDef The config definition to use for the schema
* @return The payload as a list of strings
*/
@Override
public ConfigPayload getConfig(ConfigKey configKey, com.yahoo.vespa.config.buildergen.ConfigDefinition targetDef) {
ConfigBuilder builder = InstanceResolver.resolveToBuilder(configKey, this, targetDef);
if (builder != null) {
log.log(LogLevel.DEBUG, () -> "Found builder for " + configKey);
ConfigPayload payload;
InnerCNode innerCNode = targetDef != null ? targetDef.getCNode() : null;
if (builder instanceof GenericConfig.GenericConfigBuilder) {
payload = getConfigFromGenericBuilder(builder);
} else {
payload = getConfigFromBuilder(configKey, builder, innerCNode);
}
return (innerCNode != null) ? payload.applyDefaultsFromDef(innerCNode) : payload;
}
return null;
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class DomConfigPayloadBuilderTest method put_to_leaf_map.
@Test
public void put_to_leaf_map() throws Exception {
Reader xmlConfig = new StringReader("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<config name=\"foobar\">" + " <intmap>" + " <item key=\"bar\">1338</item>" + " <item key=\"foo\">1337</item>" + " </intmap>" + "</config>");
ConfigPayload userConfig = ConfigPayload.fromBuilder(new DomConfigPayloadBuilder(null).build(getDocument(xmlConfig)));
assertPayload("{\"intmap\":{\"bar\":\"1338\",\"foo\":\"1337\"}}", userConfig);
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class DomConfigPayloadBuilderTest method camel_case_via_dashes.
@Test
public void camel_case_via_dashes() throws Exception {
Reader xmlConfig = new StringReader("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<config name=\"function-test\">" + " <some-struct> <any-value>17</any-value> </some-struct>" + "</config> ");
ConfigPayload userConfig = ConfigPayload.fromBuilder(new DomConfigPayloadBuilder(null).build(getDocument(xmlConfig)));
assertPayload("{\"someStruct\":{\"anyValue\":\"17\"}}", userConfig);
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class DomConfigPayloadBuilderTest method append_to_leaf_array.
@Test
public void append_to_leaf_array() throws Exception {
// Simulate user config from vespa-services.xml
Reader xmlConfig = new StringReader("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<config name=\"function-test\">" + " <intarr operation=\"append\">1</intarr>" + " <intarr operation=\"append\">2</intarr>" + "</config> ");
ConfigPayload userConfig = ConfigPayload.fromBuilder(new DomConfigPayloadBuilder(null).build(getDocument(xmlConfig)));
assertPayload("{\"intarr\":[\"1\",\"2\"]}", userConfig);
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class DomConfigPayloadBuilderTest method verifyThatWhitespaceIsPreservedForStrings.
// Multi line strings are not tested in 'DefaultValues', so here it is.
@Test
public void verifyThatWhitespaceIsPreservedForStrings() throws Exception {
Element configRoot = getDocument(new FileReader(new File("src/test/cfg/admin/userconfigs/whitespace-test.xml")));
ConfigPayload config = ConfigPayload.fromBuilder(new DomConfigPayloadBuilder(null).build(configRoot));
assertPayload("{\"stringVal\":\" This is a string\\n that contains different kinds of whitespace \"}", config);
}
Aggregations