Improve exceptions handling in created threads

Change-Id: I688a8070c4ce8782329ee5fc7be0dc0cc5dabe29
This commit is contained in:
Sergey Lukjanov 2013-08-14 20:15:52 +04:00 committed by Dmitry Mescheryakov
parent 037238afa6
commit 975406a04b
3 changed files with 18 additions and 7 deletions

View File

@ -119,12 +119,17 @@ def model_update(model, context=None, **kwargs):
return model_save(model, context)
def spawn(func, *args, **kwargs):
def spawn(thread_description, func, *args, **kwargs):
ctx = current().clone()
def wrapper(ctx, func, *args, **kwargs):
set_ctx(ctx)
func(*args, **kwargs)
try:
set_ctx(ctx)
func(*args, **kwargs)
set_ctx(None)
except Exception as e:
LOG.exception("Thread '%s' fails with exception: '%s'"
% (thread_description, e))
eventlet.spawn(wrapper, ctx, func, *args, **kwargs)

View File

@ -236,7 +236,9 @@ class AmbariPlugin(p.ProvisioningPluginBase):
ambari_info.get_address()))
for server in servers:
context.spawn(server.provision_ambari, ambari_info)
context.spawn("hdp-provision-instance-%s" %
server.instance.hostname,
server.provision_ambari, ambari_info)
self._wait_for_host_registrations(len(servers), ambari_info)
self._set_ambari_credentials(cluster_spec, ambari_info)
@ -680,7 +682,9 @@ class AmbariPlugin(p.ProvisioningPluginBase):
self._update_ambari_info_credentials(cluster_spec, ambari_info)
for server in servers:
context.spawn(server.provision_ambari, ambari_info)
context.spawn("hdp-scaling-instance-%s" %
server.instance.hostname,
server.provision_ambari, ambari_info)
self._wait_for_host_registrations(self._get_num_hosts(cluster),
ambari_info)

View File

@ -65,7 +65,8 @@ def scale_cluster(cluster_id, data):
to_be_enlarged.update({add_n_g.name: additional[add_n_g]})
context.model_save(cluster)
context.spawn(_provision_nodes, cluster_id, to_be_enlarged)
context.spawn("cluster-scaling-%s" % cluster_id,
_provision_nodes, cluster_id, to_be_enlarged)
return cluster
@ -84,7 +85,8 @@ def create_cluster(values):
status_description=str(ex))
LOG.info(g.format_cluster_status(cluster))
context.spawn(_provision_cluster, cluster.id)
context.spawn("cluster-creating-%s" % cluster.id,
_provision_cluster, cluster.id)
return cluster