Search in sources :

Example 6 with StringValue

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

the class ConfigProxyRpcServerTest method testRpcMethodGetModeAndSetMode.

/**
 * Tests getMode and setMode RPC commands
 */
@Test
public void testRpcMethodGetModeAndSetMode() {
    Request req = new Request("getMode");
    rpcServer.getMode(req);
    assertFalse(req.errorMessage(), req.isError());
    assertThat(req.returnValues().size(), is(1));
    assertThat(req.returnValues().get(0).asString(), is("default"));
    req = new Request("setMode");
    String mode = "memorycache";
    req.parameters().add(new StringValue(mode));
    rpcServer.setMode(req);
    assertFalse(req.errorMessage(), req.isError());
    assertThat(req.returnValues().size(), is(1));
    String[] ret = req.returnValues().get(0).asStringArray();
    assertThat(ret.length, is(2));
    assertThat(ret[0], is("0"));
    assertThat(ret[1], is("success"));
    assertThat(proxyServer.getMode().name(), is(mode));
    req = new Request("getMode");
    rpcServer.getMode(req);
    assertFalse(req.errorMessage(), req.isError());
    assertThat(req.returnValues().size(), is(1));
    assertThat(req.returnValues().get(0).asString(), is(mode));
    req = new Request("setMode");
    String oldMode = mode;
    mode = "invalid";
    req.parameters().add(new StringValue(mode));
    rpcServer.setMode(req);
    assertFalse(req.errorMessage(), req.isError());
    ret = req.returnValues().get(0).asStringArray();
    assertThat(ret.length, is(2));
    assertThat(ret[0], is("1"));
    assertThat(ret[1], is("Could not set mode to '" + mode + "'. Legal modes are '" + Mode.modes() + "'"));
    assertThat(proxyServer.getMode().name(), is(oldMode));
}
Also used : Request(com.yahoo.jrt.Request) StringValue(com.yahoo.jrt.StringValue) Test(org.junit.Test)

Example 7 with StringValue

use of com.yahoo.jrt.StringValue 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 8 with StringValue

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

the class FileDistributionRpcServer method downloadFile.

private void downloadFile(Request req) {
    FileReference fileReference = new FileReference(req.parameters().get(0).asString());
    log.log(LogLevel.DEBUG, () -> "getFile() called for file reference '" + fileReference.value() + "'");
    Optional<File> pathToFile = downloader.getFile(fileReference);
    try {
        if (pathToFile.isPresent()) {
            req.returnValues().add(new StringValue(pathToFile.get().getAbsolutePath()));
            log.log(LogLevel.DEBUG, () -> "File reference '" + fileReference.value() + "' available at " + pathToFile.get());
        } else {
            log.log(LogLevel.INFO, "File reference '" + fileReference.value() + "' not found, returning error");
            req.setError(fileReferenceDoesNotExists, "File reference '" + fileReference.value() + "' not found");
        }
    } catch (Throwable e) {
        log.log(LogLevel.WARNING, "File reference '" + fileReference.value() + "' got exception: " + e.getMessage());
        req.setError(fileReferenceInternalError, "File reference '" + fileReference.value() + "' removed");
    }
    req.returnRequest();
}
Also used : FileReference(com.yahoo.config.FileReference) StringValue(com.yahoo.jrt.StringValue) File(java.io.File)

Example 9 with StringValue

use of com.yahoo.jrt.StringValue 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 10 with StringValue

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

the class FleetControllerTest method setWantedState.

protected void setWantedState(DummyVdsNode node, State state, String reason) {
    if (supervisor == null) {
        supervisor = new Supervisor(new Transport());
    }
    NodeState ns = new NodeState(node.getType(), state);
    if (reason != null)
        ns.setDescription(reason);
    Target connection = supervisor.connect(new Spec("localhost", fleetController.getRpcPort()));
    Request req = new Request("setNodeState");
    req.parameters().add(new StringValue(node.getSlobrokName()));
    req.parameters().add(new StringValue(ns.serialize()));
    connection.invokeSync(req, timeoutS);
    if (req.isError()) {
        assertTrue("Failed to invoke setNodeState(): " + req.errorCode() + ": " + req.errorMessage(), false);
    }
    if (!req.checkReturnTypes("s")) {
        assertTrue("Failed to invoke setNodeState(): Invalid return types.", false);
    }
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) Target(com.yahoo.jrt.Target) NodeState(com.yahoo.vdslib.state.NodeState) Request(com.yahoo.jrt.Request) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue)

Aggregations

StringValue (com.yahoo.jrt.StringValue)24 Request (com.yahoo.jrt.Request)14 Spec (com.yahoo.jrt.Spec)8 Supervisor (com.yahoo.jrt.Supervisor)7 Target (com.yahoo.jrt.Target)7 Transport (com.yahoo.jrt.Transport)7 Test (org.junit.Test)7 Int32Value (com.yahoo.jrt.Int32Value)5 NodeState (com.yahoo.vdslib.state.NodeState)4 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)3 Node (com.yahoo.vdslib.state.Node)3 UnknownHostException (java.net.UnknownHostException)3 FileReference (com.yahoo.config.FileReference)2 DataValue (com.yahoo.jrt.DataValue)2 ListenFailedException (com.yahoo.jrt.ListenFailedException)2 StringArray (com.yahoo.jrt.StringArray)2 Distribution (com.yahoo.vdslib.distribution.Distribution)2 TreeSet (java.util.TreeSet)2 DoubleValue (com.yahoo.jrt.DoubleValue)1 Int32Array (com.yahoo.jrt.Int32Array)1