예제 #1
0
  @Test
  public void testCheckup() throws IOException {
    MockClock clk = new MockClock(0);
    Clock.setClock(clk);
    StatusManager stats = new StatusManager();

    // foo is in state HELLO and has configuration numbered 0
    long prev = Clock.unixTime();
    boolean needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.HELLO, 0);
    LOG.info(stats.getNodeStatuses());
    assertTrue(needsRefresh);

    // move forward in time, but not far enough to trigger being lost
    clk.forward(FlumeConfiguration.get().getConfigHeartbeatPeriod() * 5);
    stats.checkup();
    StatusManager.NodeStatus ns = stats.getNodeStatuses().get("foo");
    assertEquals(0, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.HELLO, ns.state);
    prev = ns.lastseen;

    clk.forward(FlumeConfiguration.get().getConfigHeartbeatPeriod() * 20);
    stats.checkup();
    ns = stats.getNodeStatuses().get("foo");
    assertEquals(0, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.LOST, ns.state);
    prev = ns.lastseen;

    LOG.info(ns.toString());
    LOG.info(stats.getStatus("foo").toString());
  }
예제 #2
0
  @Test
  public void testStatusManagerHeartbeats() throws IOException {
    StatusManager stats = new StatusManager();

    FlumeConfiguration cfg = FlumeConfiguration.createTestableConfiguration();
    Clock.resetDefault();
    cfg.set(FlumeConfiguration.WEBAPPS_PATH, "build/webapps");
    cfg.set(FlumeConfiguration.MASTER_STORE, "memory");

    // avoiding gossip ack manager until it shuts down cleanly.
    ConfigStore cfgStore = FlumeMaster.createConfigStore(cfg);
    FlumeMaster fm =
        new FlumeMaster(
            new CommandManager(), new ConfigManager(cfgStore), stats, new MasterAckManager(), cfg);

    fm.getSpecMan().addLogicalNode("physnode", "foo");

    // foo is in state HELLO and has configuration numbered 0
    long prev = Clock.unixTime();
    boolean needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.HELLO, 0);
    LOG.info(stats.getNodeStatuses());
    assertTrue(needsRefresh);

    StatusManager.NodeStatus ns = stats.getNodeStatuses().get("foo");
    assertEquals(0, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.HELLO, ns.state);
    prev = ns.lastseen;

    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.IDLE, 0);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh); // no new data flow version
    assertEquals(0, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.IDLE, ns.state);
    prev = ns.lastseen;

    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.ACTIVE, 10);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh); // node has updated version number, but master
    // has not
    assertEquals(10, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.ACTIVE, ns.state);
    prev = ns.lastseen;

    // same message, no refresh
    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.ACTIVE, 10);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh); // this is wierd, is this right?
    assertEquals(10, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.ACTIVE, ns.state);
    prev = ns.lastseen;

    // regress to an older version,
    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.ACTIVE, 5);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh);
    assertEquals(5, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.ACTIVE, ns.state);
    prev = ns.lastseen;

    LOG.info(stats.getReport());
    LOG.info(stats.getName());
  }
예제 #3
0
 /**
  * Return a list of the names of any nodes that have been seen. Used by the web interface to
  * populate choice inputs.
  */
 public Set<String> getKnownNodes() {
   return statman.getNodeStatuses().keySet();
 }