class Hbase < Formula
desc "Hadoop database: a distributed, scalable, big data store"
homepage "https://hbase.apache.org"
url "https://www.apache.org/dyn/closer.cgi?path=hbase/1.2.6.1/hbase-1.2.6.1-bin.tar.gz"
sha256 "3bfa55c0b2b1327cb4382c1a51dddd21a536ccbbfdbcc31e9b6f403fe21230ad"
bottle do
sha256 "ad2f8a6edee755254654904724c08c05bc9f05f82432b0b69022723624b13de8" => :mojave
sha256 "3c4084898091f6b811062aff85f2d5dcef422d720b21e60b0554a24ac611e0d9" => :high_sierra
sha256 "e2102bd08b2d94f5ac4d33938cdc76166bd085c9657f6f2ebcff47bbf3d3fd85" => :sierra
sha256 "72240c500dda738b40241eba7c157bdcb4e1a5cdec79b85fb74cbccebb02bef3" => :el_capitan
end
depends_on "ant" => :build
# 64 bit is required because of three things:
# the lzo jar has a native extension
# building native extensions requires a version of java that matches the architecture
# there is no 32 bit version of java for macOS since Java 1.7, and 1.8 is required for hbase
depends_on :arch => :x86_64
depends_on :java => "1.8"
depends_on "lzo"
depends_on "hadoop" => :optional
resource "hadoop-lzo" do
url "https://github.com/cloudera/hadoop-lzo/archive/0.4.14.tar.gz"
sha256 "aa8ddbb8b3f9e1c4b8cc3523486acdb7841cd97c002a9f2959c5b320c7bb0e6c"
end
def install
rm_f Dir["bin/*.cmd", "conf/*.cmd"]
libexec.install %w[bin conf docs lib hbase-webapps]
# Some binaries have really generic names (like `test`) and most seem to be
# too special-purpose to be permanently available via PATH.
%w[hbase start-hbase.sh stop-hbase.sh].each do |script|
(bin/script).write_env_script "#{libexec}/bin/#{script}", Language::Java.java_home_env("1.8")
end
resource("hadoop-lzo").stage do
# Fixed upstream: https://github.com/cloudera/hadoop-lzo/blob/master/build.xml#L235
inreplace "build.xml",
%r{()},
"\\1\n"
ENV["CLASSPATH"] = Dir["#{libexec}/lib/hadoop-common-*.jar"].first
ENV["CFLAGS"] = "-m64"
ENV["CXXFLAGS"] = "-m64"
ENV["CPPFLAGS"] = "-I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers"
system "ant", "compile-native", "tar"
(libexec/"lib").install Dir["build/hadoop-lzo-*/hadoop-lzo-*.jar"]
(libexec/"lib/native").install Dir["build/hadoop-lzo-*/lib/native/*"]
end
inreplace "#{libexec}/conf/hbase-env.sh" do |s|
# upstream bugs for ipv6 incompatibility:
# https://issues.apache.org/jira/browse/HADOOP-8568
# https://issues.apache.org/jira/browse/HADOOP-3619
s.gsub!("export HBASE_OPTS=\"-XX:+UseConcMarkSweepGC\"",
"export HBASE_OPTS=\"-Djava.net.preferIPv4Stack=true -XX:+UseConcMarkSweepGC\"")
s.gsub!("# export JAVA_HOME=/usr/java/jdk1.6.0/",
"export JAVA_HOME=\"$(/usr/libexec/java_home --version 1.8)\"")
# avoid deprecated-option warning issued by Java 8
s.gsub!(" -XX:PermSize=128m -XX:MaxPermSize=128m", "")
# Default `$HBASE_HOME/logs` is unsuitable as it would cause writes to the
# formula's prefix. Provide a better default but still allow override.
s.gsub!(/^# export HBASE_LOG_DIR=.*$/,
"export HBASE_LOG_DIR=\"${HBASE_LOG_DIR:-#{var}/log/hbase}\"")
end
# makes hbase usable out of the box
# upstream has been provided this patch
# https://issues.apache.org/jira/browse/HBASE-15426
inreplace "#{libexec}/conf/hbase-site.xml",
//,
<<~EOS
hbase.rootdir
#{build.with?("hadoop") ? "hdfs://localhost:9000" : "file://"+var}/hbase
hbase.zookeeper.property.clientPort
2181
hbase.zookeeper.property.dataDir
#{var}/zookeeper
hbase.zookeeper.dns.interface
lo0
hbase.regionserver.dns.interface
lo0
hbase.master.dns.interface
lo0
EOS
end
def post_install
(var/"log/hbase").mkpath
(var/"run/hbase").mkpath
end
plist_options :manual => "#{HOMEBREW_PREFIX}/opt/hbase/bin/start-hbase.sh"
def plist; <<~EOS
KeepAlive
#{build.without?("hadoop") ? "" : "\n OtherJobEnabled\n "+Formula["hadoop"].plist_name+"\n "}
Label
#{plist_name}
EnvironmentVariables
HBASE_MASTER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m
HBASE_LOG_DIR#{var}/hbase
HBASE_HOME#{opt_libexec}
HBASE_SECURITY_LOGGERINFO,RFAS
HBASE_PID_DIR#{var}/run/hbase
HBASE_NICENESS0
HBASE_IDENT_STRINGroot
HBASE_REGIONSERVER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m
HBASE_OPTS-XX:+UseConcMarkSweepGC
HBASE_ROOT_LOGGERINFO,RFA
HBASE_LOG_PREFIXhbase-root-master
HBASE_LOGFILEhbase-root-master.log
ProgramArguments
#{opt_bin}/hbase
--config
#{opt_libexec}/conf
master
start
RunAtLoad
WorkingDirectory
#{HOMEBREW_PREFIX}
StandardOutPath
#{var}/hbase/hbase.log
StandardErrorPath
#{var}/hbase/hbase.err
EOS
end
test do
assert_match "HBase #{version}", shell_output("#{bin}/hbase version 2>&1")
cp_r (libexec/"conf"), testpath
inreplace (testpath/"conf/hbase-site.xml") do |s|
s.gsub! /(hbase.rootdir.*)\n.*/, "\\1\nfile://#{testpath}/hbase"
s.gsub! /(hbase.zookeeper.property.dataDir.*)\n.*/, "\\1\n#{testpath}/zookeeper"
end
ENV["HBASE_LOG_DIR"] = testpath/"logs"
ENV["HBASE_CONF_DIR"] = testpath/"conf"
ENV["HBASE_PID_DIR"] = testpath/"pid"
system "#{bin}/start-hbase.sh"
sleep 10
begin
assert_match "Zookeeper", pipe_output("nc 127.0.0.1 2181 2>&1", "stats")
ensure
system "#{bin}/stop-hbase.sh"
end
end
end