<commit_before>#
# Author: <NAME> (<<EMAIL>>)
# Cookbook Name:: wt_kafka_mm
# Recipe:: mirror_monitor
#
# Copyright 2012, Webtrends
#

log "Deploy build is #{ENV["deploy_build"]}"
if ENV["deploy_build"] == "true" then
    log "The deploy_build value is true so un-deploy first"
else
    log "The deploy_build value is not set or is false so we will only update the configuration"
end

log_dir = File.join(node['wt_common']['log_dir_linux'], "/mirrormonitor")
install_dir = File.join(node['wt_common']['install_dir_linux'], "/mirrormonitor")

user = node['wt_kafka_mm']['user']
group = node['wt_kafka_mm']['group']

java_home = node['java']['java_home']
java_opts = node['wt_kafka_mm']['java_opts']

jmx_port = node['wt_kafka_mm']['monitor_jmx_port']

###############################################################
#
# Helper Functions
#
###############################################################

#Get the zookeeper instances in the specified environment
def getZookeeperPairs(node, env)

    # get the correct environment for the zookeeper nodes
    zookeeper_port = node['zookeeper']['client_port']

    # grab the zookeeper nodes that are currently available
    zookeeper_pairs = Array.new
    if not Chef::Config.solo
        search(:node, "role:zookeeper AND chef_environment:#{env}").each do |n|
            zookeeper_pairs << n[:fqdn]
        end
    end

    log "#{zookeeper_pairs.size} instances of zookeeper found found in #{env}"

    # append the zookeeper client port (defaults to 2181)

    i = 0
    while i < zookeeper_pairs.size do
        zookeeper_pairs[i] = zookeeper_pairs[i].concat(":#{zookeeper_port}")
        i += 1
    end

    return zookeeper_pairs
end

#update the config files
def processConfTemplates (install_dir, node, log_dir)

    #Ugly - manually create the json string
    srcEnvs = "{\"environments\":["
    count = 0;
    node['wt_kafka_mm']['sources'].each { |src_env|
      if count !=  0
        srcEnvs += ","
      end
      srcEnvs += "{\"name\":\"#{src_env}\",\"zkConnect\":\"#{getZookeeperPairs(node, src_env).join(',')}\"}"
      count += 1
    }
    srcEnvs += "]}"

    #zookeeper_pairs_target = getZookeeperPairs(node, node["wt_kafka_mm"]["target"])
    tgtEnv = "{\"name\":\"#{node["wt_kafka_mm"]["target"]}\",\"zkConnect\":\"#{getZookeeperPairs(node, node["wt_kafka_mm"]["target"]).join(',')}\"}"

    # Set up the main mirror monitor config
        template "#{install_dir}/conf/config.properties" do
      source  "mirrormonitor.config.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
        :mirrorsources  => srcEnvs,
        :mirrormachineid => node["wt_kafka_mm"]["id"],
        :mirrortarget => tgtEnv,
        :averagecount => node["wt_kafka_mm"]["averagecount"],
        :ratethreshold => node["wt_kafka_mm"]["ratethreshold"],
        :avgthreshold => node["wt_kafka_mm"]["avgthreshold"],
        :producerate => node["wt_kafka_mm"]["producerate"]
      })
    end

    # Set up the monitor producer config
        template "#{install_dir}/conf/producer.properties" do
      source  "monitor.producer.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
      })
    end

    # Set up the monitor consumer config
        template "#{install_dir}/conf/consumer.properties" do
      source  "monitor.consumer.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
      })
    end

    # Set up the monitoring properties
        template "#{install_dir}/conf/monitoring.properties" do
      source  "monitor.monitoring.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
      })
    end

    # log4j
    template "#{install_dir}/conf/log4j.xml" do
      source  "log4j.xml.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
        :log_file => "#{log_dir}/mirrormonitor.log",
        :log_level => node['wt_kafka_mm']['log_level']<commit_msg>Adding format fixes.<commit_after>#
# Author: <NAME> (<<EMAIL>>)
# Cookbook Name:: wt_kafka_mm
# Recipe:: mirror_monitor
#
# Copyright 2012, Webtrends
#

