Search in sources :

Example 11 with Request

use of com.yahoo.jrt.Request in project vespa by vespa-engine.

the class TestWithRpc method pingServer.

private void pingServer() {
    long endTime = System.currentTimeMillis() + 60_000;
    Request req = new Request("ping");
    while (System.currentTimeMillis() < endTime) {
        performRequest(req);
        if (!req.isError() && req.returnValues().size() > 0 && req.returnValues().get(0).asInt32() == 0) {
            break;
        }
        req = new Request("ping");
    }
    assertFalse(req.isError());
    assertTrue(req.returnValues().size() > 0);
    assertThat(req.returnValues().get(0).asInt32(), is(0));
}
Also used : Request(com.yahoo.jrt.Request)

Example 12 with Request

use of com.yahoo.jrt.Request in project vespa by vespa-engine.

the class RPCSendV1 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 StringValue(version.toString()));
    v.add(new StringValue(route.toString()));
    v.add(new StringValue(address.getSessionName()));
    v.add(new Int8Value(msg.getRetryEnabled() ? (byte) 1 : (byte) 0));
    v.add(new Int32Value(msg.getRetry()));
    v.add(new Int64Value(timeRemaining));
    v.add(new StringValue(msg.getProtocol()));
    v.add(new DataValue(payload));
    v.add(new Int32Value(traceLevel));
    return req;
}
Also used : Int64Value(com.yahoo.jrt.Int64Value) 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) StringValue(com.yahoo.jrt.StringValue)

Example 13 with Request

use of com.yahoo.jrt.Request 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 14 with Request

use of com.yahoo.jrt.Request in project vespa by vespa-engine.

the class FileReferenceDownloader method startDownloadRpc.

private boolean startDownloadRpc(FileReferenceDownload fileReferenceDownload) {
    Connection connection = connectionPool.getCurrent();
    Request request = new Request("filedistribution.serveFile");
    String fileReference = fileReferenceDownload.fileReference().value();
    request.parameters().add(new StringValue(fileReference));
    request.parameters().add(new Int32Value(fileReferenceDownload.downloadFromOtherSourceIfNotFound() ? 0 : 1));
    execute(request, connection);
    if (validateResponse(request)) {
        log.log(LogLevel.DEBUG, () -> "Request callback, OK. Req: " + request + "\nSpec: " + connection);
        if (request.returnValues().get(0).asInt32() == 0) {
            log.log(LogLevel.DEBUG, () -> "Found file reference '" + fileReference + "' available at " + connection.getAddress());
            return true;
        } else {
            log.log(LogLevel.DEBUG, "File reference '" + fileReference + "' not found for " + connection.getAddress());
            connectionPool.setNewCurrentConnection();
            return false;
        }
    } else {
        log.log(LogLevel.DEBUG, "Request failed. Req: " + request + "\nSpec: " + connection.getAddress() + ", error code: " + request.errorCode() + ", set error for connection and use another for next request");
        connectionPool.setError(connection, request.errorCode());
        return false;
    }
}
Also used : Connection(com.yahoo.vespa.config.Connection) Request(com.yahoo.jrt.Request) Int32Value(com.yahoo.jrt.Int32Value) StringValue(com.yahoo.jrt.StringValue)

Example 15 with Request

use of com.yahoo.jrt.Request in project vespa by vespa-engine.

the class RpcInvokerTest method assertCorrectArguments.

protected void assertCorrectArguments(String argString) {
    RpcInvoker invoker = new RpcInvoker();
    List<String> args = toList(argString);
    Request request = invoker.createRequest("testmethod", args);
    for (int i = 0; i < args.size(); i++) {
        // Strip type here if present
        String arg = args.get(i);
        if (arg.length() >= 1 && arg.charAt(1) == ':')
            arg = arg.substring(2);
        assertEquals(arg, request.parameters().get(i).toString());
    }
}
Also used : Request(com.yahoo.jrt.Request)

Aggregations

Request (com.yahoo.jrt.Request)36 Test (org.junit.Test)18 Spec (com.yahoo.jrt.Spec)14 StringValue (com.yahoo.jrt.StringValue)14 Target (com.yahoo.jrt.Target)13 Supervisor (com.yahoo.jrt.Supervisor)10 Transport (com.yahoo.jrt.Transport)10 Int32Value (com.yahoo.jrt.Int32Value)6 NodeState (com.yahoo.vdslib.state.NodeState)5 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)4 Node (com.yahoo.vdslib.state.Node)4 DataValue (com.yahoo.jrt.DataValue)3 Int8Value (com.yahoo.jrt.Int8Value)3 Distribution (com.yahoo.vdslib.distribution.Distribution)3 StringArray (com.yahoo.jrt.StringArray)2 Values (com.yahoo.jrt.Values)2 ClusterState (com.yahoo.vdslib.state.ClusterState)2 RawConfig (com.yahoo.vespa.config.RawConfig)2 JRTServerConfigRequestV3 (com.yahoo.vespa.config.protocol.JRTServerConfigRequestV3)2 ArrayList (java.util.ArrayList)2