Ejemplo n.º 1
0
 def _load(self):
     """
     Loads data relating to the recovery of a fragment for this request
     """
     super(FragmentSink, self)._load()
     self._graph_pattern = GraphPattern(r.smembers('{}gp'.format(self._request_key)))
     self._fragment_pattern = GraphPattern(r.smembers('{}:gp'.format(self._fragment_key)))
     self._filter_mapping = r.hgetall('{}filters'.format(self._request_key))
     self._dict_fields['mapping'] = r.hgetall('{}map'.format(self._request_key))
     self._dict_fields['preferred_labels'] = set(r.smembers('{}pl'.format(self._request_key)))
Ejemplo n.º 2
0
def get_request(rid):
    if not r.exists('{}:requests:{}:'.format(AGENT_ID, rid)):
        raise NotFound('The request {} does not exist'.format(rid))
    r_dict = filter_hash_attrs('{}:requests:{}:'.format(AGENT_ID, rid), lambda x: not x.startswith('__'))
    channel = r_dict['channel']
    ch_dict = r.hgetall('{}:channels:{}'.format(AGENT_ID, channel))
    broker = r_dict['broker']
    br_dict = r.hgetall('{}:brokers:{}'.format(AGENT_ID, broker))
    r_dict['channel'] = ch_dict
    r_dict['broker'] = br_dict
    if 'mapping' in r_dict:
        r_dict['mapping'] = eval(r_dict['mapping'])

    return jsonify(r_dict)
Ejemplo n.º 3
0
 def load(self):
     dict_fields = r.hgetall(self._enrichment_key)
     self.target = URIRef(dict_fields.get('target', None))
     self.fragment_id = dict_fields.get('fragment_id', None)
     self.links = map(lambda (link, v): (URIRef(link), v), [eval(pair_str) for pair_str in
                                                            r.smembers('{}:links'.format(
                                                                self._enrichment_key))])
Ejemplo n.º 4
0
    def _load(self):
        """
        Loads all delivery data
        """
        super(DeliverySink, self)._load()
        self._dict_fields['channel'] = r.hgetall('{}:channels:{}'.format(AGENT_ID, self._dict_fields['channel']))
        self._dict_fields['broker'] = r.hgetall('{}:brokers:{}'.format(AGENT_ID, self._dict_fields['broker']))
        self._dict_fields['broker']['port'] = int(self._dict_fields['broker']['port'])
        recipient = self._dict_fields['channel'].copy()
        recipient.update(self._dict_fields['broker'])
        self._dict_fields['recipient'] = recipient

        # If present, remove previously stored delivery state so it can be retrieved each time the delivery getter
        # is invoked
        try:
            del self._dict_fields['delivery']
        except KeyError:
            pass
Ejemplo n.º 5
0
 def completed(self):
     return all([eval(value) for value in r.hgetall('{}:links:status'.format(self._enrichment_key)).values()])
Ejemplo n.º 6
0
def filter_hash_attrs(key, predicate):
    hash_map = r.hgetall(key)
    visible_attrs = filter(predicate, hash_map)
    return {attr: hash_map[attr] for attr in filter(lambda x: x in visible_attrs, hash_map)}