Search in sources :

Example 6 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestMasterAddressTracker method setupMasterTracker.

/**
   * create an address tracker instance
   * @param sn if not-null set the active master
   * @param infoPort if there is an active master, set its info port.
   */
private MasterAddressTracker setupMasterTracker(final ServerName sn, final int infoPort) throws Exception {
    ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(), name.getMethodName(), null);
    ZKUtil.createAndFailSilent(zk, zk.znodePaths.baseZNode);
    // Should not have a master yet
    MasterAddressTracker addressTracker = new MasterAddressTracker(zk, null);
    addressTracker.start();
    assertFalse(addressTracker.hasMaster());
    zk.registerListener(addressTracker);
    // Use a listener to capture when the node is actually created
    NodeCreationListener listener = new NodeCreationListener(zk, zk.znodePaths.masterAddressZNode);
    zk.registerListener(listener);
    if (sn != null) {
        LOG.info("Creating master node");
        MasterAddressTracker.setMasterAddress(zk, zk.znodePaths.masterAddressZNode, sn, infoPort);
        // Wait for the node to be created
        LOG.info("Waiting for master address manager to be notified");
        listener.waitForCreation();
        LOG.info("Master node created");
    }
    return addressTracker;
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 7 with MasterAddressTracker

use of org.apache.hadoop.hbase.zookeeper.MasterAddressTracker in project hbase by apache.

the class TestMasterAddressTracker method testDeleteIfEquals.

@Test
public void testDeleteIfEquals() throws Exception {
    final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis());
    final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772);
    try {
        assertFalse("shouldn't have deleted wrong master server.", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), "some other string."));
    } finally {
        assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString()));
    }
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) Test(org.junit.Test)

Aggregations

MasterAddressTracker (org.apache.hadoop.hbase.zookeeper.MasterAddressTracker)7 Test (org.junit.Test)4 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)3 Before (org.junit.Before)2 HashSet (java.util.HashSet)1 Admin (org.apache.hadoop.hbase.client.Admin)1 CacheConfig (org.apache.hadoop.hbase.io.hfile.CacheConfig)1 MetricsHBaseServer (org.apache.hadoop.hbase.ipc.MetricsHBaseServer)1 MetricsHBaseServerWrapperStub (org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperStub)1 RpcServerInterface (org.apache.hadoop.hbase.ipc.RpcServerInterface)1 MetricsRegionServer (org.apache.hadoop.hbase.regionserver.MetricsRegionServer)1 MetricsRegionServerWrapperStub (org.apache.hadoop.hbase.regionserver.MetricsRegionServerWrapperStub)1 ZNodePaths (org.apache.hadoop.hbase.zookeeper.ZNodePaths)1