Пример #1
0
def create_tasks(
    lifecycle: Optional[Callable] = None,
    registry: Optional[registries.BaseRegistry] = None,
    standalone: bool = False,
    priority: int = 0,
    peering_name: str = peering.PEERING_DEFAULT_NAME,
    namespace: Optional[str] = None,
):
    """
    Create all the tasks needed to run the operator, but do not spawn/start them.
    The tasks are properly inter-connected depending on the runtime specification.
    They can be injected into any event loop as needed.
    """

    # The freezer and the registry are scoped to this whole task-set, to sync them all.
    lifecycle = lifecycle if lifecycle is not None else lifecycles.get_default_lifecycle(
    )
    registry = registry if registry is not None else registries.get_default_registry(
    )
    freeze = asyncio.Event()
    tasks = []

    # Monitor the peers, unless explicitly disabled.
    ourselves: Optional[peering.Peer] = peering.Peer.detect(
        id=peering.detect_own_id(),
        priority=priority,
        standalone=standalone,
        namespace=namespace,
        name=peering_name,
    )
    if ourselves:
        tasks.extend([
            asyncio.Task(peering.peers_keepalive(ourselves=ourselves)),
            asyncio.Task(
                watcher(namespace=namespace,
                        resource=ourselves.resource,
                        handler=functools.partial(
                            peering.peers_handler,
                            ourselves=ourselves,
                            freeze=freeze))),  # freeze is set/cleared
        ])

    # Resource event handling, only once for every known resource (de-duplicated).
    for resource in registry.resources:
        tasks.extend([
            asyncio.Task(
                watcher(namespace=namespace,
                        resource=resource,
                        handler=functools.partial(
                            handling.custom_object_handler,
                            lifecycle=lifecycle,
                            registry=registry,
                            resource=resource,
                            freeze=freeze))),  # freeze is only checked
        ])

    return tasks
Пример #2
0
def resume(id, namespace, peering):
    """ Resume the resource handling in the cluster. """
    login()
    ourselves = Peer(
        id=id or detect_own_id(),
        peering=peering,
        namespace=namespace,
    )
    ourselves.disappear()
Пример #3
0
def resume(id, namespace, peering_name):
    """ Resume the resource handling in the cluster. """
    config.login()
    ourselves = peering.Peer(
        id=id or peering.detect_own_id(),
        name=peering_name,
        namespace=namespace,
    )
    ourselves.disappear()
Пример #4
0
def resume(id, namespace, peering_name):
    """ Resume the resource handling in the cluster. """
    config.login()
    ourselves = peering.Peer(
        id=id or peering.detect_own_id(),
        name=peering_name,
        namespace=namespace,
    )
    loop = asyncio.get_event_loop()
    loop.run_until_complete(ourselves.disappear())
Пример #5
0
def freeze(id, message, lifetime, namespace, peering, priority):
    """ Freeze the resource handling in the cluster. """
    login()
    ourserlves = Peer(
        id=id or detect_own_id(),
        peering=peering,
        namespace=namespace,
        priority=priority,
        lifetime=lifetime,
    )
    ourserlves.keepalive()
Пример #6
0
def freeze(id, message, lifetime, namespace, peering_name, priority):
    """ Freeze the resource handling in the cluster. """
    config.login()
    ourserlves = peering.Peer(
        id=id or peering.detect_own_id(),
        name=peering_name,
        namespace=namespace,
        priority=priority,
        lifetime=lifetime,
    )
    loop = asyncio.get_event_loop()
    loop.run_until_complete(ourserlves.keepalive())