use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class NodeStateChangeCheckerTest method markAllNodesAsReportingStateUp.
private void markAllNodesAsReportingStateUp(ContentCluster cluster) {
final ClusterInfo clusterInfo = cluster.clusterInfo();
final int configuredNodeCount = cluster.clusterInfo().getConfiguredNodes().size();
for (int i = 0; i < configuredNodeCount; i++) {
clusterInfo.getDistributorNodeInfo(i).setReportedState(new NodeState(NodeType.DISTRIBUTOR, State.UP), 0);
clusterInfo.getDistributorNodeInfo(i).setHostInfo(HostInfo.createHostInfo(createDistributorHostInfo(4, 5, 6)));
clusterInfo.getStorageNodeInfo(i).setReportedState(new NodeState(NodeType.STORAGE, State.UP), 0);
}
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class DatabaseTest method testWantedStatesInZooKeeper.
// These tests work in isolation but causes other tests to hang
@Ignore
@Test
public void testWantedStatesInZooKeeper() throws Exception {
startingTest("DatabaseTest::testWantedStatesInZooKeeper");
FleetControllerOptions options = new FleetControllerOptions("mycluster");
options.zooKeeperServerAddress = "127.0.0.1";
setUpFleetController(true, options);
setUpVdsNodes(true, new DummyVdsNodeOptions());
log.info("WAITING FOR STABLE SYSTEM");
waitForStableSystem();
log.info("VALIDATE STARTING WANTED STATES");
Map<Node, NodeState> wantedStates = new TreeMap<>();
for (DummyVdsNode node : nodes) {
wantedStates.put(node.getNode(), new NodeState(node.getType(), State.UP));
}
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
log.info("SET A WANTED STATE AND SEE THAT IT GETS PROPAGATED");
setWantedState(new Node(NodeType.STORAGE, 3), new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("Yoo"), wantedStates);
waitForState("version:\\d+ distributor:10 storage:10 .3.s:m");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
log.info("SET ANOTHER WANTED STATE AND SEE THAT IT GETS PROPAGATED");
setWantedState(new Node(NodeType.DISTRIBUTOR, 2), new NodeState(NodeType.DISTRIBUTOR, State.DOWN), wantedStates);
waitForState("version:\\d+ distributor:10 .2.s:d storage:10 .3.s:m");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
log.info("SET YET ANOTHER WANTED STATE AND SEE THAT IT GETS PROPAGATED");
setWantedState(new Node(NodeType.STORAGE, 7), new NodeState(NodeType.STORAGE, State.RETIRED).setDescription("We wanna replace this node"), wantedStates);
waitForState("version:\\d+ distributor:10 .2.s:d storage:10 .3.s:m .7.s:r");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
log.info("CHECK THAT WANTED STATES PERSIST FLEETCONTROLLER RESTART");
stopFleetController();
startFleetController();
waitForState("version:\\d+ distributor:10 .2.s:d storage:10 .3.s:m .7.s:r");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
log.info("CLEAR WANTED STATE");
setWantedState(new Node(NodeType.STORAGE, 7), new NodeState(NodeType.STORAGE, State.UP), wantedStates);
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
setWantedState(new Node(NodeType.DISTRIBUTOR, 5), new NodeState(NodeType.DISTRIBUTOR, State.DOWN), wantedStates);
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
setWantedState(new Node(NodeType.DISTRIBUTOR, 2), new NodeState(NodeType.DISTRIBUTOR, State.UP), wantedStates);
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
setWantedState(new Node(NodeType.STORAGE, 9), new NodeState(NodeType.STORAGE, State.DOWN), wantedStates);
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class DatabaseTest method testWantedStateOfUnknownNode.
// These tests work in isolation but causes other tests to hang
@Ignore
@Test
public void testWantedStateOfUnknownNode() throws Exception {
startingTest("DatabaseTest::testWantedStatesOfUnknownNode");
FleetControllerOptions options = new FleetControllerOptions("mycluster");
options.minRatioOfDistributorNodesUp = 0;
options.minRatioOfStorageNodesUp = 0;
options.zooKeeperServerAddress = "localhost";
setUpFleetController(true, options);
setUpVdsNodes(true, new DummyVdsNodeOptions());
waitForStableSystem();
// Populate map of wanted states we should have
Map<Node, NodeState> wantedStates = new TreeMap<>();
for (DummyVdsNode node : nodes) {
wantedStates.put(node.getNode(), new NodeState(node.getType(), State.UP));
}
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
setWantedState(new Node(NodeType.STORAGE, 1), new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("Yoo"), wantedStates);
waitForState("version:\\d+ distributor:10 storage:10 .1.s:m");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
// This should not show up, as it is down
setWantedState(new Node(NodeType.DISTRIBUTOR, 8), new NodeState(NodeType.DISTRIBUTOR, State.DOWN), wantedStates);
waitForState("version:\\d+ distributor:10 .8.s:d storage:10 .1.s:m");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
// This should show up, as down nodes can be turned to maintenance
setWantedState(new Node(NodeType.STORAGE, 6), new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("foobar"), wantedStates);
waitForState("version:\\d+ distributor:10 .8.s:d storage:10 .1.s:m .6.s:m");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
// This should not show up, as we cannot turn a down node retired
setWantedState(new Node(NodeType.STORAGE, 7), new NodeState(NodeType.STORAGE, State.RETIRED).setDescription("foobar"), wantedStates);
waitForState("version:\\d+ distributor:10 .8.s:d storage:10 .1.s:m .6.s:m .7.s:r");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
// This should not show up, as it is down
setWantedState(new Node(NodeType.STORAGE, 8), new NodeState(NodeType.STORAGE, State.DOWN).setDescription("foobar"), wantedStates);
waitForState("version:\\d+ distributor:10 .8.s:d storage:10 .1.s:m .6.s:m .7.s:r .8.s:d");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
stopFleetController();
for (int i = 6; i < nodes.size(); ++i) nodes.get(i).disconnect();
startFleetController();
waitForState("version:\\d+ distributor:3 storage:7 .1.s:m .3.s:d .4.s:d .5.s:d .6.s:m");
setWantedState(new Node(NodeType.STORAGE, 6), new NodeState(NodeType.STORAGE, State.UP), wantedStates);
waitForState("version:\\d+ distributor:3 storage:3 .1.s:m");
for (int i = 6; i < nodes.size(); ++i) nodes.get(i).connect();
waitForState("version:\\d+ distributor:10 .8.s:d storage:10 .1.s:m .7.s:r .8.s:d");
for (DummyVdsNode node : nodes) {
assertEquals(node.getNode().toString(), wantedStates.get(node.getNode()), fleetController.getWantedNodeState(node.getNode()));
}
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class NodeStateGatherer method processResponses.
/**
* Reads replies to get node state requests and create events.
*/
public boolean processResponses(NodeStateOrHostInfoChangeHandler listener) {
boolean processedAnyResponses = false;
long currentTime = timer.getCurrentTimeInMillis();
synchronized (monitor) {
for (GetNodeStateRequest req : replies) {
processedAnyResponses = true;
NodeInfo info = req.getNodeInfo();
if (!info.isPendingGetNodeStateRequest(req)) {
log.log(LogLevel.DEBUG, "Ignoring getnodestate response from " + info.getNode() + " as request replied to is not the most recent pending request.");
continue;
}
info.removePendingGetNodeStateRequest(req);
GetNodeStateRequest.Reply reply = req.getReply();
if (reply.isError()) {
if (reply.getReturnCode() != ErrorCode.ABORT) {
NodeState newState = handleError(req, info, currentTime);
if (newState != null) {
listener.handleNewNodeState(info, newState.clone());
info.setReportedState(newState, currentTime);
} else {
log.log(LogLevel.DEBUG, "Ignoring get node state error. Need to resend");
}
} else {
log.log(LogLevel.DEBUG, "Ignoring getnodestate response from " + info.getNode() + " as it was aborted by client");
}
continue;
}
try {
NodeState state = NodeState.deserialize(info.getNode().getType(), reply.getStateString());
// For version 0 responses, we poll, so we likely have not altered the state
if (!state.equals(info.getReportedState()))
listener.handleNewNodeState(info, state.clone());
info.setReportedState(state, currentTime);
} catch (Exception e) {
log.log(LogLevel.WARNING, "Failed to process get node state response", e);
info.setReportedState(new NodeState(info.getNode().getType(), State.DOWN), currentTime);
}
// Important: The old host info should be accessible in info.getHostInfo(), see interface.
// Therefore, setHostInfo() must be called AFTER handleUpdatedHostInfo().
HostInfo hostInfo = HostInfo.createHostInfo(reply.getHostInfo());
listener.handleUpdatedHostInfo(info, hostInfo);
info.setHostInfo(hostInfo);
}
replies.clear();
}
return processedAnyResponses;
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class SetNodeStateRequest method getRequestedNodeState.
static NodeState getRequestedNodeState(Map<String, UnitState> newStates, Node n) throws StateRestApiException {
UnitState newState = newStates.get("user");
if (newState == null)
throw new InvalidContentException("No new user state given in request");
State state;
switch(newState.getId().toLowerCase()) {
case "up":
state = State.UP;
break;
case "retired":
state = State.RETIRED;
break;
case "maintenance":
state = State.MAINTENANCE;
break;
case "down":
state = State.DOWN;
break;
default:
throw new InvalidContentException("Invalid user state '" + newState.getId() + "' given.");
}
return new NodeState(n.getType(), state).setDescription(newState.getReason());
}
Aggregations