diff options
author | Nikhil Komawar <nikhil.komawar@rackspace.com> | 2014-04-21 15:13:53 -0400 |
---|---|---|
committer | Nikhil Komawar <nikhilskomawar@gmail.com> | 2014-09-02 11:45:58 -0400 |
commit | 186991bb9d2b8c568f3e9a0a89744fd6001ec74a (patch) | |
tree | 21e1245488af2c6e31b8dcfc2e21a41bea9ee0f9 /glance/domain/__init__.py | |
parent | 2e7de07c5a7c8f9d11c00499f7e85ac30f71d025 (diff) | |
download | glance-186991bb9d2b8c568f3e9a0a89744fd6001ec74a.tar.gz |
Introduces eventlet executor for Glance Tasks
A sample import script to successfully import image from http or https
location is introduced. This should work on a devstack installtion.
Also, the following changes are introduced:-
1. An interface for implementing any other type of executor.
2. Provides namespace for keeping Tasks scripts.
3. A config for choosing deployer specific executor.
4. An interface for writing Tasks scripts.
5. A module for common script related methods.
6. Logic for limiting number of simultaneous tasks execution on the
Glance API server.
partially implements bp async-glance-workers
DocImpact
Change-Id: I382472fffd0fdad43573e72b2e78a9a6ed1e1f1a
Diffstat (limited to 'glance/domain/__init__.py')
-rw-r--r-- | glance/domain/__init__.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/glance/domain/__init__.py b/glance/domain/__init__.py index 685fb9b69..71df1b86e 100644 --- a/glance/domain/__init__.py +++ b/glance/domain/__init__.py @@ -22,12 +22,16 @@ from oslo.config import cfg import six from glance.common import exception +from glance import i18n +from glance.openstack.common import excutils +from glance.openstack.common import importutils import glance.openstack.common.log as logging from glance.openstack.common import timeutils - -CONF = cfg.CONF +_LE = i18n._LE LOG = logging.getLogger(__name__) +CONF = cfg.CONF +CONF.import_opt('task_executor', 'glance.common.config', group='task') _delayed_delete_imported = False @@ -371,6 +375,7 @@ class Task(object): {'task_id': self.task_id, 'cur_status': self.status, 'new_status': new_status}) LOG.info(log_msg) + self._status = new_status else: log_msg = (_("Task [%(task_id)s] status failed to change from " "%(cur_status)s to %(new_status)s") % @@ -399,7 +404,7 @@ class Task(object): self.expires_at = timeutils.utcnow() + self._time_to_live def run(self, executor): - pass + executor.begin_processing(self.task_id) class TaskStub(object): @@ -445,6 +450,29 @@ class TaskFactory(object): ) +class TaskExecutorFactory(object): + + def __init__(self, task_repo, image_repo, image_factory): + self.task_repo = task_repo + self.image_repo = image_repo + self.image_factory = image_factory + + def new_task_executor(self, context): + try: + executor_cls = ('glance.async.%s_executor.' + 'TaskExecutor' % CONF.task.task_executor) + LOG.debug("Loading %s executor" % CONF.task.task_executor) + executor = importutils.import_class(executor_cls) + return executor(context, + self.task_repo, + self.image_repo, + self.image_factory) + except ImportError: + with excutils.save_and_reraise_exception(): + LOG.exception(_LE("Failed to load the %s executor provided " + "in the config.") % CONF.task.task_executor) + + class MetadefNamespace(object): def __init__(self, namespace_id, namespace, display_name, description, |