use of com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse in project vespa by vespa-engine.
the class SetNodeStateRequest method setWantedState.
static SetResponse setWantedState(ContentCluster cluster, SetUnitStateRequest.Condition condition, Map<String, UnitState> newStates, Node node, NodeStateOrHostInfoChangeHandler stateListener, ClusterState currentClusterState) throws StateRestApiException {
if (!cluster.hasConfiguredNode(node.getIndex())) {
throw new MissingIdException(cluster.getName(), node);
}
NodeInfo nodeInfo = cluster.getNodeInfo(node);
if (nodeInfo == null)
throw new IllegalArgumentException("Cannot set the wanted state of unknown node " + node);
NodeState wantedState = nodeInfo.getUserWantedState();
NodeState newWantedState = getRequestedNodeState(newStates, node);
NodeStateChangeChecker.Result result = cluster.calculateEffectOfNewState(node, currentClusterState, condition, wantedState, newWantedState);
log.log(LogLevel.DEBUG, "node=" + node + " current-cluster-state=" + // Includes version in output format
currentClusterState + " condition=" + condition + " wanted-state=" + wantedState + " new-wanted-state=" + newWantedState + " change-check=" + result);
boolean success = setWantedStateAccordingToResult(result, newWantedState, condition, nodeInfo, cluster, stateListener);
// If the state was successfully set, just return an "ok" message back.
String reason = success ? "ok" : result.getReason();
return new SetResponse(reason, success);
}
use of com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse in project vespa by vespa-engine.
the class SetNodeStateTest method testShouldModifyStorageSafeOk.
@Test
public void testShouldModifyStorageSafeOk() throws Exception {
setUp(false);
SetResponse setResponse = restAPI.setUnitState(new SetUnitStateRequestImpl("music/storage/1").setNewState("user", "maintenance", "whatever reason.").setCondition(SetUnitStateRequest.Condition.SAFE));
assertThat(setResponse.getWasModified(), is(true));
assertThat(setResponse.getReason(), is("ok"));
}
use of com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse in project vespa by vespa-engine.
the class SetNodeStateTest method testShouldNotModifyDistributorSafe.
@Test
public void testShouldNotModifyDistributorSafe() throws Exception {
setUp(false);
SetResponse setResponse = restAPI.setUnitState(new SetUnitStateRequestImpl("music/distributor/1").setNewState("user", "up", "whatever reason.").setCondition(SetUnitStateRequest.Condition.SAFE));
assertThat(setResponse.getWasModified(), is(false));
assertThat(setResponse.getReason(), containsString("Safe-set of node state is only supported for storage nodes"));
}
use of com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse in project vespa by vespa-engine.
the class SetNodeStatesForClusterRequest method calculateResult.
@Override
public SetResponse calculateResult(RemoteClusterControllerTask.Context context) throws StateRestApiException {
if (condition != SetUnitStateRequest.Condition.FORCE) {
// go down, etc. This is prohibited in Condition.SAFE.
throw new InvalidContentException("Setting all nodes in a cluster to a state is only supported with FORCE");
}
for (ConfiguredNode configuredNode : context.cluster.getConfiguredNodes().values()) {
Node node = new Node(NodeType.STORAGE, configuredNode.index());
SetResponse setResponse = SetNodeStateRequest.setWantedState(context.cluster, condition, newStates, node, context.nodeStateOrHostInfoChangeHandler, context.currentConsolidatedState);
if (!setResponse.getWasModified()) {
throw new InternalFailure("We have not yet implemented the meaning of " + "failing to set the wanted state for a subset of nodes: " + "condition = " + condition + ", newStates = " + newStates + ", currentConsolidatedState = " + context.currentConsolidatedState);
}
}
// 'true' here means the current state now equals the request's wanted state.
return new SetResponse("ok", true);
}
Aggregations