homebrew-core/Formula/hbase.rb

172 lines
7.0 KiB
Ruby

class Hbase < Formula
desc "Hadoop database: a distributed, scalable, big data store"
homepage "https://hbase.apache.org"
url "https://www.apache.org/dyn/closer.lua?path=hbase/2.5.2/hbase-2.5.2-bin.tar.gz"
mirror "https://archive.apache.org/dist/hbase/2.5.2/hbase-2.5.2-bin.tar.gz"
sha256 "9f32b066387f850d4d6d0680f4e77835c3a8c4316da0b5634467b9e0dcc860a8"
# We bundle hadoop-lzo which is GPL-3.0-or-later
license all_of: ["Apache-2.0", "GPL-3.0-or-later"]
bottle do
sha256 arm64_ventura: "6e40a58acfbc4ef14b96728e4ac1785ef41c3a7eb48ba214e2dd800a14301c42"
sha256 arm64_monterey: "2454df4d5e5f55fdee780aaa4de3ac6f1379a23a5cb2d253fd3b190dcca5ffb3"
sha256 arm64_big_sur: "155543e59c966827e83a924a588818b68c7fd1400cdd2f16f0abaaa59b11c23c"
sha256 ventura: "4b38ba0cadf3101dfec691cd58be94d30ad1206a67672a121a2d5f0492a37cb2"
sha256 monterey: "3cfe153f68194bc4b829bd7c5a9fad488c157db7075918903d142275b498a32c"
sha256 big_sur: "a85407545e9b43c2fd7dec7b00c29db895e563e621315e2969903db697d77534"
sha256 x86_64_linux: "92549de3fe32094a3eacd03d3b81797d1d445134135662da1f8e0c7f70cbb2b3"
end
depends_on "ant" => :build
depends_on "lzo"
depends_on "openjdk@11"
uses_from_macos "netcat" => :test
resource "hadoop-lzo" do
url "https://github.com/cloudera/hadoop-lzo/archive/0.4.14.tar.gz"
sha256 "aa8ddbb8b3f9e1c4b8cc3523486acdb7841cd97c002a9f2959c5b320c7bb0e6c"
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/b89da3afad84bbf69deed0611e5dddaaa5d39325/hbase/build.xml.patch"
sha256 "d1d65330a4367db3e17ee4f4045641b335ed42449d9e6e42cc687e2a2e3fa5bc"
end
# Fix -flat_namespace being used on Big Sur and later.
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-pre-0.4.2.418-big_sur.diff"
sha256 "83af02f2aa2b746bb7225872cab29a253264be49db0ecebb12f841562d9a2923"
directory "src/native"
end
end
def install
java_home = Language::Java.java_home("11")
rm_f Dir["bin/*.cmd", "conf/*.cmd"]
libexec.install %w[bin conf 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.overridable_java_home_env("11")
end
resource("hadoop-lzo").stage do
# Help configure to find liblzo on Linux.
unless OS.mac?
inreplace "src/native/configure",
"#define HADOOP_LZO_LIBRARY ${ac_cv_libname_lzo2}",
"#define HADOOP_LZO_LIBRARY \"#{Formula["lzo"].opt_lib/shared_library("liblzo2")}\""
end
# Fixed upstream: https://github.com/cloudera/hadoop-lzo/blob/HEAD/build.xml#L235
ENV["CLASSPATH"] = Dir["#{libexec}/lib/hadoop-common-*.jar"].first
ENV["CFLAGS"] = "-m64"
ENV["CXXFLAGS"] = "-m64"
ENV["CPPFLAGS"] = "-I#{Formula["openjdk@11"].include}"
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$/,
"export HBASE_OPTS=\"-Djava.net.preferIPv4Stack=true -XX:+UseConcMarkSweepGC\"")
s.gsub!(/^# export JAVA_HOME=.*/,
"export JAVA_HOME=\"${JAVA_HOME:-#{java_home}}\"")
# 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
# Interface name is lo on Linux, not lo0.
loopback = OS.mac? ? "lo0" : "lo"
# 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",
/<configuration>/,
<<~EOS
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file://#{var}/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>#{var}/zookeeper</value>
</property>
<property>
<name>hbase.zookeeper.dns.interface</name>
<value>#{loopback}</value>
</property>
<property>
<name>hbase.regionserver.dns.interface</name>
<value>#{loopback}</value>
</property>
<property>
<name>hbase.master.dns.interface</name>
<value>#{loopback}</value>
</property>
EOS
end
def post_install
(var/"log/hbase").mkpath
(var/"run/hbase").mkpath
end
service do
run [opt_bin/"hbase", "--config", opt_libexec/"conf", "master", "start"]
keep_alive true
working_dir HOMEBREW_PREFIX
log_path var/"hbase/hbase.log"
error_log_path var/"hbase/hbase.err"
environment_variables HBASE_HOME: opt_libexec,
HBASE_IDENT_STRING: "root",
HBASE_LOG_DIR: var/"hbase",
HBASE_LOG_PREFIX: "hbase-root-master",
HBASE_LOGFILE: "hbase-root-master.log",
HBASE_MASTER_OPTS: " -XX:PermSize=128m -XX:MaxPermSize=128m",
HBASE_NICENESS: "0",
HBASE_OPTS: "-XX:+UseConcMarkSweepGC",
HBASE_PID_DIR: var/"run/hbase",
HBASE_REGIONSERVER_OPTS: " -XX:PermSize=128m -XX:MaxPermSize=128m",
HBASE_ROOT_LOGGER: "INFO,RFA",
HBASE_SECURITY_LOGGER: "INFO,RFAS"
end
test do
port = free_port
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\n<value>file://#{testpath}/hbase</value>")
s.gsub!(/(hbase.zookeeper.property.dataDir.*)\n.*/, "\\1\n<value>#{testpath}/zookeeper</value>")
s.gsub!(/(hbase.zookeeper.property.clientPort.*)\n.*/, "\\1\n<value>#{port}</value>")
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 15
begin
assert_match "Zookeeper", pipe_output("nc 127.0.0.1 #{port} 2>&1", "stats")
ensure
system "#{bin}/stop-hbase.sh"
end
end
end