def deleteDataFromNode(self, username, filename, chunk_id, destination): channel = grpc.insecure_channel(destination) channel2 = self.activeNodeObj.getActiveIpsDict()[destination] stub = fileService_pb2_grpc.FileserviceStub(channel2) response = stub.FileDelete( fileService_pb2.FileInfo(username=username, filename=str(filename + chunk_id), sequence_no=chunk_id)) return response
def broadcastMetadata(self, username, filename, chunk_id, destination): activeIpList = self.activeNodeObj.getActiveIpsDict() for ip, channel in activeIpList.items(): stub = fileService_pb2_grpc.FileserviceStub(channel) response = stub.metadataUpdate( fileService_pb2.metadataInfo(username=username, filename=filename, chunk_id=chunk_id, destination=destination))
def informSuperNode(self_node): temp = self_node.split(":")[0] try: channel = grpc.insecure_channel(superNodeIp) if isChannelAlive(channel): stub = fileService_pb2_grpc.FileserviceStub(channel) response = stub.getLeaderInfo(fileService_pb2.ClusterInfo(ip=str(temp), port="3000", clusterName="Saket")) print(response.message) else: raise except Exception as e: print(e)
def client(): while True: choice = int( input( "What operation: 1. Upload 2. Download 3. File Search 4. File List 5. File Delete : " )) if choice == 1: channel = grpc.insecure_channel('192.168.0.9:9000') fileName = input("FileName to be uploaded: ") # start = timer() start_time = time.time() chunk_generator = get_file_chunks(fileName) # time.sleep(1) # end = timer() # print(end-start) # print("Chunks generated in %s seconds" % (time.time() - start_time)) print("Chunks generated in %s seconds" % (str( (time.time() - start_time)))) start_time = time.time() stub = fileService_pb2_grpc.FileserviceStub(channel) response = stub.UploadFile(chunk_generator) print("File Uploaded in - %s seconds" % (str(round(time.time() - start_time, 10)))) print(response) elif choice == 2: channel = grpc.insecure_channel('192.168.0.9:9000') name = input("Name of file to download") start_time = time.time() stub = fileService_pb2_grpc.FileserviceStub(channel) # res = stub.FileSearch(fileService_pb2.FileInfo(username="******", filename=name)) if True: response = stub.DownloadFile( fileService_pb2.FileInfo(username="******", filename=name)) print("Files downloaded in %s seconds" % (str(round(time.time() - start_time, 10)))) start_time = time.time() save_chunks_to_file(response, "downloads/" + name) print("Download chunks aggregated in %s seconds" % (str(round(time.time() - start_time, 10)))) print("File downloaded. ") else: print("File not found") elif choice == 3: channel = grpc.insecure_channel('192.168.0.9:9000') name = input("Name of file to Search") stub = fileService_pb2_grpc.FileserviceStub(channel) response = stub.FileSearch( fileService_pb2.FileInfo(username="******", filename=name)) print(response) elif choice == 4: channel = grpc.insecure_channel('192.168.0.9:9000') name = input("Enter username: "******"akshay", filename=name)) print("File List. ", fileList) elif choice == 5: channel = grpc.insecure_channel('192.168.0.9:9000') name = input("Name of file to Delete: ") stub = fileService_pb2_grpc.FileserviceStub(channel) res = stub.FileSearch( fileService_pb2.FileInfo(username="******", filename=name)) if res.success: response = stub.FileDelete( fileService_pb2.FileInfo(username="******", filename=name)) print(response) else: print("file not found")
def sendDataToDestination(self, chunk, node, chunk_id): channel = self.activeNodeObj.getActiveIpsDict()[node] stub = fileService_pb2_grpc.FileserviceStub(channel) chunk_generator = self.getChunksinStream(chunk, chunk_id) response = stub.UploadFile(chunk_generator)