<commit_before>#
# Cookbook Name:: hadoop
# Recipe:: hbase
#
# Copyright (C) 2013 Continuuity, Inc.
# 
# 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.
#

include_recipe 'hadoop::repo'
include_recipe 'hadoop::zookeeper'

package "hbase" do
  action :install
end

hbase_conf_dir = "/etc/hbase/#{node['hbase']['conf_dir']}"

directory hbase_conf_dir do
  mode "0755"
  owner "root"
  group "root"
  action :create
  recursive true
end

# Setup hbase-policy.xml hbase-site.xml
%w[ hbase_policy hbase_site ].each do |sitefile|
  if node['hbase'].has_key? sitefile
    myVars = { :options => node['hbase'][sitefile] }

    template "#{hbase_conf_dir}/#{sitefile.gsub('-','_')}.xml" do
      source "generic-site.xml.erb"
      mode "0644"
      owner "hdfs"
      group "hdfs"
      action :create
      variables myVars
    end
  end
end # End hbase-policy.xml hbase-site.xml

# Setup hbase-env.sh
if node['hbase'].has_key? 'hbase_env'
  myVars = { :options => node['hbase']['hbase_env'] }

  if node['hbase']['hbase_env'].has_key? 'hbase_log_dir'
    node['hbase']['hbase_env']['hbase_log_dir'].each do |dir|
      directory dir do
        owner "hdfs"
        group "hdfs"
        mode "0755"
        action :create
      end
    end
  end

  template "#{hbase_conf_dir}/hbase-env.sh" do
    source "generic-env.sh.erb"
    mode "0755"
    owner "hdfs"
    group "hdfs"
    action :create
    variables myVars
  end
end # End hbase-env.sh

# Setup hadoop-metrics.properties log4j.properties
%w[ hadoop_metrics log4j ].each do |propfile|
  if node['hbase'].has_key? propfile
    myVars = { :properties => node['hbase'][propfile] }

    template "#{hbase_conf_dir}/#{propfile.gsub('-','_')}.properties" do
      source "generic.properties.erb"
      mode "0644"
      owner "hdfs"
      group "hdfs"
      action :create
      variables myVars
    end
  end
end # End hadoop-metrics.properties log4j.properties

# Update alternatives to point to our configuration
execute "update hbase-conf alternatives" do
  command "update-alternatives --install /etc/hbase/conf hbase-conf /etc/hbase/#{node['hbase']['conf_dir']} 50"
  not_if "update-alternatives --display hbase-conf | grep best | awk '{print $5}' | grep /etc/hbase/#{node['hbase']['conf_dir']}"
end<commit_msg>Make sure hbase user owns hbase directories<commit_after>#
# Cookbook Name:: hadoop
# Recipe:: hbase
#
# Copyright (C) 2013 Continuuity, Inc.
# 
# 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.
#

include_recipe 'hadoop::repo'
include_recipe 'hadoop::zookeeper'

package "hbase" do
  action :install
end

hbase_conf_dir = "/etc/hbase/#{node['hbase']['conf_dir']}"

directory hbase_conf_dir do
  mode "0755"
  owner "root"
  group "root"
  action :create
  recursive true
end

# Setup hbase-policy.xml hbase-site.xml
%w[ hbase_policy hbase_site ].each do |sitefile|
  if node['hbase'].has_key? sitefile
    myVars = { :options => node['hbase'][sitefile] }

    template "#{hbase_conf_dir}/#{sitefile.gsub('-','_')}.xml" do
      source "generic-site.xml.erb"
      mode "0644"
      owner "hbase"
      group "hbase"
      action :create
      variables myVars
    end
  end
end # End hbase-policy.xml hbase-site.xml

# Setup hbase-env.sh
if node['hbase'].has_key? 'hbase_env'
  myVars = { :options => node['hbase']['hbase_env'] }

  if node['hbase']['hbase_env'].has_key? 'hbase_log_dir'
    node['hbase']['hbase_env']['hbase_log_dir'].each do |dir|
      directory dir do
        owner "hbase"
        group "hbase"
        mode "0755"
        action :create
      end
    end
  end

  template "#{hbase_conf_dir}/hbase-env.sh" do
    source "generic-env.sh.erb"
    mode "0755"
    owner "hdfs"
    group "hdfs"
    action :create
    variables myVars
  end
end # End hbase-env.sh

# Setup hadoop-metrics.properties log4j.properties
%w[ hadoop_metrics log4j ].each do |propfile|
  if node['hbase'].has_key? propfile
    myVars = { :properties => node['hbase'][propfile] }

    template "#{hbase_conf_dir}/#{propfile.gsub('-','_')}.properties" do
      source "generic.properties.erb"
      mode "0644"
      owner "hbase"
      group "hbase"
      action :create
      variables myVars
    end
  end
end # End hadoop-metrics.properties log4j.properties

# Update alternatives to point to our configuration
execute "update hbase-conf alternatives" do
  command "update-alternatives --install /etc/hbase/conf hbase-conf /etc/hbase/#{node['hbase']['conf_dir']} 50"
  not_if "update-alternatives --display hbase-conf | grep best | awk '{print $5}' | grep /etc/hbase/#{node['hbase']['conf_dir']}"
end
{'fraction_non_alphanumeric': 0.12684684684684686, 'fraction_numerical': 0.012252252252252252, 'mean_word_length': 3.553732567678425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, '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': '3169093', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1868, 'n_words': 535}