Example #1
0
    def test_create_apps(self):
        """Tests app api."""
        zkclient = kazoo.client.KazooClient()
        kazoo.client.KazooClient.create.return_value = '/scheduled/foo.bar#12'

        master.create_apps(zkclient, 'foo.bar', {}, 2)
        kazoo.client.KazooClient.create.assert_has_calls(
            [
                mock.call('/scheduled/foo.bar#',
                          b'{}\n',
                          makepath=True,
                          sequence=True,
                          ephemeral=False,
                          acl=mock.ANY),
                mock.call('/trace/000C/foo.bar#12,123.34,xxx,pending,created',
                          b'',
                          makepath=True,
                          acl=mock.ANY),
                # Mock call returns same instance (#12), so same task is
                # created twice.
                mock.call('/scheduled/foo.bar#',
                          b'{}\n',
                          makepath=True,
                          sequence=True,
                          ephemeral=False,
                          acl=mock.ANY),
                mock.call('/trace/000C/foo.bar#12,123.34,xxx,pending,created',
                          b'',
                          makepath=True,
                          acl=mock.ANY)
            ],
            any_order=True)
Example #2
0
    def test_create_apps(self):
        """Tests app api."""
        zkclient = kazoo.client.KazooClient()
        kazoo.client.KazooClient.create.return_value = '/scheduled/foo.bar#12'

        master.create_apps(zkclient, 'foo.bar', {}, 3)
        kazoo.client.KazooClient.create.assert_has_calls([
            mock.call('/scheduled/foo.bar#',
                      '{}\n',
                      makepath=True,
                      sequence=True,
                      ephemeral=False,
                      acl=mock.ANY)
        ] * 3)
Example #3
0
        def create(rsrc_id, rsrc, count=1):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r', count, rsrc_id, rsrc)

            if not rsrc:
                admin_app = admin.Application(context.GLOBAL.ldap.conn)
                configured = admin_app.get(rsrc_id)
            else:
                configured = rsrc
                app.verify_feature(rsrc.get('features', []))

            if '_id' in configured:
                del configured['_id']

            _validate(configured)

            if instance_plugin:
                configured = instance_plugin.add_attributes(
                    rsrc_id, configured)
            if 'proid' not in configured:
                raise Exception('Missing required attribute: proid')
            if 'environment' not in configured:
                raise Exception('Missing required attribute: environment')

            if 'identity_group' not in configured:
                configured['identity_group'] = None

            scheduled = master.create_apps(context.GLOBAL.zk.conn, rsrc_id,
                                           configured, count)
            return scheduled
Example #4
0
def start(job_id=None, app_name=None, count=1):
    """Start an application in the given cell"""
    _LOGGER.debug('app_name: %s', app_name)
    _LOGGER.debug('job_id: %s', job_id)
    _LOGGER.debug('count: %s', count)

    zkclient = context.GLOBAL.zk.conn
    scheduler = cron.get_scheduler(zkclient)

    job = scheduler.get_job(job_id)

    if not app_name:
        _LOGGER.error('No app name provided, cannot continue')
        return

    admin_app = admin.Application(context.GLOBAL.ldap.conn)

    configured = admin_app.get(app_name)

    if not configured:
        _LOGGER.info('App %s is not configured, pausing job %s', app_name,
                     job.id)
        job.pause()
        return

    instance_plugin = None
    try:
        instance_plugin = importlib.import_module(
            'treadmill.plugins.api.instance')
    except ImportError as err:
        _LOGGER.info('Unable to load auth plugin: %s', err)

    if instance_plugin:
        configured = instance_plugin.add_attributes(app_name, configured)

    if 'identity_group' not in configured:
        configured['identity_group'] = None

    if 'affinity' not in configured:
        configured['affinity'] = '{0}.{1}'.format(*app_name.split('.'))

    if '_id' in configured:
        del configured['_id']
    _LOGGER.info('Configured: %s %r', app_name, configured)

    scheduled = master.create_apps(zkclient, app_name, configured, count)
    _LOGGER.debug('scheduled: %r', scheduled)
Example #5
0
    def schedule(app, manifest, count, env, proid):
        """Schedule app(s) on the cell master"""
        data = yaml.load(manifest.read())
        # TODO: should we delete all potential attributes starting
        #                with _ ?
        if '_id' in data:
            del data['_id']

        data['environment'] = env
        if 'affinity' not in data:
            # TODO: allow custom affinity formats.
            data['affinity'] = '{0}.{1}'.format(*app.split('.'))

        data['proid'] = proid
        scheduled = master.create_apps(context.GLOBAL.zk.conn, app, data,
                                       count)
        for app_id in scheduled:
            print app_id
Example #6
0
        def create(rsrc_id, rsrc, count=1):
            """Create (configure) instance."""
            _LOGGER.info('create: count = %s, %s %r', count, rsrc_id, rsrc)

            admin_app = admin.Application(context.GLOBAL.ldap.conn)
            if not rsrc:
                configured = admin_app.get(rsrc_id)
                _LOGGER.info('Configured: %s %r', rsrc_id, configured)
            else:
                # Make sure defaults are present
                configured = admin_app.from_entry(admin_app.to_entry(rsrc))
                app.verify_feature(rsrc.get('features', []))

            if '_id' in configured:
                del configured['_id']

            _validate(configured)

            if instance_plugin:
                configured = instance_plugin.add_attributes(
                    rsrc_id, configured)

            if 'proid' not in configured:
                raise exc.TreadmillError('Missing required attribute: proid')
            if 'environment' not in configured:
                raise exc.TreadmillError(
                    'Missing required attribute: environment')

            if 'identity_group' not in configured:
                configured['identity_group'] = None

            if 'affinity' not in configured:
                configured['affinity'] = '{0}.{1}'.format(*rsrc_id.split('.'))

            scheduled = master.create_apps(context.GLOBAL.zk.conn, rsrc_id,
                                           configured, count)
            return scheduled