create default datasource info mapper for static entities

Change-Id: I29d7b6a7643b3455b8f44b785a9c102644956679
This commit is contained in:
Alexey 2017-04-26 05:33:45 +00:00
parent 3be6a0187b
commit 37d435663f
8 changed files with 154 additions and 9 deletions

View File

@ -0,0 +1,24 @@
category: RESOURCE
values:
- aggregated values:
priority: 40
original values:
- name: DELETED
operational_value: DELETED
- aggregated values:
priority: 30
original values:
- name: ERROR
operational_value: ERROR
- aggregated values:
priority: 20
original values:
- name: SUBOPTIMAL
operational_value: SUBOPTIMAL
- aggregated values:
priority: 10
original values:
- name: AVAILABLE
operational_value: OK
- name: ACTIVE
operational_value: OK

View File

@ -0,0 +1,24 @@
category: RESOURCE
values:
- aggregated values:
priority: 40
original values:
- name: DELETED
operational_value: DELETED
- aggregated values:
priority: 30
original values:
- name: ERROR
operational_value: ERROR
- aggregated values:
priority: 20
original values:
- name: SUBOPTIMAL
operational_value: SUBOPTIMAL
- aggregated values:
priority: 10
original values:
- name: AVAILABLE
operational_value: OK
- name: ACTIVE
operational_value: OK

View File

@ -20,3 +20,5 @@ values:
original values:
- name: AVAILABLE
operational_value: OK
- name: ACTIVE
operational_value: OK

View File

@ -26,6 +26,9 @@ from vitrage.utils import file as file_utils
LOG = log.getLogger(__name__)
DEFAULT_INFO_MAPPER = 'default'
class DatasourceInfoMapper(object):
OPERATIONAL_VALUES = 'operational_values'
PRIORITY_VALUES = 'priority_values'
@ -55,7 +58,8 @@ class DatasourceInfoMapper(object):
VProps.CATEGORY in new_vertex.properties else \
graph_vertex[VProps.CATEGORY]
if datasource_name in self.datasources_state_confs:
if datasource_name in self.datasources_state_confs or \
datasource_name not in self.conf.datasources.types:
value_properties = \
self.category_normalizer[category].value_properties()
operational_state, aggregated_state, state_priority = \
@ -184,7 +188,11 @@ class DatasourceInfoMapper(object):
return values_conf[upper_state] if upper_state in values_conf \
else values_conf[None]
else:
return self.UNDEFINED_DATASOURCE
values_conf = self.datasources_state_confs[
DEFAULT_INFO_MAPPER][data_type]
return values_conf[upper_state] if upper_state in values_conf \
else values_conf[None]
except Exception:
LOG.error('Exception in datasource: %s', datasource_name)
raise

View File

@ -13,6 +13,8 @@
# under the License.
from vitrage.common.constants import VertexProperties as VProps
from vitrage.entity_graph.mappings.datasource_info_mapper \
import DEFAULT_INFO_MAPPER
from vitrage.evaluator.template_fields import TemplateFields
@ -51,7 +53,10 @@ class SetStateTools(object):
def get_score(self, action_info):
state = action_info.specs.properties[TemplateFields.STATE].upper()
target_resource = action_info.specs.targets[TemplateFields.TARGET]
return self.scores[target_resource[VProps.TYPE]].get(state, 0)
target_type = target_resource[VProps.TYPE]
score_name = \
target_type if target_type in self.scores else DEFAULT_INFO_MAPPER
return self.scores[score_name].get(state, 0)
@staticmethod
def get_key(action_specs):

View File

@ -0,0 +1,24 @@
category: RESOURCE
values:
- aggregated values:
priority: 40
original values:
- name: DELETED
operational_value: DELETED
- aggregated values:
priority: 30
original values:
- name: ERROR
operational_value: ERROR
- aggregated values:
priority: 20
original values:
- name: SUBOPTIMAL
operational_value: SUBOPTIMAL
- aggregated values:
priority: 10
original values:
- name: AVAILABLE
operational_value: OK
- name: ACTIVE
operational_value: OK

View File

@ -0,0 +1,24 @@
category: RESOURCE
values:
- aggregated values:
priority: 40
original values:
- name: DELETED
operational_value: DELETED
- aggregated values:
priority: 30
original values:
- name: ERROR
operational_value: ERROR
- aggregated values:
priority: 20
original values:
- name: SUBOPTIMAL
operational_value: SUBOPTIMAL
- aggregated values:
priority: 10
original values:
- name: AVAILABLE
operational_value: OK
- name: ACTIVE
operational_value: OK

View File

@ -16,6 +16,7 @@ from oslo_config import cfg
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import VertexProperties as VProps
from vitrage.datasources.aodh import AODH_DATASOURCE
from vitrage.datasources.nagios import NAGIOS_DATASOURCE
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
@ -42,7 +43,8 @@ class TestDatasourceInfoMapper(base.BaseTest):
default=[NAGIOS_DATASOURCE,
NOVA_HOST_DATASOURCE,
NOVA_INSTANCE_DATASOURCE,
NOVA_ZONE_DATASOURCE],
NOVA_ZONE_DATASOURCE,
AODH_DATASOURCE],
help='Names of supported data sources'),
cfg.ListOpt('path',
@ -121,7 +123,7 @@ class TestDatasourceInfoMapper(base.BaseTest):
# test assertions
self.assertEqual(OperationalResourceState.NA, operational_state)
def test_operational_state_datasource_not_exists(self):
def test_operational_state_datasource_not_exists_and_state_not_exist(self):
# setup
state_manager = DatasourceInfoMapper(self.conf)
@ -131,7 +133,20 @@ class TestDatasourceInfoMapper(base.BaseTest):
'BUILDING')
# test assertions
self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
self.assertEqual(OperationalResourceState.NA,
operational_state)
def test_operational_state_datasource_not_exists_and_state_exist(self):
# setup
state_manager = DatasourceInfoMapper(self.conf)
# action
operational_state = \
state_manager.operational_state('NON EXISTING DATASOURCE',
'AVAILABLE')
# test assertions
self.assertEqual(OperationalResourceState.OK,
operational_state)
def test_state_priority(self):
@ -168,7 +183,7 @@ class TestDatasourceInfoMapper(base.BaseTest):
'ACTIVE')
# test assertions
self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
self.assertEqual(10,
state_priority)
def test_aggregated_state(self):
@ -255,7 +270,26 @@ class TestDatasourceInfoMapper(base.BaseTest):
state_manager.aggregated_state(new_vertex, None)
# test assertions
self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
self.assertEqual('ACTIVE',
new_vertex[VProps.AGGREGATED_STATE])
self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
self.assertEqual(OperationalResourceState.OK,
new_vertex[VProps.OPERATIONAL_STATE])
def test_aggregated_state_datasource_not_exists_and_wrong_state(self):
# setup
state_manager = DatasourceInfoMapper(self.conf)
metadata = {VProps.VITRAGE_STATE: 'SUSPENDED'}
new_vertex = create_vertex('12345',
entity_state='NON EXISTING STATE',
entity_category=EntityCategory.RESOURCE,
entity_type='NON EXISTING DATASOURCE',
metadata=metadata)
# action
state_manager.aggregated_state(new_vertex, None)
# test assertions
self.assertEqual('NON EXISTING STATE',
new_vertex[VProps.AGGREGATED_STATE])
self.assertEqual(OperationalResourceState.NA,
new_vertex[VProps.OPERATIONAL_STATE])