Ejemplo n.º 1
0
    def set(self, client_id, val):
        # Generating the current client's key for GCounter
        current_client_key = get_client_key(self.key, client_id)

        # Updating the client's state with the value to be set
        hot_redis.Dict(key=current_client_key,
                       client=connection)[current_client_key] = val
Ejemplo n.º 2
0
    def set(self, client_id, val):

        # Generating the current client's key for GSet
        current_client_key = get_client_key(self.key, client_id)

        # Updating the client's state with the value to be set
        hot_redis.Dict(key=current_client_key, client=connection)[current_client_key] = repr(set(eval(val)))
Ejemplo n.º 3
0
    def add_client(self, client_id):
        # Adding client ID to client list
        new_client = get_client_key(self.key, client_id)
        self.client_list.add(new_client)

        # Adding clients to component GCounters
        self.pcounter.add_client(client_id)
        self.ncounter.add_client(client_id)
Ejemplo n.º 4
0
    def set(self, client_id, val, timestamp):

        # Generating the current client's key for LWWERegister
        current_client_key = get_client_key(self.key, client_id)

        # Updating the client's state with the value to be set
        hot_redis.Dict(key=current_client_key, client=connection)[current_client_key] = str({'value': val, 'timestamp':
                                                                                             timestamp})
Ejemplo n.º 5
0
    def peek(self, client_id):
        # Generating the current client's key for GCounter
        current_client_key = get_client_key(self.key, client_id)

        # Peek at the current value
        return int(
            hot_redis.Dict(key=current_client_key,
                           client=connection)[current_client_key])
Ejemplo n.º 6
0
    def add_client(self, client_id):
        # Generating a client list key for this key
        new_client = get_client_key(self.key, client_id)
        with hot_redis.transaction():
            # Adding a new state to all the existing clients
            for client in self.client_list:
                hot_redis.Dict(key=client, client=connection)[new_client] = 0

            # Adding client to GCounter instance's client list
            self.client_list.add(new_client)

            # Adding a new state dictionary for this GCounter client
            new_client_state = hot_redis.Dict(key=new_client, client=connection)
            for client in self.client_list:
                new_client_state[client] = 0
Ejemplo n.º 7
0
def check_input_fault(key, client_id, value1, value2, data_type):
    result_dict = dict()

    # Checking for valid key
    if key is None or len(key) == 0:
        result_dict['status'] = status_codes['missing_key_or_state']
        return result_dict

    # Checking for valid client ID
    if client_id is None or len(client_id) == 0:
        result_dict['status'] = status_codes['client_id_not_found']
        return result_dict

    # Checking for valid value1
    if (value1 is None or len(value1) == 0) and value1 != "default":
        result_dict['status'] = status_codes['value_not_found']
        return result_dict

    # Checking for valid value2
    if (value2 is None or len(value2) == 0) and value2 != "default":
        result_dict['status'] = status_codes['value_not_found']
        return result_dict

    data_types = hot_redis.Dict(key=DATA_TYPES, client=connection)
    all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection)
    client_list = hot_redis.Set(key=get_client_list_key(key), client=connection)

    # Checking if client ID is valid
    if client_id not in all_clients:
        result_dict['status'] = status_codes['client_id_not_found']
        return result_dict

    # Checking if key is present
    if key not in data_types.keys():
        result_dict['status'] = status_codes['missing_key_or_state']
        return result_dict

    # Checking if the key is the right type
    if data_types[key] != data_type:
        result_dict['status'] = status_codes['data_type_mismatch']
        return result_dict

    # Checking if client is in the GCounter's client list
    if get_client_key(key=key, client_id=client_id) not in client_list:
        result_dict['status'] = status_codes['client_id_not_in_crdt']
        return result_dict

    return False
