Ejemplo n.º 1
0
    def send(self, request, context):
        print(request)
        if request.cmd == 1:
            self.db.put(request.argument)
        elif request.cmd == 2:
            self.db.delete(request.argument)
        else:
            replicator_pb2.Response(result=False)

        return replicator_pb2.Response(result=True)
Ejemplo n.º 2
0
    def synchronizer(self, request, context):

        print(" Syncronization between server and client")

        itKey = self.db.iterkeys()
        itKey.seek_to_first()
        lKey = list(itKey)

        for key in lKey:
            data = self.db.get(key)
            response = replicator_pb2.Response(operation="put",
                                               key=key.decode(),
                                               data=data.decode())
            print("Put Operation " + key.decode() + " " + data.decode())

            yield response

        while (True):
            response = self.replicator_queue.get()
            if (response.operation == "put"):
                print("Operation " + response.operation + " " + response.key +
                      " " + response.data)
            elif (response.operation == "delete"):
                print("Operation " + response.operation + " " + response.key)

            yield response
Ejemplo n.º 3
0
    def performOperation(self, request, context):
        print(request.op)
        if (request.op == 0):
            self.put(request.key, request.value)
        if (request.op == 1):
            self.delete(request.key)

        return replicator_pb2.Response(result=True)
Ejemplo n.º 4
0
    def put(self, request, context):
        """Put data in db"""
        # self.key = uuid.uuid4().hex
        value = request.data

        print("BAck to original")

        print(MyReplicatorServicer.key)
        self.master_db.put(MyReplicatorServicer.key.encode(), value.encode())
        return replicator_pb2.Response(data=MyReplicatorServicer.key)
Ejemplo n.º 5
0
 def put(self, request, context):
     print("Put to master" + request.key + "," + request.value)
     self.db.put(request.key.encode(), request.value.encode())
     return replicator_pb2.Response(value='Done')
Ejemplo n.º 6
0
 def delete(self, request, context):
     print("Deleting {} from master db".format(request.key))
     self.db.delete(request.key.encode())
     return replicator_pb2.Response(data='ok')
Ejemplo n.º 7
0
 def wrapper(self, request, context):
     resp = replicator_pb2.Response(operation="delete",
                                    key=request.key,
                                    data="")
     self.replicator_queue.put(resp)
     return func(self, request, context)
Ejemplo n.º 8
0
 def get(self, request, context):
     print("Get from master db" + request.key)
     value = self.db.get(request.key.encode())
     return replicator_pb2.Response(value=value)
Ejemplo n.º 9
0
 def put(self, request, context):
     print("Puting {}:{} to master db".format(request.key, request.val))
     self.db.put(request.key.encode(), request.data.encode())
     return replicator_pb2.Response(data='ok')
Ejemplo n.º 10
0
 def delete(self, request, context):
     print("## DELETE REQUEST")
     value = (self.db.get(request.key.encode())).decode()
     #delete data from client db
     self.db.delete(request.key.encode())
     return replicator_pb2.Response(key=request.key, value=value)
Ejemplo n.º 11
0
 def get(self, request, context):
     print("## GET REQUEST")
     #fetch data from client db
     value = (self.db.get(request.key.encode())).decode()
     return replicator_pb2.Response(key=request.key, value=value)
Ejemplo n.º 12
0
 def delete(self, request, context):
     print("Delete from master" + request.key)
     self.db.delete(request.key.encode())
     return replicator_pb2.Response(value='Done')
Ejemplo n.º 13
0
 def put(self, request, context):
     print("## PUT REQUEST")
     #add data into client db
     self.db.put(request.key.encode(), request.value.encode())
     return replicator_pb2.Response(key=request.key, value=request.value)
Ejemplo n.º 14
0
 def get(self, request, context):
     """Get data from DB"""
     return replicator_pb2.Response(
         data=(self.master_db.get(request.data.encode())).decode())
Ejemplo n.º 15
0
    def delete(self, request, context):
        """Delet data from DB"""

        self.master_db.delete(request.data.encode())
        return replicator_pb2.Response(data=request.data)
Ejemplo n.º 16
0
 def get(self, request, context):
     print("Get {} from serverStoreDB".format(request.key))
     value = self.db.get(request.key.encode())
     return replicator_pb2.Response(data=value)
Ejemplo n.º 17
0
 def delete(self, request, context):
     print("Delete {} from serverStoreDB".format(request.key))
     self.db.delete(request.key.encode())
     return replicator_pb2.Response(data='ok')
Ejemplo n.º 18
0
 def put(self, request, context):
     print("Put {} : {} to serverStoreDB".format(request.key, request.data))
     self.db.put(request.key.encode(), request.data.encode())
     return replicator_pb2.Response(data='ok')