Esempio n. 1
0
        def _list(match=None):
            """List configured instances."""
            if match is None:
                match = '*'
            if '#' not in match:
                match += '#*'

            instances = master.list_scheduled_apps(context.GLOBAL.zk.conn)
            filtered = [
                inst for inst in instances if fnmatch.fnmatch(inst, match)
            ]
            return sorted(filtered)
Esempio n. 2
0
def stop(job_id=None, app_name=None):
    """Stop an application"""
    _LOGGER.debug('app_name: %r', app_name)
    _LOGGER.debug('job_id: %s', job_id)

    zkclient = context.GLOBAL.zk.conn

    instances = master.list_scheduled_apps(zkclient)

    app_name_pattern = '{}*'.format(app_name)
    filtered = [
        inst for inst in instances if fnmatch.fnmatch(inst, app_name_pattern)
    ]

    if not filtered:
        _LOGGER.info('Nothing is running for %s', app_name)
        return

    _LOGGER.info('Stopping all instances: %r', filtered)
    master.delete_apps(zkclient, filtered)
Esempio n. 3
0
def _run_sync():
    """Sync app monitor count with instance count."""

    instance_api = instance.init(authz.NullAuthorizer())
    zkclient = context.GLOBAL.zk.conn

    while True:
        scheduled = sorted(master.list_scheduled_apps(zkclient))
        appname_f = lambda n: n[:n.find('#')]
        grouped = collections.defaultdict(
            list,
            {k: list(v)
             for k, v in itertools.groupby(scheduled, appname_f)})

        appmonitors = master.appmonitors(zkclient)
        for appname in appmonitors:
            data = master.get_appmonitor(zkclient, appname)
            if not data:
                _LOGGER.info('App monitor does not exist: %s', appname)
                continue

            count = data['count']
            current_count = len(grouped[appname])
            _LOGGER.debug('App: %s current: %s, target %s', appname,
                          current_count, count)
            if count == current_count:
                continue

            if count > current_count:
                # need to start more.
                needed = count - current_count
                scheduled = instance_api.create(appname, {}, count=needed)

            if count < current_count:
                for extra in grouped[appname][:current_count - count]:
                    instance_api.delete(extra)

        time.sleep(60)
Esempio n. 4
0
 def list():  # pylint: disable=W0622
     """List apps"""
     for appname in master.list_scheduled_apps(context.GLOBAL.zk.conn):
         print appname
Esempio n. 5
0
 def _list():
     """List configured instances."""
     return master.list_scheduled_apps(context.GLOBAL.zk.conn)