Ejemplo n.º 1
0
    def start_action(self, worker_id, action_id=None):
        '''Run the given action in a sub-thread.

        Release the action lock when the thread finishes?

        :param workder_id: ID of the worker thread; we fake workers using
                           senlin engines at the moment.
        :param action_id: ID of the action to be executed. None means the
                          1st ready action will be scheduled to run.
        '''
        def release(thread, action_id):
            '''Callback function that will be passed to GreenThread.link().'''
            # Remove action thread from thread list
            self.workers.pop(action_id)

        timestamp = wallclock()
        if action_id is not None:
            action = db_api.action_acquire(self.db_session, action_id,
                                           worker_id, timestamp)
        else:
            action = db_api.action_acquire_1st_ready(self.db_session,
                                                     worker_id,
                                                     timestamp)
        if not action:
            return

        th = self.start(action_mod.ActionProc, self.db_session, action.id)
        self.workers[action.id] = th
        th.link(release, action.id)
        return th
Ejemplo n.º 2
0
    def start_action(self, worker_id, action_id=None):
        '''Run action(s) in sub-thread(s).

        :param worker_id: ID of the worker thread; we fake workers using
                          senlin engines at the moment.
        :param action_id: ID of the action to be executed. None means all
                          ready actions will be acquired and scheduled to run.
        '''
        def launch(action_id):
            '''Launch a sub-thread to run given action.'''
            th = self.start(action_mod.ActionProc, self.db_session, action_id)
            self.workers[action_id] = th
            th.link(release, action_id)
            return th

        def release(thread, action_id):
            '''Callback function that will be passed to GreenThread.link().'''
            # Remove action thread from thread list
            self.workers.pop(action_id)

        actions_launched = 0
        if action_id is not None:
            timestamp = wallclock()
            action = db_api.action_acquire(self.db_session, action_id,
                                           worker_id, timestamp)
            if action:
                launch(action.id)
                actions_launched += 1

        batch_size = cfg.CONF.max_actions_per_batch
        batch_interval = cfg.CONF.batch_interval
        while True:
            timestamp = wallclock()
            action = db_api.action_acquire_1st_ready(self.db_session,
                                                     worker_id, timestamp)
            if action:
                if batch_size > 0 and 'NODE' in action.action:
                    if actions_launched < batch_size:
                        launch(action.id)
                        actions_launched += 1
                    else:
                        msg = _('Engine %(id)s has launched %(num)s node '
                                'actions consecutively, stop scheduling '
                                'node action for %(interval)s second...') % {
                                    'id': worker_id,
                                    'num': batch_size,
                                    'interval': batch_interval
                                }
                        LOG.debug(msg)
                        sleep(batch_interval)
                        launch(action.id)
                        actions_launched = 1
                else:
                    launch(action.id)
            else:
                break
Ejemplo n.º 3
0
    def start_action(self, worker_id, action_id=None):
        '''Run action(s) in sub-thread(s).

        :param worker_id: ID of the worker thread; we fake workers using
                          senlin engines at the moment.
        :param action_id: ID of the action to be executed. None means all
                          ready actions will be acquired and scheduled to run.
        '''
        def launch(action_id):
            '''Launch a sub-thread to run given action.'''
            th = self.start(action_mod.ActionProc, self.db_session, action_id)
            self.workers[action_id] = th
            th.link(release, action_id)
            return th

        def release(thread, action_id):
            '''Callback function that will be passed to GreenThread.link().'''
            # Remove action thread from thread list
            self.workers.pop(action_id)

        if action_id is not None:
            timestamp = wallclock()
            action = db_api.action_acquire(self.db_session, action_id,
                                           worker_id, timestamp)
            if action:
                launch(action.id)

        while True:
            timestamp = wallclock()
            action = db_api.action_acquire_1st_ready(self.db_session,
                                                     worker_id,
                                                     timestamp)
            # TODO(Yanyan Hu): Enable batch control.
            if action:
                launch(action.id)
            else:
                break
Ejemplo n.º 4
0
 def acquire_1st_ready(cls, context, owner, timestamp):
     return db_api.action_acquire_1st_ready(context, owner, timestamp)
Ejemplo n.º 5
0
 def acquire_1st_ready(cls, context, owner, timestamp):
     return db_api.action_acquire_1st_ready(context, owner, timestamp)