Search in sources :

Example 6 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class ContentBuilderTest method requireThatUserConfigCanBeSpecifiedForASearchDefinition.

@Test
public void requireThatUserConfigCanBeSpecifiedForASearchDefinition() throws Exception {
    String services = getConfigOverrideServices("<node hostalias='mockhost' distribution-key='0'/>", "  <config name='mynamespace.myconfig'>" + "    <myfield>myvalue</myfield>" + "  </config>");
    VespaModel m = new VespaModelCreatorWithMockPkg(createAppWithMusic(getHosts(), services)).create();
    String configId = "clu/search/cluster.clu/music";
    {
        GenericConfig.GenericConfigBuilder builder = new GenericConfig.GenericConfigBuilder(new ConfigDefinitionKey("myconfig", "mynamespace"), new ConfigPayloadBuilder());
        m.getConfig(builder, configId);
        assertEquals(builder.getPayload().getSlime().get().field("myfield").asString(), "myvalue");
    }
}
Also used : VespaModelCreatorWithMockPkg(com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg) GenericConfig(com.yahoo.vespa.config.GenericConfig) VespaModel(com.yahoo.vespa.model.VespaModel) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 7 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class CfgConfigPayloadBuilder method deserializeToBuilder.

public ConfigPayloadBuilder deserializeToBuilder(List<String> lines) {
    int lineNum = 1;
    ConfigPayloadBuilder payloadBuilder = new ConfigPayloadBuilder();
    for (String line : lines) {
        if (log.isLoggable(LogLevel.SPAM)) {
            log.log(LogLevel.SPAM, "line " + lineNum + ": '" + line + "'");
        }
        parseLine(line, lineNum, payloadBuilder);
        lineNum++;
    }
    if (log.isLoggable(LogLevel.DEBUG)) {
        log.log(LogLevel.DEBUG, "payload=" + payloadBuilder.toString());
    }
    return payloadBuilder;
}
Also used : ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder)

Example 8 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class CfgConfigPayloadBuilder method parseLine.

private void parseLine(final String line, int lineNum, ConfigPayloadBuilder payloadBuilder) {
    String trimmedLine = line.trim();
    if (trimmedLine.startsWith("#"))
        return;
    Pair<String, String> fieldAndValue = parseFieldAndValue(trimmedLine);
    String field = fieldAndValue.getFirst();
    String value = fieldAndValue.getSecond();
    if (field == null || value == null) {
        log.log(LogLevel.DEBUG, "Got field without value in line " + lineNum + ": " + line + ", skipping");
        return;
    }
    field = field.trim();
    value = value.trim();
    validateField(field, trimmedLine, lineNum);
    validateValue(value, trimmedLine, lineNum);
    if (log.isLoggable(LogLevel.DEBUG)) {
        log.log(LogLevel.DEBUG, "field=" + field + ",value=" + value);
    }
    List<String> fields = parseFieldList(field);
    ConfigPayloadBuilder currentBuilder = payloadBuilder;
    for (int fieldNum = 0; fieldNum < fields.size(); fieldNum++) {
        String fieldName = fields.get(fieldNum);
        boolean isLeaf = (fieldNum == fields.size() - 1);
        if (isLeaf) {
            if (isArray(fieldName)) {
                // array leaf
                ConfigPayloadBuilder.Array array = currentBuilder.getArray(getArrayName(fieldName));
                array.set(getArrayIndex(fieldName), removeQuotes(value));
            } else if (isMap(fieldName)) {
                // map leaf
                ConfigPayloadBuilder.MapBuilder map = currentBuilder.getMap(getMapName(fieldName));
                map.put(getMapKey(fieldName), removeQuotes(value));
            } else {
                // scalar leaf value
                currentBuilder.setField(fieldName, removeQuotes(value));
            }
        } else {
            if (isArray(fieldName)) {
                // array of structs
                ConfigPayloadBuilder.Array array = currentBuilder.getArray(getArrayName(fieldName));
                currentBuilder = array.get(getArrayIndex(fieldName));
            } else if (isMap(fieldName)) {
                // map of structs
                ConfigPayloadBuilder.MapBuilder map = currentBuilder.getMap(getMapName(fieldName));
                currentBuilder = map.get(getMapKey(fieldName));
            } else {
                // struct
                currentBuilder = currentBuilder.getObject(fieldName);
            }
        }
    }
}
Also used : ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder)

Aggregations

ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)8 Test (org.junit.Test)4 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)3 GenericConfig (com.yahoo.vespa.config.GenericConfig)3 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)2 VespaModel (com.yahoo.vespa.model.VespaModel)2 Element (org.w3c.dom.Element)2 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ConfigInstance (com.yahoo.config.ConfigInstance)1 Builder (com.yahoo.config.ConfigInstance.Builder)1 DefParser (com.yahoo.config.codegen.DefParser)1 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)1 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 UserConfigRepo (com.yahoo.config.model.producer.UserConfigRepo)1 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)1 VespaModelBuilder (com.yahoo.vespa.model.builder.VespaModelBuilder)1 VespaDomBuilder (com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder)1 VespaModelCreatorWithMockPkg (com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1