Merge "for ML - add resource details: id and type to alarms"
This commit is contained in:
commit
0af2b7ceb5
@ -53,8 +53,6 @@ class AlarmApis(EntityGraphApisBase):
|
|||||||
vertex_attr_filter={VProps.CATEGORY: EntityCategory.ALARM,
|
vertex_attr_filter={VProps.CATEGORY: EntityCategory.ALARM,
|
||||||
VProps.IS_DELETED: False})
|
VProps.IS_DELETED: False})
|
||||||
|
|
||||||
self._add_resource_details_to_alarms(alarms)
|
|
||||||
|
|
||||||
return json.dumps({'alarms': [v.properties for v in alarms]})
|
return json.dumps({'alarms': [v.properties for v in alarms]})
|
||||||
|
|
||||||
def _get_alarms(self, project_id, is_admin_project):
|
def _get_alarms(self, project_id, is_admin_project):
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import EdgeLabel
|
|
||||||
from vitrage.common.constants import EdgeProperties as EProps
|
from vitrage.common.constants import EdgeProperties as EProps
|
||||||
from vitrage.common.constants import EntityCategory
|
from vitrage.common.constants import EntityCategory
|
||||||
from vitrage.common.constants import VertexProperties as VProps
|
from vitrage.common.constants import VertexProperties as VProps
|
||||||
@ -199,25 +198,6 @@ class EntityGraphApisBase(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _add_resource_details_to_alarms(self, alarms):
|
|
||||||
for alarm in alarms:
|
|
||||||
try:
|
|
||||||
resources = self.entity_graph.neighbors(
|
|
||||||
v_id=alarm.vertex_id,
|
|
||||||
edge_attr_filter={EProps.RELATIONSHIP_TYPE: EdgeLabel.ON},
|
|
||||||
direction=Direction.OUT)
|
|
||||||
|
|
||||||
resource = self._get_first(resources)
|
|
||||||
if resource:
|
|
||||||
alarm["resource_id"] = resource.get(VProps.ID, '')
|
|
||||||
alarm["resource_type"] = resource.get(VProps.TYPE, '')
|
|
||||||
else:
|
|
||||||
alarm["resource_id"] = ''
|
|
||||||
alarm["resource_type"] = ''
|
|
||||||
|
|
||||||
except ValueError as ve:
|
|
||||||
LOG.error('Alarm %s\nException %s', alarm, ve)
|
|
||||||
|
|
||||||
def _is_project_admin(self, project_id):
|
def _is_project_admin(self, project_id):
|
||||||
keystone_client = ks_client(self.conf)
|
keystone_client = ks_client(self.conf)
|
||||||
project = keystone_client.projects.get(project_id)
|
project = keystone_client.projects.get(project_id)
|
||||||
|
@ -60,7 +60,6 @@ class RcaApis(EntityGraphApisBase):
|
|||||||
is_admin_project)
|
is_admin_project)
|
||||||
|
|
||||||
alarms = unified_graph.get_vertices(query_dict=ALARMS_ALL_QUERY)
|
alarms = unified_graph.get_vertices(query_dict=ALARMS_ALL_QUERY)
|
||||||
self._add_resource_details_to_alarms(alarms)
|
|
||||||
unified_graph.update_vertices(alarms)
|
unified_graph.update_vertices(alarms)
|
||||||
|
|
||||||
json_graph = unified_graph.json_output_graph(
|
json_graph = unified_graph.json_output_graph(
|
||||||
|
@ -75,7 +75,6 @@ class TopologyApis(EntityGraphApisBase):
|
|||||||
root)
|
root)
|
||||||
|
|
||||||
alarms = graph.get_vertices(query_dict=ALARMS_ALL_QUERY)
|
alarms = graph.get_vertices(query_dict=ALARMS_ALL_QUERY)
|
||||||
self._add_resource_details_to_alarms(alarms)
|
|
||||||
graph.update_vertices(alarms)
|
graph.update_vertices(alarms)
|
||||||
|
|
||||||
return graph.json_output_graph()
|
return graph.json_output_graph()
|
||||||
|
@ -37,6 +37,8 @@ class VertexProperties(object):
|
|||||||
GRAPH_INDEX = 'graph_index'
|
GRAPH_INDEX = 'graph_index'
|
||||||
RAWTEXT = 'rawtext'
|
RAWTEXT = 'rawtext'
|
||||||
RESOURCE_ID = 'resource_id'
|
RESOURCE_ID = 'resource_id'
|
||||||
|
VITRAGE_RESOURCE_ID = 'vitrage_resource_id'
|
||||||
|
VITRAGE_RESOURCE_TYPE = 'vitrage_resource_type'
|
||||||
RESOURCE = 'resource'
|
RESOURCE = 'resource'
|
||||||
IS_REAL_VITRAGE_ID = 'is_real_vitrage_id'
|
IS_REAL_VITRAGE_ID = 'is_real_vitrage_id'
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from oslo_log import log
|
|||||||
|
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
|
from vitrage.common.constants import EntityCategory
|
||||||
from vitrage.common.constants import GraphAction
|
from vitrage.common.constants import GraphAction
|
||||||
from vitrage.common.constants import VertexProperties as VProps
|
from vitrage.common.constants import VertexProperties as VProps
|
||||||
from vitrage.common.exception import VitrageError
|
from vitrage.common.exception import VitrageError
|
||||||
@ -83,6 +84,7 @@ class Processor(processor.ProcessorBase):
|
|||||||
# _find_and_fix_graph_vertex method call to the process_event method
|
# _find_and_fix_graph_vertex method call to the process_event method
|
||||||
# so it will be done in one central place
|
# so it will be done in one central place
|
||||||
self._find_and_fix_graph_vertex(new_vertex, neighbors)
|
self._find_and_fix_graph_vertex(new_vertex, neighbors)
|
||||||
|
self._add_resource_details_to_alarm(new_vertex, neighbors)
|
||||||
self.entity_graph.add_vertex(new_vertex)
|
self.entity_graph.add_vertex(new_vertex)
|
||||||
self._connect_neighbors(neighbors, set(), GraphAction.CREATE_ENTITY)
|
self._connect_neighbors(neighbors, set(), GraphAction.CREATE_ENTITY)
|
||||||
|
|
||||||
@ -107,6 +109,7 @@ class Processor(processor.ProcessorBase):
|
|||||||
|
|
||||||
if (not graph_vertex) or \
|
if (not graph_vertex) or \
|
||||||
PUtils.is_newer_vertex(graph_vertex, updated_vertex):
|
PUtils.is_newer_vertex(graph_vertex, updated_vertex):
|
||||||
|
self._add_resource_details_to_alarm(updated_vertex, neighbors)
|
||||||
PUtils.update_entity_graph_vertex(self.entity_graph,
|
PUtils.update_entity_graph_vertex(self.entity_graph,
|
||||||
graph_vertex,
|
graph_vertex,
|
||||||
updated_vertex)
|
updated_vertex)
|
||||||
@ -426,6 +429,24 @@ class Processor(processor.ProcessorBase):
|
|||||||
edge.source_id = vitrage_id
|
edge.source_id = vitrage_id
|
||||||
edge.target_id = neighbor_vertex.vertex_id
|
edge.target_id = neighbor_vertex.vertex_id
|
||||||
|
|
||||||
|
def _add_resource_details_to_alarm(self, vertex, neighbors):
|
||||||
|
|
||||||
|
if not vertex.get(VProps.CATEGORY) == EntityCategory.ALARM \
|
||||||
|
or not neighbors:
|
||||||
|
return
|
||||||
|
|
||||||
|
# for the possibility that alarm doesn't have resource
|
||||||
|
vertex.properties[VProps.VITRAGE_RESOURCE_ID] = None
|
||||||
|
vertex.properties[VProps.VITRAGE_RESOURCE_TYPE] = None
|
||||||
|
|
||||||
|
for neighbor in neighbors:
|
||||||
|
|
||||||
|
if neighbor.vertex.get(VProps.CATEGORY) == EntityCategory.RESOURCE:
|
||||||
|
vertex.properties[VProps.VITRAGE_RESOURCE_ID] = \
|
||||||
|
neighbor.vertex.vertex_id
|
||||||
|
vertex.properties[VProps.VITRAGE_RESOURCE_TYPE] = \
|
||||||
|
neighbor.vertex.get(VProps.TYPE)
|
||||||
|
|
||||||
def _get_single_graph_vertex_by_props(self, vertex, include_deleted=False):
|
def _get_single_graph_vertex_by_props(self, vertex, include_deleted=False):
|
||||||
"""Returns a single vertex by it's defining properties
|
"""Returns a single vertex by it's defining properties
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
|||||||
return self._create_vitrage_neighbors(event)
|
return self._create_vitrage_neighbors(event)
|
||||||
|
|
||||||
def _create_vitrage_neighbors(self, event):
|
def _create_vitrage_neighbors(self, event):
|
||||||
|
|
||||||
event_type = event[EVALUATOR_EVENT_TYPE]
|
event_type = event[EVALUATOR_EVENT_TYPE]
|
||||||
|
|
||||||
timestamp = transformer_base.convert_timestamp_format(
|
timestamp = transformer_base.convert_timestamp_format(
|
||||||
@ -112,7 +113,6 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if event_type in [ADD_EDGE, REMOVE_EDGE]:
|
if event_type in [ADD_EDGE, REMOVE_EDGE]:
|
||||||
|
|
||||||
relation_edge = graph_utils.create_edge(
|
relation_edge = graph_utils.create_edge(
|
||||||
source_id=event[TFields.SOURCE],
|
source_id=event[TFields.SOURCE],
|
||||||
target_id=event[TFields.TARGET],
|
target_id=event[TFields.TARGET],
|
||||||
@ -122,7 +122,6 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
|||||||
return [Neighbor(None, relation_edge)]
|
return [Neighbor(None, relation_edge)]
|
||||||
|
|
||||||
if event_type == ADD_VERTEX:
|
if event_type == ADD_VERTEX:
|
||||||
|
|
||||||
relation_edge = graph_utils.create_edge(
|
relation_edge = graph_utils.create_edge(
|
||||||
source_id=self._create_entity_key(event),
|
source_id=self._create_entity_key(event),
|
||||||
target_id=event[TFields.TARGET],
|
target_id=event[TFields.TARGET],
|
||||||
@ -133,7 +132,9 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
|||||||
VProps.IS_PLACEHOLDER: True,
|
VProps.IS_PLACEHOLDER: True,
|
||||||
VProps.UPDATE_TIMESTAMP: timestamp,
|
VProps.UPDATE_TIMESTAMP: timestamp,
|
||||||
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP],
|
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP],
|
||||||
VProps.IS_REAL_VITRAGE_ID: True
|
VProps.IS_REAL_VITRAGE_ID: True,
|
||||||
|
VProps.TYPE: event[VProps.VITRAGE_RESOURCE_TYPE],
|
||||||
|
VProps.CATEGORY: EntityCategory.RESOURCE,
|
||||||
}
|
}
|
||||||
neighbor = Vertex(event[TFields.TARGET], neighbor_props)
|
neighbor = Vertex(event[TFields.TARGET], neighbor_props)
|
||||||
return [Neighbor(neighbor, relation_edge)]
|
return [Neighbor(neighbor, relation_edge)]
|
||||||
|
@ -57,7 +57,8 @@ class RaiseAlarm(base.Recipe):
|
|||||||
|
|
||||||
target_resource = action_spec.targets[TFields.TARGET]
|
target_resource = action_spec.targets[TFields.TARGET]
|
||||||
add_vertex_params = {
|
add_vertex_params = {
|
||||||
TFields.TARGET: target_resource.vertex_id
|
TFields.TARGET: target_resource.vertex_id,
|
||||||
|
VProps.VITRAGE_RESOURCE_TYPE: target_resource[VProps.TYPE],
|
||||||
}
|
}
|
||||||
add_vertex_params.update(action_spec.properties)
|
add_vertex_params.update(action_spec.properties)
|
||||||
|
|
||||||
|
@ -16,11 +16,14 @@
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from six.moves import queue
|
from six.moves import queue
|
||||||
|
from vitrage.common.constants import DatasourceProperties as DSProp
|
||||||
from vitrage.common.constants import EdgeLabel
|
from vitrage.common.constants import EdgeLabel
|
||||||
from vitrage.common.constants import EntityCategory
|
from vitrage.common.constants import EntityCategory
|
||||||
|
from vitrage.common.constants import TemplateTopologyFields as TTFields
|
||||||
from vitrage.common.constants import VertexProperties as VProps
|
from vitrage.common.constants import VertexProperties as VProps
|
||||||
from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps
|
from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps
|
||||||
from vitrage.datasources.nagios import NAGIOS_DATASOURCE
|
from vitrage.datasources.nagios import NAGIOS_DATASOURCE
|
||||||
|
from vitrage.datasources.nagios.properties import NagiosProperties as NProps
|
||||||
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
||||||
from vitrage.entity_graph.mappings.operational_resource_state import \
|
from vitrage.entity_graph.mappings.operational_resource_state import \
|
||||||
OperationalResourceState
|
OperationalResourceState
|
||||||
@ -233,6 +236,11 @@ class TestActionExecutor(TestFunctionalBase):
|
|||||||
props[TFields.SEVERITY])
|
props[TFields.SEVERITY])
|
||||||
self.assertEqual(alarm.properties[VProps.STATE],
|
self.assertEqual(alarm.properties[VProps.STATE],
|
||||||
AlarmProps.ACTIVE_STATE)
|
AlarmProps.ACTIVE_STATE)
|
||||||
|
self.assertEqual(alarm.properties[VProps.VITRAGE_RESOURCE_ID],
|
||||||
|
action_spec.targets
|
||||||
|
[TTFields.TARGET][VProps.VITRAGE_ID]),
|
||||||
|
self.assertEqual(alarm.properties[VProps.VITRAGE_RESOURCE_TYPE],
|
||||||
|
NOVA_HOST_DATASOURCE)
|
||||||
|
|
||||||
def test_execute_add_and_remove_vertex(self):
|
def test_execute_add_and_remove_vertex(self):
|
||||||
|
|
||||||
@ -283,27 +291,28 @@ class TestActionExecutor(TestFunctionalBase):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_nagios_event(resource_name, resource_type):
|
def _get_nagios_event(resource_name, resource_type):
|
||||||
|
|
||||||
return {'last_check': '2016-02-07 15:26:04',
|
return {NProps.LAST_CHECK: '2016-02-07 15:26:04',
|
||||||
'resource_name': resource_name,
|
NProps.RESOURCE_NAME: resource_name,
|
||||||
'resource_type': resource_type,
|
NProps.RESOURCE_TYPE: resource_type,
|
||||||
'service': 'Check_MK',
|
NProps.SERVICE: 'Check_MK',
|
||||||
'status': 'CRITICAL',
|
NProps.STATUS: 'CRITICAL',
|
||||||
'status_info': 'test test test',
|
NProps.STATUS_INFO: 'test test test',
|
||||||
'vitrage_datasource_action': 'snapshot',
|
DSProp.DATASOURCE_ACTION: 'snapshot',
|
||||||
'vitrage_entity_type': 'nagios',
|
DSProp.ENTITY_TYPE: 'nagios',
|
||||||
'vitrage_sample_date': '2016-02-07 15:26:04'}
|
DSProp.SAMPLE_DATE: '2016-02-07 15:26:04'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_vitrage_add_vertex_event(target_vertex, alarm_name, severity):
|
def _get_vitrage_add_vertex_event(target_vertex, alarm_name, severity):
|
||||||
|
|
||||||
return {'target': target_vertex.vertex_id,
|
return {TTFields.TARGET: target_vertex.vertex_id,
|
||||||
'update_timestamp': '2016-03-17 11:33:32.443002',
|
VProps.UPDATE_TIMESTAMP: '2016-03-17 11:33:32.443002',
|
||||||
'vitrage_datasource_action': 'update',
|
DSProp.DATASOURCE_ACTION: 'update',
|
||||||
'alarm_name': alarm_name,
|
TFields.ALARM_NAME: alarm_name,
|
||||||
'state': 'Active',
|
VProps.STATE: 'Active',
|
||||||
'type': 'add_vertex',
|
VProps.TYPE: 'add_vertex',
|
||||||
'vitrage_entity_type': 'vitrage',
|
DSProp.ENTITY_TYPE: 'vitrage',
|
||||||
'severity': 'CRITICAL',
|
VProps.SEVERITY: 'CRITICAL',
|
||||||
'vitrage_id': 'mock_vitrage_id',
|
VProps.VITRAGE_ID: 'mock_vitrage_id',
|
||||||
'category': 'RESOURCE',
|
VProps.VITRAGE_RESOURCE_TYPE: 'nova.host',
|
||||||
'sample_timestamp': '2016-03-17 11:33:32.443002+00:00'}
|
VProps.CATEGORY: 'ALARM',
|
||||||
|
VProps.SAMPLE_TIMESTAMP: '2016-03-17 11:33:32.443002+00:00'}
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from vitrage.common.constants import VertexProperties as VProps
|
||||||
from vitrage.datasources.alarm_properties import AlarmProperties
|
from vitrage.datasources.alarm_properties import AlarmProperties
|
||||||
|
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
||||||
from vitrage.evaluator.actions.base import ActionType
|
from vitrage.evaluator.actions.base import ActionType
|
||||||
from vitrage.evaluator.actions.recipes.action_steps import ADD_VERTEX
|
from vitrage.evaluator.actions.recipes.action_steps import ADD_VERTEX
|
||||||
from vitrage.evaluator.actions.recipes.action_steps import REMOVE_VERTEX
|
from vitrage.evaluator.actions.recipes.action_steps import REMOVE_VERTEX
|
||||||
@ -29,7 +31,9 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|
||||||
cls.target_vertex = Vertex('RESOURCE:nova.host:test1')
|
cls.target_props = {VProps.TYPE: NOVA_HOST_DATASOURCE}
|
||||||
|
cls.target_vertex = Vertex('RESOURCE:nova.host:test1',
|
||||||
|
cls.target_props)
|
||||||
cls.targets = {TFields.TARGET: cls.target_vertex}
|
cls.targets = {TFields.TARGET: cls.target_vertex}
|
||||||
cls.props = {TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE'}
|
cls.props = {TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE'}
|
||||||
|
|
||||||
@ -49,7 +53,7 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
|||||||
|
|
||||||
self.assertEqual(ADD_VERTEX, action_steps[0].type)
|
self.assertEqual(ADD_VERTEX, action_steps[0].type)
|
||||||
add_vertex_step_params = action_steps[0].params
|
add_vertex_step_params = action_steps[0].params
|
||||||
self.assertEqual(3, len(add_vertex_step_params))
|
self.assertEqual(4, len(add_vertex_step_params))
|
||||||
|
|
||||||
alarm_name = add_vertex_step_params[TFields.ALARM_NAME]
|
alarm_name = add_vertex_step_params[TFields.ALARM_NAME]
|
||||||
self.assertEqual(self.props[TFields.ALARM_NAME], alarm_name)
|
self.assertEqual(self.props[TFields.ALARM_NAME], alarm_name)
|
||||||
@ -60,6 +64,11 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
|||||||
alarm_state = add_vertex_step_params[TFields.STATE]
|
alarm_state = add_vertex_step_params[TFields.STATE]
|
||||||
self.assertEqual(alarm_state, AlarmProperties.ACTIVE_STATE)
|
self.assertEqual(alarm_state, AlarmProperties.ACTIVE_STATE)
|
||||||
|
|
||||||
|
alarm_vitrage_resource_type = \
|
||||||
|
add_vertex_step_params[VProps.VITRAGE_RESOURCE_TYPE]
|
||||||
|
self.assertEqual(self.target_vertex.properties[VProps.TYPE],
|
||||||
|
alarm_vitrage_resource_type)
|
||||||
|
|
||||||
def test_get_undo_recipe(self):
|
def test_get_undo_recipe(self):
|
||||||
|
|
||||||
# Test Action
|
# Test Action
|
||||||
@ -73,8 +82,9 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
|||||||
self.assertEqual(REMOVE_VERTEX, action_steps[0].type)
|
self.assertEqual(REMOVE_VERTEX, action_steps[0].type)
|
||||||
remove_vertex_step_params = action_steps[0].params
|
remove_vertex_step_params = action_steps[0].params
|
||||||
|
|
||||||
# remove_vertex expects three params: alarm name, state and target
|
# remove_vertex expects four params: alarm name, state, target,
|
||||||
self.assertEqual(3, len(remove_vertex_step_params))
|
# and type
|
||||||
|
self.assertEqual(4, len(remove_vertex_step_params))
|
||||||
|
|
||||||
alarm_name = remove_vertex_step_params[TFields.ALARM_NAME]
|
alarm_name = remove_vertex_step_params[TFields.ALARM_NAME]
|
||||||
self.assertEqual(self.props[TFields.ALARM_NAME], alarm_name)
|
self.assertEqual(self.props[TFields.ALARM_NAME], alarm_name)
|
||||||
@ -84,3 +94,8 @@ class RaiseAlarmRecipeTest(base.BaseTest):
|
|||||||
|
|
||||||
alarm_state = remove_vertex_step_params[TFields.STATE]
|
alarm_state = remove_vertex_step_params[TFields.STATE]
|
||||||
self.assertEqual(alarm_state, AlarmProperties.INACTIVE_STATE)
|
self.assertEqual(alarm_state, AlarmProperties.INACTIVE_STATE)
|
||||||
|
|
||||||
|
alarm_vitrage_resource_type = \
|
||||||
|
remove_vertex_step_params[VProps.VITRAGE_RESOURCE_TYPE]
|
||||||
|
self.assertEqual(self.target_vertex.properties[VProps.TYPE],
|
||||||
|
alarm_vitrage_resource_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user