示例#1
0
文件: main.py 项目: CPSSD/rabble
def main():
    args = get_args()
    logger = get_logger('actors_service', args.v)
    logger.info('Creating server')

    with get_service_channel(logger, "DB_SERVICE_HOST", 1798) as db_chan, \
            get_service_channel(logger, "FOLLOWS_SERVICE_HOST", 1641) as follows_chan:
        db_stub = database_pb2_grpc.DatabaseStub(db_chan)
        follows_stub = follows_pb2_grpc.FollowsStub(follows_chan)

        users_util = UsersUtil(logger, db_stub)
        activities_util = ActivitiesUtil(logger, db_stub)
        host_name = get_host_name(logger)

        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

        servicer = Servicer(logger, users_util, activities_util, db_stub,
                            host_name, follows_stub)
        actors_pb2_grpc.add_ActorsServicer_to_server(servicer, server)

        server.add_insecure_port('0.0.0.0:1973')
        logger.info("Starting actors service on port 1973")
        server.start()
        try:
            while True:
                time.sleep(60 * 60 * 24)  # One day
        except KeyboardInterrupt:
            pass
示例#2
0
 def setUp(self):
     self.activ_util = ActivitiesUtil(Mock(), Mock())
     self.activ_util._get_activitypub_actor_url = lambda host, handle: (host + '/ap/@' + handle)
     self.activ_util.build_inbox_url = lambda handle, host: (host + '/ap/@' + handle + '/inbox')
     self.servicer = SendFollowServicer(Mock(), self.activ_util, Mock())
     self.mock_response = Mock()
     self.mock_response.text = ''
     self.mock_response.status_code = 200
示例#3
0
    def __init__(self, users_util, logger, db_stub):
        self._logger = logger
        self._db_stub = db_stub
        self._users_util = users_util
        self._activ_util = ActivitiesUtil(logger, db_stub)
        self._recommender_util = RecommendersUtil(
            logger, db_stub, self.DEFAULT_RECOMMENDER, self.ENV_VAR, self.RECOMMENDERS)

        # self.active_recommenders contains one or more recommender system
        # objects (out of the constructors in self.RECOMMENDERS).
        self.active_recommenders = self._recommender_util._get_active_recommenders()
 def setUp(self):
     os.environ["HOST_NAME"] = "cianisharrypotter.secret"
     self.activ_util = ActivitiesUtil(Mock(), Mock())
     self.activ_util._get_activitypub_actor_url = lambda host, handle: (
         host + '/ap/@' + handle)
     self.activ_util.build_inbox_url = lambda handle, host: (
         host + '/ap/@' + handle + '/inbox')
     self.servicer = SendFollowServicer(Mock(), self.activ_util, Mock())
     self.mock_response = Mock()
     self.mock_response.text = ''
     self.mock_response.status_code = 200
 def setUp(self):
     self.db = MockDB()
     self.activ_util = ActivitiesUtil(Mock(), self.db)
     self.activ_util.build_actor = lambda han, host: f'{host}/ap/@{han}'
     self.activ_util.build_inbox_url = lambda han, host: f'{host}/ap/@{han}/inbox'
     self.users_util = UsersUtil(Mock(), self.db)
     self.servicer = SendLikeServicer(Mock(), self.db, self.users_util,
                                      self.activ_util, "localhost")
     self.data = None
     self.url = None
     self.activ_util.send_activity = self.save_request
示例#6
0
 def setUp(self):
     self.req = upb.LikeUndoDetails(
         article_id=3,
         liker_handle="cian",
     )
     self.db = MockDB()
     self.activ_util = ActivitiesUtil(Mock(), self.db)
     self.users_util = UsersUtil(Mock(), self.db)
     self.hostname = "skinny_123"
     self.servicer = SendLikeUndoServicer(
         Mock(), self.db, self.activ_util, self.users_util, self.hostname)
     self.data = None
     self.url = None
     self.activ_util.send_activity = self.save_request
     self.activ_util._get_activitypub_actor_url = lambda host, handle: (host + '/' + handle)
     self.activ_util.build_inbox_url = lambda handle, host: (host + '/' + handle + '/inbox')
示例#7
0
文件: main.py 项目: SailSlick/rabble
def main():
    logger = get_logger("undo_service")
    db_stub = get_db_stub(logger)
    activ_util = ActivitiesUtil(logger, db_stub)
    users_util = UsersUtil(logger, db_stub)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    undo_pb2_grpc.add_S2SUndoServicer_to_server(
        S2SUndoServicer(logger, db_stub, activ_util, users_util), server)
    server.add_insecure_port("0.0.0.0:1608")
    logger.info("Starting Undo service on port 1608")
    server.start()
    try:
        while True:
            time.sleep(60 * 60 * 24)  # One day
    except KeyboardInterrupt:
        pass
示例#8
0
def main():
    args = get_args()
    logger = get_logger("s2s_follow_service", args.v)
    users_util = UsersUtil(logger, None)
    with get_future_channel(logger, "DB_SERVICE_HOST", 1798) as db_chan, \
            get_future_channel(logger, "FOLLOWS_SERVICE_HOST", 1641) as logger_chan:
        db_stub = database_pb2_grpc.DatabaseStub(db_chan)
        activ_util = ActivitiesUtil(logger, db_stub)
        follows_service = follows_pb2_grpc.FollowsStub(logger_chan)
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
        s2s_follow_pb2_grpc.add_S2SFollowServicer_to_server(
            FollowServicer(logger, users_util, activ_util, follows_service,
                           db_stub), server)
        server.add_insecure_port('0.0.0.0:1922')
        logger.info("Starting s2s follow server on port 1922")
        server.start()
        while True:
            time.sleep(60 * 60 * 24)  # One day
