<commit_before>#
# Cookbook Name:: aerospike-cluster
# Recipe:: package
#
# Copyright 2015, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

case node['aerospike']['package_url']
when 'auto'
  case node['aerospike']['install_edition']
  when 'community'
    package_url = value_for_platform(
      'ubuntu' => {
        '~> 14.04' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/ubuntu14",
        'default' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/ubuntu12"
      },
      'debian' => { 'default' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/debian#{node['platform_version']}" },
      %w(amazon centos redhat) => { 'default' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/#{node['aerospike']['package_suffix']}" }
    )
  when 'enterprise'
    package_url = value_for_platform(
      'ubuntu' => {
        '~> 14.04' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/ubuntu14",
        'default' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/ubuntu12"
      },
      'debian' => { 'default' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/debian#{node['platform_version']}" },
      %w(amazon centos redhat) => { 'default' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/#{node['aerospike']['package_suffix']}" }
    )
  else
    raise "invalid aerospike edition, valid are 'community, enterprise'"
  end
else
  package_url = node['aerospike']['package_url']
end

package_file = ::File.join(node['aerospike']['parent_dir'], "aerospike-server-#{node['aerospike']['install_edition']}-#{node['aerospike']['version']}-#{node['aerospike']['package_suffix']}.tgz")
package_checksum = package_sha256sum(node['aerospike']['install_edition'], node['aerospike']['version'], node['aerospike']['package_suffix']) if node['aerospike']['checksum_verify']

# download tarball
remote_file "Download #{package_file}" do
  source package_url
  checksum package_checksum if node['aerospike']['checksum_verify']
  headers('Authorization' => "Basic #{Base64.encode64("#{node['aerospike']['enterprise']['username']}:#{node['aerospike']['enterprise']['password']}").delete("\n")}") if node['aerospike']['install_edition'] == 'enterprise'
  owner node['aerospike']['user']
  group node['aerospike']['group']
  not_if { ::File.exist?(::File.join(node['aerospike']['source_dir'], 'asinstall')) }
end

# extract tarball
execute 'extract_aerospike_package' do
  user node['aerospike']['user']
  group node['aerospike']['group']
  umask node['aerospike']['umask']
  cwd node['aerospike']['parent_dir']
  command "tar xzf #{package_file}"
  creates ::File.join(node['aerospike']['source_dir'], 'asinstall')
end

remote_file "Delete #{package_file}" do
  action :delete
end

server_package_file = case node['platform']
                      when 'redhat', 'amazon', 'fedora', 'centos'
                        ::File.join(node['aerospike']['source_dir'], "aerospike-server-#{node['aerospike']['install_edition']}-#{node['aerospike']['version']}-1.#{node['aerospike']['package_suffix']}.#{node['kernel']['machine']}.rpm")
                      when 'ubuntu', 'debian'
                        ::File.join(node['aerospike']['source_dir'], "aerospike-server-#{node['aerospike']['install_edition']}-#{node['aerospike']['version']}.#{node['aerospike']['package_suffix']}.#{node['kernel']['machine']}.deb")
                      else
                        raise "unknown platform #{node['platform']}"
                      end

# Tools package could be with a different number. Example with node['aerospike']['version']='172.16.31.10':
# - aerospike-server-community-172.16.31.10-1.el7.x86_64.rpm
# - aerospike-tools-3.8.2-1.el7.x86_64.rpm
package_version = node['aerospike']['version'].split('.')[0..2].join('.')
tools_package_file = case node['platform']
                     when 'redhat', 'amazon', 'fedora', 'centos'<commit_msg>Loosed `path` parameter during refactoring. Fixed<commit_after>#
# Cookbook Name:: aerospike-cluster
# Recipe:: package
#
# Copyright 2015, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

case node['aerospike']['package_url']
when 'auto'
  case node['aerospike']['install_edition']
  when 'community'
    package_url = value_for_platform(
      'ubuntu' => {
        '~> 14.04' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/ubuntu14",
        'default' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/ubuntu12"
      },
      'debian' => { 'default' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/debian#{node['platform_version']}" },
      %w(amazon centos redhat) => { 'default' => "http://aerospike.com/download/server/#{node['aerospike']['version']}/artifact/#{node['aerospike']['package_suffix']}" }
    )
  when 'enterprise'
    package_url = value_for_platform(
      'ubuntu' => {
        '~> 14.04' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/ubuntu14",
        'default' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/ubuntu12"
      },
      'debian' => { 'default' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/debian#{node['platform_version']}" },
      %w(amazon centos redhat) => { 'default' => "http://www.aerospike.com/enterprise/download/server/#{node['aerospike']['version']}/artifact/#{node['aerospike']['package_suffix']}" }
    )
  else
    raise "invalid aerospike edition, valid are 'community, enterprise'"
  end
else
  package_url = node['aerospike']['package_url']
end

package_file = ::File.join(node['aerospike']['parent_dir'], "aerospike-server-#{node['aerospike']['install_edition']}-#{node['aerospike']['version']}-#{node['aerospike']['package_suffix']}.tgz")
package_checksum = package_sha256sum(node['aerospike']['install_edition'], node['aerospike']['version'], node['aerospike']['package_suffix']) if node['aerospike']['checksum_verify']

# download tarball
remote_file "Download #{package_file}" do
  path package_file
  source package_url
  checksum package_checksum if node['aerospike']['checksum_verify']
  headers('Authorization' => "Basic #{Base64.encode64("#{node['aerospike']['enterprise']['username']}:#{node['aerospike']['enterprise']['password']}").delete("\n")}") if node['aerospike']['install_edition'] == 'enterprise'
  owner node['aerospike']['user']
  group node['aerospike']['group']
  not_if { ::File.exist?(::File.join(node['aerospike']['source_dir'], 'asinstall')) }
end

# extract tarball
execute 'extract_aerospike_package' do
  user node['aerospike']['user']
  group node['aerospike']['group']
  umask node['aerospike']['umask']
  cwd node['aerospike']['parent_dir']
  command "tar xzf #{package_file}"
  creates ::File.join(node['aerospike']['source_dir'], 'asinstall')
end

remote_file "Delete #{package_file}" do
  path package_file
  action :delete
end

server_package_file = case node['platform']
                      when 'redhat', 'amazon', 'fedora', 'centos'
                        ::File.join(node['aerospike']['source_dir'], "aerospike-server-#{node['aerospike']['install_edition']}-#{node['aerospike']['version']}-1.#{node['aerospike']['package_suffix']}.#{node['kernel']['machine']}.rpm")
                      when 'ubuntu', 'debian'
                        ::File.join(node['aerospike']['source_dir'], "aerospike-server-#{node['aerospike']['install_edition']}-#{node['aerospike']['version']}.#{node['aerospike']['package_suffix']}.#{node['kernel']['machine']}.deb")
                      else
                        raise "unknown platform #{node['platform']}"
                      end

# Tools package could be with a different number. Example with node['aerospike']['version']='172.16.31.10':
# - aerospike-server-community-3.8.2.3-1.el7.x86_64.rpm
# - aerospike-tools-3.8.2-1.el7.x86_64.rpm
package_version = node['aerospike']['version'].split('.')[0..2].join('.')
tools_package_file = case node['platform']
                     when 'redhat', 'amazon', 'fedora', 'centos'
{'fraction_non_alphanumeric': 0.19547347069499307, 'fraction_numerical': 0.013771751894950357, 'mean_word_length': 4.895531780994336, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5587154', 'n_tokens_mistral': 3138, 'n_tokens_neox': 2897, 'n_words': 504}