Search in sources :

Example 16 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class DatabaseHandler method saveWantedStates.

public void saveWantedStates(Context context) throws InterruptedException {
    log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Checking whether wanted states have changed compared to zookeeper version.");
    Map<Node, NodeState> wantedStates = new TreeMap<>();
    for (NodeInfo info : context.getCluster().getNodeInfo()) {
        if (!info.getUserWantedState().equals(new NodeState(info.getNode().getType(), State.UP))) {
            wantedStates.put(info.getNode(), info.getUserWantedState());
        }
    }
    // - The value is different from the value we know is stored.
    if (pendingStore.wantedStates != null || currentlyStored.wantedStates == null || !currentlyStored.wantedStates.equals(wantedStates)) {
        log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Scheduling new wanted states to be stored into zookeeper.");
        pendingStore.wantedStates = wantedStates;
        doNextZooKeeperTask(context);
    }
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) NodeInfo(com.yahoo.vespa.clustercontroller.core.NodeInfo) Node(com.yahoo.vdslib.state.Node) TreeMap(java.util.TreeMap)

Example 17 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class ZooKeeperDatabase method retrieveWantedStates.

public Map<Node, NodeState> retrieveWantedStates() throws InterruptedException {
    try {
        log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Fetching wanted states at '" + zooKeeperRoot + "wantedstates'");
        Stat stat = new Stat();
        byte[] data = session.getData(zooKeeperRoot + "wantedstates", false, stat);
        Map<Node, NodeState> wanted = new TreeMap<>();
        if (data != null && data.length > 0) {
            StringTokenizer st = new StringTokenizer(new String(data, utf8), "\n", false);
            while (st.hasMoreTokens()) {
                String token = st.nextToken();
                int colon = token.indexOf(':');
                try {
                    if (colon < 0)
                        throw new Exception();
                    Node node = new Node(token.substring(0, colon));
                    NodeState nodeState = NodeState.deserialize(node.getType(), token.substring(colon + 1));
                    wanted.put(node, nodeState);
                } catch (Exception e) {
                    log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Ignoring invalid wantedstate line in zookeeper '" + token + "'.");
                }
            }
        }
        return wanted;
    } catch (InterruptedException e) {
        throw (InterruptedException) new InterruptedException("Interrupted").initCause(e);
    } catch (Exception e) {
        if (sessionOpen && reportErrors) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Failed to retrieve wanted states from zookeeper: " + e.getMessage() + "\n" + sw);
        }
        return null;
    }
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) Node(com.yahoo.vdslib.state.Node) IOException(java.io.IOException) Stat(org.apache.zookeeper.data.Stat) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 18 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class ZooKeeperDatabase method storeWantedStates.

public boolean storeWantedStates(Map<Node, NodeState> states) throws InterruptedException {
    if (states == null)
        states = new TreeMap<>();
    StringBuilder sb = new StringBuilder();
    for (Node node : states.keySet()) {
        NodeState nodeState = states.get(node);
        if (!nodeState.equals(new NodeState(node.getType(), State.UP))) {
            NodeState toStore = new NodeState(node.getType(), nodeState.getState());
            toStore.setDescription(nodeState.getDescription());
            if (!toStore.equals(nodeState)) {
                log.warning("Attempted to store wanted state with more than just a main state. Extra data stripped. Original data '" + nodeState.serialize(true));
            }
            sb.append(node.toString()).append(':').append(toStore.serialize(true)).append('\n');
        }
    }
    byte[] val = sb.toString().getBytes(utf8);
    try {
        log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Storing wanted states at '" + zooKeeperRoot + "wantedstates'");
        session.setData(zooKeeperRoot + "wantedstates", val, -1);
        return true;
    } catch (InterruptedException e) {
        throw (InterruptedException) new InterruptedException("Interrupted").initCause(e);
    } catch (Exception e) {
        if (sessionOpen && reportErrors) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Failed to store wanted states in zookeeper: " + e.getMessage() + "\n" + sw);
        }
        return false;
    }
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) StringWriter(java.io.StringWriter) Node(com.yahoo.vdslib.state.Node) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 19 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class NodeStateChangeCheckerTest method evaluateDownTransition.

private NodeStateChangeChecker.Result evaluateDownTransition(ClusterState clusterState, State reportedState, int hostInfoClusterStateVersion, int lastAlldisksBuckets) {
    ContentCluster cluster = createCluster(createNodes(4));
    NodeStateChangeChecker nodeStateChangeChecker = createChangeChecker(cluster);
    StorageNodeInfo nodeInfo = cluster.clusterInfo().getStorageNodeInfo(nodeStorage.getIndex());
    nodeInfo.setReportedState(new NodeState(NodeType.STORAGE, reportedState), 0);
    nodeInfo.setHostInfo(createHostInfoWithMetrics(hostInfoClusterStateVersion, lastAlldisksBuckets));
    return nodeStateChangeChecker.evaluateTransition(nodeStorage, clusterState, SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, DOWN_NODE_STATE);
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState)

Example 20 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class NodeStateChangeCheckerTest method testCanSetUpEvenIfOldWantedStateIsDown.

@Test
public void testCanSetUpEvenIfOldWantedStateIsDown() {
    ContentCluster cluster = createCluster(createNodes(4));
    NodeStateChangeChecker nodeStateChangeChecker = createChangeChecker(cluster);
    setAllNodesUp(cluster, HostInfo.createHostInfo(createDistributorHostInfo(4, 3, 6)));
    NodeStateChangeChecker.Result result = nodeStateChangeChecker.evaluateTransition(nodeStorage, defaultAllUpClusterState(), SetUnitStateRequest.Condition.SAFE, new NodeState(NodeType.STORAGE, State.DOWN), UP_NODE_STATE);
    assertTrue(result.settingWantedStateIsAllowed());
    assertFalse(result.wantedStateAlreadySet());
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) Test(org.junit.Test)

Aggregations

NodeState (com.yahoo.vdslib.state.NodeState)68 Node (com.yahoo.vdslib.state.Node)31 Test (org.junit.Test)30 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)21 ClusterState (com.yahoo.vdslib.state.ClusterState)11 NodeInfo (com.yahoo.vespa.clustercontroller.core.NodeInfo)6 Request (com.yahoo.jrt.Request)5 Target (com.yahoo.jrt.Target)5 State (com.yahoo.vdslib.state.State)5 ClusterFixture.storageNode (com.yahoo.vespa.clustercontroller.core.ClusterFixture.storageNode)5 HasStateReasonForNode.hasStateReasonForNode (com.yahoo.vespa.clustercontroller.core.matchers.HasStateReasonForNode.hasStateReasonForNode)5 Spec (com.yahoo.jrt.Spec)4 StringValue (com.yahoo.jrt.StringValue)4 Supervisor (com.yahoo.jrt.Supervisor)4 Transport (com.yahoo.jrt.Transport)4 DiskState (com.yahoo.vdslib.state.DiskState)4 ArrayList (java.util.ArrayList)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 HashSet (java.util.HashSet)3