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;
}
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());
}
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);
}
}
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);
}
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);
}
}
Aggregations