Search in sources :

Example 26 with ConfigPayload

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

the class Application method resolveConfig.

/**
 * Gets a config from ZK. Returns null if not found.
 */
public ConfigResponse resolveConfig(GetConfigRequest req, ConfigResponseFactory responseFactory) {
    long start = System.currentTimeMillis();
    metricUpdater.incrementRequests();
    ConfigKey<?> configKey = req.getConfigKey();
    String defMd5 = configKey.getMd5();
    if (defMd5 == null || defMd5.isEmpty()) {
        defMd5 = ConfigUtils.getDefMd5(req.getDefContent().asList());
    }
    ConfigCacheKey cacheKey = new ConfigCacheKey(configKey, defMd5);
    if (logDebug()) {
        debug("Resolving config " + cacheKey);
    }
    if (!req.noCache()) {
        ConfigResponse config = cache.get(cacheKey);
        if (config != null) {
            if (logDebug()) {
                debug("Found config " + cacheKey + " in cache");
            }
            metricUpdater.incrementProcTime(System.currentTimeMillis() - start);
            return config;
        }
    }
    ConfigDefinition def = getTargetDef(req);
    if (def == null) {
        metricUpdater.incrementFailedRequests();
        throw new UnknownConfigDefinitionException("Unable to find config definition for '" + configKey.getNamespace() + "." + configKey.getName());
    }
    if (logDebug()) {
        debug("Resolving " + configKey + " with config definition " + def);
    }
    ConfigPayload payload = model.getConfig(configKey, def);
    if (payload == null) {
        metricUpdater.incrementFailedRequests();
        throw new ConfigurationRuntimeException("Unable to resolve config " + configKey);
    }
    ConfigResponse configResponse = responseFactory.createResponse(payload, def.getCNode(), appGeneration);
    metricUpdater.incrementProcTime(System.currentTimeMillis() - start);
    if (!req.noCache()) {
        cache.put(cacheKey, configResponse, configResponse.getConfigMd5());
        metricUpdater.setCacheConfigElems(cache.configElems());
        metricUpdater.setCacheChecksumElems(cache.checkSumElems());
    }
    return configResponse;
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigDefinition(com.yahoo.vespa.config.buildergen.ConfigDefinition) UnknownConfigDefinitionException(com.yahoo.vespa.config.server.UnknownConfigDefinitionException) ConfigResponse(com.yahoo.vespa.config.protocol.ConfigResponse)

Example 27 with ConfigPayload

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

the class ConfigUtilsTest method testGetMd5OfString.

@Test
public void testGetMd5OfString() {
    String expectedMd5 = "c9246ed8c8ab55b1c463c501c84075e6";
    String expectedChangedMd5 = "f6f81062ef5f024f1912798490ba7dfc";
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    System.out.println(payload);
    assertThat(ConfigUtils.getMd5(payload.toString(true)), is(expectedMd5));
    payload.getSlime().get().setString("fabio", "bar");
    System.out.println(payload);
    assertThat(ConfigUtils.getMd5(payload.toString(true)), is(expectedChangedMd5));
}
Also used : SimpletypesConfig(com.yahoo.foo.SimpletypesConfig) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Test(org.junit.Test)

Example 28 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload 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 29 with ConfigPayload

use of com.yahoo.vespa.config.ConfigPayload 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 30 with ConfigPayload

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

the class ConfigInstancePayloadTest method config_builder_can_be_created_from_typed_payload.

@Test
public void config_builder_can_be_created_from_typed_payload() {
    FunctionTestConfig config = createVariableAccessConfigWithBuilder();
    Slime slime = new Slime();
    ConfigInstanceSerializer serializer = new ConfigInstanceSerializer(slime);
    ConfigInstance.serialize(config, serializer);
    assertFunctionTestPayload(config, new ConfigPayload(slime));
}
Also used : FunctionTestConfig(com.yahoo.foo.FunctionTestConfig) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Slime(com.yahoo.slime.Slime) 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