homebrew-core/Formula/cassandra.rb

148 lines
6.3 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.3/apache-cassandra-4.0.3-bin.tar.gz"
mirror "https://archive.apache.org/dist/cassandra/4.0.3/apache-cassandra-4.0.3-bin.tar.gz"
sha256 "33623300bef39c75c73c3b51ad45b453e40e27a0816af3a1466537aa79e5f50d"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "295d78b46ac3bca4c9d86f2ed95e4cdb674460eeb233a910b0eeee11954bf1bb"
sha256 cellar: :any_skip_relocation, big_sur: "a05b39bcb9190959ee54ca9e51d304fc355aa7685abb4811a728522f74f9276a"
sha256 cellar: :any_skip_relocation, catalina: "6d9552d54cb712149d01ad9014911af25fb47f00604943db15f91bd81ce6ba21"
sha256 cellar: :any_skip_relocation, x86_64_linux: "8719f63db4e26e335895e243ce9f317b448cf9eeb83559530d6126e96ebe25dd"
end
depends_on "cython" => :build
depends_on "openjdk@11"
depends_on "python@3.9"
depends_on "six"
resource "thrift" do
url "https://files.pythonhosted.org/packages/97/1e/3284d19d7be99305eda145b8aa46b0c33244e4a496ec66440dac19f8274d/thrift-0.13.0.tar.gz"
sha256 "9af1c86bf73433afc6010ed376a6c6aca2b54099cc0d61895f640870a9ae7d89"
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/21/83/308a74ca1104fe1e3197d31693a7a2db67c2d4e668f20f43a2fca491f9f7/click-8.0.1.tar.gz"
sha256 "8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"
end
resource "geomet" do
url "https://files.pythonhosted.org/packages/cf/21/58251b3de99e0b5ba649ff511f7f9e8399c3059dd52a643774106e929afa/geomet-0.2.1.post1.tar.gz"
sha256 "91d754f7c298cbfcabd3befdb69c641c27fe75e808b27aa55028605761d17e95"
end
def install
(var/"lib/cassandra").mkpath
(var/"log/cassandra").mkpath
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/"python")
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