Decouple the aggregated and operational values Rename statemanager to datasource_info_mapper Change-Id: Ied6220c08f10b6684e21dd22e011af246ec28d3changes/11/320811/4
parent
eafde06dbc
commit
7b21a4a985
@ -1,28 +1,29 @@
|
||||
category: ALARM
|
||||
values:
|
||||
- normalized value:
|
||||
name: CRITICAL
|
||||
priority: 50
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: critical
|
||||
- normalized value:
|
||||
name: SEVERE
|
||||
priority: 40
|
||||
operational_value: CRITICAL
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: moderate
|
||||
- normalized value:
|
||||
name: WARNING
|
||||
priority: 30
|
||||
operational_value: SEVERE
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: low
|
||||
- normalized value:
|
||||
name: UNKNOWN
|
||||
operational_value: WARNING
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: insufficient data
|
||||
- normalized value:
|
||||
name: DISABLED
|
||||
operational_value: N/A
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: OK
|
||||
operational_value: OK
|
||||
- name: UP
|
||||
operational_value: OK
|
||||
|
@ -1,36 +1,40 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
priority: 50
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- name: ERROR_DELETING
|
||||
operational_value: ERROR
|
||||
- name: ERROR_RESTORING
|
||||
operational_value: ERROR
|
||||
- name: ERROR_EXTENDING
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
priority: 40
|
||||
original values:
|
||||
- name: UNRECOGNIZED
|
||||
- normalized value:
|
||||
name: TRANSIENT
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: CREATING
|
||||
operational_value: TRANSIENT
|
||||
- name: ATTACHING
|
||||
operational_value: TRANSIENT
|
||||
- name: DELETING
|
||||
operational_value: TRANSIENT
|
||||
- name: RESTORING-BACKUP
|
||||
operational_value: TRANSIENT
|
||||
- name: BACKING-UP
|
||||
operational_value: TRANSIENT
|
||||
- name: DETACHING
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
operational_value: TRANSIENT
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: IN-USE
|
||||
- name: AVAILABLE
|
||||
operational_value: OK
|
||||
- name: IN-USE
|
||||
operational_value: OK
|
||||
|
@ -1,28 +1,26 @@
|
||||
category: ALARM
|
||||
values:
|
||||
- normalized value:
|
||||
name: CRITICAL
|
||||
priority: 50
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: CRITICAL
|
||||
operational_value: CRITICAL
|
||||
- name: DOWN
|
||||
- normalized value:
|
||||
name: SEVERE
|
||||
priority: 40
|
||||
original values:
|
||||
- normalized value:
|
||||
name: WARNING
|
||||
operational_value: CRITICAL
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: WARNING
|
||||
- normalized value:
|
||||
name: UNKNOWN
|
||||
operational_value: WARNING
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: UNKNOWN
|
||||
- normalized value:
|
||||
name: DISABLED
|
||||
operational_value: N/A
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: OK
|
||||
operational_value: OK
|
||||
- name: UP
|
||||
operational_value: OK
|
||||
|
@ -1,32 +1,27 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
priority: 60
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- aggregated values:
|
||||
priority: 50
|
||||
original values:
|
||||
- name: UNRECOGNIZED
|
||||
- normalized value:
|
||||
name: SUSPENDED
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: DOWN
|
||||
- normalized value:
|
||||
name: TRANSIENT
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: BUILD
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
operational_value: TRANSIENT
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: ACTIVE
|
||||
- name: ACTIVE
|
||||
operational_value: OK
|
||||
|
@ -1,37 +1,32 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
priority: 70
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- aggregated values:
|
||||
priority: 60
|
||||
original values:
|
||||
- name: UNRECOGNIZED
|
||||
- normalized value:
|
||||
name: SUSPENDED
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 50
|
||||
original values:
|
||||
- name: DOWN
|
||||
- normalized value:
|
||||
name: TRANSIENT
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: BUILD
|
||||
- normalized value:
|
||||
name: UNDEFINED
|
||||
operational_value: TRANSIENT
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: 'N/A'
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
operational_value: N/A
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: ACTIVE
|
||||
- name: ACTIVE
|
||||
operational_value: OK
|
||||
|
@ -1,26 +1,22 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: TERMINATED
|
||||
priority: 50
|
||||
original values:
|
||||
- name: DELETED
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- name: DELETED
|
||||
operational_value: DELETED
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: available
|
||||
- name: AVAILABLE
|
||||
operational_value: OK
|
||||
|
@ -1,55 +1,56 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: TERMINATED
|
||||
priority: 90
|
||||
- aggregated values:
|
||||
priority: 80
|
||||
original values:
|
||||
- name: DELETED
|
||||
operational_value: DELETED
|
||||
- name: HARD_DELETED
|
||||
operational_value: DELETED
|
||||
- name: SHELVED_OFFLOADED
|
||||
operational_value: DELETED
|
||||
- name: SOFT_DELETED
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
priority: 80
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
operational_value: DELETED
|
||||
- aggregated values:
|
||||
priority: 70
|
||||
original values:
|
||||
- name: UNRECOGNIZED
|
||||
- normalized value:
|
||||
name: SUSPENDED
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 60
|
||||
original values:
|
||||
- name: SUSPENDED
|
||||
operational_value: SUBOPTIMAL
|
||||
- name: PAUSED
|
||||
operational_value: SUBOPTIMAL
|
||||
- name: STOPPED
|
||||
operational_value: SUBOPTIMAL
|
||||
- name: SHELVED
|
||||
- normalized value:
|
||||
name: RESCUED
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 50
|
||||
original values:
|
||||
- name: RESCUED
|
||||
- normalized value:
|
||||
name: RESIZED
|
||||
priority: 40
|
||||
original values:
|
||||
- name: RESIZED
|
||||
- normalized value:
|
||||
name: TRANSIENT
|
||||
priority: 30
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: BUILDING
|
||||
operational_value: TRANSIENT
|
||||
- name: INITIALIZED
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
priority: 20
|
||||
operational_value: TRANSIENT
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: RESCUED
|
||||
operational_value: OK
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: ACTIVE
|
||||
- name: RESIZED
|
||||
operational_value: OK
|
||||
|
@ -1,26 +1,22 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: TERMINATED
|
||||
priority: 50
|
||||
original values:
|
||||
- name: DELETED
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- name: DELETED
|
||||
operational_value: DELETED
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: available
|
||||
- name: AVAILABLE
|
||||
operational_value: OK
|
||||
|
@ -1,26 +1,22 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: TERMINATED
|
||||
priority: 50
|
||||
original values:
|
||||
- name: DELETED
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- name: DELETED
|
||||
operational_value: DELETED
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: available
|
||||
- name: AVAILABLE
|
||||
operational_value: OK
|
||||
|
@ -1,6 +1,22 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- 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
|
||||
|
@ -1,26 +1,22 @@
|
||||
category: RESOURCE
|
||||
values:
|
||||
- normalized value:
|
||||
name: TERMINATED
|
||||
priority: 50
|
||||
original values:
|
||||
- name: DELETED
|
||||
- normalized value:
|
||||
name: ERROR
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: ERROR
|
||||
- normalized value:
|
||||
name: UNRECOGNIZED
|
||||
- name: DELETED
|
||||
operational_value: DELETED
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- normalized value:
|
||||
name: SUBOPTIMAL
|
||||
- name: ERROR
|
||||
operational_value: ERROR
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: SUBOPTIMAL
|
||||
- normalized value:
|
||||
name: RUNNING
|
||||
operational_value: SUBOPTIMAL
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: available
|
||||
operational_value: OK
|
||||
|
@ -1,27 +1,31 @@
|
||||
category: ALARM
|
||||
values:
|
||||
- normalized value:
|
||||
name: CRITICAL
|
||||
- aggregated values:
|
||||
priority: 50
|
||||
original values:
|
||||
- name: CRITICAL
|
||||
- normalized value:
|
||||
name: SEVERE
|
||||
operational_value: CRITICAL
|
||||
- aggregated values:
|
||||
priority: 40
|
||||
original values:
|
||||
- name: SEVERE
|
||||
- normalized value:
|
||||
name: WARNING
|
||||
operational_value: SEVERE
|
||||
- name: MAJOR
|
||||
operational_value: SEVERE
|
||||
- aggregated values:
|
||||
priority: 30
|
||||
original values:
|
||||
- name: WARNING
|
||||
- normalized value:
|
||||
name: UNKNOWN
|
||||
operational_value: WARNING
|
||||
- name: MINOR
|
||||
operational_value: WARNING
|
||||
- aggregated values:
|
||||
priority: 20
|
||||
original values:
|
||||
- name: UNKNOWN
|
||||
- normalized value:
|
||||
name: DISABLED
|
||||
operational_value: N/A
|
||||
- aggregated values:
|
||||
priority: 10
|
||||
original values:
|
||||
- name: OK
|
||||
operational_value: OK
|
@ -0,0 +1,42 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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 vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.entity_graph.mappings.handler_base import HandlerBase
|
||||
from vitrage.entity_graph.mappings.operational_alarm_severity \
|
||||
import OperationalAlarmSeverity
|
||||
|
||||
|
||||
class AlarmHandler(HandlerBase):
|
||||
|
||||
def __init__(self):
|
||||
super(AlarmHandler, self).__init__()
|
||||
|
||||
def undefined_property(self):
|
||||
return OperationalAlarmSeverity.NA
|
||||
|
||||
def value_properties(self):
|
||||
return [VProps.SEVERITY]
|
||||
|
||||
def set_operational_value(self, new_vertex, operational_value):
|
||||
new_vertex[VProps.OPERATIONAL_SEVERITY] = operational_value
|
||||
|
||||
def set_aggregated_value(self, new_vertex, aggregated_value):
|
||||
new_vertex[VProps.AGGREGATED_SEVERITY] = aggregated_value
|
||||
|
||||
def default_values(self):
|
||||
return [(None, OperationalAlarmSeverity.NA, 0)]
|
||||
|
||||
def get_value_class_instance(self):
|
||||
return OperationalAlarmSeverity()
|
@ -0,0 +1,225 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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 os
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.common import file_utils
|
||||
from vitrage.entity_graph.mappings.alarm_handler import AlarmHandler
|
||||
from vitrage.entity_graph.mappings.resource_handler import \
|
||||
ResourceHandler
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class DatasourceInfoMapper(object):
|
||||
OPERATIONAL_VALUES = 'operational_values'
|
||||
PRIORITY_VALUES = 'priority_values'
|
||||
UNDEFINED_DATASOURCE = 'undefined datasource'
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
self.category_normalizer = self._init_category_normalizer()
|
||||
self.datasources_state_confs = self._load_state_configurations()
|
||||
|
||||
def operational_state(self, datasource_name, state):
|
||||
return self._get_state_data(datasource_name,
|
||||
state,
|
||||
self.OPERATIONAL_VALUES)
|
||||
|
||||
def state_priority(self, datasource_name, state):
|
||||
return self._get_state_data(datasource_name,
|
||||
state,
|
||||
self.PRIORITY_VALUES)
|
||||
|
||||
def aggregated_state(self, new_vertex, graph_vertex):
|
||||
datasource_name = new_vertex[VProps.TYPE] if \
|
||||
VProps.TYPE in new_vertex.properties else \
|
||||
graph_vertex[VProps.TYPE]
|
||||
|
||||
category = new_vertex[VProps.CATEGORY] if \
|
||||
VProps.CATEGORY in new_vertex.properties else \
|
||||
graph_vertex[VProps.CATEGORY]
|
||||
|
||||
if datasource_name in self.datasources_state_confs:
|
||||
value_properties = \
|
||||
self.category_normalizer[category].value_properties()
|
||||
operational_state, aggregated_state, state_priority = \
|
||||
self._find_operational_state_and_priority(new_vertex,
|
||||
graph_vertex,
|
||||
value_properties[0],
|
||||
datasource_name)
|
||||
value_properties.pop(0)
|
||||
|
||||
for property_ in value_properties:
|
||||
t_operational_state, t_aggregated_state, t_state_priority = \
|
||||
self._find_operational_state_and_priority(new_vertex,
|
||||
graph_vertex,
|
||||
property_,
|
||||
datasource_name)
|
||||
if t_state_priority > state_priority:
|
||||
operational_state = t_operational_state
|
||||
aggregated_state = t_aggregated_state
|
||||
state_priority = t_state_priority
|
||||
|
||||
self.category_normalizer[category].set_aggregated_value(
|
||||
new_vertex, aggregated_state)
|
||||
self.category_normalizer[category].set_operational_value(
|
||||
new_vertex, operational_state)
|
||||
else:
|
||||
self.category_normalizer[category].set_aggregated_value(
|
||||
new_vertex, self.UNDEFINED_DATASOURCE)
|
||||
self.category_normalizer[category].set_operational_value(
|
||||
new_vertex, self.UNDEFINED_DATASOURCE)
|
||||
|
||||
@staticmethod
|
||||
def _init_category_normalizer():
|
||||
return {
|
||||
EntityCategory.RESOURCE: ResourceHandler(),
|
||||
EntityCategory.ALARM: AlarmHandler()
|
||||
}
|
||||
|
||||
def _load_state_configurations(self):
|
||||
valid_datasources_conf = {}
|
||||
erroneous_datasources_conf = []
|
||||
|
||||
files = file_utils.load_files(
|
||||
self.conf.entity_graph.datasources_values_dir, '.yaml')
|
||||
|
||||
for file_name in files:
|
||||
try:
|
||||
full_path = self.conf.entity_graph.datasources_values_dir \
|
||||
+ '/' + file_name
|
||||
operational_values, priority_values = \
|
||||
self._retrieve_states_and_priorities_from_file(full_path)
|
||||
valid_datasources_conf[os.path.splitext(file_name)[0]] = {
|
||||
self.OPERATIONAL_VALUES: operational_values,
|
||||
self.PRIORITY_VALUES: priority_values
|
||||
}
|
||||
except Exception as e:
|
||||
LOG.exception("Exception: %s", e)
|
||||
datasource = os.path.splitext(file_name)[0]
|
||||
LOG.error('erroneous data sources is %s',
|
||||
erroneous_datasources_conf.append(datasource))
|
||||
|
||||
self._check_state_confs_exists(
|
||||
[key for key in valid_datasources_conf.keys()],
|
||||
erroneous_datasources_conf)
|
||||
|
||||
return valid_datasources_conf
|
||||
|
||||
def _retrieve_states_and_priorities_from_file(self, full_path):
|
||||
states = {}
|
||||
priorities = {}
|
||||
config = file_utils.load_yaml_file(full_path, with_exception=True)
|
||||
category = config['category']
|
||||
|
||||
for item in config['values']:
|
||||
aggregated_values = item['aggregated values']
|
||||
priority_value = int(aggregated_values['priority'])
|
||||
|
||||
# original to operational value
|
||||
for original_state in aggregated_values['original values']:
|
||||
original_value = original_state['name']
|
||||
operational_value = original_state['operational_value']
|
||||
states[original_value.upper()] = operational_value
|
||||
priorities[original_value.upper()] = priority_value
|
||||
|
||||
self._check_validity(category, states, priorities, full_path)
|
||||
|
||||
self._add_default_states(states, priorities, category)
|
||||
|
||||
return states, priorities
|
||||
|
||||
def _add_default_states(self, states, priorities, category):
|
||||
default_values = self.category_normalizer[category].default_values()
|
||||
for original_val, operational_val, priority_val in default_values:
|
||||
states[original_val] = operational_val
|
||||
priorities[original_val] = priority_val
|
||||
|
||||
def _check_validity(self, category, states, priorities, full_path):
|
||||
# check that all the operational values exists
|
||||
state_class_instance = \
|
||||
self.category_normalizer[category].get_value_class_instance()
|
||||
operational_values = DatasourceInfoMapper.\
|
||||
_get_all_local_variables_of_class(state_class_instance)
|
||||
for operational_value in states.values():
|
||||
if operational_value not in operational_values:
|
||||
raise ValueError('operational value %s for %s is not in %s',
|
||||
operational_value, full_path,
|
||||
state_class_instance.__class__.__name__)
|
||||
|
||||
def _get_state_data(self, datasource_name, state, data_type):
|
||||
try:
|
||||
upper_state = state if not state else state.upper()
|
||||
|
||||
if datasource_name in self.datasources_state_confs:
|
||||
values_conf = self.datasources_state_confs[
|
||||
datasource_name][data_type]
|
||||
|
||||
return values_conf[upper_state] if upper_state in values_conf \
|
||||
else values_conf[None]
|
||||
else:
|
||||
return self.UNDEFINED_DATASOURCE
|
||||
except Exception:
|
||||
LOG.error('Exception in datasource: %s', datasource_name)
|
||||
raise
|
||||
|
||||
def _find_operational_state_and_priority(self,
|
||||
new_vertex,
|
||||
graph_vertex,
|
||||
property_,
|
||||
datasource_name):
|
||||
state = self._get_updated_property(new_vertex,
|
||||
graph_vertex,
|
||||
property_)
|
||||
|
||||
upper_state = state if not state else state.upper()
|
||||
|
||||
operational_state = self.operational_state(datasource_name,
|
||||
upper_state)
|
||||
|
||||
state_priority = self.state_priority(datasource_name,
|
||||
upper_state)
|
||||
|
||||
return operational_state, upper_state, state_priority
|
||||
|
||||
@staticmethod
|
||||
def _get_all_local_variables_of_class(class_instance):
|
||||
return [getattr(class_instance, attr) for attr in dir(class_instance)
|
||||
if not callable(attr) and not attr.startswith("__")]
|
||||
|
||||
def _check_state_confs_exists(self,
|
||||
ok_datasources,
|
||||
error_datasources):
|
||||
|
||||
datasource_types = self.conf.datasources.types
|
||||
datasources_with_state_conf = ok_datasources + error_datasources
|
||||
|
||||
for datasource_type in datasource_types:
|
||||
if datasource_type not in datasources_with_state_conf:
|
||||
LOG.info("No state configuration file for: %s",
|
||||
datasource_type)
|
||||
|
||||
@staticmethod
|
||||
def _get_updated_property(new_vertex, graph_vertex, prop):
|
||||
if new_vertex and prop in new_vertex.properties:
|
||||
return new_vertex[prop]
|
||||
elif graph_vertex and prop in graph_vertex.properties:
|
||||
return graph_vertex[prop]
|
||||
|
||||
return None
|
@ -0,0 +1,42 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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 vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.entity_graph.mappings.handler_base import HandlerBase
|
||||
from vitrage.entity_graph.mappings.operational_resource_state \
|
||||
import OperationalResourceState
|
||||
|
||||
|
||||
class ResourceHandler(HandlerBase):
|
||||
|
||||
def __init__(self):
|
||||
super(ResourceHandler, self).__init__()
|
||||
|
||||
def undefined_property(self):
|
||||
return OperationalResourceState.NA
|
||||
|
||||
def value_properties(self):
|
||||
return [VProps.STATE, VProps.VITRAGE_STATE]
|
||||
|
||||
def set_operational_value(self, new_vertex, operational_value):
|
||||
new_vertex[VProps.OPERATIONAL_STATE] = operational_value
|
||||
|
||||
def set_aggregated_value(self, new_vertex, aggregated_value):
|
||||
new_vertex[VProps.AGGREGATED_STATE] = aggregated_value
|
||||
|
||||
def default_values(self):
|
||||
return [(None, OperationalResourceState.NA, 0)]
|
||||
|
||||
def get_value_class_instance(self):
|
||||
return OperationalResourceState()
|
@ -1,45 +0,0 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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 vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.entity_graph.states.normalizator_base import ImportantStates
|
||||
from vitrage.entity_graph.states.normalizator_base import NormalizatorBase
|
||||
from vitrage.entity_graph.states.normalized_alarm_severity \
|
||||
import NormalizedAlarmSeverity
|
||||
|
||||
|
||||
class AlarmNormalizator(NormalizatorBase):
|
||||
|
||||
def __init__(self):
|
||||
super(AlarmNormalizator, self).__init__()
|
||||
|
||||
def important_states(self):
|
||||
return ImportantStates(NormalizedAlarmSeverity.UNKNOWN,
|
||||
NormalizedAlarmSeverity.UNDEFINED)
|
||||
|
||||
def state_properties(self):
|
||||
return [VProps.SEVERITY]
|
||||
|
||||
def set_aggregated_state(self, new_vertex, normalized_state):
|
||||
new_vertex[VProps.NORMALIZED_SEVERITY] = normalized_state
|
||||
|
||||
def set_undefined_state(self, new_vertex):
|
||||
new_vertex[VProps.NORMALIZED_SEVERITY] = \
|
||||
NormalizedAlarmSeverity.UNDEFINED
|
||||
|
||||
def default_states(self):
|
||||
return [(NormalizedAlarmSeverity.UNDEFINED, 0)]
|
||||
|
||||
def get_state_class_instance(self):
|
||||
return NormalizedAlarmSeverity()
|
@ -1,44 +0,0 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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 vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.entity_graph.states.normalizator_base import ImportantStates
|
||||
from vitrage.entity_graph.states.normalizator_base import NormalizatorBase
|
||||
from vitrage.entity_graph.states.normalized_resource_state \
|
||||
import NormalizedResourceState
|
||||
|
||||
|
||||
class ResourceNormalizator(NormalizatorBase):
|
||||
|
||||
def __init__(self):
|
||||
super(ResourceNormalizator, self).__init__()
|
||||
|
||||
def important_states(self):
|
||||
return ImportantStates(NormalizedResourceState.UNRECOGNIZED,
|
||||
NormalizedResourceState.UNDEFINED)
|
||||
|
||||
def state_properties(self):
|
||||
return [VProps.STATE, VProps.VITRAGE_STATE]
|
||||
|
||||
def set_undefined_state(self, new_vertex):
|
||||
new_vertex[VProps.AGGREGATED_STATE] = NormalizedResourceState.UNDEFINED
|
||||
|
||||
def set_aggregated_state(self, new_vertex, normalized_state):
|
||||
new_vertex[VProps.AGGREGATED_STATE] = normalized_state
|
||||
|
||||
def default_states(self):
|
||||
return [(NormalizedResourceState.UNDEFINED, 0)]
|
||||
|
||||
def get_state_class_instance(self):
|
||||
return NormalizedResourceState()
|
@ -1,244 +0,0 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# 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 os
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.common import file_utils
|
||||
from vitrage.entity_graph.states.alarm_normalizator import AlarmNormalizator
|
||||
from vitrage.entity_graph.states.normalized_resource_state \
|
||||
import NormalizedResourceState
|
||||
from vitrage.entity_graph.states.resource_normalizator import \
|
||||
ResourceNormalizator
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class StateManager(object):
|
||||
VALUES = 'values'
|
||||
PRIORITIES = 'priorities'
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
self.category_normalizator = self._init_category_normalizator()
|
||||
self.datasources_state_confs = self._load_state_configurations()
|
||||
|
||||
def normalize_state(self, category, datasource_name, state):
|
||||
try:
|
||||
upper_state = state if not state else state.upper()
|
||||
important_states = \
|
||||
self.category_normalizator[category].important_states()
|
||||
|
||||
if datasource_name in self.datasources_state_confs:
|
||||
|
||||
states_conf = self.datasources_state_confs[datasource_name]
|
||||
|
||||
return states_conf[self.VALUES][upper_state] \
|
||||
if upper_state in states_conf[self.VALUES] \
|
||||
else states_conf[self.VALUES][important_states.unknown]
|
||||
else:
|
||||
return important_states.undefined
|
||||
except Exception:
|
||||
LOG.error('Exception in datasource: %s', datasource_name)
|
||||
raise
|
||||
|
||||
def state_priority(self, datasource_name, normalized_state):
|
||||
try:
|
||||
# no need to check if normalized_state exists, cause it exists for
|
||||
# sure
|
||||
upper_state = normalized_state if not normalized_state else \
|
||||
normalized_state.upper()
|
||||
|
||||
if datasource_name in self.datasources_state_confs:
|
||||
states_conf = self.datasources_state_confs[datasource_name]
|
||||
return states_conf[self.PRIORITIES][upper_state]
|
||||
else:
|
||||
# default UNDEFINED priority
|
||||
return 0
|
||||
except Exception:
|
||||
LOG.error('Exception in datasource: %s', datasource_name)
|
||||
raise
|
||||
|
||||
def aggregated_state(self, new_vertex, graph_vertex, is_normalized=False):
|
||||
datasource_name = new_vertex[VProps.TYPE] if \
|
||||
VProps.TYPE in new_vertex.properties else \
|
||||
graph_vertex[VProps.TYPE]
|
||||
|
||||
category = new_vertex[VProps.CATEGORY] if \
|
||||
VProps.CATEGORY in new_vertex.properties else \
|
||||
graph_vertex[VProps.CATEGORY]
|
||||
|
||||
if datasource_name in self.datasources_state_confs:
|
||||
state_properties = \
|
||||
self.category_normalizator[category].state_properties()
|
||||
normalized_state, state_priority = \
|
||||
self._find_normalized_state_and_priority(new_vertex,
|
||||
graph_vertex,
|
||||
state_properties[0],
|
||||
category,
|
||||
datasource_name,
|
||||
is_normalized)
|
||||
state_properties.pop(0)
|
||||
|
||||
for property_ in state_properties:
|
||||
tmp_normalized_state, tmp_state_priority = \
|
||||
self._find_normalized_state_and_priority(new_vertex,
|
||||
graph_vertex,
|
||||
property_,
|
||||
category,
|
||||
datasource_name,
|
||||
is_normalized)
|
||||
if tmp_state_priority > state_priority:
|
||||
normalized_state = tmp_normalized_state
|
||||
state_priority = tmp_state_priority
|
||||
|
||||
self.category_normalizator[category].set_aggregated_state(
|
||||
new_vertex, normalized_state)
|
||||
else:
|
||||
self.category_normalizator[category].set_undefined_state(
|
||||
new_vertex)
|
||||
|
||||
@staticmethod
|
||||
def _init_category_normalizator():
|
||||
return {
|
||||
EntityCategory.RESOURCE: ResourceNormalizator(),
|
||||
EntityCategory.ALARM: AlarmNormalizator()
|
||||
}
|
||||
|
||||
def _load_state_configurations(self):
|
||||
ok_datasources = {}
|
||||
erroneous_datasources = []
|
||||
|
||||
files = file_utils.load_files(
|
||||
self.conf.entity_graph.datasources_values_dir, '.yaml')
|
||||
|
||||
for file_name in files:
|
||||
try:
|
||||
full_path = self.conf.entity_graph.datasources_values_dir \
|
||||
+ '/' + file_name
|
||||
states, priorities = \
|
||||
self._retrieve_states_and_priorities_from_file(full_path)
|
||||
ok_datasources[os.path.splitext(file_name)[0]] = {
|
||||
self.VALUES: states,
|
||||
self.PRIORITIES: priorities
|
||||
}
|
||||
except Exception as e:
|
||||
LOG.exception("Exception: %s", e)
|
||||
datasource = os.path.splitext(file_name)[0]
|
||||
LOG.error('erroneous data sources is %s',
|
||||
erroneous_datasources.append(datasource))
|
||||
|
||||
self._check_state_confs_exists(
|
||||
[key for key in ok_datasources.keys()],
|
||||
erroneous_datasources)
|
||||
|
||||
return ok_datasources
|
||||
|
||||
def _retrieve_states_and_priorities_from_file(self, full_path):
|
||||
states = {}
|
||||
priorities = {}
|
||||
config = file_utils.load_yaml_file(full_path, with_exception=True)
|
||||
category = config['category']
|
||||
|
||||
for item in config[self.VALUES]:
|
||||
normalized_state = item['normalized value']
|
||||
|
||||
# original to normalized value
|
||||
normalized_state_name = normalized_state['name']
|
||||
for original_state in normalized_state['original values']:
|
||||
states[original_state['name'].upper()] = normalized_state_name
|
||||
|
||||
self._add_default_states(states, priorities, category)
|
||||
|
||||
# normalized value priority
|
||||
priorities[normalized_state_name] = \
|
||||
int(normalized_state['priority'])
|
||||
|
||||
self.check_validity(category, priorities, full_path)
|
||||
|
||||
return states, priorities
|
||||
|
||||
def _add_default_states(self, states, priorities, category):
|
||||
default_values = self.category_normalizator[category].default_states()
|
||||
for state, priority in default_values:
|
||||
states[None] = state
|
||||
priorities[NormalizedResourceState.UNDEFINED] = priority
|
||||
|
||||
def check_validity(self, category, priorities, full_path):
|
||||
important_states = \
|
||||
self.category_normalizator[category].important_states()
|
||||
if important_states.unknown not in priorities:
|
||||
raise ValueError('%s state is not defined in %s',
|
||||
important_states.unknown, full_path)
|
||||
|
||||
# check that all the normalized values exists
|
||||
state_class_instance = \
|
||||
self.category_normalizator[category].get_state_class_instance()
|
||||
normalized_values = StateManager._get_all_local_variables_of_class(
|
||||
state_class_instance)
|
||||
for key in priorities.keys():
|
||||
if key not in normalized_values:
|
||||
raise ValueError('normalized value %s for %s is not in %s',
|
||||
key, full_path,
|
||||
state_class_instance.__class__.__name__)
|
||||
|
||||
def _find_normalized_state_and_priority(self,
|
||||
new_vertex,
|
||||
graph_vertex,
|
||||
property_,
|
||||
category,
|
||||
datasource_name,
|
||||
is_normalized=False):
|
||||
state = self._get_updated_property(new_vertex,
|
||||
graph_vertex,
|
||||
property_)
|
||||
|
||||
upper_state1 = state if not state else state.upper()
|
||||
|
||||
normalized_state = upper_state1 if is_normalized else \
|
||||
self.normalize_state(category, datasource_name, upper_state1)
|
||||
|
||||
state_priority = self.state_priority(datasource_name,
|
||||
normalized_state)
|
||||
|
||||
return normalized_state, state_priority
|
||||
|
||||
@staticmethod
|
||||
def _get_all_local_variables_of_class(class_instance):
|
||||
return [attr for attr in dir(class_instance) if not callable(attr) and
|
||||
not attr.startswith("__")]
|
||||
|
||||
def _check_state_confs_exists(self,
|
||||
ok_datasources,
|
||||
error_datasources):
|
||||
|
||||
datasource_types = self.conf.datasources.types
|
||||
datasources_with_state_conf = ok_datasources + error_datasources
|
||||
|
||||
for datasource_type in datasource_types:
|
||||
if datasource_type not in datasources_with_state_conf:
|
||||
LOG.info("No state configuration file for: %s",
|
||||
datasource_type)
|
||||
|
||||
@staticmethod
|
||||
def _get_updated_property(new_vertex, graph_vertex, prop):
|
||||
if new_vertex and prop in new_vertex.properties:
|
||||
return new_vertex[prop]
|
||||
elif graph_vertex and prop in graph_vertex.properties:
|
||||
return graph_vertex[prop]
|
||||
|
||||
return None
|