def configure(self, client_id):
        #tested
        print("Configuring client with id={} for  service".format(client_id))
        user = [{'id': client_id}]
        currtime = datetime.utcnow()
        client_stats = {
            "last_access_time": currtime,
            "buckets_assigned": 0,
            "buckets_processed": 0,
            "buckets_fault": 0,
            "buckets_dead": 0
        }
        state = {
            'state': ServiceManagemenDefines.ServiceState.CREATED,
            'create_datetime': currtime,
            'edit_datetime': currtime,
            'client_stats': client_stats
        }
        query = """
            UNWIND $user AS u

            MATCH (clientforservice:ClientForService {id:u.id}) 
            MERGE (clientforservice)-[:USERFOLLOWERCHECKCLIENT]->(client:UserFollowerCheckClient)
            MERGE(client)-[:STATS]->(stat:UserFollowerCheckClientStats)
            ON CREATE SET stat += $state.client_stats
        """
        execute_query(query, user=user, state=state)
        return
 def empty_bucket(self, bucket_id):
     #tested
     print("Releaseing users for {} bucket".format(bucket_id))
     state = {'uuid': bucket_id}
     query = """
         MATCH(u:User)-[r:IN__UNDEFINEDSERVICETAG__BUCKET]->(b:__UndefinedServiceTag__Bucket {uuid:$state.uuid})
         DELETE r
     """
     query = query.replace("__UNDEFINEDSERVICETAG__",
                           self.service_db_name.upper())
     query = query.replace("__UndefinedServiceTag__", self.service_db_name)
     execute_query(query, state=state)
     return True
Esempio n. 3
0
    def __store_friends_dmstatus(self, client_id, bucket_id, users, dm_link_name):
        print("Store {} users for {} bucket".format(dm_link_name, bucket_id))
        state = {'client_id':client_id, 'bucket_id':bucket_id}
        query = """
            UNWIND $users AS user

            MATCH(client:DMCheckClient {id:$state.client_id})
            MATCH(b:DMCheckBucket {uuid:$state.bucket_id})
            MATCH(u:User {screen_name: user.screen_name})
            MATCH (u)-[r:INDMCHECKBUCKET]->()
            DELETE r
            MERGE(u)<-[:DM_UNKNOWN]-(client)
        """
        query = query.replace("DM_UNKNOWN", dm_link_name)
        execute_query(query, users=users, state=state)
        return True
    def __migrate_users(self, old_linkname, new_linkname, users):
        print("Migrating {} users".format(len(users)))
        state = {'dmuser_name': self.dmuser_screen_name}
        query = """
            match(client:DMCheckClient {screen_name:$state.dmuser_name})

            UNWIND $users AS u
            match(user:User {screen_name: u.screen_name})
            merge(client)-[:__NEW_LINK__]->(user)
            with user
            match(:User {screen_name:$state.dmuser_name})-[r:__OLD_LINK___]->(user)
            DELETE r
        """
        query = query.replace("__OLD_LINK___", old_linkname)
        query = query.replace("__NEW_LINK__", new_linkname)
        execute_query(query, state=state, users=users)
        return
    def __store_users(self, client_id, bucket_id, users):
        #tested
        print("Store users for {} bucket".format(bucket_id))
        currtime = datetime.utcnow()
        state = {
            'edit_datetime': currtime,
            'client_id': client_id,
            'bucket_id': bucket_id
        }
        query = """
            UNWIND $users AS user

            MATCH(:ClientForService {id:$state.client_id})-[:USERFOLLOWERCHECKCLIENT]->(client:UserFollowerCheckClient)
            MATCH(b:UserFollowerCheckBucket {uuid:$state.bucket_id})
            MATCH(u:User {screen_name: user.screen_name})
            MATCH (u)-[r:INUSERFOLLOWERCHECKBUCKET]->()
            DELETE r

            FOREACH (f IN user.followers |
                MERGE(followeruser:User {screen_name:f.screen_name})
                SET followeruser.name = f.name,
                    followeruser.id = f.id,
                    followeruser.id_str = f.id_str,
                    followeruser.created_at = f.created_at,
                    followeruser.statuses_count = f.statuses_count,
                    followeruser.location = f.location,
                    followeruser.followers = f.followers_count,
                    followeruser.Follower = f.friends_count,
                    followeruser.statuses = f.statusus_count,
                    followeruser.description = toLower(f.description),
                    followeruser.protected = f.protected,
                    followeruser.listed_count = f.listed_count,
                    followeruser.verified = f.verified,
                    followeruser.lang = f.lang,
                    followeruser.contributors_enabled = f.contributors_enabled,
                    followeruser.profile_image_url = f.profile_image_url
                MERGE (followeruser)-[rf:FOLLOWS]->(u)
                ON CREATE SET rf.create_datetime = $state.edit_datetime
                SET rf.edit_datetime = $state.edit_datetime
            )
            MERGE(client)-[:CHECKEDUSERFOLLOWER]->(u)
        """
        execute_query(query, users=users, state=state)
        return True
