def send_result_files_back_to_client(\ self,\ input_files,\ output_files): """Send the result (output files and output messages) to the client, and replace the temporary input file names in the various messages by the original ones.""" #clean temporary input files created for tmp_input_file in input_files.values(): os.unlink(tmp_input_file) # FIXME: don't forget to send stdout and stderr # then send output files back to the client for original_output_file_name in output_files.keys(): self.__client_socket.send(Protocol.FILE_COMMAND) ProtocolUtils.send_data(self.__client_socket, original_output_file_name) # send the file tmp_output_file = open(\ output_files[original_output_file_name], 'rb') if __debug__: syslog.syslog(syslog.LOG_DEBUG | syslog.LOG_DAEMON, "Sending file : "\ + output_files[original_output_file_name]) ProtocolUtils.send_data(self.__client_socket, tmp_output_file.read()) tmp_output_file.close() os.unlink(output_files[original_output_file_name]) if __debug__: syslog.syslog(syslog.LOG_DEBUG | syslog.LOG_DAEMON, "File sent : "\ + output_files[original_output_file_name])
def send_result_files_back_to_client(\ self,\ input_files,\ output_files): """Send the result (output files and output messages) to the client, and replace the temporary input file names in the various messages by the original ones.""" #clean temporary input files created for tmp_input_file in input_files.values(): os.unlink(tmp_input_file) # FIXME: don't forget to send stdout and stderr # then send output files back to the client for original_output_file_name in output_files.keys(): self.__client_socket.send(Protocol.FILE_COMMAND) ProtocolUtils.send_data(self.__client_socket, original_output_file_name) # send the file tmp_output_file = open(\ output_files[original_output_file_name], 'rb') if __debug__: syslog.syslog(syslog.LOG_DEBUG | syslog.LOG_DAEMON, "Sending file : "\ + output_files[original_output_file_name]) ProtocolUtils.send_data(self.__client_socket, tmp_output_file.read()) tmp_output_file.close() os.unlink(output_files[original_output_file_name]) if __debug__: syslog.syslog(syslog.LOG_DEBUG | syslog.LOG_DAEMON, "File sent : "\ + output_files[original_output_file_name])
def send_output_messages(self, msg_stdout, msg_stderr, input_files,\ output_files): # replace temporary filenames in messages for original_input_file in input_files.keys(): msg_stdout = msg_stdout.replace(\ input_files[original_input_file],\ original_input_file) msg_stderr = msg_stderr.replace(\ input_files[original_input_file],\ original_input_file) # send stdout messages ProtocolUtils.send_data(self.__client_socket, msg_stdout) # send stderr messages ProtocolUtils.send_data(self.__client_socket, msg_stderr)
def send_output_messages(self, msg_stdout, msg_stderr, input_files,\ output_files): # replace temporary filenames in messages for original_input_file in input_files.keys(): msg_stdout = msg_stdout.replace(\ input_files[original_input_file],\ original_input_file) msg_stderr = msg_stderr.replace(\ input_files[original_input_file],\ original_input_file) # send stdout messages ProtocolUtils.send_data(self.__client_socket, msg_stdout) # send stderr messages ProtocolUtils.send_data(self.__client_socket, msg_stderr)
def __execute_command_remotely(self, preprocessed_files): """Execute the command associated with this compiler instance on a remote host and get the results back.""" if __debug__: print >> sys.stderr, "Distant execution of the command : "\ + " ".join(self.__compiler_command.get_after_preprocessing_options()) # here, the scheduler give an hostname to which # we would send the compilation job #FIXME: catch exception here self.__scheduler_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__scheduler_socket.connect((self.__config['scheduler_address'], int(self.__config['scheduler_port']))) ProtocolUtils.send_data(self.__scheduler_socket, Protocol.REQUEST_HOST) compiler_host = ProtocolUtils.recv_data(self.__scheduler_socket) self.__scheduler_socket.close() self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # here we connect to the compiler_host self.__socket.connect((compiler_host,\ Protocol.COMPILER_DAEMON_PORT)) # ask for a compilation job self.__socket.send(Protocol.COMPILE_COMMAND) # send the compilation command line ProtocolUtils.send_data(self.__socket, " ".join(self.__compiler_command.get_after_preprocessing_options())) # send each file along with their name if __debug__: print >> sys.stderr, "List of files to send : " + str(preprocessed_files) for (tmp_input_file, input_file_name) in preprocessed_files: if __debug__: print >> sys.stderr, "Sending of a preprocessed file: %s" % input_file_name self.__socket.send(Protocol.FILE_COMMAND) # send the file name ProtocolUtils.send_data(self.__socket, input_file_name) # send the file content # FIXME: currently we don't handle file size > 4 Gos tmp_input_file.seek(0) ProtocolUtils.send_data(self.__socket, tmp_input_file.read()) tmp_input_file.close() # unblock the compiler server self.__socket.send(Protocol.STOP_COMMAND) # get the output messages # first stdout, then stderr std_out_msg = ProtocolUtils.recv_data(self.__socket) if __debug__: print >> sys.stderr, "STDOUT message : " + std_out_msg std_err_msg = ProtocolUtils.recv_data(self.__socket) if __debug__: print >> sys.stderr, "STDERR message : " + std_err_msg # then get the output files content command = self.__socket.recv(Protocol.COMMAND_TYPE_SIZE) while command == Protocol.FILE_COMMAND: file_name = ProtocolUtils.recv_data(self.__socket) if __debug__: print >> sys.stderr, "file name : " + file_name #FIXME This is a bad patch to make DMS work well # but it have to be really fixed # Maybe the CompilerCommands class have to be reworked if "-o" in self.__compiler_command.get_command_args(): file = open(file_name, 'wb') else: file = open(os.path.basename(file_name), 'wb') file.write(ProtocolUtils.recv_data(self.__socket)) file.flush() file.close() if __debug__: print "File written." command = self.__socket.recv(Protocol.COMMAND_TYPE_SIZE) assert command == Protocol.EXIT_CODE_COMMAND print >> sys.stderr, "Command received : " + command # finally get the exit code exit_code = int(ProtocolUtils.recv_data(self.__socket)) if __debug__: print "Return code : " + str(exit_code) self.__socket.close() return exit_code
def send_exit_code(self, exit_code): """Send the exit code "exit_code" of the executed command to the client.""" self.__client_socket.send(Protocol.EXIT_CODE_COMMAND) ProtocolUtils.send_data(self.__client_socket, str(exit_code))
def send_exit_code(self, exit_code): """Send the exit code "exit_code" of the executed command to the client.""" self.__client_socket.send(Protocol.EXIT_CODE_COMMAND) ProtocolUtils.send_data(self.__client_socket, str(exit_code))
def request_host(self): host = self.store.give_host() ProtocolUtils.send_data(self.__client_socket, host) syslog.syslog(syslog.LOG_ERR | syslog.LOG_DAEMON, \ "dms Scheduler give host %s to client "%(host)\ + self.__client_address)