Esempio n. 1
0
 def replicator_put(self, requests, context):
     for request in requests:
         print("put (streaming): " + request.data)
         key = uuid.uuid4().hex
         self.db.put(bytes(key, encoding="UTF-8"), bytes(request.data, encoding="UTF-8"))
         master_already_stored_requests.append(datastore_pb2.Request(data=bytes(key, encoding="UTF-8")))
         yield datastore_pb2.Response(data=key)
Esempio n. 2
0
 def put(self, request, context):
     print("put")
     key = uuid.uuid4().hex
     print("put " + request.data + " key = " + key)
     # TODO - save key and value into DB converting request.data string to utf-8 bytes 
     self.db.put(key.encode('utf-8'), request.data.encode('utf-8'))
     return datastore_pb2.Response(data=key)
    def get(self, request, context):
        print("get")
        X = request.key.encode()
        value = self.db.get(X).decode()

        print(value)
        return datastore_pb2.Response(key=request.key, value=value)
Esempio n. 4
0
    def put(self, request, context):
        print("put")
        key = uuid.uuid4().hex

        self.db.put(str.encode(key), str.encode(request.data))

        return datastore_pb2.Response(data=key)
Esempio n. 5
0
    def get(self, request, context):
        print("get")
        # TODO - retrieve the value from DB by the given key. Needs to convert request.data string to utf-8 bytes.
        req = request.data.encode('utf-8')
        value = self.db.get(req)

        return datastore_pb2.Response(data=value)
Esempio n. 6
0
 def put(self, request, context):
     print("put")
     bid = request.bookingid
     uname = request.username
     phno = request.phoneno
     cindate = request.checkindate
     days = request.noofdays
     rtype = request.roomtype
     amt = request.price
     rno = request.roomno
     roomslist = re.findall(r'\d+', rno)
     oprtype = request.oprtype
     if (str(oprtype) == 'insert'):
         resdb = database.storeSentResponserep(self.conn,
                                               int(bid), rtype, cindate,
                                               int(days), uname, phno,
                                               int(amt))
         for i in roomslist:
             xy = int(i)
             database.storeRoom(self.conn, int(bid), int(xy))
         print("Replication Insert Done")
     elif (str(oprtype) == 'delete'):
         database.cancelBooking(self.conn, int(bid))
         print("Replication Delete Done")
     return datastore_pb2.Response(data='received')
Esempio n. 7
0
 def wrapper(*args, **kwargs):
     q.put(
         datastore_pb2.Response(op_type="update",
                                key=args[0],
                                value=args[1]))
     print("Sent Update Operation to Follower")
     func(*args, **kwargs)
Esempio n. 8
0
    def put(self, request, context):
        print("put")
        key = uuid.uuid4().hex
        # TODO - save key and value into DB converting request.data string to utf-8 bytes
        self.db.put(bytes(key, 'utf-8'), bytes(request.data, 'utf-8'))

        return datastore_pb2.Response(data=key)
Esempio n. 9
0
    def masterUpdate(self, request, context):
        print("master update: ")
        delete_key = 0
        put_key = 0
        key = 0
        put_value = "b "

        # add behaviors(put/delete) every 3 seconds
        for i in range(10):
            if (i % 3 != 0) | (i == 0):
                command = "put"
                value = put_value
                key = put_key
                put_key += 1
                put_value += 'a'
                self.db.put(chr(key).encode(), value.encode())
            if (i % 3 == 0) & (i != 0):
                command = "delete"
                value = ""
                key = delete_key
                delete_key += 1
                self.db.delete(chr(key).encode())
            yield datastore_pb2.Response(cmd=command, key=key, value=value)
            time.sleep(3)

        it = self.db.iteritems()
        it.seek_to_first()

        # prints [(b'key1', b'v1'), (b'key2, b'v2'), (b'key3', b'v3')]
        print(list(it))
Esempio n. 10
0
 def get(self, request, context):
     print("get")
     # TODO - retrieve the value from DB by the given key. Needs to convert request.data string to utf-8 bytes. 
     value=None
     key = request.data
     var2=key.encode('utf-8')
     value =  (self.db.get(var2)).decode('utf-8')
     return datastore_pb2.Response(data=value)
    def put(self, request, context):

        key = request.key
        value = request.value
        keyy_b = key.encode('utf-8')
        value_b = value.encode('utf-8')
        self.db.put(keyy_b, value_b)
        return datastore_pb2.Response(key=key, value=value)
Esempio n. 12
0
 def update(self, request, context):
     print("master in update")
     if request.operation == 'put':
         key = request.key.encode()
         value = request.value.encode()
         self.db.put(key, value)
         return datastore_pb2.Response(data='put success : {}'.format(request.key))
     elif request.operation == 'delete':
         d_key = request.key.encode()
         self.db.delete(d_key)
         return datastore_pb2.Response(data='delete success : {}'.format(request.key))
     elif request.operation == 'get':
         g_key = request.key.encode()
         value = self.db.get(g_key)
         return datastore_pb2.Response(data='get success : {} : {}'.format(request.key, value))
     else:
         print("wrong operation!")
         return datastore_pb2.Response(data='wrong operation!')
