Merge "add timezone to alarms queried from db"

This commit is contained in:
Zuul 2018-08-08 09:47:13 +00:00 committed by Gerrit Code Review
commit 08c95a9d8b
5 changed files with 27 additions and 10 deletions

View File

@ -102,7 +102,7 @@ python-novaclient==10.1.0
python-openstackclient==3.12.0
python-subunit==1.2.0
python-swiftclient==3.5.0
pytz==2018.3
pytz==2013.6
PyYAML==3.12
pyzabbix==0.7.4
reno==2.7.0

View File

@ -47,3 +47,4 @@ six>=1.11.0 # MIT
debtcollector>=1.19.0 # Apache-2.0
cotyledon>=1.6.8 # Apache-2.0
futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD
pytz>=2013.6 # MIT

View File

@ -11,10 +11,9 @@
# 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 dateutil import parser
import json
from oslo_log import log
from osprofiler import profiler
@ -107,9 +106,14 @@ class AlarmApis(EntityGraphApisBase):
alarm.payload[VProps.VITRAGE_OPERATIONAL_SEVERITY] = \
OperationalAlarmSeverity.OK
for alarm in alarms:
alarm.payload[HProps.START_TIMESTAMP] = str(alarm.start_timestamp)
start_timestamp = \
self.db.history_facade.add_utc_timezone(alarm.start_timestamp)
alarm.payload[HProps.START_TIMESTAMP] = str(start_timestamp)
if alarm.end_timestamp <= db_time():
alarm.payload[HProps.END_TIMESTAMP] = str(alarm.end_timestamp)
end_timestamp = \
self.db.history_facade.add_utc_timezone(
alarm.end_timestamp)
alarm.payload[HProps.END_TIMESTAMP] = str(end_timestamp)
return alarms

View File

@ -51,9 +51,13 @@ class RcaApis(EntityGraphApisBase):
admin=is_admin_project)
for n in db_nodes:
n.payload[HProps.START_TIMESTAMP] = str(n.start_timestamp)
start_timestamp = \
self.db.history_facade.add_utc_timezone(n.start_timestamp)
n.payload[HProps.START_TIMESTAMP] = str(start_timestamp)
if n.end_timestamp <= db_time():
n.payload[HProps.END_TIMESTAMP] = str(n.end_timestamp)
end_timestamp = \
self.db.history_facade.add_utc_timezone(n.end_timestamp)
n.payload[HProps.END_TIMESTAMP] = str(end_timestamp)
vertices = [Vertex(vertex_id=n.vitrage_id, properties=n.payload) for n
in db_nodes]

View File

@ -14,12 +14,15 @@
from __future__ import absolute_import
from oslo_db.sqlalchemy import utils as sqlalchemyutils
from oslo_log import log
from oslo_utils import timeutils
import pytz
import sqlalchemy
from sqlalchemy import and_
from sqlalchemy import or_
from oslo_db.sqlalchemy import utils as sqlalchemyutils
from oslo_log import log
from oslo_utils import timeutils
from vitrage.common.constants import EdgeLabel as ELable
from vitrage.common.constants import HistoryProps as HProps
from vitrage.common.exception import VitrageInputError
@ -51,6 +54,11 @@ class HistoryFacadeConnection(object):
self._edges.end_all_edges(end_time)
self._changes.add_end_changes(changes_to_add, end_time)
@staticmethod
def add_utc_timezone(time):
time = pytz.utc.localize(time)
return time
def count_active_alarms(self, project_id=None, is_admin_project=False):
session = self._engine_facade.get_session()