Beispiel #1
0
 def registerNodeInactivity(self, nodeId):
     """updates last_sleep_time attribute"""
     cursor = self._cnx.cursor()
     nodes = Node.selectWhere(cursor, node_id=nodeId)
     if nodes:
         node = nodes[0]
         node.last_sleep_time = int(time.time())
         node.commit(cursor, update=True)
     else:
         log.debug('No matching node found for id {%s}' % nodeId,
                   category='[warning]')
     cursor.close()
Beispiel #2
0
 def registerNodeInactivity(self, nodeId):
     """updates last_sleep_time attribute"""
     cursor = self._cnx.cursor()
     nodes = Node.selectWhere(cursor, node_id=nodeId)
     if nodes:
         node = nodes[0]
         node.last_sleep_time = int(time.time())
         node.commit(cursor, update=True)
     else:
         log.debug('No matching node found for id {%s}' % nodeId,
                   category='[warning]')
     cursor.close()        
Beispiel #3
0
 def registerNode(self, nodeId, ip, port, bandwidth=None, lastSeenTime=None):
     """this will be used as a callback in registrationclient/login"""
     print "AnonymousQuerier registerNode (callback) %s %s:%s" % \
                                                          (nodeId, ip, port)
     lastSeenTime = lastSeenTime or int(time.time())
     cursor = self._cnx.cursor()
     node = Node.selectOrInsertWhere(cursor, node_id=nodeId)[0]
     node.ip = ip
     node.port = port
     node.bandwidth = bandwidth or 1
     node.last_seen_time = lastSeenTime
     node.commit(cursor, update=True)
     cursor.close()
Beispiel #4
0
 def registerNodeActivity(self, nodeId):
     """updates last_seen_time attribute"""
     cursor = self._cnx.cursor()
     nodes = Node.selectWhere(cursor, node_id=nodeId)
     if nodes:
         node = nodes[0]
         print " ... registerNodeActivity %s:%s (%s)" % (node.ip, node.port, nodeId)
         node.last_seen_time = int(time.time())
         node.commit(cursor, update=True)
     else:
         #FIXME: that's not a warning but a BUG 
         log.debug('No matching node found for id {%s}' % nodeId,
                   category='[warning]')
     cursor.close()
Beispiel #5
0
 def registerNodeActivity(self, nodeId):
     """updates last_seen_time attribute"""
     cursor = self._cnx.cursor()
     nodes = Node.selectWhere(cursor, node_id=nodeId)
     if nodes:
         node = nodes[0]
         print " ... registerNodeActivity %s:%s (%s)" % (node.ip, node.port,
                                                         nodeId)
         node.last_seen_time = int(time.time())
         node.commit(cursor, update=True)
     else:
         #FIXME: that's not a warning but a BUG
         log.debug('No matching node found for id {%s}' % nodeId,
                   category='[warning]')
     cursor.close()
Beispiel #6
0
 def registerNode(self, nodeId, ip, port, bandwidth=None, lastSeenTime=None):
     # lastseentime param should probably never be used
     """this will be used as a callback in registrationclient/login"""
     print " ... registerNode %s:%s (%s)" % (ip, port, nodeId)
     if ip == "127.0.0.1":
         print " ... 127.0.0.1 is not an acceptable IP, we don't register this"
         return
     cursor = self._cnx.cursor()
     node = Node.selectOrInsertWhere(cursor, node_id=nodeId)[0]
     node.ip = ip
     node.node_id = nodeId
     node.port = port
     node.bandwidth = bandwidth or 1
     node.last_seen_time = lastSeenTime or int(time.time())
     node.commit(cursor, update=True)
     cursor.close()
Beispiel #7
0
 def registerNode(self,
                  nodeId,
                  ip,
                  port,
                  bandwidth=None,
                  lastSeenTime=None):
     # lastseentime param should probably never be used
     """this will be used as a callback in registrationclient/login"""
     print " ... registerNode %s:%s (%s)" % (ip, port, nodeId)
     if ip == "127.0.0.1":
         print " ... 127.0.0.1 is not an acceptable IP, we don't register this"
         return
     cursor = self._cnx.cursor()
     node = Node.selectOrInsertWhere(cursor, node_id=nodeId)[0]
     node.ip = ip
     node.node_id = nodeId
     node.port = port
     node.bandwidth = bandwidth or 1
     node.last_seen_time = lastSeenTime or int(time.time())
     node.commit(cursor, update=True)
     cursor.close()
