Search in sources :

Example 76 with Cursor

use of com.yahoo.slime.Cursor 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 77 with Cursor

use of com.yahoo.slime.Cursor 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 78 with Cursor

use of com.yahoo.slime.Cursor 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 79 with Cursor

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

the class JSONStringTestCase method getSlime4.

private Inspector getSlime4() {
    Slime slime = new Slime();
    Cursor obj = slime.setObject();
    obj.setLong("foo", 1);
    return new SlimeAdapter(slime.get());
}
Also used : SlimeAdapter(com.yahoo.data.access.slime.SlimeAdapter) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 80 with Cursor

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

the class MockClient method getDocsums.

@Override
public void getDocsums(List<FastHit> hitsContext, NodeConnection node, CompressionType compression, int uncompressedSize, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
    if (malfunctioning) {
        responseReceiver.receive(GetDocsumsResponseOrError.fromError("Malfunctioning"));
        return;
    }
    Inspector request = BinaryFormat.decode(compressor.decompress(compressedSlime, compression, uncompressedSize)).get();
    String docsumClass = request.field("class").asString();
    List<Map<String, Object>> docsumsToReturn = new ArrayList<>();
    request.field("gids").traverse((ArrayTraverser) (index, gid) -> {
        GlobalId docId = new GlobalId(gid.asData());
        docsumsToReturn.add(docsums.get(new DocsumKey(node.toString(), docId, docsumClass)));
    });
    Slime responseSlime = new Slime();
    Cursor root = responseSlime.setObject();
    Cursor docsums = root.setArray("docsums");
    for (Map<String, Object> docsumFields : docsumsToReturn) {
        Cursor docsumItem = docsums.addObject();
        Cursor docsum = docsumItem.setObject("docsum");
        for (Map.Entry<String, Object> field : docsumFields.entrySet()) {
            if (field.getValue() instanceof Integer)
                docsum.setLong(field.getKey(), (Integer) field.getValue());
            else if (field.getValue() instanceof String)
                docsum.setString(field.getKey(), (String) field.getValue());
            else
                throw new RuntimeException();
        }
    }
    byte[] slimeBytes = BinaryFormat.encode(responseSlime);
    Compressor.Compression compressionResult = compressor.compress(compression, slimeBytes);
    GetDocsumsResponse response = new GetDocsumsResponse(compressionResult.type().getCode(), slimeBytes.length, compressionResult.data(), hitsContext);
    responseReceiver.receive(GetDocsumsResponseOrError.fromResponse(response));
}
Also used : Cursor(com.yahoo.slime.Cursor) BinaryFormat(com.yahoo.slime.BinaryFormat) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) HashMap(java.util.HashMap) Compressor(com.yahoo.compress.Compressor) FastHit(com.yahoo.prelude.fastsearch.FastHit) ArrayList(java.util.ArrayList) List(java.util.List) CompressionType(com.yahoo.compress.CompressionType) Map(java.util.Map) GlobalId(com.yahoo.document.GlobalId) ArrayList(java.util.ArrayList) Compressor(com.yahoo.compress.Compressor) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) GlobalId(com.yahoo.document.GlobalId) Inspector(com.yahoo.slime.Inspector) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Cursor (com.yahoo.slime.Cursor)112 Slime (com.yahoo.slime.Slime)79 Test (org.junit.Test)33 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 DefParser (com.yahoo.config.codegen.DefParser)15 InnerCNode (com.yahoo.config.codegen.InnerCNode)15 StringReader (java.io.StringReader)15 IOException (java.io.IOException)9 ApplicationId (com.yahoo.config.provision.ApplicationId)8 JsonFormat (com.yahoo.slime.JsonFormat)8 Application (com.yahoo.vespa.hosted.controller.Application)6 List (java.util.List)6 Map (java.util.Map)6 Inspector (com.yahoo.slime.Inspector)5 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)5 Ignore (org.junit.Ignore)5 Version (com.yahoo.component.Version)4 RegionName (com.yahoo.config.provision.RegionName)4 TenantName (com.yahoo.config.provision.TenantName)4