use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class SuperModelController method resolveConfig.
/**
* Resolves global config for given request.
*
* @param request The {@link com.yahoo.vespa.config.GetConfigRequest} to find config for.
* @return a {@link com.yahoo.vespa.config.protocol.ConfigResponse} containing the response for this request.
* @throws java.lang.IllegalArgumentException if no such config was found.
*/
public ConfigResponse resolveConfig(GetConfigRequest request) {
ConfigKey<?> configKey = request.getConfigKey();
InnerCNode targetDef = getConfigDefinition(request.getConfigKey(), request.getDefContent());
ConfigPayload payload = model.getConfig(configKey);
return responseFactory.createResponse(payload, targetDef, generation);
}
use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class ConfigResponseTest method require_that_slime_response_is_initialized.
@Test
public void require_that_slime_response_is_initialized() throws IOException {
ConfigPayload configPayload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
InnerCNode targetDef = dParser.getTree();
ConfigResponse response = SlimeConfigResponse.fromConfigPayload(configPayload, targetDef, 3, "mymd5");
List<String> payload = response.getLegacyPayload();
assertNotNull(payload);
assertThat(payload.size(), is(6));
assertThat(payload.get(0), is("boolval false"));
assertThat(response.getGeneration(), is(3L));
assertThat(response.getConfigMd5(), is("mymd5"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.serialize(baos, CompressionType.UNCOMPRESSED);
assertThat(baos.toString(), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class ConfigResponseTest method require_that_slime_response_decompresses_on_serialize.
@Test
public void require_that_slime_response_decompresses_on_serialize() throws IOException {
ConfigPayload configPayload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
InnerCNode targetDef = dParser.getTree();
Utf8Array data = configPayload.toUtf8Array(true);
Utf8Array bytes = new Utf8Array(new LZ4PayloadCompressor().compress(data.getBytes()));
ConfigResponse response = new SlimeConfigResponse(bytes, targetDef, 3, "mymd5", CompressionInfo.create(CompressionType.LZ4, data.getByteLength()));
List<String> payload = response.getLegacyPayload();
assertNotNull(payload);
assertThat(payload.size(), is(6));
assertThat(payload.get(0), is("boolval false"));
assertThat(response.getGeneration(), is(3L));
assertThat(response.getConfigMd5(), is("mymd5"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.serialize(baos, CompressionType.UNCOMPRESSED);
assertThat(baos.toString(), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class RpcServerTest method createResponse.
public ConfigResponse createResponse() {
SimpletypesConfig.Builder builder = new SimpletypesConfig.Builder();
builder.intval(123);
SimpletypesConfig responseConfig = new SimpletypesConfig(builder);
ConfigPayload responsePayload = ConfigPayload.fromInstance(responseConfig);
InnerCNode targetDef = new DefParser(SimpletypesConfig.CONFIG_DEF_NAME, new StringReader(Joiner.on("\n").join(SimpletypesConfig.CONFIG_DEF_SCHEMA))).getTree();
return SlimeConfigResponse.fromConfigPayload(responsePayload, targetDef, 3l, ConfigUtils.getMd5(responsePayload));
}
use of com.yahoo.config.codegen.InnerCNode 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;
}
Aggregations