def info(self): """ Return a list of InfoResponse from all servers. 1. Invoke DB client's info() to retrieve server info for all servers. """ server_info = [] # TODO for k, v in self.maps.items(): stub = db_pb2.DBStub(channel=v) server_info.append(stub.info(db_pb2.Empty())) return server_info
def get(self, key): """ 1. Get the highest Rendezvous node for the given key. 2. Retrieve the DBClient instance reference by the node. 3. Get the value by the key via client's get(). :param key: a string key. :param value: a string key-value pair dictionary to be stored in DB. :return a GetResposne - [email protected] """ # TODO highest_node = self.get_node(key) server_channel = self.maps[str(highest_node)] stub = db_pb2.DBStub(channel=server_channel) req = db_pb2.GetRequest(id=key) return stub.get(req)
def put(self, key, value): """ 1. Get the highest Rendezvous node for the given key. 2. Retrieve the DBClient instance reference by the node. 3. Save the value into DB via client's put(). :param key: a string key. :param value: a string key-value pair dictionary to be stored in DB. :return a PutResponse - [email protected] NOTE: Both key and value must be the string type. """ # TODO highest_node = self.get_node(key) server_channel = self.maps[str(highest_node)] stub = db_pb2.DBStub(channel=server_channel) _data = db_pb2.Data(entry=value) req = db_pb2.PutRequest(id=key, data=_data) return stub.put(req)
def __init__(self, host='0.0.0.0', port=3000): _channel = grpc.insecure_channel('%s:%d' % (host, port)) self.stub = db_pb2.DBStub(channel=_channel) print("Client connected to %s:%d" % (host, port))