Search in sources :

Example 1 with Int32Value

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

the class RpcServerTest method testGetNodeState.

@Test
public void testGetNodeState() throws Exception {
    startingTest("RpcServerTest::testGetNodeState");
    Set<ConfiguredNode> configuredNodes = new TreeSet<>();
    for (int i = 0; i < 10; i++) configuredNodes.add(new ConfiguredNode(i, false));
    FleetControllerOptions options = new FleetControllerOptions("mycluster", configuredNodes);
    options.minRatioOfStorageNodesUp = 0;
    options.maxInitProgressTime = 30000;
    options.stableStateTimePeriod = 60000;
    setUpFleetController(true, options);
    setUpVdsNodes(true, new DummyVdsNodeOptions());
    waitForStableSystem();
    setWantedNodeState(State.DOWN, NodeType.DISTRIBUTOR, 2);
    setWantedNodeState(State.RETIRED, NodeType.STORAGE, 2);
    setWantedNodeState(State.MAINTENANCE, NodeType.STORAGE, 7);
    waitForCompleteCycle();
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(0).disconnect();
    nodes.get(3).disconnect();
    nodes.get(5).disconnect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:m .2.s:m .7.s:m");
    timer.advanceTime(1000000);
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:d .2.s:d .7.s:m");
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(3).setNodeState(new NodeState(nodes.get(3).getType(), State.INITIALIZING).setInitProgress(0.2));
    nodes.get(3).connect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:i .1.i:0.2 .2.s:d .7.s:m");
    int rpcPort = fleetController.getRpcPort();
    supervisor = new Supervisor(new Transport());
    Target connection = supervisor.connect(new Spec("localhost", rpcPort));
    assertTrue(connection.isValid());
    Request req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(0));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
    NodeState reported = NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(1).asString());
    assertTrue(req.returnValues().get(1).asString(), reported.getState().oneOf("d-"));
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(2));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(2).asString()).getState());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(4));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("", req.returnValues().get(0).asString());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(15));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.METHOD_FAILED, req.errorCode());
    assertEquals("No node distributor.15 exists in cluster mycluster", req.errorMessage());
    assertFalse(req.toString(), req.checkReturnTypes("ssss"));
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(1));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("s:i i:0.2", req.returnValues().get(0).asString());
    assertEquals("s:i i:0.2", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(2));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
    reported = NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(1).asString());
    assertTrue(req.returnValues().get(1).asString(), reported.getState().oneOf("d-"));
    assertEquals(State.RETIRED, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(5));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("", req.returnValues().get(0).asString());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(7));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) NodeState(com.yahoo.vdslib.state.NodeState) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) Request(com.yahoo.jrt.Request) Target(com.yahoo.jrt.Target) TreeSet(java.util.TreeSet) Int32Value(com.yahoo.jrt.Int32Value) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue) Test(org.junit.Test)

Example 2 with Int32Value

use of com.yahoo.jrt.Int32Value 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 3 with Int32Value

use of com.yahoo.jrt.Int32Value 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 4 with Int32Value

use of com.yahoo.jrt.Int32Value 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 5 with Int32Value

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

the class FileReceiver method receiveFileEof.

@SuppressWarnings({ "UnusedDeclaration" })
public final void receiveFileEof(Request req) {
    log.log(LogLevel.DEBUG, () -> "Received method call '" + req.methodName() + "' with parameters : " + req.parameters());
    FileReference reference = new FileReference(req.parameters().get(0).asString());
    int sessionId = req.parameters().get(1).asInt32();
    long xxhash = req.parameters().get(2).asInt64();
    Session session = getSession(sessionId);
    int retval = verifySession(session, sessionId, reference);
    File file = session.close(xxhash);
    downloader.completedDownloading(reference, file);
    synchronized (sessions) {
        sessions.remove(sessionId);
    }
    req.returnValues().add(new Int32Value(retval));
}
Also used : Int32Value(com.yahoo.jrt.Int32Value) FileReference(com.yahoo.config.FileReference) File(java.io.File)

Aggregations

Int32Value (com.yahoo.jrt.Int32Value)13 Request (com.yahoo.jrt.Request)6 StringValue (com.yahoo.jrt.StringValue)5 FileReference (com.yahoo.config.FileReference)4 DataValue (com.yahoo.jrt.DataValue)4 Int8Value (com.yahoo.jrt.Int8Value)4 Compressor (com.yahoo.compress.Compressor)2 Values (com.yahoo.jrt.Values)2 Cursor (com.yahoo.slime.Cursor)2 Slime (com.yahoo.slime.Slime)2 NodeState (com.yahoo.vdslib.state.NodeState)2 FileReferenceDownload (com.yahoo.vespa.filedistribution.FileReferenceDownload)2 IOException (java.io.IOException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 Int64Value (com.yahoo.jrt.Int64Value)1 ListenFailedException (com.yahoo.jrt.ListenFailedException)1 Spec (com.yahoo.jrt.Spec)1 StringArray (com.yahoo.jrt.StringArray)1 Supervisor (com.yahoo.jrt.Supervisor)1 Target (com.yahoo.jrt.Target)1