Search in sources :

Example 1 with JsonFormat

use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.

the class DomConfigPayloadBuilderTest method assertPayload.

private void assertPayload(String expected, ConfigPayload payload) {
    try {
        ByteArrayOutputStream a = new ByteArrayOutputStream();
        new JsonFormat(true).encode(a, payload.getSlime());
        assertThat(a.toString(), is(expected));
    } catch (Exception e) {
        fail("Exception thrown when encoding slime: " + e.getMessage());
    }
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException)

Example 2 with JsonFormat

use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.

the class SlimeTraceSerializerTest method toJson.

private String toJson(TraceNode root) throws IOException {
    Slime slime = new Slime();
    SlimeTraceSerializer serializer = new SlimeTraceSerializer(slime.setObject());
    root.accept(serializer);
    JsonFormat format = new JsonFormat(true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    format.encode(baos, slime);
    return Utf8.toString(baos.toByteArray());
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime)

Example 3 with JsonFormat

use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.

the class ConfigPayloadBuilderTest method require_that_builder_can_be_created_from_payload.

@Test
public void require_that_builder_can_be_created_from_payload() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("foo", "bar");
    Cursor obj = root.setObject("foorio");
    obj.setString("bar", "bam");
    Cursor obj2 = obj.setObject("bario");
    obj2.setString("bim", "bul");
    Cursor a2 = obj.setArray("blim");
    Cursor arrayobj = a2.addObject();
    arrayobj.setString("fim", "fam");
    Cursor arrayobj2 = a2.addObject();
    arrayobj2.setString("blim", "blam");
    Cursor a1 = root.setArray("arrio");
    a1.addString("himbio");
    ConfigPayloadBuilder builder = new ConfigPayloadBuilder(new ConfigPayload(slime));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ConfigPayload.fromBuilder(builder).serialize(baos, new JsonFormat(true));
    assertThat(baos.toString(), is("{\"foo\":\"bar\",\"foorio\":{\"bar\":\"bam\",\"bario\":{\"bim\":\"bul\"},\"blim\":[{\"fim\":\"fam\"},{\"blim\":\"blam\"}]},\"arrio\":[\"himbio\"]}"));
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 4 with JsonFormat

use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.

the class DeployHandlerLoggerTest method testLogging.

private void testLogging(boolean verbose, String expectedPattern) throws IOException {
    Slime slime = new Slime();
    Cursor array = slime.setArray();
    DeployLogger logger = new DeployHandlerLogger(array, verbose, new ApplicationId.Builder().tenant("testtenant").applicationName("testapp").build());
    logMessages(logger);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new JsonFormat(true).encode(baos, slime);
    assertTrue(Pattern.matches(expectedPattern, baos.toString()));
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) DeployHandlerLogger(com.yahoo.vespa.config.server.deploy.DeployHandlerLogger) DeployLogger(com.yahoo.config.application.api.DeployLogger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 5 with JsonFormat

use of com.yahoo.slime.JsonFormat in project vespa by vespa-engine.

the class UpgraderResponse method render.

@Override
public void render(OutputStream outputStream) throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setDouble("upgradesPerMinute", upgrader.upgradesPerMinute());
    Cursor array = root.setArray("confidenceOverrides");
    upgrader.confidenceOverrides().forEach((version, confidence) -> {
        Cursor object = array.addObject();
        object.setString(version.toString(), confidence.name());
    });
    new JsonFormat(true).encode(outputStream, slime);
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Aggregations

JsonFormat (com.yahoo.slime.JsonFormat)15 Slime (com.yahoo.slime.Slime)10 Cursor (com.yahoo.slime.Cursor)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 IOException (java.io.IOException)2 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)1 DeployLogger (com.yahoo.config.application.api.DeployLogger)1 Utf8Array (com.yahoo.text.Utf8Array)1 DeployHandlerLogger (com.yahoo.vespa.config.server.deploy.DeployHandlerLogger)1 MessageDigest (java.security.MessageDigest)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Test (org.junit.Test)1