homebrew-core/Formula/cassandra.rb

151 lines
6.5 KiB
Ruby

class Cassandra < Formula
include Language::Python::Virtualenv
include Language::Python::Shebang
desc "Eventually consistent, distributed key-value store"
homepage "https://cassandra.apache.org"
url "https://www.apache.org/dyn/closer.lua?path=cassandra/4.0.6/apache-cassandra-4.0.6-bin.tar.gz"
mirror "https://archive.apache.org/dist/cassandra/4.0.6/apache-cassandra-4.0.6-bin.tar.gz"
sha256 "86d14a8e158e4e8554388b1aab598efcb879ddb09c480edecabb3c350b58fe6b"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "b366a17ac367a87f153e0199ffc03c9f27660ad70bebda7f363a94492007a584"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "f7e3ea8d6192df791b56b0bf8654cea3eacd05bb1f9183a018c80bd90b4d9de0"
sha256 cellar: :any_skip_relocation, monterey: "950f0706dfeb0c7281798dcc74b9e00549b410f0333e71db9e80233ba2a68b71"
sha256 cellar: :any_skip_relocation, big_sur: "6f85abd368546c8593bb18a4f5c1c9d5dba6f66effdce65be5acbd299053fcdd"
sha256 cellar: :any_skip_relocation, catalina: "360a5fae30e52a4f6abaf3bcbe48be34d39a89b7e4ec54096585a89b74d1a3fa"
sha256 cellar: :any_skip_relocation, x86_64_linux: "057539ded17cb290b0bde96bb6133b9a35411c5b76821bcf9245db1ec9a91e54"
end
depends_on "libcython" => :build
depends_on "openjdk@11"
depends_on "python@3.10"
depends_on "six"
resource "thrift" do
url "https://files.pythonhosted.org/packages/e4/23/dd951c9883cb49a73b750bdfe91e39d78e8a3f1f7175608634f381a197d5/thrift-0.16.0.tar.gz"
sha256 "2b5b6488fcded21f9d312aa23c9ff6a0195d0f6ae26ddbd5ad9e3e25dfc14408"
end
resource "cql" do
url "https://files.pythonhosted.org/packages/0b/15/523f6008d32f05dd3c6a2e7c2f21505f0a785b6dc8949cad325306858afc/cql-1.4.0.tar.gz"
sha256 "7857c16d8aab7b736ab677d1016ef8513dedb64097214ad3a50a6c550cb7d6e0"
end
resource "cassandra-driver" do
url "https://files.pythonhosted.org/packages/af/aa/3d3a6dae349d4f9b69d37e6f3f8b8ef286a06005aa312f0a3dc7af0eb556/cassandra-driver-3.25.0.tar.gz"
sha256 "8ad7d7c090eb1cac6110b3bfc1fd2d334ac62f415aac09350ebb8d241b7aa7ee"
end
resource "click" do
url "https://files.pythonhosted.org/packages/59/87/84326af34517fca8c58418d148f2403df25303e02736832403587318e9e8/click-8.1.3.tar.gz"
sha256 "7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"
end
resource "geomet" do
url "https://files.pythonhosted.org/packages/be/9c/dc5a874b12bbab2981edf92d7d03b9d37de6261655b57590a166c890b148/geomet-0.3.0.tar.gz"
sha256 "cb52411978ee01ff104ab48f108d7333b14423ae7a15a65fee25b7d29bda2e1b"
end
def install
(var/"lib/cassandra").mkpath
(var/"log/cassandra").mkpath
python3 = "python3.10"
venv = virtualenv_create(libexec/"vendor", python3)
venv.pip_install resources
inreplace "conf/cassandra.yaml", "/var/lib/cassandra", var/"lib/cassandra"
inreplace "conf/cassandra-env.sh", "/lib/", "/"
inreplace "bin/cassandra", "-Dcassandra.logdir\=$CASSANDRA_LOG_DIR",
"-Dcassandra.logdir\=#{var}/log/cassandra"
inreplace "bin/cassandra.in.sh" do |s|
s.gsub! "CASSANDRA_HOME=\"`dirname \"$0\"`/..\"",
"CASSANDRA_HOME=\"#{libexec}\""
# Store configs in etc, outside of keg
s.gsub! "CASSANDRA_CONF=\"$CASSANDRA_HOME/conf\"",
"CASSANDRA_CONF=\"#{etc}/cassandra\""
# Jars installed to prefix, no longer in a lib folder
s.gsub! "\"$CASSANDRA_HOME\"/lib/*.jar",
"\"$CASSANDRA_HOME\"/*.jar"
# The jammm Java agent is not in a lib/ subdir either:
s.gsub! "JAVA_AGENT=\"$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-",
"JAVA_AGENT=\"$JAVA_AGENT -javaagent:$CASSANDRA_HOME/jamm-"
# Storage path
s.gsub! "cassandra_storagedir\=\"$CASSANDRA_HOME/data\"",
"cassandra_storagedir\=\"#{var}/lib/cassandra\""
s.gsub! "#JAVA_HOME=/usr/local/jdk6",
"JAVA_HOME=#{Language::Java.overridable_java_home_env("11")[:JAVA_HOME]}"
end
rm Dir["bin/*.bat", "bin/*.ps1"]
# This breaks on `brew uninstall cassandra && brew install cassandra`
# https://github.com/Homebrew/homebrew/pull/38309
pkgetc.install Dir["conf/*"]
libexec.install Dir["*.txt", "{bin,interface,javadoc,pylib,lib/licenses}"]
libexec.install Dir["lib/*.jar"]
pkgshare.install [libexec/"bin/cassandra.in.sh", libexec/"bin/stop-server"]
inreplace Dir[
libexec/"bin/cassandra*",
libexec/"bin/debug-cql",
libexec/"bin/nodetool",
libexec/"bin/sstable*",
], %r{`dirname "?\$0"?`/cassandra.in.sh},
pkgshare/"cassandra.in.sh"
# Make sure tools are installed
rm Dir[buildpath/"tools/bin/*.bat"] # Delete before install to avoid copying useless files
(libexec/"tools").install Dir[buildpath/"tools/lib/*.jar"]
# Tools use different cassandra.in.sh and should be changed differently
mv buildpath/"tools/bin/cassandra.in.sh", buildpath/"tools/bin/cassandra-tools.in.sh"
inreplace buildpath/"tools/bin/cassandra-tools.in.sh" do |s|
# Tools have slightly different path to CASSANDRA_HOME
s.gsub! "CASSANDRA_HOME=\"`dirname $0`/../..\"", "CASSANDRA_HOME=\"#{libexec}\""
# Store configs in etc, outside of keg
s.gsub! "CASSANDRA_CONF=\"$CASSANDRA_HOME/conf\"", "CASSANDRA_CONF=\"#{etc}/cassandra\""
# Core Jars installed to prefix, no longer in a lib folder
s.gsub! "\"$CASSANDRA_HOME\"/lib/*.jar", "\"$CASSANDRA_HOME\"/*.jar"
# Tools Jars are under tools folder
s.gsub! "\"$CASSANDRA_HOME\"/tools/lib/*.jar", "\"$CASSANDRA_HOME\"/tools/*.jar"
# Storage path
s.gsub! "cassandra_storagedir\=\"$CASSANDRA_HOME/data\"", "cassandra_storagedir\=\"#{var}/lib/cassandra\""
end
pkgshare.install [buildpath/"tools/bin/cassandra-tools.in.sh"]
# Update tools script files
inreplace Dir[buildpath/"tools/bin/*"],
"`dirname \"$0\"`/cassandra.in.sh",
pkgshare/"cassandra-tools.in.sh"
venv_bin = libexec/"vendor/bin"
rw_info = python_shebang_rewrite_info(venv_bin/python3)
rewrite_shebang rw_info, libexec/"bin/cqlsh.py"
# Make sure tools are available
bin.install Dir[buildpath/"tools/bin/*"]
bin.write_exec_script Dir[libexec/"bin/*"]
(bin/"cqlsh").write_env_script libexec/"bin/cqlsh", PATH: "#{venv_bin}:$PATH"
end
service do
run [opt_bin/"cassandra", "-f"]
keep_alive true
working_dir var/"lib/cassandra"
end
test do
assert_match version.to_s, shell_output("#{bin}/cassandra -v")
output = shell_output("#{bin}/cqlsh localhost 2>&1", 1)
assert_match "Connection error", output
end
end