def GetMatches(self, request, context): key = self.CH.hash(request.username) print(f'GetMatches - Server {SERVER_ID} / Username {request.username} / Username key: {key}') node = self.CH.find_successor(key) if node.server_id != SERVER_ID: print(f'GetMatches - Redirected to server {node.server_id}') try: with grpc.insecure_channel(f'{node.host}:{node.port}') as channel: stub = API_pb2_grpc.APIStub(channel) for match in stub.GetMatches(request): yield match except Exception as e: print(e) yield API_pb2.Match() else: print(f'GetMatches - Server {SERVER_ID} executing the action') error, data = matches.get_matches(self.LSMT, request, context) for match in data['matches']: pb_match = API_pb2.Match() pb_match.id = match['id'] pb_match.recruiter.username = match['recruiter'] pb_match.employee.username = match['employee'] pb_match.recruiter_match = match['recruiter_match'] pb_match.employee_match = match['employee_match'] yield pb_match
def RejectMatch(self, request, context): key = self.CH.hash(request.employee.username) print(f'RejectMatch - Employee Server {SERVER_ID} / Username {request.employee.username} / Username key: {key}') node = self.CH.find_successor(key) if node.server_id != SERVER_ID: print(f'RejectMatch - Redirected to server {node.server_id}') try: with grpc.insecure_channel(f'{node.host}:{node.port}') as channel: stub = API_pb2_grpc.APIStub(channel) return stub.RejectMatch(request) except Exception as e: context.set_code(grpc.StatusCode.INVALID_ARGUMENT) context.set_details('Wrong Credentials') return API_pb2.Match() key = self.CH.hash(request.recruiter.username) print(f'RejectMatch - Recruiter Server {SERVER_ID} / Username {request.recruiter.username} / Username key: {key}') node = self.CH.find_successor(key) if node.server_id != SERVER_ID: print(f'RejectMatch - Redirected to server {node.server_id}') try: with grpc.insecure_channel(f'{node.host}:{node.port}') as channel: stub = API_pb2_grpc.APIStub(channel) stub.ReplicateRejectMatch(request) except Exception as e: print(e) print(f'RejectMatch - Server {SERVER_ID} executing the action') error, data = matches.reject_match(self.LSMT, request, context) if error: context.set_code(grpc.StatusCode.INVALID_ARGUMENT) context.set_details(data['msg']) return API_pb2.Match() else: pb_match = API_pb2.Match() pb_match.id = data['match']['id'] pb_match.recruiter.username = data['match']['recruiter'] pb_match.employee.username = data['match']['employee'] return pb_match