def connected_nodestacks(registry, tdir, looper, connection_timeout, tconf):
    genKeys(tdir, registry.keys())
    stacks = []
    for name, ha in registry.items():
        printer = Printer(name)
        stackParams = dict(name=name,
                           ha=ha,
                           basedirpath=tdir,
                           auth_mode=AuthMode.RESTRICTED.value)
        reg = copy(registry)
        reg.pop(name)
        stack = KITZStack(stackParams, printer.print, reg)
        stack.listenerQuota = tconf.NODE_TO_NODE_STACK_QUOTA
        stack.listenerSize = tconf.NODE_TO_NODE_STACK_SIZE
        stacks.append(stack)

    motors = prepStacks(looper, *stacks, connect=False, useKeys=True)

    looper.run(
        eventually(checkStacksConnected,
                   stacks,
                   retryWait=1,
                   timeout=connection_timeout))

    return stacks, motors
Exemplo n.º 2
0
 def start(self, restricted=None, reSetupAuth=True):
     KITZStack.start(self, restricted=restricted, reSetupAuth=reSetupAuth)
     # Calling service lifecycle to allow creation of remotes
     # that this stack needs to connect to
     # self.serviceLifecycle()
     logger.info("{}{} listening for other nodes at {}:{}".format(
         CONNECTION_PREFIX, self, *self.ha),
                 extra={"tags": ["node-listening"]})
Exemplo n.º 3
0
 def __init__(self, stackParams: dict, msgHandler: Callable,
              registry: Dict[str, HA], seed=None, sighex: str=None,
              config=None):
     config = config or getConfig()
     Batched.__init__(self)
     KITZStack.__init__(self, stackParams, msgHandler, registry=registry,
                        seed=seed, sighex=sighex, config=config)
     MessageProcessor.__init__(self, allowDictOnly=False)
Exemplo n.º 4
0
 def __init__(self, stackParams: dict, msgHandler: Callable,
              registry: Dict[str, HA], seed=None, sighex: str=None,
              config=None, metrics=NullMetricsCollector()):
     config = config or getConfig()
     Batched.__init__(self, config=config, metrics=metrics)
     KITZStack.__init__(self, stackParams, msgHandler, registry=registry,
                        seed=seed, sighex=sighex, config=config,
                        metrics=metrics,
                        mt_incoming_size=MetricType.INCOMING_NODE_MESSAGE_SIZE,
                        mt_outgoing_size=MetricType.OUTGOING_NODE_MESSAGE_SIZE)
     MessageProcessor.__init__(self, allowDictOnly=False)
Exemplo n.º 5
0
def create_stack(name, looper, tdir, tconf):
    msh_handler = CounterMsgsHandler()
    stackParams = dict(name=name, ha=REGISTRY[name], basedirpath=tdir,
                       auth_mode=AuthMode.RESTRICTED.value)
    stack = KITZStack(stackParams, msgHandler=msh_handler.handler, registry=REGISTRY, config=tconf)
    motor = prepStacks(looper, *[stack], connect=False, useKeys=True)[0]
    return stack, motor, msh_handler
Exemplo n.º 6
0
def create_stack(name, looper, tdir, tconf):
    printer = Printer(name)
    stackParams = dict(name=name, ha=REGISTRY[name], basedirpath=tdir,
                       auth_mode=AuthMode.RESTRICTED.value)
    stack = KITZStack(stackParams, msgHandler=printer.print, registry=REGISTRY, config=tconf)
    patch_ping_pong(stack)
    motor = prepStacks(looper, *[stack], connect=False, useKeys=True)[0]
    return stack, motor
def connected_nodestacks(registry, tdir, looper, connection_timeout, tconf):
    genKeys(tdir, registry.keys())
    stacks = []
    for name, ha in registry.items():
        printer = Printer(name)
        stackParams = dict(name=name, ha=ha, basedirpath=tdir,
                           auth_mode=AuthMode.RESTRICTED.value)
        reg = copy(registry)
        reg.pop(name)
        stack = KITZStack(stackParams, printer.print, reg)
        stack.listenerQuota = tconf.NODE_TO_NODE_STACK_QUOTA
        stack.listenerSize = tconf.NODE_TO_NODE_STACK_SIZE
        stacks.append(stack)

    motors = prepStacks(looper, *stacks, connect=False, useKeys=True)

    looper.run(eventually(
        checkStacksConnected, stacks, retryWait=1, timeout=connection_timeout))

    return stacks, motors
Exemplo n.º 8
0
def testKitZStacksCommunication(registry, tdir, looper):
    # TODO: Use a packet capture tool
    genKeys(tdir, registry.keys())
    stacks = []
    names = []
    for name, ha in registry.items():
        printer = Printer(name)
        stackParams = dict(name=name, ha=ha, basedirpath=tdir,
                           auth_mode=AuthMode.RESTRICTED.value)
        reg = copy(registry)
        reg.pop(name)
        stack = KITZStack(stackParams, printer.print, reg)
        stacks.append(stack)
        names.append((name, printer))

    prepStacks(looper, *stacks, connect=False, useKeys=True)
    # TODO: the connection may not be established for the first try because
    # some of the stacks may not have had a remote yet (that is they haven't had yet called connect)
    timeout = 4 * KITZStack.RETRY_TIMEOUT_RESTRICTED + 1
    looper.run(eventually(
        checkStacksConnected, stacks, retryWait=1, timeout=timeout))

    def send_recv():
        for i, j in combinations(range(len(stacks)), 2):
            alpha = stacks[i]
            beta = stacks[j]

            alpha.send({'greetings': 'hi'}, beta.name)
            beta.send({'greetings': 'hello'}, alpha.name)

            looper.run(
                eventually(chkPrinted, names[i][1], {'greetings': 'hello'}, timeout=15))
            looper.run(eventually(chkPrinted, names[j][1], {
                       'greetings': 'hi'}, timeout=15))

            names[i][1].reset()
            names[j][1].reset()

    def pr():
        for stack in stacks:
            for r in stack.remotes.values():
                print(r._lastSocketEvents())

    for _ in range(100):
        # send_recv()
        looper.run(eventually(
            checkStacksConnected, stacks, retryWait=1, timeout=timeout))
        # pr()
        looper.runFor(30)
Exemplo n.º 9
0
def testKitZStacksConnected(registry, tdir, looper, tconf):
    genKeys(tdir, registry.keys())
    stacks = []
    for name, ha in registry.items():
        printer = Printer(name)
        stackParams = dict(name=name, ha=ha, basedirpath=tdir, auth_mode=AuthMode.RESTRICTED.value)
        reg = copy(registry)
        reg.pop(name)
        stack = KITZStack(stackParams, printer.print, reg)
        stacks.append(stack)

    prepStacks(looper, *stacks, connect=False, useKeys=True)
    # TODO: the connection may not be established for the first try because
    # some of the stacks may not have had a remote yet (that is they haven't had yet called connect)
    timeout = 2*tconf.RETRY_TIMEOUT_RESTRICTED+1
    looper.run(eventually(
        checkStacksConnected, stacks, retryWait=1, timeout=timeout))