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.conf.Configuration;
24 import org.apache.hadoop.hbase.Abortable;
25 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
26 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
27 import org.apache.zookeeper.KeeperException;
28
29 public class ReplicationQueuesClientZKImpl extends ReplicationStateZKBase implements
30 ReplicationQueuesClient {
31
32 public ReplicationQueuesClientZKImpl(final ZooKeeperWatcher zk, Configuration conf,
33 Abortable abortable) {
34 super(zk, conf, abortable);
35 }
36
37 @Override
38 public void init() throws ReplicationException {
39 try {
40 ZKUtil.createWithParents(this.zookeeper, this.queuesZNode);
41 } catch (KeeperException e) {
42 throw new ReplicationException("Internal error while initializing a queues client", e);
43 }
44 }
45
46 @Override
47 public List<String> getLogsInQueue(String serverName, String queueId) {
48 String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
49 znode = ZKUtil.joinZNode(znode, queueId);
50 List<String> result = null;
51 try {
52 result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
53 } catch (KeeperException e) {
54 this.abortable.abort("Failed to get list of hlogs for queueId=" + queueId
55 + " and serverName=" + serverName, e);
56 }
57 return result;
58 }
59
60 @Override
61 public List<String> getAllQueues(String serverName) {
62 String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
63 List<String> result = null;
64 try {
65 result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
66 } catch (KeeperException e) {
67 this.abortable.abort("Failed to get list of queues for serverName=" + serverName, e);
68 }
69 return result;
70 }
71
72 }