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