Esempio n. 13
0
 def put(self, request, context):
     print("put")
     key = uuid.uuid4().hex
     # TODO - save key and value into DB converting request.data string to utf-8 bytes
     k = key.encode('utf-8')
     value = request.data
     u = value.encode('utf-8')
     self.db.put(k, u)
     return datastore_pb2.Response(data=key)
Esempio n. 14
0
 def get(self, request, context):
     print("get")
     X = request.data.decode('utf-8')
     value = self.db.get(X)
     print("----------")
     print(value)
     print("**********")
     print(self.db1.get(X))
     return datastore_pb2.Response(k=X, val=value)
Esempio n. 15
0
 def put(self, request, context):
     print("put")
     key = uuid.uuid4().hex
     var=key.encode('utf-8')
     temp=request.data
     var1=temp.encode('utf-8')
     self.db.put(var,var1)
     # TODO - save key and value into DB converting request.data string to utf-8 bytes 
     
     return datastore_pb2.Response(data=key)
Esempio n. 16
0
 def put(self, request, context):
     print("put")
     key = uuid.uuid4().hex
     # save key and value into DB converting request.data string to utf-8 bytes
     '''Rocksdb works on bytes hence it can not comprehend the string.
     First we need to extract the data from the request which is a string,
     and then we use encodings libraary to encode it to bytes.
     Finally provide the encoded byte value to the db , alongwith the encoded value
     of the key. Do db.put to add the key-value into the database.
     '''
     self.db.put(key.encode(), request.data.encode())
     return datastore_pb2.Response(data=key)
Esempio n. 17
0
 def get(self, request, context):
     print("get")
     # retrieve the value from DB by the given key. Needs to convert request.data string to utf-8 bytes.
     '''Rocksdb works on bytes hence it can not comprehend the string.
     First we need to extract the data from the request which is a string,
     and then we use encodings libraary to encode it to bytes.
     Finally provide the encoded byte value to the db , alongwith the encoded value
     of the key. Do db.get to get the value from the database for the key provided by user.
     The value returned will be in bytes and hence we need to decode it to the string.
     We use encodings library to decode the value retrieved from the data and send it as response.
     '''
     value = (self.db.get(request.data.encode())).decode()
     return datastore_pb2.Response(data=value)
Esempio n. 18
0
 def put(self, request, context):
     print("Put{}:{} to master_db".format(request.key, request.data))
     data = self.db.put(request.key.encode(), request.data.encode())
     return datastore_pb2.Response(value=data)
Esempio n. 19
0
 def get(self, request, context):
     print("Get{} from master_db".format(request.key))
     data = self.db.get(request.key.encode())
     return datastore_pb2.Response(value=data)
Esempio n. 20
0
 def get(self, request, context):
     print("get")
     return datastore_pb2.Response(data='received')
Esempio n. 21
0
 def delete(self, request, context):
     print("Delete{} from master_db".format(request.key))
     self.db.delete(request.key.encode())
     return datastore_pb2.Response(value='0')
Esempio n. 22
0
 def func_wrapper(self, request, context):
     key = f(self, request, context)
     self.history.append(key + ',' + request.data)
     return datastore_pb2.Response(data=key)
Esempio n. 23
0
    def get(self, request, context):
        print("get")
        # TODO - retrieve the value from DB by the given key. Needs to convert request.data string to utf-8 bytes.
        value = None

        return datastore_pb2.Response(data=value)
Esempio n. 24
0
 def connect_server(self, request, context):
     for item in self.history[request.data:]:
         yield datastore_pb2.Response(data=item)
Esempio n. 25
0
 def wrapper(self, request, context):
     key = op(self, request, context)
     self.history.append(op.__name__ + ',' + key + ',' + request.data)
     return datastore_pb2.Response(data=key)
Esempio n. 26
0
 def get(self, request, context):
     print("get")
     # TODO - retrieve the value from DB by the given key. Needs to convert request.data string to utf-8 bytes.
     # value = self.get(key)
     value = self.db.get(bytes(request.data, encoding='ascii'))
     return datastore_pb2.Response(data=value)
Esempio n. 27
0
 def replicate(self, request, context):
     for item in self.history:
         yield datastore_pb2.Response(data=item)
Esempio n. 28
0
    def get(self, request, context):
        print("get")

        value = self.db.get(str.encode(request.data))

        return datastore_pb2.Response(data=value)
Esempio n. 29
0
 def get(self, request, context):
     value = self.db.get(request.data.encode())
     return datastore_pb2.Response(data=value)