Search in sources :

Example 31 with ConfigPayload

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;
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigBuilder(com.yahoo.config.ConfigBuilder)

Example 32 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 33 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 34 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 35 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Element(org.w3c.dom.Element) Test(org.junit.Test)

Aggregations

ConfigPayload (com.yahoo.vespa.config.ConfigPayload)41 Test (org.junit.Test)29 InnerCNode (com.yahoo.config.codegen.InnerCNode)10 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)6 Slime (com.yahoo.slime.Slime)6 Element (org.w3c.dom.Element)6 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 FunctionTestConfig (com.yahoo.foo.FunctionTestConfig)4 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)4 DefParser (com.yahoo.config.codegen.DefParser)3 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)3 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)3 StringReader (java.io.StringReader)3 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 CfgConfigPayloadBuilder (com.yahoo.config.subscription.CfgConfigPayloadBuilder)2 ConfigInterruptedException (com.yahoo.config.subscription.ConfigInterruptedException)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 Utf8Array (com.yahoo.text.Utf8Array)2 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)2