Search in sources :

Example 21 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class TestReplicationAdmin method testNamespacesAndTableCfsConfigConflict.

@Test
public void testNamespacesAndTableCfsConfigConflict() throws Exception {
    String ns1 = "ns1";
    String ns2 = "ns2";
    final TableName tableName1 = TableName.valueOf(ns1 + ":" + name.getMethodName());
    final TableName tableName2 = TableName.valueOf(ns2 + ":" + name.getMethodName() + "2");
    ReplicationPeerConfig rpc = new ReplicationPeerConfig();
    rpc.setClusterKey(KEY_ONE);
    hbaseAdmin.addReplicationPeer(ID_ONE, rpc);
    rpc = admin.getPeerConfig(ID_ONE);
    Set<String> namespaces = new HashSet<String>();
    namespaces.add(ns1);
    rpc.setNamespaces(namespaces);
    admin.updatePeerConfig(ID_ONE, rpc);
    rpc = admin.getPeerConfig(ID_ONE);
    Map<TableName, List<String>> tableCfs = new HashMap<>();
    tableCfs.put(tableName1, new ArrayList<>());
    rpc.setTableCFsMap(tableCfs);
    try {
        admin.updatePeerConfig(ID_ONE, rpc);
        fail("Should throw ReplicationException, because table " + tableName1 + " conflict with namespace " + ns1);
    } catch (IOException e) {
    // OK
    }
    rpc = admin.getPeerConfig(ID_ONE);
    tableCfs.clear();
    tableCfs.put(tableName2, new ArrayList<>());
    rpc.setTableCFsMap(tableCfs);
    admin.updatePeerConfig(ID_ONE, rpc);
    rpc = admin.getPeerConfig(ID_ONE);
    namespaces.clear();
    namespaces.add(ns2);
    rpc.setNamespaces(namespaces);
    try {
        admin.updatePeerConfig(ID_ONE, rpc);
        fail("Should throw ReplicationException, because namespace " + ns2 + " conflict with table " + tableName2);
    } catch (IOException e) {
    // OK
    }
    admin.removePeer(ID_ONE);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class TestReplicationAdmin method testSetPeerNamespaces.

@Test
public void testSetPeerNamespaces() throws Exception {
    String ns1 = "ns1";
    String ns2 = "ns2";
    ReplicationPeerConfig rpc = new ReplicationPeerConfig();
    rpc.setClusterKey(KEY_ONE);
    hbaseAdmin.addReplicationPeer(ID_ONE, rpc);
    rpc = admin.getPeerConfig(ID_ONE);
    Set<String> namespaces = new HashSet<>();
    namespaces.add(ns1);
    namespaces.add(ns2);
    rpc.setNamespaces(namespaces);
    admin.updatePeerConfig(ID_ONE, rpc);
    namespaces = admin.getPeerConfig(ID_ONE).getNamespaces();
    assertEquals(2, namespaces.size());
    assertTrue(namespaces.contains(ns1));
    assertTrue(namespaces.contains(ns2));
    rpc = admin.getPeerConfig(ID_ONE);
    namespaces.clear();
    namespaces.add(ns1);
    rpc.setNamespaces(namespaces);
    admin.updatePeerConfig(ID_ONE, rpc);
    namespaces = admin.getPeerConfig(ID_ONE).getNamespaces();
    assertEquals(1, namespaces.size());
    assertTrue(namespaces.contains(ns1));
    admin.removePeer(ID_ONE);
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class TestReplicationAdminWithClusters method testReplicationPeerConfigUpdateCallback.

@Test(timeout = 300000)
public void testReplicationPeerConfigUpdateCallback() throws Exception {
    String peerId = "1";
    ReplicationPeerConfig rpc = new ReplicationPeerConfig();
    rpc.setClusterKey(utility2.getClusterKey());
    rpc.setReplicationEndpointImpl(TestUpdatableReplicationEndpoint.class.getName());
    rpc.getConfiguration().put("key1", "value1");
    admin1.addReplicationPeer(peerId, rpc);
    rpc.getConfiguration().put("key1", "value2");
    admin.updatePeerConfig(peerId, rpc);
    if (!TestUpdatableReplicationEndpoint.hasCalledBack()) {
        synchronized (TestUpdatableReplicationEndpoint.class) {
            TestUpdatableReplicationEndpoint.class.wait(2000L);
        }
    }
    assertEquals(true, TestUpdatableReplicationEndpoint.hasCalledBack());
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) Test(org.junit.Test)

Example 24 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class TestReplicationAdminWithTwoDifferentZKClusters method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    utility1 = new HBaseTestingUtility(conf1);
    utility1.startMiniCluster();
    admin = new ReplicationAdmin(conf1);
    conf2 = HBaseConfiguration.create(conf1);
    conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
    conf2.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2182);
    utility2 = new HBaseTestingUtility(conf2);
    utility2.startMiniCluster();
    ReplicationPeerConfig config = new ReplicationPeerConfig();
    config.setClusterKey(utility2.getClusterKey());
    admin.addPeer(peerId, config, null);
    HTableDescriptor table = new HTableDescriptor(tableName);
    HColumnDescriptor fam = new HColumnDescriptor(famName);
    fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
    table.addFamily(fam);
    utility1.getAdmin().createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
    utility1.waitUntilAllRegionsAssigned(tableName);
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) BeforeClass(org.junit.BeforeClass)

Example 25 with ReplicationPeerConfig

use of org.apache.hadoop.hbase.replication.ReplicationPeerConfig in project hbase by apache.

the class TestReplicationAdmin method testEnableDisable.

/**
   * basic checks that when we add a peer that it is enabled, and that we can disable
   * @throws Exception
   */
@Test
public void testEnableDisable() throws Exception {
    ReplicationPeerConfig rpc1 = new ReplicationPeerConfig();
    rpc1.setClusterKey(KEY_ONE);
    admin.addPeer(ID_ONE, rpc1, null);
    assertEquals(1, admin.getPeersCount());
    assertTrue(admin.getPeerState(ID_ONE));
    admin.disablePeer(ID_ONE);
    assertFalse(admin.getPeerState(ID_ONE));
    try {
        admin.getPeerState(ID_SECOND);
    } catch (ReplicationPeerNotFoundException e) {
    // OK!
    }
    admin.removePeer(ID_ONE);
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReplicationPeerNotFoundException(org.apache.hadoop.hbase.ReplicationPeerNotFoundException) Test(org.junit.Test)

Aggregations

ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)42 Test (org.junit.Test)18 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 List (java.util.List)10 TableName (org.apache.hadoop.hbase.TableName)10 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)7 Configuration (org.apache.hadoop.conf.Configuration)7 ReplicationAdmin (org.apache.hadoop.hbase.client.replication.ReplicationAdmin)7 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 ReplicationPeerNotFoundException (org.apache.hadoop.hbase.ReplicationPeerNotFoundException)6 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)6 TreeMap (java.util.TreeMap)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)5 Map (java.util.Map)4 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)4 ReplicationPeerDescription (org.apache.hadoop.hbase.replication.ReplicationPeerDescription)4