Module: TestingServer
- Defined in:
- lib/testing_server/testing_server.rb,
lib/testing_server.rb,
lib/testing_server/version.rb
Overview
Testing server. Assumes that content and backup servers are running. The server runs 24-7, generates/deletes files and validates content at backup periodically.
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
- .generate_mem_report ⇒ Object
- .init_log4r ⇒ Object
- .run_backup_testing_server ⇒ Object
- .run_content_testing_server ⇒ Object
- .send_email(is_master_ok, is_cur_synch_ok, is_backup_ok, numb_backuped_contents) ⇒ Object
Class Method Details
.generate_mem_report ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/testing_server/testing_server.rb', line 190 def generate_mem_report # Generate memory report current_objects_counters = {} time = Time.now current_objects_counters['Time'] = time.to_i count = ObjectSpace.each_object(String).count current_objects_counters['String'] = count count = ObjectSpace.each_object(ContentData::ContentData).count current_objects_counters['ContentData'] = count dir_count = ObjectSpace.each_object(FileMonitoring::DirStat).count current_objects_counters['DirStat'] = dir_count file_count = ObjectSpace.each_object(FileMonitoring::FileStat).count current_objects_counters['FileStat'] = file_count # Generate report and update global counters report = "" current_objects_counters.each_key { |type| $objects_counters[type] = 0 unless $objects_counters[type] diff = current_objects_counters[type] - $objects_counters[type] report += "Type:#{type} raised in:#{diff} \n" $objects_counters[type] = current_objects_counters[type] } final_report = "Memory report at Time:#{time}:\n#{report}\n" $log4r.info(final_report) final_report end |
.init_log4r ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/testing_server/testing_server.rb', line 41 def init_log4r #init log4r log_path = Params['testing_log_path'] unless log_path raise("pls specify testing log path through param:'testing_log_path'") end log_dir = File.dirname(log_path) FileUtils.mkdir_p(log_dir) unless File.exists?(log_dir) $log4r = Log4r::Logger.new 'BBFS testing server log' $log4r.trace = true formatter = Log4r::PatternFormatter.new(:pattern => "[%d] [%m]") #file setup file_config = { "filename" => Params['testing_log_path'], "maxsize" => Params['log_rotation_size'], "trunc" => true } file_outputter = Log4r::RollingFileOutputter.new("testing_log", file_config) file_outputter.level = Log4r::INFO file_outputter.formatter = formatter $log4r.outputters << file_outputter end |
.run_backup_testing_server ⇒ Object
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 = []; = Queue.new # used for synchronization between servers = Time.now.to_i # holds boolean whether all contents according to this timestamp that should be backed are backed and OK is_cur_synch_ok = nil # holds boolean whether all already backuped files are OK is_backup_ok = nil # holds boolean whether master is valid. receive from master is_master_ok = nil # number of contents must be backuped this synch # with current scenarios this number expected to grow # used to check that file_generator is actually running numb_backuped_contents = 0 all_threads << Thread.new do ContentServer.run_backup_server end receive_msg_proc = lambda do || $log4r.info("message received: #{}") .push() end tcp = Networking::TCPClient.new(Params['content_server_hostname'], Params['testing_server_port'], receive_msg_proc) all_threads << tcp.tcp_thread # used to request index from master per validation interval of time all_threads << Thread.new do while(true) do sleep Params['validation_interval'] = Time.now.to_i tcp.send_obj([:GET_INDEX, ]) $log4r.info "GET_INDEX sent with timestamp #{}" end end # gets messages from master via queue # handles them according to type while(true) do msg_type, , msg_body = .pop $log4r.info "#{msg_type} : #{} : #{msg_body.class}" unless ( == ) # TODO problem of servers synch. What should be done here? $log4r.warning "Timestamps differs: requested #{} : received #{}" end case msg_type when :PUT_INDEX # index of already backuped contents backuped_index = ContentData::ContentData.new backuped_index.from_file Params['local_content_data_path'] # index contains only master current contents # that must be backuped according to backup_time_requirement parameter index_must_be_backuped = ContentData::ContentData.new(msg_body) # we backup contents, so content mtime used to determine contents should be validated index_must_be_backuped.each_content do |checksum, size, mtime| if ( - 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 |
.run_content_testing_server ⇒ Object
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 |
# File 'lib/testing_server/testing_server.rb', line 65 def run_content_testing_server Log.info('Testing server started') init_log4r $log4r.info 'Testing server started' all_threads = []; = Queue.new all_threads << Thread.new do ContentServer.run_content_server end all_threads << Thread.new do fg = FileGenerator::FileGenerator.new fg.run end receive_msg_proc = lambda do |addr_info, | $log4r.info("message received: #{}") .push() end tcp = Networking::TCPServer.new(Params['testing_server_port'], receive_msg_proc) all_threads << tcp.tcp_thread while(true) do msg_type, = .pop if msg_type == :GET_INDEX cur_index = ContentData::ContentData.new cur_index.from_file(Params['local_content_data_path']) tcp.send_obj([:PUT_INDEX, , cur_index]) $log4r.info "PUT_INDEX sent with timestamp #{}" is_index_ok = cur_index.validate tcp.send_obj([:PUT_VALIDATION, , is_index_ok]) $log4r.info "PUT_VALIDATION sent with timestamp #{}" end end end |
.send_email(is_master_ok, is_cur_synch_ok, is_backup_ok, numb_backuped_contents) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/testing_server/testing_server.rb', line 216 def send_email(is_master_ok, is_cur_synch_ok, is_backup_ok, numb_backuped_contents) msg =<<EOF Master index ok: #{is_master_ok} Backup index ok: #{is_backup_ok} Backup includes all master files upto -#{Params['backup_time_requirement']} sec: #{is_cur_synch_ok} Number of contents must be back-up: #{numb_backuped_contents} #{generate_mem_report} EOF Email.send_email(Params['from_email'], Params['from_email_password'], Params['to_email'], 'Testing server update', msg) end |