Beispiel #8
0
 def indexDocument(self, nodeId, futureDoc):
     """Inserts or update information in table documents,
     file_info, document_score and word
     :type nodeId: node_id or None if working locally
     """
     # XXX Decide if we can compute the content_hash and mime_type
     # ourselves or if the indexer should do it and
     # pass the values as an argument
     cursor = self._cnx.cursor()
     try:
         # insert or update in table file_info
         fileinfo = FileInfo.selectWhere(cursor, file_name=futureDoc.filename)
         # insert title into text to be able to find documents according
         # to their title (e.g: searching 'foo' should find 'foo.pdf')
         futureDoc.text = '%s %s' % (futureDoc.title, futureDoc.text)
         if fileinfo:
             fileinfo = fileinfo[0]
             fileinfo.file_time = futureDoc.lastModificationTime
             fileinfo.state = futureDoc.state
             fileinfo.file_state = futureDoc.file_state
             doc = Document.selectWhere(cursor,
                                        db_document_id=fileinfo.db_document_id)
             if not doc or doc[0].document_id!=futureDoc.content_hash :
                 # no document was found or a document with another content
                 # in both case, we create a new Document in database
                 # (we don't want to modify the existing one, because it
                 # can be shared by several files)
                 doc = self._createDocument(cursor, futureDoc)
                 fileinfo.db_document_id = doc.db_document_id
             else:
                 # document has not changed
                 doc = doc[0]
                 if doc.state != futureDoc.state:
                     doc.state = futureDoc.state
                     doc.commit(cursor, update=True)
             fileinfo.commit(cursor, update=True)
         else:
             # file unknown
             # try to find a Document with same hash value
             doc = Document.selectWhere(cursor,
                                        document_id=futureDoc.content_hash)
             if doc:
                 doc = doc[0]
                 doc.state = futureDoc.state
                 doc.publication_time = max(doc.publication_time,
                                            futureDoc.lastModificationTime)
                 doc.commit(cursor, update=True)
             else:
                 doc = self._createDocument(cursor, futureDoc)
                 doc = Document.selectWhere(cursor, document_id=futureDoc.content_hash)[0]
             fileinfo = FileInfo(db_document_id=doc.db_document_id,
                                 file_name=futureDoc.filename,
                                 file_time=futureDoc.lastModificationTime,
                                 state=futureDoc.state,
                                 file_state=futureDoc.file_state)
             fileinfo.commit(cursor, update=False)
         self._updateScores(cursor, doc.db_document_id, futureDoc.text)
         # update last seen time only if not working locally
         if nodeId is not None:
             provider = DocumentProvider.selectOrInsertWhere(cursor,
                                                             db_document_id=doc.db_document_id,
                                                             node_id=nodeId)[0]
             provider.last_providing_time = int(time.time())
             provider.commit(cursor, update=True)
             nodes = Node.selectWhere(cursor, node_id=nodeId)
             if not nodes:
                 self._cnx.rollback()
                 cursor.close()
                 raise ValueError('provider %s is not registered in our database !')
             node = nodes[0]
             node.last_seen_time = int(time.time())
             node.commit(cursor, update=True)
         cursor.close()
         self._cnx.commit()
     except:
         self._cnx.rollback()
         raise
Beispiel #9
0
 def getActiveNeighbors(self, nodeId, nbNodes):
     cursor = self._cnx.cursor() 
     nodes = Node.selectActive(cursor, nodeId, nbNodes) 
     cursor.close()
     return nodes
Beispiel #10
0
    def indexDocument(self, nodeId, futureDoc):
        """Inserts or update information in table documents,
        file_info, document_score and word"""
        # XXX Decide if we can compute the content_hash and mime_type
        # ourselves or if the indexer should do it and
        # pass the values as an argument
        cursor = self._cnx.cursor()
        # insert or update in table file_info
        fileinfo = FileInfo.selectWhere(cursor, file_name=futureDoc.filename)
        # insert title into text to be able to find documents according
        # to their title (e.g: searching 'foo' should find 'foo.pdf')
        futureDoc.text = '%s %s' % (futureDoc.title, futureDoc.text)
        if fileinfo:
            fileinfo = fileinfo[0]
            fileinfo.file_time = futureDoc.lastModificationTime
            fileinfo.state = futureDoc.state
            fileinfo.file_state = futureDoc.file_state
            doc = Document.selectWhere(cursor,
                                       db_document_id=fileinfo.db_document_id)
            if not doc or doc[0].document_id!=futureDoc.content_hash :
                # no document was found or a document with another content
                # in both case, we create a new Document in database
                # (we don't want to modify the existing one, because it
                # can be shared by several files)
                doc = self._createDocument(cursor, futureDoc)
                fileinfo.db_document_id = doc.db_document_id
            else:
                # document has not changed
                doc = doc[0]
                if doc.state != futureDoc.state:
                    doc.state = futureDoc.state
                    doc.commit(cursor, update=True)
                
            fileinfo.commit(cursor, update=True)
                
        else:
            # file unknown
            # try to find a Document with same hash value
            doc = Document.selectWhere(cursor,
                                       document_id=futureDoc.content_hash)
            if doc:
                doc = doc[0]
                doc.state = futureDoc.state
                doc.publication_time = max(doc.publication_time,
                                           futureDoc.lastModificationTime)
                doc.commit(cursor, update=True)
            else:
                doc = self._createDocument(cursor, futureDoc)
                doc = Document.selectWhere(cursor, document_id=futureDoc.content_hash)[0]

            fileinfo = FileInfo(db_document_id=doc.db_document_id,
                                file_name=futureDoc.filename,
                                file_time=futureDoc.lastModificationTime,
                                state=futureDoc.state,
                                file_state=futureDoc.file_state)
            fileinfo.commit(cursor, update=False)

        self._updateScores(cursor, doc.db_document_id, futureDoc.text)
        provider = DocumentProvider.selectOrInsertWhere(cursor,
                                          db_document_id=doc.db_document_id,
                                          node_id=nodeId)[0]
        provider.last_providing_time = int(time.time())
        provider.commit(cursor, update=True)
        node = Node.selectWhere(cursor, node_id=nodeId)[0]
        node.last_seen_time = int(time.time())
        node.commit(cursor, update=True)
        cursor.close()
        self._cnx.commit()
Beispiel #11
0
 def getActiveNeighbors(self, nodeId, nbNodes):
     cursor = self._cnx.cursor() 
     nodes = Node.selectActive(cursor, nodeId, nbNodes) 
     cursor.close()
     return nodes
Beispiel #12
0
 def getRegisteredNeighbors(self, nodeId, nbNodes):
     cursor = self._cnx.cursor() 
     nodes = Node.selectRegistered(cursor, nodeId, nbNodes) 
     cursor.close()
     return nodes
Beispiel #13
0
 def registerNodeActivity(self, nodeId):
     cursor = self._cnx.cursor()
     node = Node.selectWhere(cursor, node_id=nodeId)[0]
     node.last_seen_time = int(time.time())
     node.commit(cursor, update=True)
     cursor.close()