Added support for basic stream API.
added find methods for basic stream get/search and reset operation. also, added gerrit .gitreview Change-Id: I79e11730336f6200be2143f1943a9bf2dbabda7a
This commit is contained in:
parent
e0256a3fdb
commit
c5ae51e5ed
5
.gitreview
Normal file
5
.gitreview
Normal file
@ -0,0 +1,5 @@
|
||||
[gerrit]
|
||||
host=review.openstack.org
|
||||
port=29418
|
||||
project=stackforge/stacktach-winchester.git
|
||||
|
@ -234,6 +234,34 @@ class DBInterface(object):
|
||||
return self.set_stream_state(stream, models.StreamState.retry_expire)
|
||||
return stream
|
||||
|
||||
@sessioned
|
||||
def find_streams(self, stream_id=None, state=None, older_than=None, younger_than=None,
|
||||
name=None, distinguishing_traits=None,
|
||||
session=None, include_events=False):
|
||||
q = session.query(models.Stream)
|
||||
if stream_id is not None:
|
||||
q = q.filter(models.Stream.id == stream_id)
|
||||
if state is not None:
|
||||
q = q.filter(models.Stream.state == int(state))
|
||||
if older_than is not None:
|
||||
q = q.filter(models.Stream.first_event < older_than)
|
||||
if younger_than is not None:
|
||||
q = q.filter(models.Stream.last_event > younger_than)
|
||||
if name is not None:
|
||||
q = q.filter(models.Stream.name == name)
|
||||
if distinguishing_traits is not None:
|
||||
for name, val in distinguishing_traits.items():
|
||||
q = q.filter(models.Stream.distinguished_by.any(and_(
|
||||
models.DistinguishingTrait.name == name,
|
||||
models.DistinguishingTrait.value == val)))
|
||||
stream_info = []
|
||||
for stream in q.all():
|
||||
info = stream.as_dict
|
||||
if include_events:
|
||||
info['events'] = self.get_stream_events(stream, session=session)
|
||||
stream_info.append(info)
|
||||
return stream_info
|
||||
|
||||
@sessioned
|
||||
def purge_stream(self, stream, session=None):
|
||||
if stream not in session:
|
||||
|
@ -354,6 +354,19 @@ class Stream(ProxiedDictMixin, Base):
|
||||
def distinguished_by_dict(self):
|
||||
return dict(self._proxied)
|
||||
|
||||
@property
|
||||
def as_dict(self):
|
||||
return {'name': self.name,
|
||||
'id': self.id,
|
||||
'state': StreamState(self.state).name,
|
||||
'first_event': self.first_event,
|
||||
'last_event': self.last_event,
|
||||
'fire_timestamp': self.fire_timestamp,
|
||||
'expire_timestamp': self.expire_timestamp,
|
||||
'distinguishing_traits': self.distinguished_by_dict}
|
||||
|
||||
|
||||
|
||||
def __init__(self, name, first_event, last_event=None, expire_timestamp=None,
|
||||
fire_timestamp=None, state=None, state_serial_no=None):
|
||||
self.name = name
|
||||
|
Loading…
x
Reference in New Issue
Block a user