Esempio n. 1
0
 def start_raft(self):
     common.raft_status.clear()
     common.vip_status.clear()
     common.raft_restart.clear()
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     loop.create_task(raftos.register(self.node, cluster=self.clusters))
     loop.run_until_complete(self.run_node())
Esempio n. 2
0
    def _get_signature(self, params=None):
        if params is None:
            params = {}

        msg = ''.join(map(str, sorted(params.values()))).encode()
        return hmac.new(self.key.encode(), msg=msg).hexdigest()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--conf')
    parser.add_argument('--node')
    parser.add_argument('--cluster')
    args = parser.parse_args()

    cluster = ['127.0.0.1:{}'.format(port) for port in args.cluster.split()]
    node = '127.0.0.1:{}'.format(args.node)

    beatle = Beatle(config_path=args.conf, beatle_id=node)
    logger.info('Starting beatle node: {}'.format(node))

    loop = asyncio.get_event_loop()
    loop.create_task(raftos.register(node, cluster=cluster))
    raftos.configure({
        'log_path': '/var/log/beatle/',
        'serializer': raftos.serializers.JSONSerializer,
        'on_leader': beatle.on_leader
    })
    loop.run_until_complete(beatle.run())
Esempio n. 3
0
import raftos

loop.create_task(
    raftos.register(
        # node running on this machine
        '127.0.0.1:8000',

        # other servers
        cluster=['127.0.0.1:8001', '127.0.0.1:8002']))
loop.run_forever()
Esempio n. 4
0
    data = raftos.Replicated(name='data')


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--node')
    parser.add_argument('--cluster')
    args = parser.parse_args()

    cluster = ['127.0.0.1:{}'.format(port) for port in args.cluster.split()]
    node = '127.0.0.1:{}'.format(args.node)

    raftos.configure({
        'log_path': './'
    })
    raftos.register(node, cluster=cluster)

    obj = Class()
    while True:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(asyncio.sleep(5))

        try:
            obj.data = {
                'id': random.randint(1, 1000),
                'data': {
                    'amount': random.randint(1, 1000) * 1000,
                    'created_at': datetime.now().strftime('%d/%m/%y %H:%M')
                }
            }
        except raftos.exceptions.NotALeaderException: