def ReplicateFile(self, request, context):
     #print("request =", request.shortest_path[request.currentpos])
     # # next_node = request.shortest_path[request.currentpos]
     # if request.currentpos == len(request.shortest_path) - 1:
     #     cache.saveVClock(str(request), str(request))
     #     return fileService_pb2.ack(success=True, message="Data Replicated.")
     # else:
     # forward_server_addr = self.getneighbordata(next_node)
     #path = json.loads(request.shortest_path)
     forward_coordinates = request.shortest_path[request.currentpos]
     print("forward coord =", forward_coordinates)
     forward_server_addr = self.getneighbordata(forward_coordinates)
     print("forward IP =", forward_server_addr)
     forward_port = 5555
     forward_channel = grpc.insecure_channel(forward_server_addr + ":" +
                                             str(forward_port))
     forward_stub = fileService_pb2_grpc.FileserviceStub(forward_channel)
     request.currentpos += 1
     rList = [1, 2, 3, 4, 5]
     arr = bytearray(rList)
     updated_request = fileService_pb2.FileData(
         initialReplicaServer=request.initialReplicaServer,
         bytearray=request.bytearray,
         vClock=request.vClock,
         shortest_path=request.shortest_path,
         currentpos=request.currentpos + 1)
     forward_resp = forward_stub.ReplicateFile(updated_request)
     print("forward_resp", forward_resp)
     return fileService_pb2.ack(success=True, message="Data Forwarded.")
Beispiel #2
0
 def ReplicateFile(self, request, context):
     print("request", request.shortest_path)
     # next_node = request.shortest_path[request.currentpos]
     if request.currentpos == len(request.shortest_path) - 1:
         cache.set(request, request)
         return fileService_pb2.ack(success=True,
                                    message="Data Replicated.")
     else:
         # forward_server_addr = self.getneighbordata(next_node)
         forward_server_addr = "169.105.246.6"
         forward_port = 50051
         forward_channel = grpc.insecure_channel(forward_server_addr + ":" +
                                                 str(forward_port))
         forward_stub = fileService_pb2_grpc.FileserviceStub(
             forward_channel)
         request.currentpos += 1
         rList = [1, 2, 3, 4, 5]
         arr = bytearray(rList)
         updated_request = fileService_pb2.FileData(
             initialReplicaServer=request.initialReplicaServer,
             bytearray=request.bytearray,
             vClock=request.vClock,
             shortest_path=request.shortest_path,
             currentpos=request.currentpos + 1)
         forward_resp = forward_stub.ReplicateFile(updated_request)
         print("forward_resp", forward_resp)
         return fileService_pb2.ack(success=True, message="Data Forwarded.")
 def initiateReplication(self):
     serverAddress = "169.105.246."
     serverPort = 50051
     rList = [1, 2, 3, 4, 5]
     arr = bytes(rList)
     channel = grpc.insecure_channel(serverAddress + ":" + str(serverPort))
     replicate_stub = fileService_pb2_grpc.FileserviceStub(channel)
     request = fileService_pb2.FileData(initialReplicaServer="169.105.246.4", bytearray=arr,
                                         vClock="My V Clock", shortest_path=self.path, currentpos=0)
     resp = replicate_stub.ReplicateFile(request)
     print("Replication response", resp)