<commit_before>use_inline_resources

include DatomicLibrary::Mixin::Attributes
include DatomicLibrary::Mixin::Status

require 'etc'

action :install do
  remote_file local_file_path do
    source datomic_download_url
    owner username
    group username
    checksum node[:datomic][:checksum]
  end

  execute "unzip #{local_file_path} -d #{home_dir}" do
    cwd download_dir
    not_if { ::File.exists?(temporary_zip_dir) }
  end

  execute "chown -R #{username}:#{username} #{temporary_zip_dir}" do
    not_if { Etc.getpwuid(::File.stat(temporary_zip_dir).uid).name == username }
  end

  datomic_jars 'Install extra jars' do
    jars node[:datomic][:extra_jars]
    lib_dir "#{temporary_zip_dir}/lib"
    owner username
    group username
  end

  protocol = node[:datomic][:protocol]
  if(protocol == 'sql')
    ojdbc_jar_url = node[:datomic][:ojdbc_jar_url]

    Chef::Application.fatal! 'You must set node[:datomic][:ojdbc_jar_url]' if ojdbc_jar_url.nil?
    Chef::Application.fatal! 'The sql protocol requires a datomic license, specify with node[:datomic][:datomic_license_key]' if node[:datomic][:datomic_license_key].nil?

    ojdbc_file = "#{temporary_zip_dir}/lib/ojdbc.jar"

    remote_file ojdbc_file do
      source ojdbc_jar_url
      owner username
      group username
      checksum node[:datomic][:ojdbc_jar_checksum]
    end
  end

  riak_host = node[:datomic][:riak_host]
  riak_bucket = node[:datomic][:riak_bucket]

  if(protocol == 'riak')
    Chef::Application.fatal! 'You must set node[:datomic][:riak_host]' if riak_host.nil?
    Chef::Application.fatal! 'You must set node[:datomic][:riak_bucket]' if riak_bucket.nil?
  end

  template "#{temporary_zip_dir}/transactor.properties" do
    source 'transactor.properties.erb'
    owner username
    group username
    cookbook 'datomic'
    mode 00755
    variables({
      :hostname => node[:fqdn],
      :sql_user => node[:datomic][:sql_user],
      :sql_password => node[:datomic][:sql_password],
      :sql_url => node[:datomic][:sql_url],
      :license_key => node[:datomic][:datomic_license_key],
      :protocol => protocol,
      :write_concurrency => node[:datomic][:concurrency][:write],
      :read_concurrency => node[:datomic][:concurrency][:read],
      :memcached_hosts => node[:datomic][:memcached_hosts],
      :memory_index_threshold => node[:datomic][:memory_index_threshold],
      :memory_index_max => node[:datomic][:memory_index_max],
      :object_cache_max => node[:datomic][:object_cache_max],
      :metrics_callback => node[:datomic][:metrics_callback],<commit_msg>remote file resources in the default provider now use :create_if_missing so they will not download the file if it exists already on the filesystem<commit_after>use_inline_resources

include DatomicLibrary::Mixin::Attributes
include DatomicLibrary::Mixin::Status

require 'etc'

action :install do
  remote_file local_file_path do
    source datomic_download_url
    owner username
    group username
    checksum node[:datomic][:checksum]
    action :create_if_missing
  end

  execute "unzip #{local_file_path} -d #{home_dir}" do
    cwd download_dir
    not_if { ::File.exists?(temporary_zip_dir) }
  end

  execute "chown -R #{username}:#{username} #{temporary_zip_dir}" do
    not_if { Etc.getpwuid(::File.stat(temporary_zip_dir).uid).name == username }
  end

  datomic_jars 'Install extra jars' do
    jars node[:datomic][:extra_jars]
    lib_dir "#{temporary_zip_dir}/lib"
    owner username
    group username
  end

  protocol = node[:datomic][:protocol]
  if(protocol == 'sql')
    ojdbc_jar_url = node[:datomic][:ojdbc_jar_url]

    Chef::Application.fatal! 'You must set node[:datomic][:ojdbc_jar_url]' if ojdbc_jar_url.nil?
    Chef::Application.fatal! 'The sql protocol requires a datomic license, specify with node[:datomic][:datomic_license_key]' if node[:datomic][:datomic_license_key].nil?

    ojdbc_file = "#{temporary_zip_dir}/lib/ojdbc.jar"

    remote_file ojdbc_file do
      source ojdbc_jar_url
      owner username
      group username
      checksum node[:datomic][:ojdbc_jar_checksum]
      action :create_if_missing
    end
  end

  riak_host = node[:datomic][:riak_host]
  riak_bucket = node[:datomic][:riak_bucket]

  if(protocol == 'riak')
    Chef::Application.fatal! 'You must set node[:datomic][:riak_host]' if riak_host.nil?
    Chef::Application.fatal! 'You must set node[:datomic][:riak_bucket]' if riak_bucket.nil?
  end

  template "#{temporary_zip_dir}/transactor.properties" do
    source 'transactor.properties.erb'
    owner username
    group username
    cookbook 'datomic'
    mode 00755
    variables({
      :hostname => node[:fqdn],
      :sql_user => node[:datomic][:sql_user],
      :sql_password => node[:datomic][:sql_password],
      :sql_url => node[:datomic][:sql_url],
      :license_key => node[:datomic][:datomic_license_key],
      :protocol => protocol,
      :write_concurrency => node[:datomic][:concurrency][:write],
      :read_concurrency => node[:datomic][:concurrency][:read],
      :memcached_hosts => node[:datomic][:memcached_hosts],
      :memory_index_threshold => node[:datomic][:memory_index_threshold],
      :memory_index_max => node[:datomic][:memory_index_max],
      :object_cache_max => node[:datomic][:object_cache_max],
      :metrics_callback => node[:datomic][:metrics_callback],
{'fraction_non_alphanumeric': 0.1272250327899569, 'fraction_numerical': 0.001873711823121604, 'mean_word_length': 4.654661016949152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4186153', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1754, 'n_words': 344}