예제 #1
0
def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    kvstore_pb2_grpc.add_KeyValueStoreServicer_to_server(
        KVStoreServer(), server)
    chaosmonkey_pb2_grpc.add_ChaosMonkeyServicer_to_server(
        ChaosMonkeyServer(), server)

    server.add_insecure_port('[::]' + PORT)
    server.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
예제 #2
0
def start_server(address, id, server_list_file, server_config_file, remote):
    # 1024*1024 = 10MB is the size

    server_config = json.load(open(server_config_file))
    server_name = f'{id}-{address.replace(":", "-")}'

    logger = logging.getLogger('raft')
    logger.setLevel(logging.INFO)

    # # Terminal log output
    # term_handler = logging.StreamHandler(sys.stdout)
    # term_handler.setLevel(logging.INFO)
    # term_handler.setFormatter(logging.Formatter("[%(asctime)s - %(levelname)s]: %(message)s"))
    # logger.addHandler(term_handler)
    # # Record write-ahead log (wal) once get rpc 'appendEntries'
    # os.makedirs('log', exist_ok=True)
    # wal_handler = logging.FileHandler(f'log/{server_name}-wal.log')
    # wal_handler.setLevel(logging.CRITICAL)
    # wal_handler.setFormatter(logging.Formatter("[%(asctime)s - %(levelname)s]: %(message)s"))
    # # WARN: this will overwrite the log
    # logger.addHandler(wal_handler)
    # logger.addHandler(term_handler)

    server = grpc.server(futures.ThreadPoolExecutor())
    addr_list = []
    with open(server_list_file, 'r') as file:
        reader = csv.DictReader(file)
        if remote:
            pass
        else:
            for row in reader:
                addr_list.append(f"{row['address']}:{row['port']}")

    kvserver = KVServer(addr_list, id, server_config)
    kvstore_pb2_grpc.add_KeyValueStoreServicer_to_server(kvserver, server)
    chaosmonkey_pb2_grpc.add_ChaosMonkeyServicer_to_server(
        kvserver.cmserver, server)
    server.add_insecure_port(address)
    # Register gRPC listener
    server.start()
    # Initially run as a follower
    kvserver.run()
    logger.info(f'{socket.gethostname()}')
    logger.info(f'Server [{server_name}] listening {address}')
    try:
        while True:
            time.sleep(24 * 60 * 60)
    except KeyboardInterrupt:
        server.stop(0)
예제 #3
0
def serve(config_path, myIp, myPort):
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    storage_service_pb2_grpc.add_KeyValueStoreServicer_to_server(
        StorageServer(config_path, myIp, myPort), server)
    chaosmonkey_pb2_grpc.add_ChaosMonkeyServicer_to_server(
        ChaosServer(), server)

    server.add_insecure_port(myIp + ':' + myPort)
    try:
        server.start()
    except Exception as e:
        print('Server start failed!')
        print(str(e))

    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
예제 #4
0
def start_server(address, id, join, server_config_file):
    # 1024*1024 = 10MB is the size

    server_config = json.load(open(server_config_file))
    server_name = f'{id}-{address.replace(":", "-")}'

    logger = logging.getLogger('Chord')
    logger.setLevel(logging.INFO)
    # # Terminal log output
    # term_handler = logging.StreamHandler(sys.stdout)
    # term_handler.setLevel(logging.INFO)
    # term_handler.setFormatter(logging.Formatter("[%(asctime)s - %(levelname)s]: %(message)s"))
    # logger.addHandler(term_handler)
    # # Record write-ahead log (wal) once get rpc 'appendEntries'
    # os.makedirs('log', exist_ok=True)
    # wal_handler = logging.FileHandler(f'log/{server_name}-wal.log')
    # wal_handler.setLevel(logging.CRITICAL)
    # wal_handler.setFormatter(logging.Formatter("[%(asctime)s - %(levelname)s]: %(message)s"))
    # # WARN: this will overwrite the log
    # logger.addHandler(wal_handler)
    # logger.addHandler(term_handler)
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=20))
    virtual_node = Virtual_node(id, address, join, server_config)
    server_pb2_grpc.add_ServerServicer_to_server(virtual_node, server)
    chaosmonkey_pb2_grpc.add_ChaosMonkeyServicer_to_server(
        virtual_node.cmserver, server)
    server.add_insecure_port(address)
    server.start()
    virtual_node.run()
    logger.info(f'{socket.gethostname()}')
    logger.info(f'Server [{server_name}] listening {address}')
    try:
        while True:
            time.sleep(24 * 60 * 60)
    except KeyboardInterrupt:
        server.stop(0)