Search in sources :

Example 26 with NodeState

use of com.yahoo.vdslib.state.NodeState 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 27 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class ClusterFixture method reportStorageNodeState.

public ClusterFixture reportStorageNodeState(final int index, State state, String description) {
    final Node node = new Node(NodeType.STORAGE, index);
    final NodeState nodeState = new NodeState(NodeType.STORAGE, state);
    nodeState.setDescription(description);
    doReportNodeState(node, nodeState);
    return this;
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) Node(com.yahoo.vdslib.state.Node)

Example 28 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class ClusterFixture method proposeDistributorWantedState.

public ClusterFixture proposeDistributorWantedState(final int index, State state) {
    final ClusterState stateBefore = rawGeneratedClusterState();
    final Node node = new Node(NodeType.DISTRIBUTOR, index);
    final NodeState nodeState = new NodeState(NodeType.DISTRIBUTOR, state);
    nodeState.setDescription("mockdesc");
    NodeInfo nodeInfo = cluster.getNodeInfo(node);
    nodeInfo.setWantedState(nodeState);
    nodeStateChangeHandler.proposeNewNodeState(stateBefore, nodeInfo, nodeState);
    return this;
}
Also used : ClusterState(com.yahoo.vdslib.state.ClusterState) NodeState(com.yahoo.vdslib.state.NodeState) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) Node(com.yahoo.vdslib.state.Node)

Example 29 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class RpcServerTest method testGetNodeStateWithConfiguredRetired.

@Test
public void testGetNodeStateWithConfiguredRetired() throws Exception {
    startingTest("RpcServerTest::testGetNodeStateWithConfiguredRetired");
    List<ConfiguredNode> configuredNodes = new ArrayList<>();
    for (int i = 0; i < 9; i++) configuredNodes.add(new ConfiguredNode(i, false));
    // Last node is configured retired
    configuredNodes.add(new ConfiguredNode(9, true));
    FleetControllerOptions options = new FleetControllerOptions("mycluster", configuredNodes);
    options.minRatioOfStorageNodesUp = 0;
    options.maxInitProgressTime = 30000;
    options.stableStateTimePeriod = 60000;
    setUpFleetController(true, options);
    setUpVdsNodes(true, new DummyVdsNodeOptions(), false, configuredNodes);
    waitForState("version:\\d+ distributor:10 storage:10 .9.s:r");
    setWantedNodeState(State.DOWN, NodeType.DISTRIBUTOR, 2);
    setWantedNodeState(State.RETIRED, NodeType.STORAGE, 2);
    setWantedNodeState(State.MAINTENANCE, NodeType.STORAGE, 7);
    waitForCompleteCycle();
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(0).disconnect();
    nodes.get(3).disconnect();
    nodes.get(5).disconnect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:m .2.s:m .7.s:m .9.s:r");
    timer.advanceTime(1000000);
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:d .2.s:d .7.s:m .9.s:r");
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(3).setNodeState(new NodeState(nodes.get(3).getType(), State.INITIALIZING).setInitProgress(0.2));
    nodes.get(3).connect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:i .1.i:0.2 .2.s:d .7.s:m .9.s:r");
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 30 with NodeState

use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.

the class RpcServerTest method testGetNodeState.

@Test
public void testGetNodeState() throws Exception {
    startingTest("RpcServerTest::testGetNodeState");
    Set<ConfiguredNode> configuredNodes = new TreeSet<>();
    for (int i = 0; i < 10; i++) configuredNodes.add(new ConfiguredNode(i, false));
    FleetControllerOptions options = new FleetControllerOptions("mycluster", configuredNodes);
    options.minRatioOfStorageNodesUp = 0;
    options.maxInitProgressTime = 30000;
    options.stableStateTimePeriod = 60000;
    setUpFleetController(true, options);
    setUpVdsNodes(true, new DummyVdsNodeOptions());
    waitForStableSystem();
    setWantedNodeState(State.DOWN, NodeType.DISTRIBUTOR, 2);
    setWantedNodeState(State.RETIRED, NodeType.STORAGE, 2);
    setWantedNodeState(State.MAINTENANCE, NodeType.STORAGE, 7);
    waitForCompleteCycle();
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(0).disconnect();
    nodes.get(3).disconnect();
    nodes.get(5).disconnect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:m .2.s:m .7.s:m");
    timer.advanceTime(1000000);
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:d .2.s:d .7.s:m");
    timer.advanceTime(1000000);
    // Make fleet controller notice that time has changed before any disconnects
    waitForCompleteCycle();
    nodes.get(3).setNodeState(new NodeState(nodes.get(3).getType(), State.INITIALIZING).setInitProgress(0.2));
    nodes.get(3).connect();
    waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:i .1.i:0.2 .2.s:d .7.s:m");
    int rpcPort = fleetController.getRpcPort();
    supervisor = new Supervisor(new Transport());
    Target connection = supervisor.connect(new Spec("localhost", rpcPort));
    assertTrue(connection.isValid());
    Request req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(0));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
    NodeState reported = NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(1).asString());
    assertTrue(req.returnValues().get(1).asString(), reported.getState().oneOf("d-"));
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(2));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(2).asString()).getState());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(4));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("", req.returnValues().get(0).asString());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("distributor"));
    req.parameters().add(new Int32Value(15));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.METHOD_FAILED, req.errorCode());
    assertEquals("No node distributor.15 exists in cluster mycluster", req.errorMessage());
    assertFalse(req.toString(), req.checkReturnTypes("ssss"));
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(1));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("s:i i:0.2", req.returnValues().get(0).asString());
    assertEquals("s:i i:0.2", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(2));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.DOWN, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
    reported = NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(1).asString());
    assertTrue(req.returnValues().get(1).asString(), reported.getState().oneOf("d-"));
    assertEquals(State.RETIRED, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(5));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals("", req.returnValues().get(0).asString());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals("", req.returnValues().get(2).asString());
    req = new Request("getNodeState");
    req.parameters().add(new StringValue("storage"));
    req.parameters().add(new Int32Value(7));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("ssss"));
    assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
    assertEquals("t:946080000", req.returnValues().get(1).asString());
    assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) NodeState(com.yahoo.vdslib.state.NodeState) ConfiguredNode(com.yahoo.vdslib.distribution.ConfiguredNode) Request(com.yahoo.jrt.Request) Target(com.yahoo.jrt.Target) TreeSet(java.util.TreeSet) Int32Value(com.yahoo.jrt.Int32Value) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue) Test(org.junit.Test)

Aggregations

NodeState (com.yahoo.vdslib.state.NodeState)68 Node (com.yahoo.vdslib.state.Node)31 Test (org.junit.Test)30 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)21 ClusterState (com.yahoo.vdslib.state.ClusterState)11 NodeInfo (com.yahoo.vespa.clustercontroller.core.NodeInfo)6 Request (com.yahoo.jrt.Request)5 Target (com.yahoo.jrt.Target)5 State (com.yahoo.vdslib.state.State)5 ClusterFixture.storageNode (com.yahoo.vespa.clustercontroller.core.ClusterFixture.storageNode)5 HasStateReasonForNode.hasStateReasonForNode (com.yahoo.vespa.clustercontroller.core.matchers.HasStateReasonForNode.hasStateReasonForNode)5 Spec (com.yahoo.jrt.Spec)4 StringValue (com.yahoo.jrt.StringValue)4 Supervisor (com.yahoo.jrt.Supervisor)4 Transport (com.yahoo.jrt.Transport)4 DiskState (com.yahoo.vdslib.state.DiskState)4 ArrayList (java.util.ArrayList)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 HashSet (java.util.HashSet)3