Search in sources :

Example 6 with JsonFormat

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

the class JobsResponse method render.

@Override
public void render(OutputStream stream) throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor jobArray = root.setArray("jobs");
    for (String jobName : jobControl.jobs()) jobArray.addObject().setString("name", jobName);
    Cursor inactiveArray = root.setArray("inactive");
    for (String jobName : jobControl.inactiveJobs()) inactiveArray.addString(jobName);
    new JsonFormat(true).encode(stream, slime);
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 7 with JsonFormat

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

the class ResourcesResponse method render.

@Override
public void render(OutputStream stream) throws IOException {
    String parentUrlString = parentUrl.toString();
    if (!parentUrlString.endsWith("/"))
        parentUrlString = parentUrlString + "/";
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor array = root.setArray("resources");
    for (String subResource : subResources) {
        array.addObject().setString("url", parentUrlString + subResource + "/");
    }
    new JsonFormat(true).encode(stream, slime);
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 8 with JsonFormat

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

the class GenericConfigBuilderTest method getString.

private String getString(GenericConfig.GenericConfigBuilder builder) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    builder.getPayload().serialize(baos, new JsonFormat(true));
    return baos.toString();
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 9 with JsonFormat

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

the class ConfigUtils method getMd5.

/**
 * Computes Md5 hash of a list of strings. The only change to input lines before
 * computing md5 is to skip empty lines.
 *
 * @param payload a config payload
 * @return the Md5 hash of the list, with lowercase letters
 */
public static String getMd5(ConfigPayload payload) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        payload.serialize(baos, new JsonFormat(true));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    MessageDigest md5 = getMd5Instance();
    md5.update(baos.toByteArray());
    return HexDump.toHexString(md5.digest()).toLowerCase();
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) MessageDigest(java.security.MessageDigest)

Example 10 with JsonFormat

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

the class ConfigPayload method toUtf8Array.

public Utf8Array toUtf8Array(boolean compact) {
    ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
    try {
        new JsonFormat(compact).encode(os, slime);
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new Utf8Array(os.toByteArray());
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Utf8Array(com.yahoo.text.Utf8Array)

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