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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/testing_server/testing_server.rb', line 104
def run_backup_testing_server
Log.info('Testing server started')
init_log4r
$log4r.info 'Testing server started'
all_threads = [];
messages = Queue.new
validation_timestamp = Time.now.to_i
is_cur_synch_ok = nil
is_backup_ok = nil
is_master_ok = nil
numb_backuped_contents = 0
all_threads << Thread.new do
ContentServer.run_backup_server
end
receive_msg_proc = lambda do |message|
$log4r.info("message received: #{message}")
messages.push(message)
end
tcp = Networking::TCPClient.new(Params['content_server_hostname'],
Params['testing_server_port'], receive_msg_proc)
all_threads << tcp.tcp_thread
all_threads << Thread.new do
while(true) do
sleep Params['validation_interval']
validation_timestamp = Time.now.to_i
tcp.send_obj([:GET_INDEX, validation_timestamp])
$log4r.info "GET_INDEX sent with timestamp #{validation_timestamp}"
end
end
while(true) do
msg_type, response_validation_timestamp, msg_body = messages.pop
$log4r.info "#{msg_type} : #{validation_timestamp} : #{msg_body.class}"
unless (validation_timestamp == response_validation_timestamp)
$log4r.warning "Timestamps differs: requested #{validation_timestamp} : received #{response_validation_timestamp}"
end
case msg_type
when :PUT_INDEX
backuped_index = ContentData::ContentData.new
backuped_index.from_file Params['local_content_data_path']
index_must_be_backuped = ContentData::ContentData.new(msg_body)
index_must_be_backuped.each_content do |checksum, size, mtime|
if (validation_timestamp - mtime < Params['backup_time_requirement'])
index_must_be_backuped.remove_content checksum
end
end
is_cur_synch_ok =
Validations::IndexValidations.validate_remote_index index_must_be_backuped, backuped_index
is_backup_ok = backuped_index.validate
numb_backuped_contents = index_must_be_backuped.contents_size
when :PUT_VALIDATION
is_master_ok = msg_body
else
$log4r.error "Incorrect message received: #{msg_type}"
end
unless (is_master_ok.nil? || is_cur_synch_ok.nil? || is_backup_ok.nil?)
send_email is_master_ok, is_cur_synch_ok, is_backup_ok, numb_backuped_contents
is_master_ok = nil
is_cur_synch_ok = nil
is_backup_ok = nil
numb_backuped_contents = 0
end
end
end
|