~ceilometer-drivers/ceilometer/trunk

« back to all changes in this revision

Viewing changes to ceilometer/openstack/common/rpc/matchmaker.py

  • Committer: Angus Salkeld
  • Date: 2012-11-03 00:31:11 UTC
  • Revision ID: git-v1:4c43441d9dafedbc1b73cf8abdec32b1ccb65a71
Update common (except policy)

Change-Id: I17a89a15ff3af5b9f31bf14b1bbe29b024cfc8c1

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
        return False
133
133
 
134
134
 
135
 
class PublisherBinding(Binding):
136
 
    """Match on publishers keys, where key starts with 'publishers.' string."""
137
 
    def test(self, key):
138
 
        if key.startswith('publishers~'):
139
 
            return True
140
 
        return False
141
 
 
142
 
 
143
135
class StubExchange(Exchange):
144
136
    """Exchange that does nothing."""
145
137
    def run(self, key):
190
182
        return [(key + '.' + host, host)]
191
183
 
192
184
 
193
 
class PublisherRingExchange(RingExchange):
194
 
    """Fanout Exchange based on a hashmap."""
195
 
    def __init__(self, ring=None):
196
 
        super(PublisherRingExchange, self).__init__(ring)
197
 
 
198
 
    def run(self, key):
199
 
        # Assume starts with "publishers~", strip it for lookup.
200
 
        nkey = key.split('publishers~')[1:][0]
201
 
        if not self._ring_has(nkey):
202
 
            LOG.warn(
203
 
                _("No key defining hosts for topic '%s', "
204
 
                  "see ringfile") % (nkey, )
205
 
            )
206
 
            return []
207
 
        return map(lambda x: (key + '.' + x, x), self.ring[nkey])
208
 
 
209
 
 
210
185
class FanoutRingExchange(RingExchange):
211
186
    """Fanout Exchange based on a hashmap."""
212
187
    def __init__(self, ring=None):
221
196
                  "see ringfile") % (nkey, )
222
197
            )
223
198
            return []
224
 
        return map(lambda x: (key + '.' + x, x), self.ring[nkey] +
225
 
                   ['localhost'])
 
199
        return map(lambda x: (key + '.' + x, x), self.ring[nkey])
226
200
 
227
201
 
228
202
class LocalhostExchange(Exchange):
253
227
    """
254
228
    def __init__(self, ring=None):
255
229
        super(MatchMakerRing, self).__init__()
256
 
        self.add_binding(PublisherBinding(), PublisherRingExchange(ring))
257
230
        self.add_binding(FanoutBinding(), FanoutRingExchange(ring))
258
231
        self.add_binding(DirectBinding(), DirectExchange())
259
232
        self.add_binding(TopicBinding(), RoundRobinRingExchange(ring))
266
239
    """
267
240
    def __init__(self):
268
241
        super(MatchMakerLocalhost, self).__init__()
269
 
        self.add_binding(PublisherBinding(), LocalhostExchange())
270
242
        self.add_binding(FanoutBinding(), LocalhostExchange())
271
243
        self.add_binding(DirectBinding(), DirectExchange())
272
244
        self.add_binding(TopicBinding(), LocalhostExchange())
281
253
    def __init__(self):
282
254
        super(MatchMakerLocalhost, self).__init__()
283
255
 
284
 
        self.add_binding(PublisherBinding(), StubExchange())
285
256
        self.add_binding(FanoutBinding(), StubExchange())
286
257
        self.add_binding(DirectBinding(), StubExchange())
287
258
        self.add_binding(TopicBinding(), StubExchange())