Ejemplo n.º 8
0
    def add_client(self, client_id):
        # Generating a client list key for this key
        new_client = get_client_key(self.key, client_id)
        with hot_redis.transaction():
            # Adding a new state to all the existing clients
            for client in self.client_list:
                hot_redis.Dict(key=client, client=connection)[new_client] = 0

            # Adding client to GCounter instance's client list
            self.client_list.add(new_client)

            # Adding a new state dictionary for this GCounter client
            new_client_state = hot_redis.Dict(key=new_client,
                                              client=connection)
            for client in self.client_list:
                new_client_state[client] = 0
Ejemplo n.º 9
0
    def add_client(self, client_id):
        # Generating a client list key for this key
        new_client = get_client_key(self.key, client_id)

        with hot_redis.transaction():
            # Adding a new state to all the existing clients
            for client in self.client_list:
                hot_redis.Dict(key=client, client=connection)[new_client] = str({'timestamp': -1, 'value': None})

            # Adding client to LWWERegister instance's client list
            self.client_list.add(new_client)

            # Adding a new state dictionary for this LWWERegister client
            new_client_state = hot_redis.Dict(key=new_client, client=connection)
            for client in self.client_list:
                new_client_state[client] = str({'timestamp': -1, 'value': None})
Ejemplo n.º 10
0
def check_input_fault(key, client_id, timestamp, data_type):
    result_dict = dict()

    # Checking for valid key
    if key is None or len(key) == 0:
        result_dict['status'] = status_codes['missing_key_or_state']
        return result_dict

    # Checking for valid client ID
    if client_id is None or len(client_id) == 0:
        result_dict['status'] = status_codes['client_id_not_found']
        return result_dict

    # Checking validity of timestamp
    if timestamp != -1.0:
        try:
            timestamp = float(timestamp)
        except ValueError:
            result_dict['status'] = status_codes['timestamp_not_valid']
            return result_dict

    data_types = hot_redis.Dict(key=DATA_TYPES, client=connection)
    all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection)
    client_list = hot_redis.Set(key=get_client_list_key(key),
                                client=connection)

    # Checking if client ID is valid
    if client_id not in all_clients:
        result_dict['status'] = status_codes['client_id_not_found']
        return result_dict

    # Checking if key is present
    if key not in data_types.keys():
        result_dict['status'] = status_codes['missing_key_or_state']
        return result_dict

    # Checking if the key is the right type
    if data_types[key] != data_type:
        result_dict['status'] = status_codes['data_type_mismatch']
        return result_dict

    # Checking if client is in the GCounter's client list
    if get_client_key(key=key, client_id=client_id) not in client_list:
        result_dict['status'] = status_codes['client_id_not_in_crdt']
        return result_dict

    return False
Ejemplo n.º 11
0
def check_input_fault(key, client_id, timestamp, data_type):
    result_dict = dict()

    # Checking for valid key
    if key is None or len(key) == 0:
        result_dict['status'] = status_codes['missing_key_or_state']
        return result_dict

    # Checking for valid client ID
    if client_id is None or len(client_id) == 0:
        result_dict['status'] = status_codes['client_id_not_found']
        return result_dict

    # Checking validity of timestamp
    if timestamp != -1.0:
        try:
            timestamp = float(timestamp)
        except ValueError:
            result_dict['status'] = status_codes['timestamp_not_valid']
            return result_dict

    data_types = hot_redis.Dict(key=DATA_TYPES, client=connection)
    all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection)
    client_list = hot_redis.Set(key=get_client_list_key(key), client=connection)

    # Checking if client ID is valid
    if client_id not in all_clients:
        result_dict['status'] = status_codes['client_id_not_found']
        return result_dict

    # Checking if key is present
    if key not in data_types.keys():
        result_dict['status'] = status_codes['missing_key_or_state']
        return result_dict

    # Checking if the key is the right type
    if data_types[key] != data_type:
        result_dict['status'] = status_codes['data_type_mismatch']
        return result_dict

    # Checking if client is in the GCounter's client list
    if get_client_key(key=key, client_id=client_id) not in client_list:
        result_dict['status'] = status_codes['client_id_not_in_crdt']
        return result_dict

    return False
