Search in sources :

Example 96 with Slime

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

the class ConfigChangeActionsSlimeConverterTest method toJson.

private static String toJson(ConfigChangeActions actions) throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    new ConfigChangeActionsSlimeConverter(actions).toSlime(root);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    new JsonFormat(false).encode(outputStream, slime);
    return outputStream.toString();
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 97 with Slime

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

the class HttpHandlerTest method testResponse.

@Test
public void testResponse() throws IOException {
    final String message = "failed";
    HttpHandler httpHandler = new HttpTestHandler(new InvalidApplicationException(message));
    HttpResponse response = httpHandler.handle(HttpRequest.createTestRequest("foo", com.yahoo.jdisc.http.HttpRequest.Method.GET));
    assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.render(baos);
    Slime data = new Slime();
    new JsonDecoder().decode(data, baos.toByteArray());
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.INVALID_APPLICATION_PACKAGE.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : JsonDecoder(com.yahoo.slime.JsonDecoder) HttpResponse(com.yahoo.container.jdisc.HttpResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Test(org.junit.Test)

Example 98 with Slime

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

the class Dispatcher method toSlime.

private static Slime toSlime(String rankProfile, String summaryClass, String docType, SessionId sessionId, List<FastHit> hits) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    if (summaryClass != null) {
        root.setString("class", summaryClass);
    }
    if (sessionId != null) {
        root.setData("sessionid", sessionId.asUtf8String().getBytes());
    }
    if (docType != null) {
        root.setString("doctype", docType);
    }
    if (rankProfile != null) {
        root.setString("ranking", rankProfile);
    }
    Cursor gids = root.setArray("gids");
    for (FastHit hit : hits) {
        gids.addData(hit.getGlobalId().getRawId());
    }
    return slime;
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 99 with Slime

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

the class ProjectBundleClassPaths method save.

static void save(OutputStream out, ProjectBundleClassPaths mappings) throws IOException {
    Slime slime = new Slime();
    Cursor rootCursor = slime.setObject();
    Cursor mainBundleCursor = rootCursor.setObject("mainBundle");
    BundleClasspathMapping.save(mainBundleCursor, mappings.mainBundle);
    Cursor dependenciesCursor = rootCursor.setArray("providedDependencies");
    mappings.providedDependencies.forEach(d -> BundleClasspathMapping.save(dependenciesCursor.addObject(), d));
    new JsonFormat(false).encode(out, slime);
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 100 with Slime

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

the class ProjectBundleClassPaths method load.

static ProjectBundleClassPaths load(byte[] bytes) {
    Slime slime = new Slime();
    new JsonDecoder().decode(slime, bytes);
    Inspector inspector = slime.get();
    BundleClasspathMapping mainBundle = BundleClasspathMapping.load(inspector.field("mainBundle"));
    Inspector dependenciesInspector = inspector.field("providedDependencies");
    List<BundleClasspathMapping> providedDependencies = new ArrayList<>();
    for (int i = 0; i < dependenciesInspector.entries(); i++) {
        providedDependencies.add(BundleClasspathMapping.load(dependenciesInspector.entry(i)));
    }
    return new ProjectBundleClassPaths(mainBundle, providedDependencies);
}
Also used : JsonDecoder(com.yahoo.slime.JsonDecoder) ArrayList(java.util.ArrayList) Inspector(com.yahoo.slime.Inspector) Slime(com.yahoo.slime.Slime)

Aggregations

Slime (com.yahoo.slime.Slime)131 Cursor (com.yahoo.slime.Cursor)76 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)23 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)22 DefParser (com.yahoo.config.codegen.DefParser)14 InnerCNode (com.yahoo.config.codegen.InnerCNode)14 StringReader (java.io.StringReader)14 JsonFormat (com.yahoo.slime.JsonFormat)10 ApplicationId (com.yahoo.config.provision.ApplicationId)9 Inspector (com.yahoo.slime.Inspector)9 Application (com.yahoo.vespa.hosted.controller.Application)9 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)8 IOException (java.io.IOException)8 Version (com.yahoo.component.Version)7 JsonDecoder (com.yahoo.slime.JsonDecoder)6 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)6 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 DeployLogger (com.yahoo.config.application.api.DeployLogger)4 TenantName (com.yahoo.config.provision.TenantName)4