~ubuntu-branches/ubuntu/vivid/heat/vivid

« back to all changes in this revision

Viewing changes to heat/engine/stack_lock.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-04-15 13:55:31 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20150415135531-ife9cdiuch673nsf
Tags: 2015.1~rc1-0ubuntu1
* New upstream milestone release for Openstack kilo;
  - d/control: Align with upstream dependencies. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from heat.common.i18n import _LI
24
24
from heat.common.i18n import _LW
25
25
from heat.common import messaging as rpc_messaging
26
 
from heat.db import api as db_api
 
26
from heat.objects import stack_lock as stack_lock_object
 
27
from heat.rpc import api as rpc_api
27
28
 
28
29
cfg.CONF.import_opt('engine_life_check_timeout', 'heat.common.config')
29
30
 
40
41
    @staticmethod
41
42
    def engine_alive(context, engine_id):
42
43
        client = rpc_messaging.get_rpc_client(
43
 
            version='1.0', topic="heat-engine-listener",
 
44
            version='1.0', topic=rpc_api.LISTENER_TOPIC,
44
45
            server=engine_id)
45
46
        client_context = client.prepare(
46
47
            timeout=cfg.CONF.engine_life_check_timeout)
53
54
    def generate_engine_id():
54
55
        return str(uuid.uuid4())
55
56
 
 
57
    def get_engine_id(self):
 
58
        return stack_lock_object.StackLock.get_engine_id(self.stack.id)
 
59
 
56
60
    def try_acquire(self):
57
61
        """
58
62
        Try to acquire a stack lock, but don't raise an ActionInProgress
59
63
        exception or try to steal lock.
60
64
        """
61
 
        return db_api.stack_lock_create(self.stack.id, self.engine_id)
 
65
        return stack_lock_object.StackLock.create(self.stack.id,
 
66
                                                  self.engine_id)
62
67
 
63
68
    def acquire(self, retry=True):
64
69
        """
67
72
        :param retry: When True, retry if lock was released while stealing.
68
73
        :type retry: boolean
69
74
        """
70
 
        lock_engine_id = db_api.stack_lock_create(self.stack.id,
71
 
                                                  self.engine_id)
 
75
        lock_engine_id = stack_lock_object.StackLock.create(self.stack.id,
 
76
                                                            self.engine_id)
72
77
        if lock_engine_id is None:
73
78
            LOG.debug("Engine %(engine)s acquired lock on stack "
74
79
                      "%(stack)s" % {'engine': self.engine_id,
87
92
                         "%(engine)s will attempt to steal the lock"),
88
93
                     {'stack': self.stack.id, 'engine': self.engine_id})
89
94
 
90
 
            result = db_api.stack_lock_steal(self.stack.id, lock_engine_id,
91
 
                                             self.engine_id)
 
95
            result = stack_lock_object.StackLock.steal(self.stack.id,
 
96
                                                       lock_engine_id,
 
97
                                                       self.engine_id)
92
98
 
93
99
            if result is None:
94
100
                LOG.info(_LI("Engine %(engine)s successfully stole the lock "
116
122
    def release(self, stack_id):
117
123
        """Release a stack lock."""
118
124
        # Only the engine that owns the lock will be releasing it.
119
 
        result = db_api.stack_lock_release(stack_id, self.engine_id)
 
125
        result = stack_lock_object.StackLock.release(stack_id,
 
126
                                                     self.engine_id)
120
127
        if result is True:
121
128
            LOG.warn(_LW("Lock was already released on stack %s!"), stack_id)
122
129
        else: