-
Notifications
You must be signed in to change notification settings - Fork 2
/
rakefile
165 lines (123 loc) · 6.17 KB
/
rakefile
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require 'net/http'
require 'uri'
require 'rake/clean'
NEO4J_VERSION = ENV['VERSION'] ? ENV['VERSION'] : '1.8-SNAPSHOT'
local_ip = 'localhost'
# This is where you configure the product version
extension = RUBY_PLATFORM =~ /i386/ ? "windows.zip" : "unix.tar.gz"
filename = "neo4j-enterprise-#{NEO4J_VERSION}"
CLEAN.include(['machineA', 'machineB', 'machineC', "neo4j-enterprise-#{NEO4J_VERSION}", filename])
archive = filename + "-" + extension
# Three machines by default. You can add more, but be sure to give each a unique name
machines = ["machineA", "machineB", "machineC"]
cluster_name="local.jvm.only.cluster"
zk_client_port = 2181
web_server_port = 7474
https_port = 8484
ha_server_id = 1
ha_server = 6001
jmx_port = 3637
backup_port = 1234
def replace_in_file(regex, replacement, file)
text = File.read(file)
str = text.gsub(regex, replacement)
File.open(file, "w") { |file| file << str }
end
def coordinators_list(machines, local_ip, start_port)
str = "ha.coordinators="
machines = (1..machines.length).collect { |i| "#{local_ip}:#{(start_port + i) -1 }" }.join(',')
str + machines
end
def server_list(machines, local_ip)
(1..machines.length).collect {|i| "server.#{i}=#{local_ip}:#{(2888 +i-1)}:#{(3888 +i-1)}\n" }.to_s
end
task :download_neo4j do
puts 'Looking for: ' + archive
unless File.exists?(archive)
uri = "http://dist.neo4j.org/"
sh "wget #{uri + archive}"
end
end
task :uncompress => :download_neo4j do
next if File.exists?(filename)
if RUBY_PLATFORM =~ /i386/
puts "Unzipping: #{archive}"
command = "unzip #{archive}"
else
puts "untarring: " + archive
command = "tar -xzf " + archive
end
sh command
end
task :clone => :uncompress do
machines.each { |machine| cp_r filename, machine }
end
def neo_command(command)
commands = {:windows => {:backup => 'Neo4jBackup.bat', :shell => 'Neo4jShell', :coordinator => 'Neo4jCoordinator'},
:unix => {:backup => 'neo4j-backup', :shell => 'neo4j-shell', :coordinator => 'neo4j-coordinator'}}
platform = RUBY_PLATFORM =~ /i386/ ? :windows : :unix
commands[platform][command.to_sym]
end
task :change_config do
machine_list = server_list(machines, local_ip)
machines.each_with_index do |machine, i|
local_ha_server_port = (ha_server+i).to_s
local_web_server_port = (web_server_port+i).to_s
local_backup_port = (backup_port + i).to_s
local_zk_client_port = (zk_client_port+i).to_s
local_web_server_https_port = (https_port+i).to_s
local_ha_server_id = (ha_server_id+i).to_s
local_jmx_port = (jmx_port+i).to_s
replace_in_file('ha.pull_interval = 10', 'ha.pull_interval = 1ms', "#{machine}/conf/neo4j.properties")
replace_in_file('#ha.coordinators=localhost:2181', coordinators_list(machines, local_ip, zk_client_port), "#{machine}/conf/neo4j.properties")
replace_in_file('#ha.cluster_name =', "ha.cluster_name=#{cluster_name}", "#{machine}/conf/neo4j.properties")
replace_in_file('enable_online_backup=true', "enable_online_backup=port=#{local_backup_port}", "#{machine}/conf/neo4j.properties")
replace_in_file('#ha.server_id=', "ha.server_id=#{local_ha_server_id}", "#{machine}/conf/neo4j.properties")
replace_in_file("#ha.server = localhost:6001", "ha.server = #{local_ip}:#{local_ha_server_port}", "#{machine}/conf/neo4j.properties")
replace_in_file('server.1=localhost:2888:3888', machine_list, "#{machine}/conf/coord.cfg")
replace_in_file('#server.2=my_second_server:2889:3889', "", "#{machine}/conf/coord.cfg")
replace_in_file('#server.3=192.168.1.1:2890:3890', "", "#{machine}/conf/coord.cfg")
replace_in_file('clientPort=2181', "clientPort=#{local_zk_client_port}", "#{machine}/conf/coord.cfg")
replace_in_file('org.neo4j.server.webserver.port=7474', "org.neo4j.server.webserver.port=#{local_web_server_port}", "#{machine}/conf/neo4j-server.properties")
replace_in_file('NEO4J_SERVER_PORT=${org_neo4j_server_webserver_port:=7474}', "NEO4J_SERVER_PORT=${org_neo4j_server_webserver_port:=#{local_web_server_port}}", "#{machine}/bin/neo4j")
replace_in_file('org.neo4j.server.webserver.https.port=7473', "org.neo4j.server.webserver.https.port=#{local_web_server_https_port}", "#{machine}/conf/neo4j-server.properties")
replace_in_file('#org.neo4j.server.database.mode=HA', "org.neo4j.server.database.mode=HA", "#{machine}/conf/neo4j-server.properties")
replace_in_file('#wrapper.java.additional.3=-Dcom.sun.management.jmxremote.port=3637', "wrapper.java.additional.3=-Dcom.sun.management.jmxremote.port=#{local_jmx_port}", "#{machine}/conf/neo4j-wrapper.conf")
replace_in_file('#wrapper.java.additional.4=-Dcom.sun.management.jmxremote.authenticate=true', "wrapper.java.additional.4=-Dcom.sun.management.jmxremote.authenticate=false#{local_jmx_port}", "#{machine}/conf/neo4j-wrapper.conf")
end
end
task :start_coordinators do
count = 1
machines.each do |machine|
File.open(machine + '/data/coordinator/myid', "w") { |file| file << count }
count += 1
end
machines.each do |machine|
sh "#{machine}/bin/#{neo_command(:coordinator)} start &"
end
puts "waiting a sec for the coordinators to be ready ...."
sleep 10
end
task :start_cluster do
machines.each do |machine|
sh "#{machine}/bin/neo4j start &"
sleep 10
end
end
task :setup_cluster => [:clone, :change_config, :start_coordinators, :start_cluster]
task :test => :setup_cluster do
# Create a node on machineA
sh(machines[0] + "/bin/#{neo_command(:shell)} -c mknode")
# Make sure it's propagated to the slaves
sh(machines[1] + "/bin/#{neo_command(:shell)} -c \"cd -a 1 && set name prop1\"")
#do an onine backup on machine 3
sh(machines[2].to_s + "/bin/#{neo_command(:backup)} -full -from ha://"+local_ip+":"+zk_client_port.to_s + " -to " + machines[2].to_s+ "/backup -ha.cluster_name "+cluster_name)
# Create a node on machineC
sh(machines[2] + "/bin/#{neo_command(:shell)} -c mknode")
#stop master (machineA)
sh(machines[0].to_s << "/bin/neo4j stop")
#incremental backup
sh(machines[2].to_s + "/bin/#{neo_command(:backup)} -incremental -from ha://"+local_ip+":"+(zk_client_port+1).to_s + " -to " + machines[2].to_s+ "/backup -ha.cluster_name "+cluster_name)
end
task :qa => [:download_neo4j, :setup_cluster, :test]
task :default => :qa