Search in sources :

Example 31 with Cursor

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

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

the class JSONStringTestCase method getSlime5.

private Inspector getSlime5() {
    Slime slime = new Slime();
    Cursor arr = slime.setArray();
    arr.addLong(1);
    arr.addLong(2);
    arr.addLong(3);
    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 33 with Cursor

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

the class RPCSendV2 method encodeRequest.

@Override
protected Request encodeRequest(Version version, Route route, RPCServiceAddress address, Message msg, long timeRemaining, byte[] payload, int traceLevel) {
    Request req = new Request(METHOD_NAME);
    Values v = req.parameters();
    v.add(new Int8Value(CompressionType.NONE.getCode()));
    v.add(new Int32Value(0));
    v.add(new DataValue(new byte[0]));
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString(VERSION_F, version.toString());
    root.setString(ROUTE_F, route.toString());
    root.setString(SESSION_F, address.getSessionName());
    root.setString(PROTOCOL_F, msg.getProtocol().toString());
    root.setBool(USERETRY_F, msg.getRetryEnabled());
    root.setLong(RETRY_F, msg.getRetry());
    root.setLong(TIMEREMAINING_F, msg.getTimeRemaining());
    root.setLong(TRACELEVEL_F, traceLevel);
    root.setData(BLOB_F, payload);
    byte[] serializedSlime = BinaryFormat.encode(slime);
    Compressor.Compression compressionResult = compressor.compress(serializedSlime);
    v.add(new Int8Value(compressionResult.type().getCode()));
    v.add(new Int32Value(compressionResult.uncompressedSize()));
    v.add(new DataValue(compressionResult.data()));
    return req;
}
Also used : DataValue(com.yahoo.jrt.DataValue) Request(com.yahoo.jrt.Request) Values(com.yahoo.jrt.Values) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value) Compressor(com.yahoo.compress.Compressor) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 34 with Cursor

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

the class RPCSendV2 method createResponse.

@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
    ret.add(new Int8Value(CompressionType.NONE.getCode()));
    ret.add(new Int32Value(0));
    ret.add(new DataValue(new byte[0]));
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString(VERSION_F, version.toString());
    root.setDouble(RETRYDELAY_F, reply.getRetryDelay());
    root.setString(PROTOCOL_F, reply.getProtocol().toString());
    root.setData(BLOB_F, payload);
    if (reply.getTrace().getLevel() > 0) {
        root.setString(TRACE_F, reply.getTrace().getRoot().encode());
    }
    if (reply.getNumErrors() > 0) {
        Cursor array = root.setArray(ERRORS_F);
        for (int i = 0; i < reply.getNumErrors(); i++) {
            Cursor e = array.addObject();
            Error mbusE = reply.getError(i);
            e.setLong(CODE_F, mbusE.getCode());
            e.setString(MSG_F, mbusE.getMessage());
            if (mbusE.getService() != null) {
                e.setString(SERVICE_F, mbusE.getService());
            }
        }
    }
    byte[] serializedSlime = BinaryFormat.encode(slime);
    Compressor.Compression compressionResult = compressor.compress(serializedSlime);
    ret.add(new Int8Value(compressionResult.type().getCode()));
    ret.add(new Int32Value(compressionResult.uncompressedSize()));
    ret.add(new DataValue(compressionResult.data()));
}
Also used : DataValue(com.yahoo.jrt.DataValue) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value) Error(com.yahoo.messagebus.Error) Compressor(com.yahoo.compress.Compressor) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 35 with Cursor

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

the class JsonFormat method encode.

/**
 * Serialize the given tensor into JSON format
 */
public static byte[] encode(Tensor tensor) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor cellsArray = root.setArray("cells");
    for (Iterator<Tensor.Cell> i = tensor.cellIterator(); i.hasNext(); ) {
        Tensor.Cell cell = i.next();
        Cursor cellObject = cellsArray.addObject();
        encodeAddress(tensor.type(), cell.getKey(), cellObject.setObject("address"));
        cellObject.setDouble("value", cell.getValue());
    }
    return com.yahoo.slime.JsonFormat.toJsonBytes(slime);
}
Also used : Tensor(com.yahoo.tensor.Tensor) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

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