Beispiel #1
0
    def trace(last, snapshot, app):
        """Trace application events.

        Invoking treadmill_trace with non existing application instance will
        cause the utility to wait for the specified instance to be started.

        Specifying already finished instance of the application will display
        historical trace information and exit status.
        """
        if '#' not in app:
            # Instance is not specified, list matching and exit.
            tasks = zk.list_history(context.GLOBAL.zk.conn, app)
            if not tasks:
                print('# Trace information does not exist.', file=sys.stderr)
                return

            elif not last:
                for task in sorted(tasks):
                    print(task)
                return

            else:
                task = sorted(tasks)[-1]

        else:
            task = app

        trace = zk.AppTrace(
            context.GLOBAL.zk.conn,
            task,
            callback=printer.AppTracePrinter()
        )

        trace.run(snapshot=snapshot)
        try:
            while not trace.wait(timeout=1):
                pass

        except KeyboardInterrupt:
            pass
Beispiel #2
0
    def trace(last, snapshot, app):
        """Trace application events.

        Invoking treadmill_trace with non existing application instance will
        cause the utility to wait for the specified instance to be started.

        Specifying already finished instance of the application will display
        historical trace information and exit status.
        """
        if '#' not in app:
            # Instance is not specified, list matching and exit.
            traces = zk.list_traces(context.GLOBAL.zk.conn, app)
            if not traces:
                click.echo('# Trace information does not exist.', err=True)
                return

            elif not last:
                for instance_id in traces:
                    cli.out(instance_id)
                return

            else:
                instance_id = traces[-1]

        else:
            instance_id = app

        trace = zk.AppTrace(context.GLOBAL.zk.conn,
                            instance_id,
                            callback=printer.AppTracePrinter())

        trace.run(snapshot=snapshot)
        try:
            while not trace.wait(timeout=1):
                pass

        except KeyboardInterrupt:
            pass
Beispiel #3
0
            def _watch_scheduled(data, _stat, event):
                """Watch on scheduled node."""

                if data is None and event is None:
                    # ZNode is not there yet
                    _LOGGER.info('Waiting for %r', instance)
                    return True

                elif event is not None and event.type == 'DELETED':

                    trace = zk.AppTrace(zkclient, instance, callback)
                    trace.run(snapshot=True, ctx=info)

                    print_yaml(info)

                    finished.append(info)
                    if len(finished) == expected_nb:
                        done_event.set()
                    return False

                else:
                    # ZNode is here, waiting for instance to terminate.
                    return True
Beispiel #4
0
 def test_wait_snapshot(self):
     """Tests that .wait() return True when not initialized."""
     zkclient = kazoo.client.KazooClient()
     trace = zk.AppTrace(zkclient, None, None)
     self.assertTrue(trace.wait())