This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathoffset_monitor.rb
138 lines (115 loc) · 4.21 KB
/
offset_monitor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# coding: UTF-8
# Cookbook Name:: cerner_kafka
# Recipe:: offset_monitor
# Create an array for storing errors we should verify before doing anything
errors = Array.new
# Verify we have a list of zookeeper instances
if node["kafka"]["zookeepers"].nil? || (!node["kafka"]["zookeepers"].is_a? Array) || node["kafka"]["zookeepers"].empty?
errors.push "node[:kafka][:zookeepers] was not set properly. It was either nil, not an Array, or empty."
end
# Raise an exception if there are any problems
raise "Unable to run kafka::offsetmonitor : [#{errors.join ", "}]" unless errors.empty?
# Set all default attributes that are built from other attributes
node.default["kafka"]["offset_monitor"]["install_dir"] = "#{node["kafka"]["base_dir"]}/KafkaOffsetMonitor"
zookeepers = node["kafka"]["zookeepers"].join ","
zookeepers += node["kafka"]["zookeeper_chroot"] unless node["kafka"]["zookeeper_chroot"].nil?
node.default["kafka"]["offset_monitor"]["options"]["--zk"] = zookeepers
log4j_jar_path = File.join(node["kafka"]["offset_monitor"]["install_dir"], 'log4j.jar')
log "Installing #{node["kafka"]["offset_monitor"]["url"]} to #{node["kafka"]["offset_monitor"]["install_dir"]}"
include_recipe "java"
# setup kafka group
group node["kafka"]["group"] do
action :create
end
# setup kafka user
user node["kafka"]["user"] do
comment "Kafka user"
gid node["kafka"]["group"]
shell "/bin/bash"
home "/home/#{node["kafka"]["user"]}"
manage_home true
end
# Ensure the Kafka log directory exists
directory node["kafka"]["log_dir"] do
action :create
owner node["kafka"]["user"]
group node["kafka"]["group"]
mode 00755
recursive true
end
# Ensure the install directory exists
directory node["kafka"]["offset_monitor"]["install_dir"] do
action :create
owner node["kafka"]["user"]
group node["kafka"]["group"]
mode 00755
recursive true
end
# Download kafka offset monitor jar
remote_file File.join(node["kafka"]["offset_monitor"]["install_dir"], 'KafkaOffsetMonitor.jar') do
action :create
source node["kafka"]["offset_monitor"]["url"]
owner node["kafka"]["user"]
group node["kafka"]["group"]
mode 00644
backup false
notifies :restart, "service[kafka-offset-monitor]"
end
if node["kafka"]["offset_monitor"]["include_log4j_jar"]
# Download and include the log4j binding jar for offset monitor
remote_file log4j_jar_path do
action :create
source node["kafka"]["offset_monitor"]["log4j_url"]
owner node["kafka"]["user"]
group node["kafka"]["group"]
mode 00644
backup false
notifies :restart, "service[kafka-offset-monitor]"
end
else
# Ensure the log4j file is removed
file log4j_jar_path do
action :delete
notifies :restart, "service[kafka-offset-monitor]"
end
end
# logging config for the offset monitor
template File.join(node["kafka"]["offset_monitor"]["install_dir"], 'offset_monitor_log4j.properties') do
source "key_equals_value.erb"
owner node["kafka"]["user"]
group node["kafka"]["group"]
variables({
:properties => node["kafka"]["offset_monitor"]["log4j.properties"].to_hash
})
mode 00755
notifies :restart, "service[kafka-offset-monitor]"
end
# Write JAAS configuration file if enabled
if node["kafka"]["kerberos"]["enable"]
jaas_path = "#{node['kafka']['offset_monitor']['install_dir']}/jaas.conf"
# add JAAS config location as default JVM parameter
node.default['kafka']['offset_monitor']['java_options']['-Djava.security.auth.login.config='] = jaas_path
# Verify required attributes are set
raise "Kerberos keytab location must be configured" if node["kafka"]["kerberos"]["keytab"].nil?
raise "Kerberos realm or principal must be configured" if node["kafka"]["kerberos"]["principal"].end_with? '@'
template jaas_path do
source "jaas_client_config.erb"
owner node["kafka"]["user"]
group node["kafka"]["group"]
mode 00755
notifies :restart, "service[kafka-offset-monitor]"
end
end
# Create init.d script for kafka offset monitor
template "/etc/init.d/kafka-offset-monitor" do
source "kafka_offset_monitor_initd.erb"
owner "root"
group "root"
mode 00755
notifies :restart, "service[kafka-offset-monitor]"
end
# Start/Enable kafka offset monitor service
service "kafka-offset-monitor" do
action [:enable, :start]
supports :restart => true
end