def __init__(self, cluster_config): WorkerHandler.__init__(self, cluster_config['key'], cluster_config['nodes'][0], cluster_config['port'], cluster_config['node_name']) self.config = cluster_config self.integrity_received_and_processed = threading.Event() self.integrity_received_and_processed.clear() # False
def process_request(self, command, data): logger.debug("[Worker] [Request-R ]: '{0}'.".format(command)) if command == 'echo-m': return 'ok-m ', data.decode() elif command == 'sync_m_c': cmf_thread = WorkerProcessMasterFiles(manager_handler=self, filename=data, stopper=self.stopper) cmf_thread.start() return 'ack', self.set_worker_thread(command, cmf_thread, data) elif command == 'sync_m_c_ok': logger.info("[Worker] [Integrity ]: The master has verified that the integrity is right.") self.integrity_received_and_processed.set() return 'ack', "Thanks2!" elif command == 'sync_m_c_err': logger.info("[Worker] [Integrity ]: The master was not able to verify the integrity.") self.integrity_received_and_processed.set() return 'ack', "Thanks!" elif command == 'file_status': master_files = get_files_status('master', get_md5=True) worker_files = get_files_status('worker', get_md5=True) files = master_files files.update(worker_files) return 'json', json.dumps(files) else: return WorkerHandler.process_request(self, command, data)
def process_response(self, response): # FixMe: Move this line to communications answer, payload = self.split_data(response) logger.debug("[Worker] [Response-R ]: '{0}'.".format(answer)) if answer == 'ok-c': # test response_data = '[response_only_for_worker] Master answered: {}.'.format(payload) else: response_data = WorkerHandler.process_response(self, response) return response_data
def handle_connect(self): WorkerHandler.handle_connect(self) dir_path = "{}/queue/cluster/{}".format(common.ossec_path, self.name) if not os.path.exists(dir_path): mkdir_with_mode(dir_path)