Exemple #1
0
    def get(self):
        result = None
    
    
        # get arguments
        substr = self.get_argument('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = tornado.options.options.redis_host, 
                              port = tornado.options.options.redis_port,
                              db = tornado.options.options.redis_db_idtf)
        result = {}
        sys = []
        main = []
        common = []
        max_n = tornado.options.options.idtf_serach_limit
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 200)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            if cursor == 0:
                break
            for idtf in reply[1]:
                if len(sys) == max_n and len(main) == max_n and len(common) == max_n:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < max_n:
                    sys.append([addr.to_id(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < max_n:
                    main.append([addr.to_id(), utf[10:]])
                elif utf.startswith(u"idtf:common:") and len(common) < max_n:
                    common.append([addr.to_id(), utf[12:]])
                    

        sctp_client = new_sctp_client()
        keys = Keynodes(sctp_client)
        keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
        keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
        keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                    
        result[keynode_nrel_system_identifier.to_id()] = sys
        result[keynode_nrel_main_idtf.to_id()] = main
        result[keynode_nrel_idtf.to_id()] = common
        
        sctp_client.shutdown()
        self.set_header("Content-Type", "application/json")
        self.finish(json.dumps(result))
Exemple #2
0
    def get(self):
        result = None
    
    
        # get arguments
        substr = self.get_argument('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = tornado.options.options.redis_host, 
                              port = tornado.options.options.redis_port,
                              db = tornado.options.options.redis_db_idtf)
        result = {}
        sys = []
        main = []
        common = []
        max_n = tornado.options.options.idtf_serach_limit
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 200)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            if cursor == 0:
                break
            for idtf in reply[1]:
                if len(sys) == max_n and len(main) == max_n and len(common) == max_n:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < max_n:
                    sys.append([addr.to_id(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < max_n:
                    main.append([addr.to_id(), utf[10:]])
                elif utf.startswith(u"idtf:common:") and len(common) < max_n:
                    common.append([addr.to_id(), utf[12:]])
                    

        sctp_client = new_sctp_client()
        keys = Keynodes(sctp_client)
        keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
        keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
        keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                    
        result[keynode_nrel_system_identifier.to_id()] = sys
        result[keynode_nrel_main_idtf.to_id()] = main
        result[keynode_nrel_idtf.to_id()] = common
        
        sctp_client.shutdown()
        self.set_header("Content-Type", "application/json")
        self.finish(json.dumps(result))
Exemple #3
0
def idtf_find(request):
    result = None
    if request.is_ajax():
        # get arguments
        substr = request.GET.get('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = settings.REDIS_HOST, port = settings.REDIS_PORT, db = settings.REDIS_DB)
        result = {}
        sys = []
        main = []
        common = []
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 200)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            if cursor == 0:
                break
            for idtf in reply[1]:
                if len(sys) == settings.IDTF_SEARCH_LIMIT and len(main) == settings.IDTF_SEARCH_LIMIT and len(common) == settings.IDTF_SEARCH_LIMIT:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < settings.IDTF_SEARCH_LIMIT:
                    sys.append([addr.to_id(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < settings.IDTF_SEARCH_LIMIT:
                    main.append([addr.to_id(), utf[10:]])   
                elif utf.startswith(u"idtf:common:") and len(common) < settings.IDTF_SEARCH_LIMIT:
                    common.append([addr.to_id(), utf[12:]])          
                    

        sctp_client = new_sctp_client()
        keys = Keynodes(sctp_client)    
        keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
        keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
        keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                    
        result[keynode_nrel_system_identifier.to_id()] = sys
        result[keynode_nrel_main_idtf.to_id()] = main
        result[keynode_nrel_idtf.to_id()] = common
        
        result = json.dumps(result)

    return HttpResponse(result, 'application/json')
Exemple #4
0
    def get(self):
        result = None

        # get arguments
        substr = self.get_argument('substr', None)

        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host=tornado.options.options.redis_host,
                              port=tornado.options.options.redis_port,
                              db=tornado.options.options.redis_db_idtf)
        result = {}
        sys = []
        main = []
        common = []
        max_n = tornado.options.options.idtf_serach_limit

        def appendSorted(array, data):
            if len(array) > 0:
                idx = 0
                inserted = False
                for idx in xrange(len(array)):
                    if len(array[idx][1]) > len(data[1]):
                        array.insert(idx, data)
                        inserted = True
                        break
                    idx = idx + 1

                if not inserted and len(array) < max_n:
                    array.append(data)

                if (len(array) > max_n):
                    array.pop()
            else:
                array.append(data)

        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 1000)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])

            for idtf in reply[1]:
                if len(sys) == max_n and len(main) == max_n and len(
                        common) == max_n:
                    break

                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < max_n:
                    appendSorted(sys, [addr.to_int(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < max_n:
                    appendSorted(main, [addr.to_int(), utf[10:]])
                elif utf.startswith(u"idtf:common:") and len(common) < max_n:
                    appendSorted(common, [addr.to_int(), utf[12:]])

            if cursor == 0:
                break

        with SctpClientInstance() as sctp_client:
            keys = Keynodes(sctp_client)
            keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
            keynode_nrel_system_identifier = keys[
                KeynodeSysIdentifiers.nrel_system_identifier]
            keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]

            result['sys'] = sys
            result['main'] = main
            result['common'] = common

            self.set_header("Content-Type", "application/json")
            self.finish(json.dumps(result))
Exemple #5
0
    def get(self):
        result = None
    
    
        # get arguments
        substr = self.get_argument('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = tornado.options.options.redis_host, 
                              port = tornado.options.options.redis_port,
                              db = tornado.options.options.redis_db_idtf)
        result = {}
        sys = []
        main = []
        common = []
        max_n = tornado.options.options.idtf_serach_limit
        
        def appendSorted(array, data):
            if len(array) > 0:
                idx = 0
                inserted = False
                for idx in xrange(len(array)):
                    if len(array[idx][1]) > len(data[1]):
                        array.insert(idx, data)
                        inserted = True
                        break;
                    idx = idx + 1
                
                if not inserted and len(array) < max_n:
                    array.append(data)
                
                if (len(array) > max_n):
                    array.pop()
            else:
                array.append(data)
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 1000)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            
            for idtf in reply[1]:
                if len(sys) == max_n and len(main) == max_n and len(common) == max_n:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < max_n:
                    appendSorted(sys, [addr.to_int(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < max_n:
                    appendSorted(main, [addr.to_int(), utf[10:]])
                elif utf.startswith(u"idtf:common:") and len(common) < max_n:
                    appendSorted(common, [addr.to_int(), utf[12:]])

            if cursor == 0:
                break
                                
        with SctpClientInstance() as sctp_client:
            keys = Keynodes(sctp_client)
            keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
            keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
            keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                        
            result['sys'] = sys
            result['main'] = main
            result['common'] = common
            
            self.set_header("Content-Type", "application/json")
            self.finish(json.dumps(result))