<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Cookbook Name:: cassandra
# Recipe:: default
#
# Copyright 2012, Webtrends Inc.
#
# All rights reserved - Do Not Redistribute
#

build_uri = node['cassandra']['build_uri']
if (build_uri =~ /\/([^\/]*)$/)
	rpmfile = $1
end

package "apache-cassandra1" do
	action :install
	ignore_failure true
end

remote_file "#{Chef::Config[:file_cache_path]}/#{rpmfile}" do
	source build_uri
	not_if "rpm -qa | egrep -q apache-cassandra1"
	notifies :install, "rpm_package[apache-cassandra1]", :immediately
end

rpm_package "apache-cassandra1" do
	source "#{Chef::Config[:file_cache_path]}/#{rpmfile}"
	only_if {::File.exists?("#{Chef::Config[:file_cache_path]}/#{rpmfile}")}
	action :nothing
end

file "apache-cassandra1" do
	path "#{Chef::Config[:file_cache_path]}/#{rpmfile}"
	action :delete
end

# Drop the JNA Jar.
bash "installJNA" do
user "root"
  code <<-EOH
  if [ ! -e /usr/share/cassandra/lib/jna.jar ]; then
    wget #{node['cassandra']['jna_url']} -O /usr/share/cassandra/lib/jna.jar
    chown cassandra /usr/share/cassandra/lib/jna.jar
    chmod 755 /usr/share/cassandra/lib/jna.jar
  fi
  EOH
end

# Drop MX4J jar.
bash "installMX4J" do
user "root"
  cwd "#{Chef::Config[:file_cache_path]}"
  code <<-EOH
  if [ ! -e /usr/share/cassandra/lib/mx4j-tools.jar ]; then
    wget #{node['cassandra']['mx4j_url']}
    tar zxvf mx4j-3.0.2.tar.gz mx4j-3.0.2/lib/mx4j-tools.jar
    cp mx4j-3.0.2/lib/mx4j-tools.jar /usr/share/cassandra/lib/
    chown cassandra:cassandra /usr/share/cassandra/lib/mx4j-tools.jar
    chmod 755 /usr/share/cassandra/lib/mx4j-tools.jar
  fi
  EOH
end

#Create collectd plugin for cassandra
template "#{node[:collectd][:plugin_conf_dir]}/#{file}.conf" do<commit_msg>fixed template creation in cassandra cookbook<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Cookbook Name:: cassandra
# Recipe:: default
#
# Copyright 2012, Webtrends Inc.
#
# All rights reserved - Do Not Redistribute
#

build_uri = node['cassandra']['build_uri']
if (build_uri =~ /\/([^\/]*)$/)
	rpmfile = $1
end

package "apache-cassandra1" do
	action :install
	ignore_failure true
end

remote_file "#{Chef::Config[:file_cache_path]}/#{rpmfile}" do
	source build_uri
	not_if "rpm -qa | egrep -q apache-cassandra1"
	notifies :install, "rpm_package[apache-cassandra1]", :immediately
end

rpm_package "apache-cassandra1" do
	source "#{Chef::Config[:file_cache_path]}/#{rpmfile}"
	only_if {::File.exists?("#{Chef::Config[:file_cache_path]}/#{rpmfile}")}
	action :nothing
end

file "apache-cassandra1" do
	path "#{Chef::Config[:file_cache_path]}/#{rpmfile}"
	action :delete
end

# Drop the JNA Jar.
bash "installJNA" do
user "root"
  code <<-EOH
  if [ ! -e /usr/share/cassandra/lib/jna.jar ]; then
    wget #{node['cassandra']['jna_url']} -O /usr/share/cassandra/lib/jna.jar
    chown cassandra /usr/share/cassandra/lib/jna.jar
    chmod 755 /usr/share/cassandra/lib/jna.jar
  fi
  EOH
end

# Drop MX4J jar.
bash "installMX4J" do
user "root"
  cwd "#{Chef::Config[:file_cache_path]}"
  code <<-EOH
  if [ ! -e /usr/share/cassandra/lib/mx4j-tools.jar ]; then
    wget #{node['cassandra']['mx4j_url']}
    tar zxvf mx4j-3.0.2.tar.gz mx4j-3.0.2/lib/mx4j-tools.jar
    cp mx4j-3.0.2/lib/mx4j-tools.jar /usr/share/cassandra/lib/
    chown cassandra:cassandra /usr/share/cassandra/lib/mx4j-tools.jar
    chmod 755 /usr/share/cassandra/lib/mx4j-tools.jar
  fi
  EOH
end

#Create collectd plugin for cassandra
template "#{node[:collectd][:plugin_conf_dir]}/collectd_cassandra.conf" do
{'fraction_non_alphanumeric': 0.1679498146564015, 'fraction_numerical': 0.020530367835757058, 'mean_word_length': 4.331306990881459, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380451', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1450, 'n_words': 280}