@Test public void testSafeSetStateDistributors() { NodeStateChangeChecker nodeStateChangeChecker = createChangeChecker(createCluster(createNodes(1))); NodeStateChangeChecker.Result result = nodeStateChangeChecker.evaluateTransition( nodeDistributor, defaultAllUpClusterState(), SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, MAINTENANCE_NODE_STATE); assertFalse(result.settingWantedStateIsAllowed()); assertFalse(result.wantedStateAlreadySet()); assertThat(result.getReason(), containsString("Safe-set of node state is only supported for storage nodes")); }
public Result evaluateTransition( Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition, NodeState oldState, NodeState newState) { if (condition == SetUnitStateRequest.Condition.FORCE) { return Result.allowSettingOfWantedState(); } if (condition != SetUnitStateRequest.Condition.SAFE) { return Result.createDisallowed("Condition not implemented: " + condition.name()); } if (node.getType() != NodeType.STORAGE) { return Result.createDisallowed("Safe-set of node state is only supported for storage nodes! " + "Requested node type: " + node.getType().toString()); } NodeInfo nodeInfo = clusterInfo.getStorageNodeInfo(node.getIndex()); if (nodeInfo == null) { return Result.createDisallowed("Unknown node " + node); } if (newState.getState().equals(oldState.getState())) { return Result.createAlreadySet(); } switch (newState.getState()) { case UP: return canSetStateUp(nodeInfo); case MAINTENANCE: return canSetStateMaintenanceTemporarily(node, clusterState); case DOWN: return canSetStateDownPermanently(nodeInfo, clusterState); default: return Result.createDisallowed("Destination node state unsupported in safe mode: " + newState); } }
NodeStateChangeChecker { public Result evaluateTransition( Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition, NodeState oldState, NodeState newState) { if (condition == SetUnitStateRequest.Condition.FORCE) { return Result.allowSettingOfWantedState(); } if (condition != SetUnitStateRequest.Condition.SAFE) { return Result.createDisallowed("Condition not implemented: " + condition.name()); } if (node.getType() != NodeType.STORAGE) { return Result.createDisallowed("Safe-set of node state is only supported for storage nodes! " + "Requested node type: " + node.getType().toString()); } NodeInfo nodeInfo = clusterInfo.getStorageNodeInfo(node.getIndex()); if (nodeInfo == null) { return Result.createDisallowed("Unknown node " + node); } if (newState.getState().equals(oldState.getState())) { return Result.createAlreadySet(); } switch (newState.getState()) { case UP: return canSetStateUp(nodeInfo); case MAINTENANCE: return canSetStateMaintenanceTemporarily(node, clusterState); case DOWN: return canSetStateDownPermanently(nodeInfo, clusterState); default: return Result.createDisallowed("Destination node state unsupported in safe mode: " + newState); } } }
NodeStateChangeChecker { public Result evaluateTransition( Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition, NodeState oldState, NodeState newState) { if (condition == SetUnitStateRequest.Condition.FORCE) { return Result.allowSettingOfWantedState(); } if (condition != SetUnitStateRequest.Condition.SAFE) { return Result.createDisallowed("Condition not implemented: " + condition.name()); } if (node.getType() != NodeType.STORAGE) { return Result.createDisallowed("Safe-set of node state is only supported for storage nodes! " + "Requested node type: " + node.getType().toString()); } NodeInfo nodeInfo = clusterInfo.getStorageNodeInfo(node.getIndex()); if (nodeInfo == null) { return Result.createDisallowed("Unknown node " + node); } if (newState.getState().equals(oldState.getState())) { return Result.createAlreadySet(); } switch (newState.getState()) { case UP: return canSetStateUp(nodeInfo); case MAINTENANCE: return canSetStateMaintenanceTemporarily(node, clusterState); case DOWN: return canSetStateDownPermanently(nodeInfo, clusterState); default: return Result.createDisallowed("Destination node state unsupported in safe mode: " + newState); } } NodeStateChangeChecker(
            int minStorageNodesUp,
            double minRatioOfStorageNodesUp,
            int requiredRedundancy,
            ClusterInfo clusterInfo); }
NodeStateChangeChecker { public Result evaluateTransition( Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition, NodeState oldState, NodeState newState) { if (condition == SetUnitStateRequest.Condition.FORCE) { return Result.allowSettingOfWantedState(); } if (condition != SetUnitStateRequest.Condition.SAFE) { return Result.createDisallowed("Condition not implemented: " + condition.name()); } if (node.getType() != NodeType.STORAGE) { return Result.createDisallowed("Safe-set of node state is only supported for storage nodes! " + "Requested node type: " + node.getType().toString()); } NodeInfo nodeInfo = clusterInfo.getStorageNodeInfo(node.getIndex()); if (nodeInfo == null) { return Result.createDisallowed("Unknown node " + node); } if (newState.getState().equals(oldState.getState())) { return Result.createAlreadySet(); } switch (newState.getState()) { case UP: return canSetStateUp(nodeInfo); case MAINTENANCE: return canSetStateMaintenanceTemporarily(node, clusterState); case DOWN: return canSetStateDownPermanently(nodeInfo, clusterState); default: return Result.createDisallowed("Destination node state unsupported in safe mode: " + newState); } } NodeStateChangeChecker(
            int minStorageNodesUp,
            double minRatioOfStorageNodesUp,
            int requiredRedundancy,
            ClusterInfo clusterInfo); Result evaluateTransition(
            Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition,
            NodeState oldState, NodeState newState); }
NodeStateChangeChecker { public Result evaluateTransition( Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition, NodeState oldState, NodeState newState) { if (condition == SetUnitStateRequest.Condition.FORCE) { return Result.allowSettingOfWantedState(); } if (condition != SetUnitStateRequest.Condition.SAFE) { return Result.createDisallowed("Condition not implemented: " + condition.name()); } if (node.getType() != NodeType.STORAGE) { return Result.createDisallowed("Safe-set of node state is only supported for storage nodes! " + "Requested node type: " + node.getType().toString()); } NodeInfo nodeInfo = clusterInfo.getStorageNodeInfo(node.getIndex()); if (nodeInfo == null) { return Result.createDisallowed("Unknown node " + node); } if (newState.getState().equals(oldState.getState())) { return Result.createAlreadySet(); } switch (newState.getState()) { case UP: return canSetStateUp(nodeInfo); case MAINTENANCE: return canSetStateMaintenanceTemporarily(node, clusterState); case DOWN: return canSetStateDownPermanently(nodeInfo, clusterState); default: return Result.createDisallowed("Destination node state unsupported in safe mode: " + newState); } } NodeStateChangeChecker(
            int minStorageNodesUp,
            double minRatioOfStorageNodesUp,
            int requiredRedundancy,
            ClusterInfo clusterInfo); Result evaluateTransition(
            Node node, ClusterState clusterState, SetUnitStateRequest.Condition condition,
            NodeState oldState, NodeState newState); static final String BUCKETS_METRIC_NAME; static final Map<String, String> BUCKETS_METRIC_DIMENSIONS; }