Search in sources :

Example 21 with InnerCNode

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

Example 22 with InnerCNode

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\"}"));
}
Also used : SimpletypesConfig(com.yahoo.foo.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 23 with InnerCNode

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\"}"));
}
Also used : SimpletypesConfig(com.yahoo.foo.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) StringReader(java.io.StringReader) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Example 24 with InnerCNode

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));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser)

Example 25 with InnerCNode

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

Aggregations

InnerCNode (com.yahoo.config.codegen.InnerCNode)28 Test (org.junit.Test)23 DefParser (com.yahoo.config.codegen.DefParser)21 StringReader (java.io.StringReader)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 Cursor (com.yahoo.slime.Cursor)15 Slime (com.yahoo.slime.Slime)14 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)10 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)7 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 Ignore (org.junit.Ignore)5 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)3 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)2 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Utf8Array (com.yahoo.text.Utf8Array)1 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)1 ConfigResponse (com.yahoo.vespa.config.protocol.ConfigResponse)1