Exemple #1
0
    def configure(app, count):
        """Create, get or modify an app monitor configuration"""
        zkclient = context.GLOBAL.zk.conn
        if count is not None:
            master.update_appmonitor(zkclient, app, count)

        cli.out(formatter(master.get_appmonitor(zkclient, app)))
Exemple #2
0
    def configure(app, count):
        """Configures app monitor."""
        zkclient = context.GLOBAL.zk.conn
        if count is not None:
            master.update_appmonitor(zkclient, app, count)

        cli.out(formatter(master.get_appmonitor(zkclient, app)))
Exemple #3
0
    def _list():
        """List all configured monitors"""
        zkclient = context.GLOBAL.zk.conn
        monitors = [
            master.get_appmonitor(zkclient, app)
            for app in master.appmonitors(zkclient)
        ]

        cli.out(formatter(monitors))
Exemple #4
0
        def _list(match=None):
            """List configured monitors."""
            if match is None:
                match = '*'

            zkclient = context.GLOBAL.zk.conn
            monitors = [
                master.get_appmonitor(zkclient, app)
                for app in master.appmonitors(zkclient)
            ]

            filtered = [
                monitor for monitor in monitors
                if (monitor is not None and
                    fnmatch.fnmatch(monitor['_id'], match))
            ]
            return sorted(filtered)
Exemple #5
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)
Exemple #6
0
 def update(rsrc_id, rsrc):
     """Update application configuration."""
     zkclient = context.GLOBAL.zk.conn
     master.update_appmonitor(zkclient, rsrc_id, rsrc['count'])
     return master.get_appmonitor(zkclient, rsrc_id)
Exemple #7
0
 def create(rsrc_id, rsrc):
     """Create (configure) application monitor."""
     zkclient = context.GLOBAL.zk.conn
     master.update_appmonitor(zkclient, rsrc_id, rsrc['count'])
     return master.get_appmonitor(zkclient, rsrc_id)
Exemple #8
0
 def get(rsrc_id):
     """Get application monitor configuration."""
     zkclient = context.GLOBAL.zk.conn
     return master.get_appmonitor(zkclient, rsrc_id,
                                  raise_notfound=True)