def send_checksum_info(self): try: for rmt_host in self.alive_workers: if rmt_host != self.host: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((rmt_host, self.worker_port)) send_all_encrypted(sock, 'buffer_count') send_all_encrypted(sock, self.send_buffer_count[rmt_host]) except KeyboardInterrupt: raise except: pass #forfeit the current compute
def broadCastFile_delete(self, targets, filename): for target in targets: try: target_host, target_nodeName, sock = self.getParams(target) except: continue send_all_encrypted(sock, self.message_delete_file) send_all_encrypted(sock, filename) logging.debug( stampedMsg( '{} asking for deletion of file {} to node {}'.format( self.nodeName, filename, target_nodeName)))
def broadCastData_delete(self, targets, data): # in this case, data is just filename for target in targets: try: target_host, target_nodeName, sock = self.getParams(target) except: continue send_all_encrypted(sock, self.message_delete_data) send_all_encrypted(sock, data) logging.debug( stampedMsg('broadCast file data deletion: {}'.format(data)))
def load_and_preprocess(self, conn, addr): start_time = time.time() print('receive command to load file') self.addr = addr[0] self.input_filename, self.v_to_m_dict, self.num_vertices = receive_all_decrypted( conn) self.input_filename, _ = receive_all_to_target(conn, 0.001) self.preprocess(self.input_filename) print('preprocess done after {} seconds'.format(time.time() - start_time)) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.addr, self.master_port)) send_all_encrypted(sock, Commons.ack_preprocess)
def collect_results(self): self.result_files = [0] * self.num_workers for ix in range(self.num_workers): worker = self.alive_workers[ix] self.result_files[ix] = 'file_piece_' + str(ix) + '_out' self.send_to_worker( [Commons.request_result, self.result_files[ix]], worker) while (self.num_process_done < self.num_workers): sleep(1) for ix in range(self.num_workers): dfsWrapper(self.dfs.getFile, self.result_files[ix]) combine_files(self.output_filename, self.result_files) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.client_ip, self.driver_port)) send_all_encrypted(sock, self.client_message) send_all_from_file(sock, self.output_filename, 0.001) self.remote_end_tasks()
def onProcessFail(self, failed_process): failed_process = failed_process.split('_')[0] failed_ip = socket.gethostbyname(failed_process) if self.role == 'master' and failed_ip in self.masters_workers[ 2:] and failed_ip not in self.dup_check: #print('One of the workers {} has left...'.format(failed_process)) self.dup_check[failed_ip] = True sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.host, self.master_port)) send_all_encrypted(sock, self.message_fail) send_all_encrypted(sock, failed_ip) elif self.role == 'standby' and failed_ip == self.masters_workers[0]: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.host, self.port)) send_all_encrypted(sock, self.message_congrats) send_all_encrypted(sock, failed_ip)
def send_to_worker(self, list_of_things, worker): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((worker, self.worker_port)) send_all_encrypted(sock, list_of_things[0]) send_all_encrypted(sock, list_of_things[1:]) return sock
def server_task(self): #first, start local timer, the rest of the process follows this timer self.timer.tic() # a monitor receive message, check and response, also multicase failure message self.monitor = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.monitor.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.monitor.bind((self.host, self.port)) self.monitor.listen(5) # self.monitor.listen(10) # UDP doesn't support this logging.info(stampedMsg('FS Monitoring process opens.')) # keep receiving msgs from other VMs # receiving heartbeat and other messages # pdb.set_trace() while True: try: conn, addr = self.monitor.accept() rmtHost = socket.gethostbyaddr(addr[0])[0] logging.debug( stampedMsg('FS Monitor recieve instruction from {}'). format(rmtHost)) except socket.error, e: logging.warning("Caught exception socket.error : %s" % e) logging.warning( stampedMsg('Fail to receive signal from clients {}'.format( rmtHost))) break #TODO: should we break listening if UDP reception has troubles? message = receive_all_decrypted(conn) # the instruction if not message: # possibly never called in UDP logging.info( stampedMsg('Receiving stop signal from clients {}'.format( rmtHost))) break # log whatever recieved logging.debug(stampedMsg(message)) if message == self.message_file: # if receive leave signal # include filename info for debugging purposes if rmtHost == self.hostName: filename = str(receive_all_decrypted(conn)) else: filename, _ = receive_all_to_target( conn, self.messageInterval) logging.info( stampedMsg('receiving file {} from {}'.format( filename, rmtHost))) self.local_file_info[filename] = datetime.datetime.now( ).isoformat() if filename in self.global_file_info: self.global_file_info[filename][0] = self.timer.toc() elif message == self.message_data: # .... filename, file_nodes = receive_all_decrypted(conn) filename = str( filename) # get rid of annoying utf-encoding prefix file_nodes = list(map(str, file_nodes)) self.global_file_info[filename] = [ self.timer.toc(), file_nodes ] elif message == self.message_ask_time: filename = receive_all_decrypted(conn) send_all_encrypted(conn, self.local_file_info[filename]) elif message == self.message_ask_file: filename = receive_all_decrypted(conn) send_all_from_file(conn, filename, self.messageInterval) elif message == self.message_delete_data: filename = receive_all_decrypted(conn) if filename in self.global_file_info: del self.global_file_info[filename] elif message == self.message_delete_file: filename = receive_all_decrypted(conn) if filename in self.local_file_info: del self.local_file_info[filename] try: os.remove(filename) except: logging.debug( stampedMsg( 'Deleting file {} failed'.format(filename)))