示例#9
0
def main():
    logger = get_logger("likes_service")
    db_stub = get_db_stub(logger)
    user_util = UsersUtil(logger, db_stub)
    activ_util = ActivitiesUtil(logger, db_stub)
    recommender_util = RecommendersUtil(logger, db_stub)
    post_recommendation_stub = recommender_util.get_post_recommendation_stub()
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    like_pb2_grpc.add_S2SLikeServicer_to_server(
        S2SLikeServicer(logger, db_stub, user_util, activ_util,
                        post_recommendation_stub), server)
    server.add_insecure_port("0.0.0.0:1848")
    logger.info("Starting Like service on port 1848")
    server.start()
    try:
        while True:
            time.sleep(60 * 60 * 24)  # One day
    except KeyboardInterrupt:
        pass
示例#10
0
文件: main.py 项目: SailSlick/rabble
def main():
    logger = get_logger("announce_service")
    db_stub = get_db_stub(logger)
    article_stub = get_article_stub(logger)
    user_util = UsersUtil(logger, db_stub)
    activ_util = ActivitiesUtil(logger, db_stub)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    announce_pb2_grpc.add_AnnounceServicer_to_server(
        AnnounceServicer(logger, db_stub, user_util, activ_util, article_stub),
        server
    )
    server.add_insecure_port("0.0.0.0:1919")
    logger.info("Starting Announce service on port 1919")
    server.start()
    try:
        while True:
            time.sleep(60 * 60 * 24)  # One day
    except KeyboardInterrupt:
        pass
示例#11
0
文件: main.py 项目: CPSSD/rabble
def main():
    args = get_args()
    logger = get_logger("update_service", args.v)
    db_stub = get_db_stub(logger)
    md_stub = get_md_stub(logger)
    activ_util = ActivitiesUtil(logger, db_stub)
    users_util = UsersUtil(logger, db_stub)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    update_pb2_grpc.add_S2SUpdateServicer_to_server(
        S2SUpdateServicer(logger, db_stub, md_stub, activ_util, users_util),
        server)
    server.add_insecure_port("0.0.0.0:2029")
    logger.info("Starting Update service on port 2029")
    server.start()
    try:
        while True:
            time.sleep(60 * 60 * 24)  # One day
    except KeyboardInterrupt:
        pass
示例#12
0
文件: main.py 项目: SailSlick/rabble
def main():
    logger = get_logger("create_service")
    logger.info("Creating db connection")

    with get_service_channel(logger, "DB_SERVICE_HOST", 1798) as db_chan:
        db_stub = database_pb2_grpc.DatabaseStub(db_chan)
        users_util = UsersUtil(logger, db_stub)
        activ_util = ActivitiesUtil(logger, db_stub)

        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
        approver_pb2_grpc.add_ApproverServicer_to_server(
            ApproverServicer(logger, db_stub, activ_util, users_util),
            server,
        )

        server.add_insecure_port('0.0.0.0:2077')
        logger.info("Starting approver service on port 2077")
        server.start()
        while True:
            time.sleep(60 * 60 * 24)  # One day
示例#13
0
def main():
    logger = get_logger("create_service")

    db_channel = get_service_channel(logger, "DB_SERVICE_HOST", 1798)
    db_stub = database_pb2_grpc.DatabaseStub(db_channel)
    article_channel = get_future_channel(logger, "ARTICLE_SERVICE_HOST", 1601)
    article_stub = article_pb2_grpc.ArticleStub(article_channel)
    logger.info("Creating create server")
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    users_util = UsersUtil(logger, db_stub)
    activ_util = ActivitiesUtil(logger, db_stub)
    create_pb2_grpc.add_CreateServicer_to_server(
        CreateServicer(db_stub, article_stub, logger, users_util, activ_util),
        server
    )
    server.add_insecure_port('0.0.0.0:1922')
    logger.info("Starting create server on port 1922")
    server.start()
    try:
        while True:
            time.sleep(60 * 60 * 24)  # One day
    except KeyboardInterrupt:
        db_channel.close()
        pass
示例#14
0
 def setUp(self):
     os.environ["HOST_NAME"] = "b.com"
     self.activ_util = ActivitiesUtil(Mock(), Mock())
     self.activ_util._hostname = 'b.com'
示例#15
0
 def setUp(self):
     activ_util = ActivitiesUtil(Mock(), Mock())
     activ_util.send_activity = Mock(return_value=(None, None))
     self.servicer = SendApprovalServicer(Mock(), activ_util)
示例#16
0
 def __init__(self, logger, db_stub):
     self._logger = logger
     self._db = db_stub
     self._activ_util = ActivitiesUtil(logger, db_stub)
示例#17
0
 def setUp(self):
     self.activ_util = ActivitiesUtil(Mock(), Mock())
     self.activ_util._host_name = 'b.com'