1 #!/usr/bin/env hbase-jruby
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with this
5 # work for additional information regarding copyright ownership. The ASF
6 # licenses this file to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
18 # Prints the hostname of the machine running the active master.
21 import org.apache.hadoop.hbase.HBaseConfiguration
22 import org.apache.hadoop.hbase.ServerName
23 import org.apache.hadoop.hbase.zookeeper.ZKUtil
24 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher
26 # disable debug/info logging on this script for clarity
27 log_level = org.apache.log4j.Level::ERROR
28 org.apache.log4j.Logger.getLogger('org.apache.hadoop.hbase').setLevel(log_level)
29 org.apache.log4j.Logger.getLogger('org.apache.zookeeper').setLevel(log_level)
31 config = HBaseConfiguration.create
33 zk = ZooKeeperWatcher.new(config, 'get-active-master', nil)
35 master_address = ZKUtil.getData(zk, zk.masterAddressZNode)
37 puts ServerName.parseFrom(master_address).getHostname()
39 puts 'Master not running'