Versioned objects - Event
Prototype implementation of oslo.versionedobjects. This patch adds Event object. Implements: blueprint versioned-objects Co-Authored-By: ShaoHe Feng <shaohe.feng@intel.com> Co-Authored-By: Grzegorz Grasza <grzegorz.grasza@intel.com> Change-Id: Ifdff1289aba4bf09130047f63d4e745d591fe16a
This commit is contained in:
parent
4f69bfa4d9
commit
dfc3847f10
@ -16,7 +16,7 @@ import six
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.common import identifier
|
||||
from heat.db import api as db_api
|
||||
from heat.objects import event as event_object
|
||||
|
||||
|
||||
class Event(object):
|
||||
@ -52,7 +52,7 @@ class Event(object):
|
||||
from heat.engine import stack as parser
|
||||
|
||||
ev = (event if event is not None else
|
||||
db_api.event_get(context, event_id))
|
||||
event_object.Event.get_by_id(context, event_id))
|
||||
if ev is None:
|
||||
message = _('No event exists with id "%s"') % str(event_id)
|
||||
raise exception.NotFound(message)
|
||||
@ -84,7 +84,7 @@ class Event(object):
|
||||
if self.timestamp is not None:
|
||||
ev['created_at'] = self.timestamp
|
||||
|
||||
new_ev = db_api.event_create(self.context, ev)
|
||||
new_ev = event_object.Event.create(self.context, ev)
|
||||
self.id = new_ev.id
|
||||
return self.id
|
||||
|
||||
|
@ -51,6 +51,7 @@ from heat.engine import stack_lock
|
||||
from heat.engine import template as templatem
|
||||
from heat.engine import watchrule
|
||||
from heat.engine import worker
|
||||
from heat.objects import event as event_object
|
||||
from heat.objects import resource as resource_objects
|
||||
from heat.objects import snapshot as snapshot_object
|
||||
from heat.objects import stack as stack_object
|
||||
@ -1016,13 +1017,17 @@ class EngineService(service.Service):
|
||||
if stack_identity is not None:
|
||||
st = self._get_stack(cnxt, stack_identity, show_deleted=True)
|
||||
|
||||
events = db_api.event_get_all_by_stack(cnxt, st.id, limit=limit,
|
||||
events = event_object.Event.get_all_by_stack(
|
||||
cnxt,
|
||||
st.id,
|
||||
limit=limit,
|
||||
marker=marker,
|
||||
sort_keys=sort_keys,
|
||||
sort_dir=sort_dir,
|
||||
filters=filters)
|
||||
else:
|
||||
events = db_api.event_get_all_by_tenant(cnxt, limit=limit,
|
||||
events = event_object.Event.get_all_by_tenant(
|
||||
cnxt, limit=limit,
|
||||
marker=marker,
|
||||
sort_keys=sort_keys,
|
||||
sort_dir=sort_dir,
|
||||
|
80
heat/objects/event.py
Normal file
80
heat/objects/event.py
Normal file
@ -0,0 +1,80 @@
|
||||
# Copyright 2014 Intel Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Event object
|
||||
"""
|
||||
|
||||
from oslo_versionedobjects import base
|
||||
from oslo_versionedobjects import fields
|
||||
|
||||
from heat.db import api as db_api
|
||||
from heat.objects import fields as heat_fields
|
||||
|
||||
|
||||
class Event(base.VersionedObject, base.VersionedObjectDictCompat):
|
||||
fields = {
|
||||
'id': fields.IntegerField(nullable=False),
|
||||
'stack_id': fields.StringField(nullable=False),
|
||||
'uuid': fields.StringField(nullable=False),
|
||||
'resource_action': fields.StringField(nullable=True),
|
||||
'resource_status': fields.StringField(nullable=True),
|
||||
'resource_name': fields.StringField(nullable=True),
|
||||
'physical_resource_id': fields.StringField(nullable=True),
|
||||
'resource_status_reason': fields.StringField(nullable=True),
|
||||
'resource_type': fields.StringField(nullable=True),
|
||||
'resource_properties': heat_fields.JsonField(nullable=True),
|
||||
'created_at': fields.DateTimeField(read_only=True),
|
||||
'updated_at': fields.DateTimeField(nullable=True),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _from_db_object(context, event, db_event):
|
||||
for field in event.fields:
|
||||
event[field] = db_event[field]
|
||||
event._context = context
|
||||
event.obj_reset_changes()
|
||||
return event
|
||||
|
||||
@classmethod
|
||||
def get_by_id(cls, context, event_id):
|
||||
db_event = db_api.event_get(context, event_id)
|
||||
return cls._from_db_object(context, cls(context), db_event)
|
||||
|
||||
@classmethod
|
||||
def get_all(cls, context):
|
||||
return [cls._from_db_object(context, cls(), db_event)
|
||||
for db_event in db_api.event_get_all(context)]
|
||||
|
||||
@classmethod
|
||||
def get_all_by_tenant(cls, context, **kwargs):
|
||||
return [cls._from_db_object(context, cls(), db_event)
|
||||
for db_event in db_api.event_get_all_by_tenant(context,
|
||||
**kwargs)]
|
||||
|
||||
@classmethod
|
||||
def get_all_by_stack(cls, context, stack_id, **kwargs):
|
||||
return [cls._from_db_object(context, cls(), db_event)
|
||||
for db_event in db_api.event_get_all_by_stack(context,
|
||||
stack_id,
|
||||
**kwargs)]
|
||||
|
||||
@classmethod
|
||||
def count_all_by_stack(cls, context, stack_id):
|
||||
return db_api.event_count_all_by_stack(context, stack_id)
|
||||
|
||||
@classmethod
|
||||
def create(cls, context, values):
|
||||
return cls._from_db_object(context, cls(),
|
||||
db_api.event_create(context, values))
|
Loading…
Reference in New Issue
Block a user