Esempio n. 6
0
    def __change_state_dmcheck_client(self, client_id, client_state):
        #tested
        print("Changing state to {} for client with id={}".format(client_state, client_id))
        currtime = datetime.utcnow()
        client_stats = {"last_access_time": currtime}
        state = {'state':client_state, 'edit_datetime':currtime, 'client_stats':client_stats}
        user = [{'id':client_id}]
        query = """
            UNWIND $user AS u

            MATCH (client:DMCheckClient {id:u.id})
                SET client.state = $state.state,
                    client.edit_datetime = datetime($state.edit_datetime)
            WITH client
                MATCH(client)-[:STATS]->(stat:DMCheckClientStats)
                    SET stat += $state.client_stats
        """
        execute_query(query, user=user, state=state)
        return
Esempio n. 7
0
 def __add_dmcheck_client(self, client_id, screen_name, dm_from_id, dm_from_screen_name):
    #tested
     print("Adding client with id={}, screen name={}, DM src[{}/{}]".format(client_id, screen_name, dm_from_id, dm_from_screen_name))
     currtime = datetime.utcnow()
     client_stats = {"last_access_time": currtime, "buckets_assigned":0, "buckets_processed":0, "buckets_fault":0, "buckets_dead":0}
     state = {'state':DMCheckCypherStoreClientIntf.ClientState.CREATED, 'create_datetime': currtime, 'edit_datetime':currtime, 'client_stats':client_stats}
     user = [{'screen_name':screen_name, 'id':client_id, 'dm_from_id':dm_from_id, 'dm_from_screen_name':dm_from_screen_name}]
     query = """
         UNWIND $user AS u
         MATCH (clientforservice:ClientForService {id:u.id}) 
         MERGE (client:DMCheckClient {id:u.id})
             SET client.screen_name = u.screen_name,
                 client.dm_from_id = u.dm_from_id,
                 client.dm_from_screen_name = u.dm_from_screen_name,
                 client.state = $state.state,
                 client.create_datetime = datetime($state.create_datetime),
                 client.edit_datetime = datetime($state.edit_datetime)
         MERGE(client)-[:STATS]->(stat:DMCheckClientStats)
         ON CREATE SET stat += $state.client_stats
         MERGE (clientforservice)-[:DMCHECKCLIENT]->(client)
     """
     execute_query(query, user=user, state=state)
     return
 def remove_bucket(self, bucket_id):
     #tested
     print("Releaseing users for {} bucket".format(bucket_id))
     currtime = datetime.utcnow()
     client_stats = {"last_access_time": currtime}
     #TODO: Fix it to use service ID variable
     state = {
         'uuid': bucket_id,
         'client_stats': client_stats,
         'service_id': self.service_db_name
     }
     query = """
         MATCH(b:__UndefinedServiceTag__Bucket {uuid:$state.uuid})-[rs:BUCKETFORSERVICE]->(service:ServiceForClient {id:$state.service_id})
         MATCH(b)-[r:__UNDEFINEDSERVICETAG__CLIENT]->(client:__UndefinedServiceTag__Client)-[:STATS]->(stat:__UndefinedServiceTag__ClientStats)
             SET stat.buckets_processed = stat.buckets_processed + 1,
                 stat.last_access_time = $state.client_stats.last_access_time               
         DELETE r,rs,b
     """
     query = query.replace("__UNDEFINEDSERVICETAG__",
                           self.service_db_name.upper())
     query = query.replace("__UndefinedServiceTag__", self.service_db_name)
     execute_query(query, state=state)
     return True
    def __add_buckets_to_db(self, buckets):
        #tested
        print("Adding {} buckets to DB".format(len(buckets)))
        currtime = datetime.utcnow()
        state = {'edit_datetime': currtime, 'service_id': self.service_id}
        #TODO: Check if it is needed to replace MERGE with MATCH for user
        query = """
            UNWIND $buckets AS bs
            MATCH(service:ServiceForClient {id:$state.service_id})
            MERGE(bucket:__UndefinedServiceTag__Bucket {uuid:bs.bucket_uuid})-[:BUCKETFORSERVICE]->(service)
                SET bucket.edit_datetime = datetime($state.edit_datetime),
                    bucket.priority = bs.bucket_priority

            FOREACH (u IN bs.bucket |
                MERGE(user:User {screen_name:u.name})
                MERGE (user)-[:IN__UNDEFINEDSERVICETAG__BUCKET]->(bucket)
            )
        """
        query = query.replace("__UNDEFINEDSERVICETAG__",
                              self.service_db_name.upper())
        query = query.replace("__UndefinedServiceTag__", self.service_db_name)
        execute_query(query, buckets=buckets, state=state)
        return
    def configure(self, defaults):
        #tested
        print("Configuring service metadata info")
        currtime = datetime.utcnow()
        state = {
            'create_datetime': currtime,
            'service_id': self.service_id,
            'defaults': defaults
        }
        query = """
            MATCH(service:ServiceForClient {id:$state.service_id})
            MERGE(service)-[:__UNDEFINEDSERVICETAG__SERVICEMETA]->(servicemeta:__UndefinedServiceTag__ServiceMeta)
            ON CREATE SET servicemeta.create_datetime = datetime($state.create_datetime)

            MERGE(servicemeta)-[:DEFAULTS]->(defaults:ServiceDefaults)
            ON CREATE SET defaults += $state.defaults
        """
        query = query.replace("__UNDEFINEDSERVICETAG__",
                              self.service_db_name.upper())
        query = query.replace("__UndefinedServiceTag__", self.service_db_name)
        execute_query(query, state=state)
        print("Successfully configured service metadata info")
        return