Search in sources :

Example 11 with Node

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

the class DatabaseHandler method loadWantedStates.

public boolean loadWantedStates(Context context) throws InterruptedException {
    log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Retrieving node wanted states.");
    synchronized (databaseMonitor) {
        if (database != null && !database.isClosed()) {
            currentlyStored.wantedStates = database.retrieveWantedStates();
        }
    }
    Map<Node, NodeState> wantedStates = currentlyStored.wantedStates;
    if (wantedStates == null) {
        if (usingZooKeeper()) {
            log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Failed to retrieve wanted states from ZooKeeper. Assuming UP for all nodes.");
        }
        wantedStates = new TreeMap<>();
    }
    boolean altered = false;
    for (Node node : wantedStates.keySet()) {
        NodeInfo nodeInfo = context.getCluster().getNodeInfo(node);
        // ignore wanted state of nodes which doesn't exist
        if (nodeInfo == null)
            continue;
        NodeState wantedState = wantedStates.get(node);
        if (!nodeInfo.getUserWantedState().equals(wantedState)) {
            nodeInfo.setWantedState(wantedState);
            context.getNodeStateUpdateListener().handleNewWantedNodeState(nodeInfo, wantedState);
            altered = true;
        }
        log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Node " + node + " has wanted state " + wantedState);
    }
    // Remove wanted state from any node having a wanted state set that is no longer valid
    for (NodeInfo info : context.getCluster().getNodeInfo()) {
        NodeState wantedState = wantedStates.get(info.getNode());
        if (wantedState == null && !info.getUserWantedState().equals(new NodeState(info.getNode().getType(), State.UP))) {
            info.setWantedState(null);
            context.getNodeStateUpdateListener().handleNewWantedNodeState(info, info.getWantedState().clone());
            altered = true;
        }
    }
    return altered;
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) NodeInfo(com.yahoo.vespa.clustercontroller.core.NodeInfo) Node(com.yahoo.vdslib.state.Node)

Example 12 with Node

use of com.yahoo.vdslib.state.Node 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 13 with Node

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

the class ZooKeeperDatabase method retrieveStartTimestamps.

@Override
public Map<Node, Long> retrieveStartTimestamps() throws InterruptedException {
    try {
        log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Fetching start timestamps at '" + zooKeeperRoot + "starttimestamps'");
        Stat stat = new Stat();
        byte[] data = session.getData(zooKeeperRoot + "starttimestamps", false, stat);
        Map<Node, Long> wanted = new TreeMap<Node, Long>();
        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 n = new Node(token.substring(0, colon));
                    Long timestamp = Long.valueOf(token.substring(colon + 1));
                    wanted.put(n, timestamp);
                } catch (Exception e) {
                    log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Ignoring invalid starttimestamp 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 start timestamps from zookeeper: " + e.getMessage() + "\n" + sw);
        }
        return null;
    }
}
Also used : 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 14 with Node

use of com.yahoo.vdslib.state.Node 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 15 with Node

use of com.yahoo.vdslib.state.Node 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)

Aggregations

Node (com.yahoo.vdslib.state.Node)65 Test (org.junit.Test)34 NodeState (com.yahoo.vdslib.state.NodeState)32 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)31 ClusterFixture.storageNode (com.yahoo.vespa.clustercontroller.core.ClusterFixture.storageNode)15 HasStateReasonForNode.hasStateReasonForNode (com.yahoo.vespa.clustercontroller.core.matchers.HasStateReasonForNode.hasStateReasonForNode)15 ClusterState (com.yahoo.vdslib.state.ClusterState)9 NodeInfo (com.yahoo.vespa.clustercontroller.core.NodeInfo)6 NodeType (com.yahoo.vdslib.state.NodeType)5 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 Request (com.yahoo.jrt.Request)4 State (com.yahoo.vdslib.state.State)4 IOException (java.io.IOException)4 Spec (com.yahoo.jrt.Spec)3 StringValue (com.yahoo.jrt.StringValue)3 Supervisor (com.yahoo.jrt.Supervisor)3 Target (com.yahoo.jrt.Target)3 Transport (com.yahoo.jrt.Transport)3 TreeMap (java.util.TreeMap)3