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.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 KeeperException {
39      ZKUtil.createWithParents(this.zookeeper, this.queuesZNode);
40    }
41  
42    @Override
43    public List<String> getLogsInQueue(String serverName, String queueId) {
44      String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
45      znode = ZKUtil.joinZNode(znode, queueId);
46      List<String> result = null;
47      try {
48        result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
49      } catch (KeeperException e) {
50        this.abortable.abort("Failed to get list of hlogs for queueId=" + queueId
51            + " and serverName=" + serverName, e);
52      }
53      return result;
54    }
55  
56    @Override
57    public List<String> getAllQueues(String serverName) {
58      String znode = ZKUtil.joinZNode(this.queuesZNode, serverName);
59      List<String> result = null;
60      try {
61        result = ZKUtil.listChildrenNoWatch(this.zookeeper, znode);
62      } catch (KeeperException e) {
63        this.abortable.abort("Failed to get list of queues for serverName=" + serverName, e);
64      }
65      return result;
66    }
67  
68  }