def handle_put(self, db, p): """Insert new file into the database and send data nodes to save the file. """ # Fill code #getting fname, fsize from packet using the getFileInfo() function from Packet.py. #Storing the file in the database using the function InsertFile from mds_db.py. if db.InsertFile(p.getFileInfo()[0], p.getFileInfo()[1]): # Fill code print("file inserted") #creating response for the copy client. print("packet creation begin") packet_send = Packet() packet_send.BuildPutResponse( db.GetDataNodes() ) #db.GetDataNodes() gives me the data node list for the copy client. packet_response = packet_send.getEncodedPacket( ) #encoding packet to send to the copy client. self.request.sendall(packet_response) #print("packet sent") pass else: self.request.sendall("DUP")
def handle_put(self, db, p): """Insert new file into the database and send data nodes to save the file. """ # Fill code # packet that comes from copy client info = [p.packet['fname'], p.packet['fsize']] if db.InsertFile(info[0], info[1]): # Fill code nids = db.GetDataNodes() print(nids, 'nids line 67 file meta-data.py') dataNodes_packet = Packet() dataNodes_packet.BuildPutResponse(nids) self.request.sendall(dataNodes_packet.getEncodedPacket()) # send to the copy server else: self.request.sendall(b"DUP")
def handle_put(self, db, p): """Insert new file into the database and send data nodes to save the file. """ # Fill code info = p.getFileInfo() print info packet = Packet() packet.BuildPutResponse(db.GetDataNodes()) response = packet.getEncodedPacket() try: if db.InsertFile(info[0], info[1]): # Fill code self.request.send("ACK") else: self.request.send("DUP") self.request.send(response) except: self.request.send("NAK")
def handle_put(self, db, p): """ Insert new file in database and respond with list of available data nodes. - List of tuples if succesfully inserted - DUP if trying to insert a duplicate of the file. """ # Get (fname, fsize) from packet fname, fsize = p.getFileInfo() print "\t- Retrieving file info from packet..." # Insert file into MDS and send list of available data nodes back to copy.py if db.InsertFile(fname, fsize): print "\t- Inserted file into MDS! Sending back available data nodes..." nodelist = db.GetDataNodes() q = Packet() q.BuildPutResponse(nodelist) self.request.sendall(q.getEncodedPacket()) print "\t- Done!" else: self.request.sendall("DUP") print "\t- File already exists in MDS!"