@Override public boolean clusterUp() { return clusterState != null && clusterState.getClusterState().oneOf("u"); }
@Override public boolean equals(Object o) { if (!(o instanceof DiskState)) { return false; } DiskState other = (DiskState) o; if (state.equals(other.state) && Math.abs(capacity - other.capacity) < 0.00000001) { return true; } return false; }
@Override public int hashCode() { // NOTE: capacity cannot be part of the hashCode return state.hashCode(); } }
public String serialize(String prefix, boolean includeDescription) { boolean empty = true; StringBuilder sb = new StringBuilder(); if (!state.equals(State.UP) || prefix.length() < 2) { sb.append(prefix).append("s:").append(state.serialize()); empty = false; } if (Math.abs(capacity - 1.0) > 0.000000001) { if (empty) { empty = false; } else { sb.append(' '); } sb.append(prefix).append("c:").append(capacity); } if (includeDescription && description.length() > 0) { if (!empty) { sb.append(' '); } sb.append(prefix).append("m:").append(StringUtilities.escape(description, ' ')); } return sb.toString(); }
case 's': if (key.length() > 1) break; setState(State.get(value)); continue; case 'c':
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("DiskState(").append(state.serialize()); if (Math.abs(capacity - 1.0) > 0.00000001) { sb.append(", capacity ").append(capacity); } if (description.length() > 0) { sb.append(": ").append(description); } sb.append(")"); return sb.toString(); }
/** * Sets the state of this cluster state. In particular, it does not set the cluster state, * no matter what the function name says. */ public void setClusterState(State s) { if (!s.validClusterState()) { throw new IllegalArgumentException("Illegal cluster state " + s); } state = s; }
@Override public String toString() { String id = name(); String lower = id.substring(1).toLowerCase(); return id.charAt(0) + lower; }
public void verifyValidInSystemState(NodeType type) { if (!state.validCurrentNodeState(type)) { throw new IllegalArgumentException("State " + state + " cannot fit in system state for node of type: " + type); } if (type.equals(NodeType.DISTRIBUTOR) && Math.abs(capacity - 1.0) > 0.000000001) { throw new IllegalArgumentException("Capacity should not be set for a distributor node"); } if (type.equals(NodeType.DISTRIBUTOR) && Math.abs(reliability - 1.0) > 0.000000001) { throw new IllegalArgumentException("Reliability should not be set for a distributor node"); } if (type.equals(NodeType.DISTRIBUTOR) && !diskStates.isEmpty()) { throw new IllegalArgumentException("Disk states should not be set for a distributor node"); } }
public String toString(boolean compact) { StringBuilder sb = new StringBuilder(); if (compact) { sb.append(state.serialize().toUpperCase()); } else { sb.append(state); sb.append(compact ? ", r " : ", reliability ").append(reliability); if (state.equals(State.INITIALIZING)) { sb.append(compact ? ", i " : ", init progress ").append(compact ? String.format(Locale.ENGLISH, "%.3g", initProgress) : initProgress); if (type.equals(NodeType.STORAGE)) {
case 'c': if (key.equals("cluster")) { setClusterState(State.get(value)); continue;
if (state != State.UP){ empty = false; sb.append(prefix).append("s:").append(state.serialize());
public void updateValidTargets(ClusterState state) { List<Integer> validRandomTargets = new ArrayList<>(); for (int i=0; i<state.getNodeCount(NodeType.DISTRIBUTOR); ++i) { if (state.getNodeState(new Node(NodeType.DISTRIBUTOR, i)).getState().oneOf(upStates)) validRandomTargets.add(i); } this.validRandomTargets = validRandomTargets; this.totalTargets = state.getNodeCount(NodeType.DISTRIBUTOR); } public abstract String getTargetSpec(Integer distributor, RoutingContext context);
private boolean metaInformationSimilarTo(final ClusterState other) { if (version != other.version || !state.equals(other.state)) { return false; } if (distributionBits != other.distributionBits) { return false; } return nodeCount.equals(other.nodeCount); }
if (!state.equals(State.UP)) { sb.append(" cluster:").append(state.serialize()); while (distributorNodeCount > 0 && getNodeState(new Node(NodeType.DISTRIBUTOR, distributorNodeCount - 1)).getState().equals(State.DOWN)) --distributorNodeCount; while (storageNodeCount > 0 && getNodeState(new Node(NodeType.STORAGE, storageNodeCount - 1)).getState().equals(State.DOWN)) --storageNodeCount;
case 's': if (key.length() > 1) break; newState.setState(State.get(value)); continue; case 'b':
public int hashCode() { return state.hashCode() ^ diskStates.hashCode() ^ Double.valueOf(capacity).hashCode() ^ Double.valueOf(reliability).hashCode(); }
@Override public boolean nodeUp() { return !clusterUp() && clusterState.getNodeState(new Node(NodeType.STORAGE, clusterIndex)).getState().oneOf("uir"); } }