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));
}
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;
}
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();
}
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;
}
}
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);
}
}
Aggregations