use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class DomConfigPayloadBuilderTest method require_that_item_syntax_works_with_struct.
@Test
public void require_that_item_syntax_works_with_struct() throws ParserConfigurationException {
Element configRoot = getDocument("<config name=\"arraytypes\" version=\"1\">" + " <lolarray>" + " <item><foo>hei</foo><bar>hei2</bar></item>" + " <item><foo>hoo</foo><bar>hoo2</bar></item>" + " <item><foo>happ</foo><bar>happ2</bar></item>" + " </lolarray>" + "</config>");
ConfigPayload userConfig = ConfigPayload.fromBuilder(new DomConfigPayloadBuilder(null).build(configRoot));
assertPayload("{\"lolarray\":[{\"foo\":\"hei\",\"bar\":\"hei2\"},{\"foo\":\"hoo\",\"bar\":\"hoo2\"},{\"foo\":\"happ\",\"bar\":\"happ2\"}]}", userConfig);
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class JarConfigSubscription method nextConfig.
@Override
public boolean nextConfig(long timeout) {
if (checkReloaded()) {
// Not supporting changing the payload for jar
return true;
}
if (zipEntry == null) {
// First time polled
JarFile jarFile = null;
try {
jarFile = new JarFile(jarName);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
zipEntry = getEntry(jarFile, path);
if (zipEntry == null)
throw new IllegalArgumentException("Config '" + key.getName() + "' not found in '" + jarName + "!/" + path + "'.");
T config = null;
try {
ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(IOUtils.readAll(new InputStreamReader(jarFile.getInputStream(zipEntry), "UTF-8")).split("\n")));
config = payload.toInstance(configClass, key.getConfigId());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
} catch (IOException e) {
throw new ConfigurationRuntimeException(e);
}
setConfig(0L, config);
try {
jarFile.close();
} catch (IOException e) {
throw new ConfigurationRuntimeException(e);
}
return true;
}
// TODO: Should wait and detect changes
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
throw new ConfigInterruptedException(e);
}
return false;
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class MemoryCacheTest method setup.
@Before
public void setup() {
ArrayList<String> defContent = new ArrayList<>();
defContent.add("bar string");
Slime slime = new Slime();
slime.setString("bar \"value\"");
payload = Payload.from(new ConfigPayload(slime));
slime = new Slime();
slime.setString("bar \"baz\"");
payload2 = Payload.from(new ConfigPayload(slime));
slime = new Slime();
slime.setString("bar \"value2\"");
payloadDifferentMd5 = Payload.from(new ConfigPayload(slime));
config = new RawConfig(configKey, defMd5, payload, configMd5, generation, defContent, Optional.empty());
config2 = new RawConfig(configKey2, defMd52, payload2, configMd5, generation, defContent, Optional.empty());
configDifferentMd5 = new RawConfig(configKey, differentDefMd5, payloadDifferentMd5, configMd5, generation, defContent, Optional.empty());
cacheKey = new ConfigCacheKey(configKey, config.getDefMd5());
cacheKey2 = new ConfigCacheKey(configKey2, config2.getDefMd5());
cacheKeyDifferentMd5 = new ConfigCacheKey(configKey, differentDefMd5);
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class JRTConfigRequestBase method createPayload.
private static Payload createPayload(String value) {
Slime slime = new Slime();
slime.setObject().setString("myfield", value);
return Payload.from(new ConfigPayload(slime));
}
use of com.yahoo.vespa.config.ConfigPayload in project vespa by vespa-engine.
the class RawConfigSubscription method nextConfig.
@Override
public boolean nextConfig(long timeout) {
if (checkReloaded()) {
return true;
}
if (payload == null) {
payload = inputPayload;
ConfigPayload configPayload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(payload.split("\n")));
setConfig(0L, configPayload.toInstance(configClass, key.getConfigId()));
return true;
}
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
throw new ConfigInterruptedException(e);
}
return false;
}
Aggregations