add sample_timestamp and change update_timestamp

Change-Id: I562716e7cc7b4e4b5d7e6bbab3bd828a05b0096b
This commit is contained in:
Alexey Weyl 2016-03-17 15:17:32 +02:00
parent e1e8382d46
commit a62a2dc056
27 changed files with 124 additions and 112 deletions

View File

@ -24,6 +24,7 @@ class VertexProperties(object):
AGGREGATED_STATE = 'aggregated_state'
PROJECT_ID = 'project_id'
UPDATE_TIMESTAMP = 'update_timestamp'
SAMPLE_TIMESTAMP = 'sample_timestamp'
NAME = 'name'
IS_PLACEHOLDER = 'is_placeholder'
SEVERITY = 'severity'

View File

@ -17,8 +17,8 @@ from oslo_config import cfg
OPTS = [
cfg.IntOpt('interval',
default=600,
min=180,
default=720,
min=10,
help='interval between consistency checks (in seconds)'),
cfg.IntOpt('min_time_to_delete',
default=60,

View File

@ -92,7 +92,7 @@ class ConsistencyEnforcer(object):
query = {
'and': [
{'!=': {VProps.TYPE: EntityType.VITRAGE}},
{'<': {VProps.UPDATE_TIMESTAMP: str(utcnow() - timedelta(
{'<': {VProps.SAMPLE_TIMESTAMP: str(utcnow() - timedelta(
seconds=2 * self.conf.consistency.interval))}}
]
}
@ -105,7 +105,7 @@ class ConsistencyEnforcer(object):
query = {
'and': [
{'==': {VProps.IS_DELETED: True}},
{'<': {VProps.UPDATE_TIMESTAMP: str(utcnow() - timedelta(
{'<': {VProps.SAMPLE_TIMESTAMP: str(utcnow() - timedelta(
seconds=self.conf.consistency.min_time_to_delete))}}
]
}
@ -119,7 +119,7 @@ class ConsistencyEnforcer(object):
'and': [
{'==': {VProps.CATEGORY: EntityCategory.ALARM}},
{'==': {VProps.TYPE: EntityType.VITRAGE}},
{'<': {VProps.UPDATE_TIMESTAMP: timestamp}}
{'<': {VProps.SAMPLE_TIMESTAMP: timestamp}}
]
}
return self.graph.get_vertices(query_dict=query)

View File

@ -63,7 +63,7 @@ class EntityGraph(NXGraph):
def mark_vertex_as_deleted(self, vertex):
"""Marks the vertex as is deleted, and updates deletion timestamp"""
vertex[VProps.IS_DELETED] = True
vertex[VProps.UPDATE_TIMESTAMP] = str(utcnow())
vertex[VProps.SAMPLE_TIMESTAMP] = str(utcnow())
self.update_vertex(vertex)
def mark_edge_as_deleted(self, edge):
@ -99,12 +99,12 @@ class EntityGraph(NXGraph):
@staticmethod
def check_timestamp(graph_vertex, new_vertex):
curr_timestamp = graph_vertex.get(VProps.UPDATE_TIMESTAMP)
curr_timestamp = graph_vertex.get(VProps.SAMPLE_TIMESTAMP)
if not curr_timestamp:
return True
current_time = parser.parse(curr_timestamp)
new_time = parser.parse(new_vertex[VProps.UPDATE_TIMESTAMP])
new_time = parser.parse(new_vertex[VProps.SAMPLE_TIMESTAMP])
return current_time <= new_time
@staticmethod

View File

@ -11,15 +11,16 @@
# 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 copy
from oslo_log import log as logging
from oslo_utils import importutils
from vitrage.common.constants import EdgeProperties as EProps
from vitrage.common.constants import EntityType
from vitrage.common.constants import SynchronizerProperties as SyncProps
from vitrage.common.constants import SyncMode
from vitrage.common.constants import VertexProperties as VProps
from vitrage.common import datetime_utils
from vitrage.evaluator.actions.base import ActionMode
from vitrage.evaluator.actions.base import ActionType
@ -116,7 +117,8 @@ class ActionExecutor(object):
event[SyncProps.SYNC_MODE] = SyncMode.UPDATE
event[SyncProps.SYNC_TYPE] = EntityType.VITRAGE
event[EProps.UPDATE_TIMESTAMP] = str(datetime_utils.utcnow())
event[VProps.UPDATE_TIMESTAMP] = str(datetime_utils.utcnow())
event[VProps.SAMPLE_TIMESTAMP] = str(datetime_utils.utcnow())
@staticmethod
def _register_action_recipes():

View File

@ -50,7 +50,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
if event_type == UPDATE_VERTEX:
properties = {
VProps.VITRAGE_STATE: event[VProps.VITRAGE_STATE],
VProps.UPDATE_TIMESTAMP: event[VProps.UPDATE_TIMESTAMP]
VProps.UPDATE_TIMESTAMP: event[VProps.UPDATE_TIMESTAMP],
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP]
}
return Vertex(event[VProps.VITRAGE_ID], properties)
@ -58,6 +59,7 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
metadata = {
VProps.UPDATE_TIMESTAMP: event[VProps.UPDATE_TIMESTAMP],
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP],
VProps.NAME: event[TFields.ALARM_NAME],
VProps.SEVERITY: event[TFields.SEVERITY],
VProps.STATE: event[VProps.STATE]
@ -66,7 +68,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
self.extract_key(event),
entity_category=EntityCategory.ALARM,
entity_type=VITRAGE_TYPE,
update_timestamp=event[EProps.UPDATE_TIMESTAMP],
update_timestamp=event[VProps.UPDATE_TIMESTAMP],
sample_timestamp=event[VProps.SAMPLE_TIMESTAMP],
metadata=metadata)
return None
@ -95,7 +98,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
neighbor_props = {
VProps.IS_PLACEHOLDER: True,
EProps.UPDATE_TIMESTAMP: event[EProps.UPDATE_TIMESTAMP]
VProps.UPDATE_TIMESTAMP: event[VProps.UPDATE_TIMESTAMP],
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP]
}
neighbor = Vertex(event[TFields.TARGET], neighbor_props)
return [transformer_base.Neighbor(neighbor, relation_edge)]

View File

@ -88,7 +88,6 @@ class ScenarioEvaluator(object):
ActionMode.DO))
if actions:
LOG.info("About to perform %s actions", len(actions.values()))
LOG.debug("Actions to perform: %s", actions.values())
for action in actions.values():
action_spce = action[0]

View File

@ -25,6 +25,7 @@ def create_vertex(vitrage_id,
entity_state=None,
is_deleted=False,
update_timestamp=None,
sample_timestamp=None,
is_placeholder=False,
metadata=None):
"""A builder to create a vertex
@ -43,6 +44,8 @@ def create_vertex(vitrage_id,
:type is_deleted: boolean
:param update_timestamp:
:type update_timestamp: str
:param sample_timestamp:
:type sample_timestamp: str
:param metadata:
:type metadata: dict
:param is_placeholder:
@ -58,6 +61,7 @@ def create_vertex(vitrage_id,
VConst.CATEGORY: entity_category,
VConst.IS_DELETED: is_deleted,
VConst.UPDATE_TIMESTAMP: update_timestamp,
VConst.SAMPLE_TIMESTAMP: sample_timestamp,
VConst.IS_PLACEHOLDER: is_placeholder,
VConst.VITRAGE_ID: vitrage_id
}

View File

@ -67,7 +67,7 @@ class VitrageNotifier(object):
topic=topic)
def notify(self, event_type, data):
LOG.info('notify : ' + event_type + ' ' + str(data))
LOG.debug('notify : ' + event_type + ' ' + str(data))
if self.notifier:
try:
self.notifier.info({}, event_type, data)

View File

@ -54,13 +54,19 @@ class AodhTransformer(BaseAlarmTransformer):
metadata[AodhProps.STATE_TIMESTAMP] = \
entity_event[AodhProps.STATE_TIMESTAMP]
sample_timestamp = entity_event[SyncProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(
AodhTransformer._timestamp(entity_event), sample_timestamp)
return graph_utils.create_vertex(
self.extract_key(entity_event),
entity_id=entity_event[AodhProps.ALARM_ID],
entity_category=EntityCategory.ALARM,
entity_type=entity_event[SyncProps.SYNC_TYPE],
entity_state=AlarmProps.ALARM_ACTIVE_STATE,
update_timestamp=AodhTransformer._timestamp(entity_event),
update_timestamp=update_timestamp,
sample_timestamp=sample_timestamp,
metadata=metadata)
def _create_neighbors(self, entity_event):

View File

@ -11,6 +11,7 @@
# 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 oslo_log import log as logging
from vitrage.common.constants import EdgeLabels
@ -39,11 +40,16 @@ class NagiosTransformer(BaseAlarmTransformer):
def _create_entity_vertex(self, entity_event):
timestamp = datetime_utils.change_time_str_format(
update_timestamp = datetime_utils.change_time_str_format(
entity_event[NagiosProperties.LAST_CHECK],
'%Y-%m-%d %H:%M:%S',
tbase.TIMESTAMP_FORMAT)
sample_timestamp = entity_event[SyncProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(update_timestamp,
sample_timestamp)
metadata = {
VProps.NAME: entity_event[NagiosProperties.SERVICE],
VProps.SEVERITY: entity_event[NagiosProperties.STATUS],
@ -55,7 +61,8 @@ class NagiosTransformer(BaseAlarmTransformer):
entity_category=EntityCategory.ALARM,
entity_type=entity_event[SyncProps.SYNC_TYPE],
entity_state=AlarmProps.ALARM_ACTIVE_STATE,
update_timestamp=timestamp,
update_timestamp=update_timestamp,
sample_timestamp=sample_timestamp,
metadata=metadata)
def _create_neighbors(self, entity_event):
@ -78,7 +85,7 @@ class NagiosTransformer(BaseAlarmTransformer):
def _create_neighbor(self,
vitrage_id,
timestamp,
sample_timestamp,
resource_type,
resource_name):
transformer = self.transformers[resource_type]
@ -87,7 +94,7 @@ class NagiosTransformer(BaseAlarmTransformer):
properties = {
VProps.TYPE: resource_type,
VProps.ID: resource_name,
VProps.UPDATE_TIMESTAMP: timestamp
VProps.SAMPLE_TIMESTAMP: sample_timestamp
}
resource_vertex = transformer.create_placeholder_vertex(properties)

View File

@ -43,11 +43,6 @@ class HostTransformer(transformer_base.TransformerBase):
SyncMode.INIT_SNAPSHOT: ('zone',)
}
TIMESTAMP = {
SyncMode.SNAPSHOT: (SyncProps.SAMPLE_DATE,),
SyncMode.INIT_SNAPSHOT: (SyncProps.SAMPLE_DATE,)
}
def __init__(self, transformers):
self.transformers = transformers
@ -62,16 +57,18 @@ class HostTransformer(transformer_base.TransformerBase):
entity_key = self.extract_key(entity_event)
timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode])
sample_timestamp = entity_event[SyncProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(None,
sample_timestamp)
return graph_utils.create_vertex(
entity_key,
entity_id=host_name,
entity_category=EntityCategory.RESOURCE,
entity_type=self.HOST_TYPE,
update_timestamp=timestamp,
update_timestamp=update_timestamp,
sample_timestamp=sample_timestamp,
metadata=metadata)
def _create_neighbors(self, entity_event):
@ -80,13 +77,9 @@ class HostTransformer(transformer_base.TransformerBase):
neighbors = []
timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode])
zone_neighbor = self._create_zone_neighbor(
entity_event,
timestamp,
entity_event[SyncProps.SAMPLE_DATE],
self.extract_key(entity_event),
self.ZONE_NAME[sync_mode])
@ -97,7 +90,7 @@ class HostTransformer(transformer_base.TransformerBase):
def _create_zone_neighbor(self,
entity_event,
timestamp,
sample_timestamp,
host_vertex_id,
zone_name_path):
@ -109,7 +102,7 @@ class HostTransformer(transformer_base.TransformerBase):
properties = {
VProps.ID: zone_name,
VProps.UPDATE_TIMESTAMP: timestamp
VProps.SAMPLE_TIMESTAMP: sample_timestamp
}
zone_neighbor = zone_transformer.create_placeholder_vertex(
properties)
@ -147,5 +140,5 @@ class HostTransformer(transformer_base.TransformerBase):
entity_id=properties[VProps.ID],
entity_category=EntityCategory.RESOURCE,
entity_type=self.HOST_TYPE,
update_timestamp=properties[VProps.UPDATE_TIMESTAMP],
sample_timestamp=properties[VProps.SAMPLE_TIMESTAMP],
is_placeholder=True)

View File

@ -102,10 +102,18 @@ class InstanceTransformer(transformer_base.TransformerBase):
state = extract_field_value(
entity_event,
self.INSTANCE_STATE[sync_mode])
# TODO(Alexey): need to check here that only the UPDATE sync_mode will
# update the UPDATE_TIMESTAMP property
update_timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode])
sample_timestamp = entity_event[SyncProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(update_timestamp,
sample_timestamp)
return graph_utils.create_vertex(
entity_key,
entity_id=entity_id,
@ -113,6 +121,7 @@ class InstanceTransformer(transformer_base.TransformerBase):
entity_type=self.INSTANCE_TYPE,
entity_state=state,
update_timestamp=update_timestamp,
sample_timestamp=sample_timestamp,
metadata=metadata)
def _create_neighbors(self, entity_event):
@ -123,15 +132,10 @@ class InstanceTransformer(transformer_base.TransformerBase):
host_transformer = self.transformers[EntityType.NOVA_HOST]
if host_transformer:
update_timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode])
host_neighbor = self._create_host_neighbor(
self.extract_key(entity_event),
extract_field_value(entity_event, self.HOST_NAME[sync_mode]),
update_timestamp,
entity_event[SyncProps.SAMPLE_DATE],
host_transformer)
neighbors.append(host_neighbor)
else:
@ -169,11 +173,11 @@ class InstanceTransformer(transformer_base.TransformerBase):
@staticmethod
def _create_host_neighbor(vertex_id,
host_name,
timestamp,
sample_timestamp,
host_transformer):
properties = {
VProps.ID: host_name,
VProps.UPDATE_TIMESTAMP: timestamp
VProps.SAMPLE_TIMESTAMP: sample_timestamp
}
host_vertex = host_transformer.create_placeholder_vertex(properties)
@ -196,7 +200,7 @@ class InstanceTransformer(transformer_base.TransformerBase):
entity_id=properties[VProps.ID],
entity_category=EntityCategory.RESOURCE,
entity_type=self.INSTANCE_TYPE,
update_timestamp=properties[VProps.UPDATE_TIMESTAMP],
sample_timestamp=properties[VProps.SAMPLE_TIMESTAMP],
is_placeholder=True)
def key_values(self, *args):

View File

@ -46,11 +46,6 @@ class ZoneTransformer(transformer_base.TransformerBase):
SyncMode.INIT_SNAPSHOT: ('zoneState', 'available',)
}
TIMESTAMP = {
SyncMode.SNAPSHOT: (SyncProps.SAMPLE_DATE,),
SyncMode.INIT_SNAPSHOT: (SyncProps.SAMPLE_DATE,)
}
HOSTS = {
SyncMode.SNAPSHOT: ('hosts',),
SyncMode.INIT_SNAPSHOT: ('hosts',)
@ -90,9 +85,10 @@ class ZoneTransformer(transformer_base.TransformerBase):
state = self.STATE_AVAILABLE if is_available \
else self.STATE_UNAVAILABLE
timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode])
sample_timestamp = entity_event[SyncProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(None,
sample_timestamp)
return graph_utils.create_vertex(
entity_key,
@ -100,7 +96,8 @@ class ZoneTransformer(transformer_base.TransformerBase):
entity_category=EntityCategory.RESOURCE,
entity_type=self.ZONE_TYPE,
entity_state=state,
update_timestamp=timestamp,
update_timestamp=update_timestamp,
sample_timestamp=sample_timestamp,
metadata=metadata)
def _create_neighbors(self, entity_event):
@ -115,11 +112,6 @@ class ZoneTransformer(transformer_base.TransformerBase):
host_transformer = self.transformers[EntityType.NOVA_HOST]
if host_transformer:
timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode])
for key in hosts:
host_available = extract_field_value(
@ -138,7 +130,7 @@ class ZoneTransformer(transformer_base.TransformerBase):
zone_vertex_id,
key,
host_state,
timestamp)
entity_event[SyncProps.SAMPLE_DATE])
neighbors.append(host_neighbor)
else:
LOG.warning('Cannot find host transformer')
@ -156,7 +148,8 @@ class ZoneTransformer(transformer_base.TransformerBase):
relationship_type=EdgeLabels.CONTAINS)
return transformer_base.Neighbor(node_vertex, relation_edge)
def _create_host_neighbor(self, zone_id, host_name, host_state, timestamp):
def _create_host_neighbor(self, zone_id, host_name,
host_state, sample_timestamp):
host_transformer = self.transformers['nova.host']
@ -169,7 +162,7 @@ class ZoneTransformer(transformer_base.TransformerBase):
entity_category=EntityCategory.RESOURCE,
entity_type=EntityType.NOVA_HOST,
entity_state=host_state,
update_timestamp=timestamp)
sample_timestamp=sample_timestamp)
relation_edge = graph_utils.create_edge(
source_id=zone_id,
@ -203,5 +196,5 @@ class ZoneTransformer(transformer_base.TransformerBase):
entity_id=properties[VProps.ID],
entity_category=EntityCategory.RESOURCE,
entity_type=self.ZONE_TYPE,
update_timestamp=properties[VProps.UPDATE_TIMESTAMP],
sample_timestamp=properties[VProps.SAMPLE_TIMESTAMP],
is_placeholder=True)

View File

@ -40,7 +40,9 @@ class StaticPhysicalTransformer(transformer_base.TransformerBase):
def _create_entity_vertex(self, entity_event):
sync_type = entity_event[VProps.TYPE]
entity_id = entity_event[VProps.ID]
timestamp = entity_event[SyncProps.SAMPLE_DATE]
sample_timestamp = entity_event[SyncProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(None,
sample_timestamp)
state = entity_event[VProps.STATE]
entity_key = self.extract_key(entity_event)
metadata = self._extract_metadata(entity_event)
@ -50,7 +52,8 @@ class StaticPhysicalTransformer(transformer_base.TransformerBase):
entity_id=entity_id,
entity_category=EntityCategory.RESOURCE,
entity_type=sync_type,
update_timestamp=timestamp,
update_timestamp=update_timestamp,
sample_timestamp=sample_timestamp,
entity_state=state,
metadata=metadata)
@ -71,7 +74,7 @@ class StaticPhysicalTransformer(transformer_base.TransformerBase):
return neighbors
def _create_neighbor(self, neighbor_details, entity_type,
entity_key, timestamp):
entity_key, sample_timestamp):
neighbor_type = neighbor_details[VProps.TYPE]
entity_transformer = self.transformers[neighbor_type]
@ -84,7 +87,7 @@ class StaticPhysicalTransformer(transformer_base.TransformerBase):
properties = {
VProps.TYPE: neighbor_type,
VProps.ID: neighbor_id,
VProps.UPDATE_TIMESTAMP: timestamp
VProps.SAMPLE_TIMESTAMP: sample_timestamp
}
neighbor = entity_transformer.create_placeholder_vertex(properties)
@ -144,7 +147,7 @@ class StaticPhysicalTransformer(transformer_base.TransformerBase):
entity_id=properties[VProps.ID],
entity_category=EntityCategory.RESOURCE,
entity_type=properties[VProps.TYPE],
update_timestamp=properties[VProps.UPDATE_TIMESTAMP],
sample_timestamp=properties[VProps.SAMPLE_TIMESTAMP],
is_placeholder=True)
@staticmethod

View File

@ -189,3 +189,7 @@ class TransformerBase(object):
return entity_event[SyncProps.SYNC_MODE] == SyncMode.INIT_SNAPSHOT and\
SyncProps.EVENT_TYPE in entity_event and \
entity_event[SyncProps.EVENT_TYPE] == EventAction.END_MESSAGE
@staticmethod
def _format_update_timestamp(update_timestamp, sample_timestamp):
return update_timestamp if update_timestamp else sample_timestamp

View File

@ -103,8 +103,8 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase):
# Action
# eventlet.spawn(self._process_events)
processor_thread = threading.Thread(target=self._process_events)
self.consistency_enforcer.initializing_process()
processor_thread.start()
self.consistency_enforcer.initializing_process()
# Test Assertions
num_correct_alarms = num_of_host_alarms + \
@ -191,7 +191,7 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase):
# set part of the instances as deleted
for i in range(6, 9):
instance_vertices[i][VProps.IS_DELETED] = True
instance_vertices[i][VProps.UPDATE_TIMESTAMP] = str(
instance_vertices[i][VProps.SAMPLE_TIMESTAMP] = str(
current_time + timedelta(seconds=2 * consistency_interval + 1))
self.processor.entity_graph.update_vertex(instance_vertices[i])
@ -241,7 +241,7 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase):
def _update_timestamp(self, lst, timestamp):
for vertex in lst:
vertex[VProps.UPDATE_TIMESTAMP] = str(timestamp)
vertex[VProps.SAMPLE_TIMESTAMP] = str(timestamp)
self.processor.entity_graph.update_vertex(vertex)
def _process_events(self):

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import multiprocessing
import Queue
from oslo_config import cfg
@ -235,7 +234,7 @@ class TestActionExecutor(TestEntityGraphFunctionalBase):
before_alarms = processor.entity_graph.get_vertices(
vertex_attr_filter=alarm_vertex_attrs)
event_queue = multiprocessing.Queue()
event_queue = Queue.Queue()
action_executor = ActionExecutor(event_queue)
# Test Action - undo
@ -258,7 +257,8 @@ class TestActionExecutor(TestEntityGraphFunctionalBase):
'status': 'CRITICAL',
'status_info': 'test test test',
'sync_mode': 'snapshot',
'sync_type': 'nagios'}
'sync_type': 'nagios',
'sample_date': '2016-02-07 15:26:04'}
@staticmethod
def _get_vitrage_add_vertex_event(target_id, alarm_name, severity):
@ -270,4 +270,5 @@ class TestActionExecutor(TestEntityGraphFunctionalBase):
'state': 'Active',
'type': 'add_vertex',
'sync_type': 'vitrage',
'severity': 'CRITICAL'}
'severity': 'CRITICAL',
'sample_timestamp': '2016-03-17 11:33:32.443002+00:00'}

View File

@ -73,7 +73,8 @@ class TestScenarioEvaluator(TestEntityGraphFunctionalBase):
'status': 'CRITICAL',
'status_info': 'ok',
'sync_mode': 'snapshot',
'sync_type': 'nagios'}
'sync_type': 'nagios',
'sample_date': '2016-02-07 15:26:04'}
processor.process_event(nagios_event)
# The set_state action should have added an event to the queue, so
processor.process_event(event_queue.get())

View File

@ -1,5 +1,6 @@
{
"sync_mode": "update",
"sample_date": "2015-12-01T12:46:41Z",
"publisher_id": "compute.emalin-devstack",
"event_type": "compute.instance.pause.end|compute.instance.delete.end|compute.instance.create.start",
"payload" :

View File

@ -6,6 +6,7 @@
"status": "CRITICAL|WARNING|UNKNOWN",
"last_check": "2016-02-07 15:26:04",
"duration": "61d 21h 52m 38s",
"sample_date": "2015-12-01T12:46:41Z",
"attempt": "1/1",
"status_info": "OK - user: 0\\.6%, system: 0\\.3%, wait: 0\\.4%",
"sync_mode": "snapshot|init_snapshot|update"

View File

@ -129,7 +129,7 @@ class TestEntityGraphUnitBase(base.BaseTest):
entity_type=alarm_type,
entity_state='active',
is_deleted=False,
update_timestamp=utcnow(),
sample_timestamp=utcnow(),
is_placeholder=False,
)

View File

@ -92,7 +92,7 @@ class TestProcessor(TestEntityGraphUnitBase):
# update instance event with state running
vertex.properties[VProps.STATE] = 'RUNNING'
vertex.properties[VProps.UPDATE_TIMESTAMP] = str(utcnow())
vertex.properties[VProps.SAMPLE_TIMESTAMP] = str(utcnow())
processor.update_entity(vertex, neighbors)
# check state

View File

@ -53,7 +53,7 @@ class NovaHostTransformerTest(base.BaseTest):
# Test action
properties = {
VertexProperties.ID: host_name,
VertexProperties.UPDATE_TIMESTAMP: timestamp
VertexProperties.SAMPLE_TIMESTAMP: timestamp
}
placeholder = host_transformer.create_placeholder_vertex(properties)
@ -63,7 +63,7 @@ class NovaHostTransformerTest(base.BaseTest):
expected_id_values = host_transformer.key_values(host_name)
self.assertEqual(tuple(observed_id_values), expected_id_values)
observed_time = placeholder.get(VertexProperties.UPDATE_TIMESTAMP)
observed_time = placeholder.get(VertexProperties.SAMPLE_TIMESTAMP)
self.assertEqual(observed_time, timestamp)
observed_subtype = placeholder.get(VertexProperties.TYPE)
@ -127,15 +127,12 @@ class NovaHostTransformerTest(base.BaseTest):
event,
HostTransformer(self.transformers).ZONE_NAME[sync_mode]
)
time = tbase.extract_field_value(
event,
HostTransformer(self.transformers).TIMESTAMP[sync_mode]
)
time = event[SyncProps.SAMPLE_DATE]
zt = self.transformers[EntityType.NOVA_ZONE]
properties = {
VertexProperties.ID: zone_name,
VertexProperties.UPDATE_TIMESTAMP: time
VertexProperties.SAMPLE_TIMESTAMP: time
}
expected_neighbor = zt.create_placeholder_vertex(properties)
self.assertEqual(expected_neighbor, zone.vertex)
@ -170,11 +167,8 @@ class NovaHostTransformerTest(base.BaseTest):
vertex[VertexProperties.TYPE]
)
expected_timestamp = extract_value(
event,
HostTransformer.TIMESTAMP[sync_mode]
)
observed_timestamp = vertex[VertexProperties.UPDATE_TIMESTAMP]
expected_timestamp = event[SyncProps.SAMPLE_DATE]
observed_timestamp = vertex[VertexProperties.SAMPLE_TIMESTAMP]
self.assertEqual(expected_timestamp, observed_timestamp)
expected_name = extract_value(

View File

@ -51,7 +51,7 @@ class NovaInstanceTransformerTest(base.BaseTest):
timestamp = datetime.datetime.utcnow()
properties = {
VertexProperties.ID: instance_id,
VertexProperties.UPDATE_TIMESTAMP: timestamp
VertexProperties.SAMPLE_TIMESTAMP: timestamp
}
transformer = InstanceTransformer(self.transformers)
@ -64,7 +64,7 @@ class NovaInstanceTransformerTest(base.BaseTest):
expected_id_values = transformer.key_values(instance_id)
self.assertEqual(tuple(observed_id_values), expected_id_values)
observed_time = placeholder.get(VertexProperties.UPDATE_TIMESTAMP)
observed_time = placeholder.get(VertexProperties.SAMPLE_TIMESTAMP)
self.assertEqual(observed_time, timestamp)
observed_type = placeholder.get(VertexProperties.TYPE)
@ -155,7 +155,7 @@ class NovaInstanceTransformerTest(base.BaseTest):
def _validate_vertex_props(self, vertex, event):
self.assertEqual(10, len(vertex.properties))
self.assertEqual(11, len(vertex.properties))
sync_mode = event[SyncProps.SYNC_MODE]
@ -191,11 +191,8 @@ class NovaInstanceTransformerTest(base.BaseTest):
observed_state = vertex[VertexProperties.STATE]
self.assertEqual(expected_state, observed_state)
expected_timestamp = extract_value(
event,
InstanceTransformer.TIMESTAMP[sync_mode]
)
observed_timestamp = vertex[VertexProperties.UPDATE_TIMESTAMP]
expected_timestamp = event[SyncProps.SAMPLE_DATE]
observed_timestamp = vertex[VertexProperties.SAMPLE_TIMESTAMP]
self.assertEqual(expected_timestamp, observed_timestamp)
expected_name = extract_value(
@ -217,12 +214,12 @@ class NovaInstanceTransformerTest(base.BaseTest):
sync_mode = event[SyncProps.SYNC_MODE]
host_name = tbase.extract_field_value(event, it.HOST_NAME[sync_mode])
time = tbase.extract_field_value(event, it.TIMESTAMP[sync_mode])
time = event[SyncProps.SAMPLE_DATE]
ht = self.transformers[EntityType.NOVA_HOST]
properties = {
VertexProperties.ID: host_name,
VertexProperties.UPDATE_TIMESTAMP: time
VertexProperties.SAMPLE_TIMESTAMP: time
}
expected_neighbor = ht.create_placeholder_vertex(properties)
self.assertEqual(expected_neighbor, h_neighbor.vertex)
@ -309,7 +306,7 @@ class NovaInstanceTransformerTest(base.BaseTest):
self.assertEqual(host_vertex_id, neighbor.vertex.vertex_id)
self.assertEqual(
time,
neighbor.vertex.get(VertexProperties.UPDATE_TIMESTAMP)
neighbor.vertex.get(VertexProperties.SAMPLE_TIMESTAMP)
)
# test relation edge

View File

@ -52,7 +52,7 @@ class NovaZoneTransformerTest(base.BaseTest):
# Test action
properties = {
VertexProperties.ID: zone_name,
VertexProperties.UPDATE_TIMESTAMP: timestamp
VertexProperties.SAMPLE_TIMESTAMP: timestamp
}
placeholder = zone_transformer.create_placeholder_vertex(properties)
@ -63,7 +63,7 @@ class NovaZoneTransformerTest(base.BaseTest):
zone_name)
self.assertEqual(tuple(observed_id_values), expected_id_values)
observed_time = placeholder.get(VertexProperties.UPDATE_TIMESTAMP)
observed_time = placeholder.get(VertexProperties.SAMPLE_TIMESTAMP)
self.assertEqual(observed_time, timestamp)
observed_subtype = placeholder.get(VertexProperties.TYPE)
@ -217,11 +217,8 @@ class NovaZoneTransformerTest(base.BaseTest):
vertex[VertexProperties.TYPE]
)
expected_timestamp = extract_value(
event,
zone_transform.TIMESTAMP[sync_mode]
)
observed_timestamp = vertex[VertexProperties.UPDATE_TIMESTAMP]
expected_timestamp = event[SyncProps.SAMPLE_DATE]
observed_timestamp = vertex[VertexProperties.SAMPLE_TIMESTAMP]
self.assertEqual(expected_timestamp, observed_timestamp)
expected_name = extract_value(

View File

@ -57,7 +57,7 @@ class TestStaticPhysicalTransformer(base.BaseTest):
properties = {
VProps.TYPE: switch_type,
VProps.ID: switch_name,
VProps.UPDATE_TIMESTAMP: timestamp
VProps.SAMPLE_TIMESTAMP: timestamp
}
placeholder = static_transformer.create_placeholder_vertex(properties)
@ -69,7 +69,7 @@ class TestStaticPhysicalTransformer(base.BaseTest):
switch_type, switch_name)
self.assertEqual(tuple(observed_id_values), expected_id_values)
observed_time = placeholder.get(VProps.UPDATE_TIMESTAMP)
observed_time = placeholder.get(VProps.SAMPLE_TIMESTAMP)
self.assertEqual(observed_time, timestamp)
observed_subtype = placeholder.get(VProps.TYPE)
@ -155,7 +155,7 @@ class TestStaticPhysicalTransformer(base.BaseTest):
def _validate_switch_vertex_props(self, vertex, event):
self._validate_common_vertex_props(vertex, event)
self.assertEqual(event[SyncProps.SAMPLE_DATE],
vertex[VProps.UPDATE_TIMESTAMP])
vertex[VProps.SAMPLE_TIMESTAMP])
self.assertEqual(event[VProps.NAME], vertex[VProps.NAME])
self.assertEqual(event[VProps.STATE], vertex[VProps.STATE])
self.assertFalse(vertex[VProps.IS_PLACEHOLDER])