panko  8.1.0
About: OpenStack Panko is an event storage service and REST API for Ceilometer.
The "Ussuri" series (maintained release).
  Fossies Dox: panko-8.1.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

__init__.py
Go to the documentation of this file.
2# Copyright 2012 New Dream Network, LLC (DreamHost)
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15"""Storage backend management
16"""
17
18from oslo_config import cfg
19from oslo_log import log
20import six
21import six.moves.urllib.parse as urlparse
22from stevedore import driver
23import tenacity
24
25from panko import utils
26
27LOG = log.getLogger(__name__)
28
29
30OPTS = [
31 cfg.IntOpt('event_time_to_live',
32 default=-1,
33 help=("Number of seconds that events are kept "
34 "in the database for (<= 0 means forever).")),
35 cfg.IntOpt('events_delete_batch_size',
36 default=0,
37 min=0,
38 help=("Number of events to be deleted in one iteration "
39 "from the database for (0 means all).")),
40 cfg.StrOpt('event_connection',
41 secret=True,
42 deprecated_for_removal=True,
43 help='The connection string used to connect '
44 'to the event database - rather use ${database.connection}'),
45 cfg.BoolOpt('es_ssl_enabled',
46 default=False,
47 help="Enable HTTPS connection in the Elasticsearch "
48 "connection"),
49 cfg.StrOpt('es_index_name',
50 default='events',
51 help='The name of the index in Elasticsearch')
52]
53
54
55class StorageUnknownWriteError(Exception):
56 """Error raised when an unknown error occurs while recording."""
57
58
59class StorageBadVersion(Exception):
60 """Error raised when the storage backend version is not good enough."""
61
62
63class StorageBadAggregate(Exception):
64 """Error raised when an aggregate is unacceptable to storage backend."""
65 code = 400
66
67
68class InvalidMarker(Exception):
69 """Invalid pagination marker parameters"""
70
71
73 retries = conf.database.max_retries
74
75 @tenacity.retry(
76 reraise=True,
77 wait=tenacity.wait_fixed(conf.database.retry_interval),
78 stop=(tenacity.stop_after_attempt(retries) if retries >= 0
79 else tenacity.stop_never)
80 )
81 def _inner():
82 url = (conf.database.connection or
83 getattr(conf.database, 'event_connection', None))
84 return get_connection(url, conf)
85
86 return _inner()
87
88
89def get_connection(url, conf):
90 """Return an open connection to the database."""
91 connection_scheme = urlparse.urlparse(url).scheme
92 # SqlAlchemy connections specify may specify a 'dialect' or
93 # 'dialect+driver'. Handle the case where driver is specified.
94 engine_name = connection_scheme.split('+')[0]
95 # NOTE: translation not applied bug #1446983
96 LOG.debug('looking for %(name)r driver in panko.storage',
97 {'name': engine_name})
98 mgr = driver.DriverManager('panko.storage', engine_name)
99 return mgr.driver(url, conf)
100
101
102class EventFilter(object):
103 """Properties for building an Event query.
104
105 :param start_timestamp: UTC start datetime (mandatory)
106 :param end_timestamp: UTC end datetime (mandatory)
107 :param event_type: the name of the event. None for all.
108 :param message_id: the message_id of the event. None for all.
109 :param admin_proj: the project_id of admin role. None if non-admin user.
110 :param traits_filter: the trait filter dicts, all of which are optional.
111 This parameter is a list of dictionaries that specify trait values:
112
113 .. code-block:: python
114
115 {'key': <key>,
116 'string': <value>,
117 'integer': <value>,
118 'datetime': <value>,
119 'float': <value>,
120 'op': <eq, lt, le, ne, gt or ge> }
121 """
122
123 def __init__(self, start_timestamp=None, end_timestamp=None,
124 event_type=None, message_id=None, traits_filter=None,
125 admin_proj=None):
126 self.start_timestampstart_timestamp = utils.sanitize_timestamp(start_timestamp)
127 self.end_timestampend_timestamp = utils.sanitize_timestamp(end_timestamp)
128 self.message_idmessage_id = message_id
129 self.event_typeevent_type = event_type
130 self.traits_filtertraits_filter = traits_filter or []
131 self.admin_projadmin_proj = admin_proj
132
133 def __repr__(self):
134 return ("<EventFilter(start_timestamp: %s,"
135 " end_timestamp: %s,"
136 " event_type: %s,"
137 " traits: %s)>" %
138 (self.start_timestampstart_timestamp,
139 self.end_timestampend_timestamp,
140 self.event_typeevent_type,
141 six.text_type(self.traits_filtertraits_filter)))
def __init__(self, start_timestamp=None, end_timestamp=None, event_type=None, message_id=None, traits_filter=None, admin_proj=None)
Definition: __init__.py:125
def get_connection(url, conf)
Definition: __init__.py:89
def get_connection_from_config(conf)
Definition: __init__.py:72