Search in sources :

Example 1 with State

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

the class ClusterStateView method getIndicesOfUpNodes.

/**
 * Returns the set of nodes that are up for a given node type. Non-private for testing.
 */
static Set<Integer> getIndicesOfUpNodes(ClusterState clusterState, NodeType type) {
    int nodeCount = clusterState.getNodeCount(type);
    Set<Integer> nodesBeingUp = new HashSet<>();
    for (int i = 0; i < nodeCount; ++i) {
        Node node = new Node(type, i);
        NodeState nodeState = clusterState.getNodeState(node);
        State state = nodeState.getState();
        if (state == State.UP || state == State.INITIALIZING || state == State.RETIRED || state == State.MAINTENANCE) {
            nodesBeingUp.add(i);
        }
    }
    return nodesBeingUp;
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) ClusterState(com.yahoo.vdslib.state.ClusterState) NodeState(com.yahoo.vdslib.state.NodeState) State(com.yahoo.vdslib.state.State) Node(com.yahoo.vdslib.state.Node) HashSet(java.util.HashSet)

Example 2 with State

use of com.yahoo.vdslib.state.State 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());
}
Also used : InvalidContentException(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException) NodeState(com.yahoo.vdslib.state.NodeState) UnitState(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.UnitState) ClusterState(com.yahoo.vdslib.state.ClusterState) NodeState(com.yahoo.vdslib.state.NodeState) State(com.yahoo.vdslib.state.State) UnitState(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.UnitState)

Example 3 with State

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

the class NodeStateChangeCheckerTest method setAllNodesUp.

private void setAllNodesUp(ContentCluster cluster, HostInfo distributorHostInfo) {
    for (int x = 0; x < cluster.clusterInfo().getConfiguredNodes().size(); x++) {
        State state = State.UP;
        cluster.clusterInfo().getDistributorNodeInfo(x).setReportedState(new NodeState(NodeType.DISTRIBUTOR, state), 0);
        cluster.clusterInfo().getDistributorNodeInfo(x).setHostInfo(distributorHostInfo);
        cluster.clusterInfo().getStorageNodeInfo(x).setReportedState(new NodeState(NodeType.STORAGE, state), 0);
    }
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) NodeState(com.yahoo.vdslib.state.NodeState) ClusterState(com.yahoo.vdslib.state.ClusterState) State(com.yahoo.vdslib.state.State)

Example 4 with State

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

the class NodeStateChangeCheckerTest method transitionToMaintenanceWithOneStorageNodeDown.

private NodeStateChangeChecker.Result transitionToMaintenanceWithOneStorageNodeDown(int storageNodeIndex, boolean alternatingUpRetiredAndInitializing) {
    ContentCluster cluster = createCluster(createNodes(4));
    NodeStateChangeChecker nodeStateChangeChecker = createChangeChecker(cluster);
    for (int x = 0; x < cluster.clusterInfo().getConfiguredNodes().size(); x++) {
        State state = State.UP;
        // Pick some retired and initializing nodes too
        if (alternatingUpRetiredAndInitializing) {
            // TODO: Move this into the calling test
            if (x % 3 == 1)
                state = State.RETIRED;
            else if (x % 3 == 2)
                state = State.INITIALIZING;
        }
        cluster.clusterInfo().getDistributorNodeInfo(x).setReportedState(new NodeState(NodeType.DISTRIBUTOR, state), 0);
        cluster.clusterInfo().getDistributorNodeInfo(x).setHostInfo(HostInfo.createHostInfo(createDistributorHostInfo(4, 5, 6)));
        cluster.clusterInfo().getStorageNodeInfo(x).setReportedState(new NodeState(NodeType.STORAGE, state), 0);
    }
    ClusterState clusterState = defaultAllUpClusterState();
    if (storageNodeIndex >= 0) {
        // TODO: Move this into the calling test
        NodeState downNodeState = new NodeState(NodeType.STORAGE, State.DOWN);
        cluster.clusterInfo().getStorageNodeInfo(storageNodeIndex).setReportedState(downNodeState, 4);
        clusterState.setNodeState(new Node(NodeType.STORAGE, storageNodeIndex), downNodeState);
    }
    return nodeStateChangeChecker.evaluateTransition(nodeStorage, clusterState, SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE);
}
Also used : ClusterState(com.yahoo.vdslib.state.ClusterState) NodeState(com.yahoo.vdslib.state.NodeState) NodeState(com.yahoo.vdslib.state.NodeState) ClusterState(com.yahoo.vdslib.state.ClusterState) State(com.yahoo.vdslib.state.State) Node(com.yahoo.vdslib.state.Node) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode)

Example 5 with State

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

the class SetNodeStateRequest method setDistributorWantedState.

/**
 * Set the wanted state on the distributor to something appropriate given the storage is being
 * set to (or is equal to) newStorageWantedState.
 */
private static void setDistributorWantedState(ContentCluster cluster, int index, NodeState newStorageWantedState, NodeStateOrHostInfoChangeHandler stateListener) {
    Node distributorNode = new Node(NodeType.DISTRIBUTOR, index);
    NodeInfo nodeInfo = cluster.getNodeInfo(distributorNode);
    if (nodeInfo == null) {
        throw new IllegalStateException("Missing distributor at index " + distributorNode.getIndex());
    }
    State newState;
    switch(newStorageWantedState.getState()) {
        case MAINTENANCE:
            newState = State.DOWN;
            break;
        case RETIRED:
            newState = State.UP;
            break;
        default:
            newState = newStorageWantedState.getState();
            if (!newState.validWantedNodeState(distributorNode.getType())) {
                throw new IllegalStateException("Distributor cannot be set to wanted state " + newState);
            }
    }
    NodeState newWantedState = new NodeState(distributorNode.getType(), newState);
    newWantedState.setDescription(newStorageWantedState.getDescription());
    NodeState currentWantedState = nodeInfo.getUserWantedState();
    if (newWantedState.getState() != currentWantedState.getState() || !Objects.equals(newWantedState.getDescription(), currentWantedState.getDescription())) {
        setNewWantedState(nodeInfo, newWantedState, stateListener);
    }
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) NodeInfo(com.yahoo.vespa.clustercontroller.core.NodeInfo) UnitState(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.UnitState) ClusterState(com.yahoo.vdslib.state.ClusterState) NodeState(com.yahoo.vdslib.state.NodeState) State(com.yahoo.vdslib.state.State) Node(com.yahoo.vdslib.state.Node)

Aggregations

ClusterState (com.yahoo.vdslib.state.ClusterState)7 NodeState (com.yahoo.vdslib.state.NodeState)7 State (com.yahoo.vdslib.state.State)7 Node (com.yahoo.vdslib.state.Node)4 UnitState (com.yahoo.vespa.clustercontroller.utils.staterestapi.response.UnitState)2 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)1 NodeInfo (com.yahoo.vespa.clustercontroller.core.NodeInfo)1 HostInfo (com.yahoo.vespa.clustercontroller.core.hostinfo.HostInfo)1 StorageNode (com.yahoo.vespa.clustercontroller.core.hostinfo.StorageNode)1 InvalidContentException (com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException)1 HashSet (java.util.HashSet)1