Ejemplo n.º 12
0
    def get(self, client_id=None):
        # Getting the client's key for this GCounter
        if client_id is None:
            current_client_key = random.choice(list(self.client_list.value))
        else:
            current_client_key = get_client_key(self.key, client_id)

        # Merging state from every other client for this GCounter
        for client in self.client_list:
            self.merge(current_client_key, client)

        # Updating the states from all other clients as the client's latest state
        current_client_state = hot_redis.Dict(key=current_client_key, client=connection)

        # Getting the final merged value
        count = 0
        for val in current_client_state.values():
            count += int(val)

        return count
Ejemplo n.º 13
0
    def get(self, client_id):
        # Getting the client's key for this GSet
        current_client_key = get_client_key(self.key, client_id)

        # Merging state from every other client for this GSet
        for client in self.client_list:
            self.merge(current_client_key, client)

        # Updating the states from all other clients as the client's latest state
        current_client_state = hot_redis.Dict(key=current_client_key, client=connection)

        # Getting the final merged value
        count = set()
        for val in current_client_state.values():
            count = count.union(eval(val))

        current_client_state[current_client_key] = repr(count)
        print repr(count)
        print current_client_state[current_client_key]

        return str(list(count))
Ejemplo n.º 14
0
    def get(self, client_id=None):
        # Getting the client's key for this GCounter
        if client_id is None:
            current_client_key = random.choice(list(self.client_list.value))
        else:
            current_client_key = get_client_key(self.key, client_id)

        # Merging state from every other client for this GCounter
        for client in self.client_list:
            self.merge(current_client_key, client)

        # Updating the states from all other clients as the client's latest state
        current_client_state = hot_redis.Dict(key=current_client_key,
                                              client=connection)

        # Getting the final merged value
        count = 0
        for val in current_client_state.values():
            count += int(val)

        return count
Ejemplo n.º 15
0
    def get(self, client_id):
        # Getting the client's key for this LWWERegister
        current_client_key = get_client_key(self.key, client_id)

        # Merging state from every other client for this LWWERegister
        for client in self.client_list:
            self.merge(current_client_key, client)

        # Updating the states from all other clients as the client's latest state
        current_client_state = hot_redis.Dict(key=current_client_key, client=connection)

        register = dict()
        register['value'] = eval(current_client_state[current_client_key])['value']
        register['timestamp'] = eval(current_client_state[current_client_key])['timestamp']
        for value in current_client_state.values():
            value = eval(value)
            if value['timestamp'] > register['timestamp']:
                register['value'] = value['value']
                register['timestamp'] = value['timestamp']

        current_client_state[current_client_key] = str(register)
        return str(register)
Ejemplo n.º 16
0
    def get(self, client_id):
        # Getting the client's key for this GSet
        current_client_key = get_client_key(self.key, client_id)

        # Merging state from every other client for this GSet
        for client in self.client_list:
            self.merge(current_client_key, client)

        # Updating the states from all other clients as the client's latest state
        current_client_state = hot_redis.Dict(key=current_client_key,
                                              client=connection)

        # Getting the final merged value
        count = set()
        for val in current_client_state.values():
            count = count.union(eval(val))

        current_client_state[current_client_key] = repr(count)
        print repr(count)
        print current_client_state[current_client_key]

        return str(list(count))
Ejemplo n.º 17
0
 def add_client(self, client_id):
     # Adding client ID to client list
     new_client = get_client_key(self.key, client_id)
     self.client_list.add(new_client)
Ejemplo n.º 18
0
 def add_client(self, client_id):
     # Adding client ID to client list
     new_client = get_client_key(self.key, client_id)
     self.client_list.add(new_client)
Ejemplo n.º 19
0
    def peek(self, client_id):
        # Generating the current client's key for GCounter
        current_client_key = get_client_key(self.key, client_id)

        # Peek at the current value
        return int(hot_redis.Dict(key=current_client_key, client=connection)[current_client_key])