def GET(self): valid_filters = ['tag'] filters = self.filters(valid_filters) criteria_filters = {} tags = filters.get('tag', []) if tags: criteria_filters['tags'] = {'$all': filters.get('tag', [])} criteria = Criteria.from_client_input({'filters': criteria_filters}) serialized_task_statuses = [] for task in TaskStatusManager.find_by_criteria(criteria): task.update(serialization.dispatch.spawned_tasks(task)) serialized_task_statuses.append(task) return self.ok(serialized_task_statuses)
def GET(self): valid_filters = ['tag'] filters = self.filters(valid_filters) criteria_filters = {} tags = filters.get('tag', []) if tags: criteria_filters['tags'] = {'$all': filters.get('tag', [])} criteria = Criteria.from_client_input({'filters': criteria_filters}) serialized_task_statuses = [] for task in TaskStatusManager.find_by_criteria(criteria): task.update(serialization.dispatch.spawned_tasks(task)) task.update(serialization.dispatch.task_result_href(task)) serialized_task_statuses.append(task) return self.ok(serialized_task_statuses)
def _delete_worker(name, normal_shutdown=False): """ Delete the Worker with _id name from the database, cancel any associated tasks and reservations If the worker shutdown normally, no message is logged, otherwise an error level message is logged. Default is to assume the worker did not shut down normally. Any resource reservations associated with this worker are cleaned up by this function. Any tasks associated with this worker are explicitly canceled. :param name: The name of the worker you wish to delete. In the database, the _id field is the name. :type name: basestring :param normal_shutdown: True if the worker shutdown normally, False otherwise. Defaults to False. :type normal_shutdown: bool """ if normal_shutdown is False: msg = _( 'The worker named %(name)s is missing. Canceling the tasks in its queue.' ) msg = msg % {'name': name} logger.error(msg) # Delete the worker document worker_list = list( resources.filter_workers(Criteria(filters={'_id': name}))) if len(worker_list) > 0: worker_document = worker_list[0] worker_document.delete() # Delete all reserved_resource documents for the worker ReservedResource.get_collection().remove({'worker_name': name}) # Cancel all of the tasks that were assigned to this worker's queue worker = Worker.from_bson({'_id': name}) for task in TaskStatusManager.find_by_criteria( Criteria( filters={ 'worker_name': worker.name, 'state': { '$in': constants.CALL_INCOMPLETE_STATES } })): cancel(task['task_id'])
def _delete_worker(name, normal_shutdown=False): """ Delete the Worker with _id name from the database. This Task can only safely be performed by the resource manager at this time, so be sure to queue it in the RESOURCE_MANAGER_QUEUE. If the worker shutdown normally, no message is logged, otherwise an error level message is logged. Default is to assume the work did not shut down normally. :param name: The name of the worker you wish to delete. In the database, the _id field is the name. :type name: basestring :param normal_shutdown: True if the worker shutdown normally, False otherwise. Defaults to False. :type normal_shutdown: bool """ worker_list = list( resources.filter_workers(Criteria(filters={'_id': name}))) if len(worker_list) == 0: # Potentially _delete_worker() may be called with the database not containing any entries. # https://bugzilla.redhat.com/show_bug.cgi?id=1091922 return worker = worker_list[0] if normal_shutdown is False: msg = _( 'The worker named %(name)s is missing. Canceling the tasks in its queue.' ) msg = msg % {'name': worker.name} logger.error(msg) # Cancel all of the tasks that were assigned to this worker's queue for task in TaskStatusManager.find_by_criteria( Criteria( filters={ 'queue': worker.queue_name, 'state': { '$in': constants.CALL_INCOMPLETE_STATES } })): cancel(task['task_id']) # Finally, delete the worker worker.delete()
def _delete_queue(queue, normal_shutdown=False): """ Delete the AvailableQueue with _id queue from the database. This Task can only safely be performed by the resource manager at this time, so be sure to queue it in the RESOURCE_MANAGER_QUEUE. If the worker shutdown normally, no message is logged, otherwise an error level message is logged. Default is to assume the work did not shut down normally. :param queue: The name of the queue you wish to delete. In the database, the _id field is the name. :type queue: basestring :param normal_shutdown: True if the worker associated with the queue shutdown normally, False otherwise. Defaults to False. :type normal_shutdown: bool """ queue_list = list(resources.filter_available_queues(Criteria(filters={'_id': queue}))) if len(queue_list) == 0: # Potentially _delete_queue() may be called with the database not containing any entries. # https://bugzilla.redhat.com/show_bug.cgi?id=1091922 return queue = queue_list[0] if normal_shutdown is False: msg = _('The worker named %(name)s is missing. Canceling the tasks in its queue.') % { 'name': queue.name} logger.error(msg) # Cancel all of the tasks that were assigned to this queue for task in TaskStatusManager.find_by_criteria( Criteria( filters={'queue': queue.name, 'state': {'$in': constants.CALL_INCOMPLETE_STATES}})): cancel(task['task_id']) # Finally, delete the queue queue.delete()
def _delete_queue(queue): """ Delete the AvailableQueue with _id queue from the database. This Task can only safely be performed by the resource manager at this time, so be sure to queue it in the RESOURCE_MANAGER_QUEUE. :param queue: The name of the queue you wish to delete. In the database, the _id field is the name. :type queue: basestring """ queue = list(resources.filter_available_queues(Criteria(filters={'_id': queue})))[0] # Cancel all of the tasks that were assigned to this queue msg = _('The worker named %(name)s is missing. Canceling the tasks in its queue.') msg = msg % {'name': queue.name} logger.error(msg) for task in TaskStatusManager.find_by_criteria( Criteria( filters={'queue': queue.name, 'state': {'$in': dispatch_constants.CALL_INCOMPLETE_STATES}})): cancel(task['task_id']) # Finally, delete the queue queue.delete()
def _delete_worker(name, normal_shutdown=False): """ Delete the Worker with _id name from the database. This Task can only safely be performed by the resource manager at this time, so be sure to queue it in the RESOURCE_MANAGER_QUEUE. If the worker shutdown normally, no message is logged, otherwise an error level message is logged. Default is to assume the work did not shut down normally. :param name: The name of the worker you wish to delete. In the database, the _id field is the name. :type name: basestring :param normal_shutdown: True if the worker shutdown normally, False otherwise. Defaults to False. :type normal_shutdown: bool """ worker_list = list(resources.filter_workers(Criteria(filters={'_id': name}))) if len(worker_list) == 0: # If no workers are found then there is nothing to do. return worker = worker_list[0] if normal_shutdown is False: msg = _('The worker named %(name)s is missing. Canceling the tasks in its queue.') msg = msg % {'name': worker.name} logger.error(msg) # Cancel all of the tasks that were assigned to this worker's queue for task in TaskStatusManager.find_by_criteria( Criteria( filters={'queue': worker.queue_name, 'state': {'$in': constants.CALL_INCOMPLETE_STATES}})): cancel(task['task_id']) # Finally, delete the worker worker.delete()
def test_find_by_criteria(self, mock_query): criteria = Criteria() TaskStatusManager.find_by_criteria(criteria) mock_query.assert_called_once_with(criteria)
def test_find_by_criteria(self, mock_query): criteria = Criteria() TaskStatusManager.find_by_criteria(criteria) mock_query.assert_called_once_with(criteria)