View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
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  import org.apache.zookeeper.data.Stat;
30  
31  @InterfaceAudience.Private
32  public class ReplicationQueuesClientZKImpl extends ReplicationStateZKBase implements
33      ReplicationQueuesClient {
34  
35    public ReplicationQueuesClientZKImpl(final ZooKeeperWatcher zk, Configuration conf,
36        Abortable abortable) {
37      super(zk, conf, abortable);
38    }
39  
40    @Override
41    public void init() throws ReplicationException {
42      try {
43        ZKUtil.createWithParents(this.zookeeper, this.queuesZNode);
44      } catch (KeeperException e) {
45        throw new ReplicationException("Internal error while initializing a queues client", e);
46      }
47    }
48  
49    @Override
50    public List<String> getListOfReplicators() throws KeeperException {
51      return super.getListOfReplicatorsZK();
52    }
53  
54    @Override
55    public List<String> getLogsInQueue(String serverName, String queueId) throws KeeperException {
56      String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
57      znode = ZKUtil.joinZNode(znode, queueId);
58      List<String> result = null;
59      try {
60        result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
61      } catch (KeeperException e) {
62        this.abortable.abort("Failed to get list of wals for queueId=" + queueId
63            + " and serverName=" + serverName, e);
64        throw e;
65      }
66      return result;
67    }
68  
69    @Override
70    public List<String> getAllQueues(String serverName) throws KeeperException {
71      String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
72      List<String> result = null;
73      try {
74        result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
75      } catch (KeeperException e) {
76        this.abortable.abort("Failed to get list of queues for serverName=" + serverName, e);
77        throw e;
78      }
79      return result;
80    }
81  
82    @Override public int getQueuesZNodeCversion() throws KeeperException {
83      try {
84        Stat stat = new Stat();
85        ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat);
86        return stat.getCversion();
87      } catch (KeeperException e) {
88        this.abortable.abort("Failed to get stat of replication rs node", e);
89        throw e;
90      }
91    }
92  }