Search in sources :

Example 6 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Element(org.w3c.dom.Element) Test(org.junit.Test)

Example 7 with ConfigPayload

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;
}
Also used : CfgConfigPayloadBuilder(com.yahoo.config.subscription.CfgConfigPayloadBuilder) ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException)

Example 8 with ConfigPayload

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);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigCacheKey(com.yahoo.vespa.config.ConfigCacheKey) ArrayList(java.util.ArrayList) Slime(com.yahoo.slime.Slime) RawConfig(com.yahoo.vespa.config.RawConfig) Before(org.junit.Before)

Example 9 with ConfigPayload

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

Example 10 with ConfigPayload

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

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