homebrew-core/Formula/cassandra.rb

152 lines
6.7 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.1.0/apache-cassandra-4.1.0-bin.tar.gz"
mirror "https://archive.apache.org/dist/cassandra/4.1.0/apache-cassandra-4.1.0-bin.tar.gz"
sha256 "e4fd6ef4a9e32eb297886c4bf04b42a8c740864e1fe8cc93deb240d576d607ae"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_ventura: "dda2455a952b5c13eff5f8ed7d6e3fd12f8b473d0acf969eef529c01e7262159"
sha256 cellar: :any_skip_relocation, arm64_monterey: "26497667e88a297847fc70df9df523ca3dcf2e6bb52b3c8b48bb9f221bfa8446"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "1c670a228ea5298163efb99a3215476424802305e1ce0942901f11f08b9830fb"
sha256 cellar: :any_skip_relocation, ventura: "4f0f7ff4b12546d0a3bc19cde3bcf1373506be98dc1ce5f8c6ebd2e130de7953"
sha256 cellar: :any_skip_relocation, monterey: "a0d96a62ef5a3dfac4f3eda755519b35f83cc57db727ac102b4d92cba2ac4549"
sha256 cellar: :any_skip_relocation, big_sur: "e8575ba10cca5156a8ae1c83c0d10f3708567141b16b6363fa7fa693726afcaa"
sha256 cellar: :any_skip_relocation, x86_64_linux: "ee0b557fcbe7fa1cc0a66c21abae6e8ba12e1593a006553cf024b1ca9dbcdaff"
end
depends_on "libcython" => :build
depends_on "openjdk@11"
depends_on "python@3.10" # Python 3.11 issue: https://issues.apache.org/jira/browse/CASSANDRA-18088
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