Search in sources :

Example 1 with SetResponse

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);
}
Also used : SetResponse(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse) NodeState(com.yahoo.vdslib.state.NodeState) MissingIdException(com.yahoo.vespa.clustercontroller.core.restapiv2.MissingIdException) NodeInfo(com.yahoo.vespa.clustercontroller.core.NodeInfo) NodeStateChangeChecker(com.yahoo.vespa.clustercontroller.core.NodeStateChangeChecker)

Example 2 with SetResponse

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"));
}
Also used : SetResponse(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse) Test(org.junit.Test)

Example 3 with SetResponse

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"));
}
Also used : SetResponse(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse) Test(org.junit.Test)

Example 4 with SetResponse

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);
}
Also used : SetResponse(com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse) InvalidContentException(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException) InternalFailure(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InternalFailure) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode)

Aggregations

SetResponse (com.yahoo.vespa.clustercontroller.utils.staterestapi.response.SetResponse)4 Test (org.junit.Test)2 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)1 NodeState (com.yahoo.vdslib.state.NodeState)1 NodeInfo (com.yahoo.vespa.clustercontroller.core.NodeInfo)1 NodeStateChangeChecker (com.yahoo.vespa.clustercontroller.core.NodeStateChangeChecker)1 MissingIdException (com.yahoo.vespa.clustercontroller.core.restapiv2.MissingIdException)1 InternalFailure (com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InternalFailure)1 InvalidContentException (com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException)1