Always load database graph snapshot on restart

Depends-On: Ia4ee9c34bb68f3b6821ef752893f3a98d4bafc24
Depends-On: Id8f1d77802c0071df778f4a9b7fb0a25c473cf9c
Change-Id: I703083ea337447439ca80c2468f2f47cf18735e0
This commit is contained in:
Idan Hefetz 2018-08-13 14:11:16 +00:00 committed by Anna Reznikov
parent 72d018cc7d
commit fe2f62748f
4 changed files with 4 additions and 28 deletions

View File

@ -11,8 +11,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from datetime import timedelta
from oslo_log import log
from vitrage.common.constants import VertexProperties as VProps
@ -20,13 +18,10 @@ from vitrage.graph import Edge
from vitrage.graph import Vertex
from vitrage.storage.sqlalchemy import models
from vitrage.utils.datetime import utcnow
LOG = log.getLogger(__name__)
EPSILON = 30
class GraphPersistency(object):
def __init__(self, conf, db, graph):
@ -48,15 +43,8 @@ class GraphPersistency(object):
except Exception:
LOG.exception("Graph is not stored")
def _recent_snapshot_time(self):
t = utcnow(with_timezone=False)
t = t - timedelta(seconds=3 * self.conf.datasources.snapshots_interval)
t = t - timedelta(seconds=EPSILON)
return t
def query_recent_snapshot(self):
timestamp = self._recent_snapshot_time()
return self.db.graph_snapshots.query(timestamp=timestamp)
return self.db.graph_snapshots.query()
def replay_events(self, graph, event_id):
LOG.info('Getting events from database')

View File

@ -236,8 +236,8 @@ class GraphSnapshotsConnection(object):
"""
raise NotImplementedError('update graph snapshot not implemented')
def query(self, timestamp=None):
"""Yields latest graph snapshot taken until timestamp.
def query(self):
"""Yields latest graph snapshot
:rtype: vitrage.storage.sqlalchemy.models.GraphSnapshot
"""

View File

@ -20,7 +20,6 @@ from oslo_log import log
from sqlalchemy import and_
from sqlalchemy.engine import url as sqlalchemy_url
from sqlalchemy import func
from sqlalchemy import or_
from vitrage.common.exception import VitrageInputError
from vitrage.entity_graph.mappings.operational_alarm_severity import \
@ -373,11 +372,8 @@ class GraphSnapshotsConnection(base.GraphSnapshotsConnection, BaseTableConn):
with session.begin():
session.merge(graph_snapshot)
def query(self, timestamp=None):
def query(self):
query = self.query_filter(models.GraphSnapshot)
query = query.filter(
or_(models.GraphSnapshot.updated_at >= timestamp,
models.GraphSnapshot.created_at >= timestamp))
return query.first()
def query_snapshot_event_id(self):

View File

@ -11,8 +11,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import time
from oslo_config import cfg
from vitrage.common.constants import EdgeProperties
@ -36,7 +34,6 @@ class TestGraphPersistor(TestFunctionalBase, TestConfiguration):
cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources')
cls.add_db(cls.conf)
cls.load_datasources(cls.conf)
graph_persistency.EPSILON = 0.1
def test_graph_store_and_query_recent_snapshot(self):
g = GraphGenerator().create_graph()
@ -47,11 +44,6 @@ class TestGraphPersistor(TestFunctionalBase, TestConfiguration):
recovered_graph = self.load_snapshot(recovered_data)
self.assert_graph_equal(g, recovered_graph)
time.sleep(graph_persistency.EPSILON + 0.1 +
3 * self.conf.datasources.snapshots_interval)
recovered_data = graph_persistor.query_recent_snapshot()
self.assertIsNone(recovered_data, 'Should not be a recent snapshot')
def test_event_store_and_replay_events(self):
g = GraphGenerator().create_graph()
vertices = g.get_vertices()