1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.replication;
20
21 import java.util.List;
22
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.Abortable;
26 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
27 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
28 import org.apache.zookeeper.KeeperException;
29
30 @InterfaceAudience.Private
31 public class ReplicationQueuesClientZKImpl extends ReplicationStateZKBase implements
32 ReplicationQueuesClient {
33
34 public ReplicationQueuesClientZKImpl(final ZooKeeperWatcher zk, Configuration conf,
35 Abortable abortable) {
36 super(zk, conf, abortable);
37 }
38
39 @Override
40 public void init() throws ReplicationException {
41 try {
42 ZKUtil.createWithParents(this.zookeeper, this.queuesZNode);
43 } catch (KeeperException e) {
44 throw new ReplicationException("Internal error while initializing a queues client", e);
45 }
46 }
47
48 @Override
49 public List<String> getLogsInQueue(String serverName, String queueId) {
50 String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
51 znode = ZKUtil.joinZNode(znode, queueId);
52 List<String> result = null;
53 try {
54 result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
55 } catch (KeeperException e) {
56 this.abortable.abort("Failed to get list of hlogs for queueId=" + queueId
57 + " and serverName=" + serverName, e);
58 }
59 return result;
60 }
61
62 @Override
63 public List<String> getAllQueues(String serverName) {
64 String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
65 List<String> result = null;
66 try {
67 result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
68 } catch (KeeperException e) {
69 this.abortable.abort("Failed to get list of queues for serverName=" + serverName, e);
70 }
71 return result;
72 }
73
74 }