use of com.yahoo.jrt.Request in project vespa by vespa-engine.
the class RpcServerTest method testSetNodeStateOutOfRange.
@Test
public void testSetNodeStateOutOfRange() throws Exception {
startingTest("RpcServerTest::testSetNodeStateOutOfRange");
FleetControllerOptions options = new FleetControllerOptions("mycluster");
options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(2, 10)));
setUpFleetController(true, options);
setUpVdsNodes(true, new DummyVdsNodeOptions());
waitForStableSystem();
int rpcPort = fleetController.getRpcPort();
supervisor = new Supervisor(new Transport());
Target connection = supervisor.connect(new Spec("localhost", rpcPort));
assertTrue(connection.isValid());
Request req = new Request("setNodeState");
req.parameters().add(new StringValue("storage/cluster.mycluster/storage/10"));
req.parameters().add(new StringValue("s:m"));
connection.invokeSync(req, timeoutS);
assertEquals(req.toString(), ErrorCode.METHOD_FAILED, req.errorCode());
assertEquals(req.toString(), "Cannot set wanted state of node storage.10. Index does not correspond to a configured node.", req.errorMessage());
req = new Request("setNodeState");
req.parameters().add(new StringValue("storage/cluster.mycluster/distributor/10"));
req.parameters().add(new StringValue("s:m"));
connection.invokeSync(req, timeoutS);
assertEquals(req.toString(), ErrorCode.METHOD_FAILED, req.errorCode());
assertEquals(req.toString(), "Cannot set wanted state of node distributor.10. Index does not correspond to a configured node.", req.errorMessage());
req = new Request("setNodeState");
req.parameters().add(new StringValue("storage/cluster.mycluster/storage/9"));
req.parameters().add(new StringValue("s:m"));
connection.invokeSync(req, timeoutS);
assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
waitForState("version:\\d+ distributor:10 storage:10 .9.s:m");
}
use of com.yahoo.jrt.Request in project vespa by vespa-engine.
the class RpcServerTest method testPrintStatistics.
public void testPrintStatistics() {
Request req = new Request("printStatistics");
rpcServer.printStatistics(req);
assertThat(req.returnValues().get(0).asString(), is("Delayed responses queue size: 0"));
}
use of com.yahoo.jrt.Request in project vespa by vespa-engine.
the class RpcServer method handleRpcRequests.
public boolean handleRpcRequests(ContentCluster cluster, ClusterState systemState, NodeStateOrHostInfoChangeHandler changeListener, NodeAddedOrRemovedListener addedListener) {
boolean handledAnyRequests = false;
if (!isConnected()) {
long time = timer.getCurrentTimeInMillis();
try {
connect();
} catch (ListenFailedException e) {
if (!e.getMessage().equals(lastConnectError) || time - lastConnectErrorTime > 60 * 1000) {
lastConnectError = e.getMessage();
lastConnectErrorTime = time;
log.log(LogLevel.WARNING, "Failed to bind RPC server to port " + port + ": " + e.getMessage());
}
} catch (Exception e) {
if (!e.getMessage().equals(lastConnectError) || time - lastConnectErrorTime > 60 * 1000) {
lastConnectError = e.getMessage();
lastConnectErrorTime = time;
log.log(LogLevel.WARNING, "Failed to initailize RPC server socket: " + e.getMessage());
}
}
}
for (int j = 0; j < 10; ++j) {
// Max perform 10 RPC requests per cycle.
Request req;
synchronized (monitor) {
if (rpcRequests.isEmpty())
break;
Iterator<Request> it = rpcRequests.iterator();
req = it.next();
it.remove();
handledAnyRequests = true;
}
try {
if (req.methodName().equals("getMaster")) {
log.log(LogLevel.DEBUG, "Resolving RPC getMaster request");
Integer master = masterHandler.getMaster();
String masterReason = masterHandler.getMasterReason();
req.returnValues().add(new Int32Value(master == null ? -1 : master));
req.returnValues().add(new StringValue(masterReason == null ? "No reason given" : masterReason));
req.returnRequest();
continue;
}
if (!masterHandler.isMaster()) {
throw new IllegalStateException("Refusing to answer RPC calls as we are not the master fleetcontroller.");
}
if (req.methodName().equals("getNodeList")) {
log.log(LogLevel.DEBUG, "Resolving RPC getNodeList request");
List<String> slobrok = new ArrayList<String>();
List<String> rpc = new ArrayList<String>();
for (NodeInfo node : cluster.getNodeInfo()) {
String s1 = node.getSlobrokAddress();
String s2 = node.getRpcAddress();
assert (s1 != null);
slobrok.add(s1);
rpc.add(s2 == null ? "" : s2);
}
req.returnValues().add(new StringArray(slobrok.toArray(new String[slobrok.size()])));
req.returnValues().add(new StringArray(rpc.toArray(new String[rpc.size()])));
req.returnRequest();
} else if (req.methodName().equals("getSystemState")) {
log.log(LogLevel.DEBUG, "Resolving RPC getSystemState request");
req.returnValues().add(new StringValue(""));
req.returnValues().add(new StringValue(systemState.toString(true)));
req.returnRequest();
} else if (req.methodName().equals("getNodeState")) {
log.log(LogLevel.DEBUG, "Resolving RPC getNodeState request");
NodeType nodeType = NodeType.get(req.parameters().get(0).asString());
int nodeIndex = req.parameters().get(1).asInt32();
Node node = new Node(nodeType, nodeIndex);
// First parameter is current state in system state
NodeState ns = systemState.getNodeState(node);
req.returnValues().add(new StringValue(systemState.getNodeState(node).serialize()));
// Second parameter is state node is reporting
NodeInfo nodeInfo = cluster.getNodeInfo(node);
if (nodeInfo == null)
throw new RuntimeException("No node " + node + " exists in cluster " + cluster.getName());
NodeState fromNode = nodeInfo.getReportedState();
req.returnValues().add(new StringValue(fromNode == null ? "unknown" : fromNode.serialize()));
// Third parameter is state node has been requested to be in
req.returnValues().add(new StringValue(nodeInfo.getWantedState().serialize()));
// Fourth parameter is RPC address of node
req.returnValues().add(new StringValue(nodeInfo.getRpcAddress() == null ? "" : nodeInfo.getRpcAddress()));
req.returnRequest();
} else if (req.methodName().equals("setNodeState")) {
String slobrokAddress = req.parameters().get(0).asString();
int lastSlash = slobrokAddress.lastIndexOf('/');
int nextButLastSlash = slobrokAddress.lastIndexOf('/', lastSlash - 1);
if (lastSlash == -1 || nextButLastSlash == -1) {
throw new IllegalStateException("Invalid slobrok address '" + slobrokAddress + "'.");
}
NodeType nodeType = NodeType.get(slobrokAddress.substring(nextButLastSlash + 1, lastSlash));
Integer nodeIndex = Integer.valueOf(slobrokAddress.substring(lastSlash + 1));
NodeInfo node = cluster.getNodeInfo(new Node(nodeType, nodeIndex));
if (node == null)
throw new IllegalStateException("Cannot set wanted state of node " + new Node(nodeType, nodeIndex) + ". Index does not correspond to a configured node.");
NodeState nodeState = NodeState.deserialize(nodeType, req.parameters().get(1).asString());
if (nodeState.getDescription().equals("") && !nodeState.getState().equals(State.UP) && !nodeState.getState().equals(State.RETIRED)) {
nodeState.setDescription("Set by remote RPC client");
}
NodeState oldState = node.getUserWantedState();
String message = (nodeState.getState().equals(State.UP) ? "Clearing wanted nodeState for node " + node : "New wantedstate '" + nodeState.toString() + "' stored for node " + node);
if (!oldState.equals(nodeState) || !oldState.getDescription().equals(nodeState.getDescription())) {
if (!nodeState.getState().validWantedNodeState(nodeType)) {
throw new IllegalStateException("State " + nodeState.getState() + " can not be used as wanted state for node of type " + nodeType);
}
node.setWantedState(nodeState);
changeListener.handleNewWantedNodeState(node, nodeState);
} else {
message = "Node " + node + " already had wanted state " + nodeState.toString();
log.log(LogLevel.DEBUG, message);
}
req.returnValues().add(new StringValue(message));
req.returnRequest();
if (nodeState.getState() == State.UP && node.getPrematureCrashCount() > 0) {
log.log(LogLevel.INFO, "Clearing premature crash count of " + node.getPrematureCrashCount() + " as wanted state was set to up");
node.setPrematureCrashCount(0);
}
}
} catch (Exception e) {
if (log.isLoggable(LogLevel.DEBUG)) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
log.log(LogLevel.DEBUG, "Failed RPC Request: " + sw);
}
String errorMsg = e.getMessage();
if (errorMsg == null) {
errorMsg = e.toString();
}
req.setError(ErrorCode.METHOD_FAILED, errorMsg);
req.returnRequest();
}
}
return handledAnyRequests;
}
use of com.yahoo.jrt.Request in project vespa by vespa-engine.
the class ConfigProxyRpcServerTest method testRpcMethodUpdateSources.
/**
* Tests updateSources RPC command
*/
@Test
public void testRpcMethodUpdateSources() {
Request req = new Request("updateSources");
String spec1 = "tcp/a:19070";
String spec2 = "tcp/b:19070";
req.parameters().add(new StringValue(spec1 + "," + spec2));
rpcServer.updateSources(req);
assertFalse(req.errorMessage(), req.isError());
assertThat(req.returnValues().size(), is(1));
assertThat(req.returnValues().get(0).asString(), is("Updated config sources to: " + spec1 + "," + spec2));
proxyServer.setMode(Mode.ModeName.MEMORYCACHE.name());
req = new Request("updateSources");
req.parameters().add(new StringValue(spec1 + "," + spec2));
rpcServer.updateSources(req);
assertFalse(req.errorMessage(), req.isError());
assertThat(req.returnValues().size(), is(1));
assertThat(req.returnValues().get(0).asString(), is("Cannot update sources when in '" + Mode.ModeName.MEMORYCACHE.name().toLowerCase() + "' mode"));
// TODO source connections needs to have deterministic order to work
/*req = new Request("listSourceConnections");
rpcServer.listSourceConnections(req);
assertFalse(req.errorMessage(), req.isError());
final String[] ret = req.returnValues().get(0).asStringArray();
assertThat(ret.length, is(2));
assertThat(ret[0], is("Current source: " + spec1));
assertThat(ret[1], is("All sources:\n" + spec2 + "\n" + spec1 + "\n"));
*/
}
use of com.yahoo.jrt.Request in project vespa by vespa-engine.
the class ConfigProxyRpcServerTest method testRpcMethodListCachedConfig.
/**
* Tests listCachedConfig RPC command
*/
@Test
public void testRpcMethodListCachedConfig() {
Request req = new Request("listCachedConfig");
rpcServer.listCachedConfig(req);
assertFalse(req.errorMessage(), req.isError());
String[] ret = req.returnValues().get(0).asStringArray();
assertThat(req.returnValues().size(), is(1));
assertThat(ret.length, is(0));
final RawConfig config = ProxyServerTest.fooConfig;
proxyServer.getMemoryCache().put(config);
req = new Request("listCachedConfig");
rpcServer.listCachedConfig(req);
assertFalse(req.errorMessage(), req.isError());
assertThat(req.returnValues().size(), is(1));
ret = req.returnValues().get(0).asStringArray();
assertThat(ret.length, is(1));
assertThat(ret[0], is(config.getNamespace() + "." + config.getName() + "," + config.getConfigId() + "," + config.getGeneration() + "," + config.getConfigMd5()));
}
Aggregations