예제 #1
0
            def _process(rsrc):
                try:
                    if '_id' not in rsrc:
                        raise exc.InvalidInputError(
                            __name__,
                            'delta is missing _id attribute: {}'.format(rsrc)
                        )

                    rsrc_id = rsrc['_id']
                    if proid != rsrc_id.partition('.')[0]:
                        raise exc.InvalidInputError(
                            __name__,
                            'instance id does not match proid: {} {}'.format(
                                proid,
                                rsrc_id
                            )
                        )

                    delta = {rsrc_id: rsrc['priority']}
                    masterapi.update_app_priorities(
                        context.GLOBAL.zk.conn,
                        delta
                    )
                    return masterapi.get_app(context.GLOBAL.zk.conn, rsrc_id)
                except Exception as err:  # pylint: disable=W0703
                    return {'_error': {'_id': rsrc_id,
                                       'why': str(err)}}
예제 #2
0
파일: master.py 프로젝트: ceache/treadmill
    def configure(priority, instance):
        """View app instance configuration"""
        if priority is not None:
            masterapi.update_app_priorities(context.GLOBAL.zk.conn,
                                            {instance: priority})

        scheduled = masterapi.get_app(context.GLOBAL.zk.conn, instance)
        cli.out(formatter(scheduled))
예제 #3
0
        def update(rsrc_id, rsrc):
            """Update instance configuration."""
            _LOGGER.info('update: %s %r', rsrc_id, rsrc)

            delta = {rsrc_id: rsrc['priority']}

            masterapi.update_app_priorities(context.GLOBAL.zk.conn, delta)
            return masterapi.get_app(context.GLOBAL.zk.conn, rsrc_id)
예제 #4
0
    def test_update_app_priority_noop(self):
        """Tests app api."""
        zkclient = kazoo.client.KazooClient()

        # kazoo.client.KazooClient.create.return_value = '/events/001-apps-1'
        masterapi.update_app_priorities(zkclient, {'foo.bar#1': 10,
                                                   'foo.bar#2': 20})
        treadmill.zkutils.update.assert_has_calls(
            [
                mock.call(mock.ANY, '/scheduled/foo.bar#1', {'priority': 10},
                          check_content=True),
                mock.call(mock.ANY, '/scheduled/foo.bar#2', {'priority': 20},
                          check_content=True),
            ],
            any_order=True
        )

        # Verify that event is placed correctly.
        self.assertFalse(treadmill.scheduler.masterapi.create_event.called)
예제 #5
0
    def test_update_app_priority(self):
        """Tests app api."""
        zkclient = kazoo.client.KazooClient()

        kazoo.client.KazooClient.create.return_value = '/events/001-apps-1'
        masterapi.update_app_priorities(zkclient, {'foo.bar#1': 10,
                                                   'foo.bar#2': 20})
        kazoo.client.KazooClient.set.assert_has_calls(
            [
                mock.call('/scheduled/foo.bar#1', b'{priority: 10}\n'),
                mock.call('/scheduled/foo.bar#2', b'{priority: 20}\n'),
            ],
            any_order=True
        )

        # Verify that event is placed correctly.
        kazoo.client.KazooClient.create.assert_called_with(
            '/events/001-apps-', mock.ANY,
            makepath=True, acl=mock.ANY, sequence=True, ephemeral=False
        )