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");
}
}
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;
}
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);
}
}
}
}
Aggregations