log "Deploy build is #{ENV["deploy_build"]}"
if ENV["deploy_build"] == "true" then
    log "The deploy_build value is true so un-deploy first"
else
    log "The deploy_build value is not set or is false so we will only update the configuration"
end

log_dir = File.join(node['wt_common']['log_dir_linux'], "/mirrormonitor")
install_dir = File.join(node['wt_common']['install_dir_linux'], "/mirrormonitor")

user = node['wt_kafka_mm']['user']
group = node['wt_kafka_mm']['group']

java_home = node['java']['java_home']
java_opts = node['wt_kafka_mm']['java_opts']

jmx_port = node['wt_kafka_mm']['monitor_jmx_port']

###############################################################
#
# Helper Functions
#
###############################################################

#Get the zookeeper instances in the specified environment
def getZookeeperPairs(node, env)

    # get the correct environment for the zookeeper nodes
    zookeeper_port = node['zookeeper']['client_port']

    # grab the zookeeper nodes that are currently available
    zookeeper_pairs = Array.new
    if not Chef::Config.solo
        search(:node, "role:zookeeper AND chef_environment:#{env}").each do |n|
            zookeeper_pairs << n[:fqdn]
        end
    end

    log "#{zookeeper_pairs.size} instances of zookeeper found found in #{env}"

    # append the zookeeper client port (defaults to 2181)

    i = 0
    while i < zookeeper_pairs.size do
        zookeeper_pairs[i] = zookeeper_pairs[i].concat(":#{zookeeper_port}")
        i += 1
    end

    return zookeeper_pairs
end

#update the config files
def processConfTemplates (install_dir, node, log_dir)

    #Ugly - manually create the json string
    srcEnvs = "{\"environments\":["
    count = 0;
    node['wt_kafka_mm']['sources'].each { |src_env|
      if count !=  0
        srcEnvs += ","
      end
      srcEnvs += "{\"name\":\"#{src_env}\",\"zkConnect\":\"#{getZookeeperPairs(node, src_env).join(',')}\"}"
      count += 1
    }
    srcEnvs += "]}"

    #zookeeper_pairs_target = getZookeeperPairs(node, node["wt_kafka_mm"]["target"])
    tgtEnv = "{\"name\":\"#{node["wt_kafka_mm"]["target"]}\",\"zkConnect\":\"#{getZookeeperPairs(node, node["wt_kafka_mm"]["target"]).join(',')}\"}"

    # Set up the main mirror monitor config
    template "#{install_dir}/conf/config.properties" do
      source  "mirrormonitor.config.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
        :mirrorsources  => srcEnvs,
        :mirrormachineid => node["wt_kafka_mm"]["id"],
        :mirrortarget => tgtEnv,
        :averagecount => node["wt_kafka_mm"]["averagecount"],
        :ratethreshold => node["wt_kafka_mm"]["ratethreshold"],
        :avgthreshold => node["wt_kafka_mm"]["avgthreshold"],
        :producerate => node["wt_kafka_mm"]["producerate"]
      })
    end

    # Set up the monitor producer config
    template "#{install_dir}/conf/producer.properties" do
      source  "monitor.producer.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
      })
    end

    # Set up the monitor consumer config
    template "#{install_dir}/conf/consumer.properties" do
      source  "monitor.consumer.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
      })
    end

    # Set up the monitoring properties
    template "#{install_dir}/conf/monitoring.properties" do
      source  "monitor.monitoring.properties.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
      })
    end

    # log4j
    template "#{install_dir}/conf/log4j.xml" do
      source  "log4j.xml.erb"
      owner   "root"
      group   "root"
      mode    00644
      variables({
        :log_file => "#{log_dir}/mirrormonitor.log",
        :log_level => node['wt_kafka_mm']['log_level']
{'fraction_non_alphanumeric': 0.16764156813939016, 'fraction_numerical': 0.010205351586807717, 'mean_word_length': 3.2294736842105265, 'pattern_counts': {'":': 12, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4661654', 'n_tokens_mistral': 2699, 'n_tokens_neox': 2636, 'n_words': 575}