Skip to content

Commit

Permalink
Transform compute_task notifications
Browse files Browse the repository at this point in the history
The following notifications have been transformed to
the versioned notification framework.

* compute_task.build_instances
* compute_task.migrate_server
* compute_task.rebuild_server

Co-Authored-By: Takashi Natsume <natsume.takashi@lab.ntt.co.jp>
Change-Id: Ibfb0a6db5920d921c4fc7cabf3f4d2838ea7f421
Implements: bp versioned-notification-transformation-stein
  • Loading branch information
Alex Szarka and natsumetakashi committed Nov 21, 2018
1 parent 7217e38 commit fe4e47d
Show file tree
Hide file tree
Showing 28 changed files with 1,031 additions and 24 deletions.
1 change: 1 addition & 0 deletions doc/api_samples/images/images-details-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
}
],
"metadata": {
"architecture": "x86_64",
"kernel_id": "nokernel",
"ramdisk_id": "nokernel"
},
Expand Down
11 changes: 11 additions & 0 deletions doc/notification_samples/common_payloads/ComputeTaskPayload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"nova_object.version": "1.0",
"nova_object.namespace": "nova",
"nova_object.name": "ComputeTaskPayload",
"nova_object.data": {
"instance_uuid": "d5e6a7b7-80e5-4166-85a3-cd6115201082",
"reason": {"$ref": "ExceptionPayload.json#"},
"request_spec": {"$ref": "RequestSpecPayload.json#"},
"state": "error"
}
}
12 changes: 12 additions & 0 deletions doc/notification_samples/common_payloads/ExceptionPayload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"nova_object.version": "1.1",
"nova_object.namespace": "nova",
"nova_object.name": "ExceptionPayload",
"nova_object.data": {
"function_name": "_schedule_instances",
"module_name": "nova.conductor.manager",
"exception": "NoValidHost",
"exception_message": "No valid host was found. There are not enough hosts available.",
"traceback": "Traceback (most recent call last):\n File \"nova/conductor/manager.py\", line ..."
}
}
28 changes: 28 additions & 0 deletions doc/notification_samples/common_payloads/ImageMetaPayload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"nova_object.namespace": "nova",
"nova_object.data": {
"checksum": null,
"container_format": "raw",
"created_at": "2011-01-01T01:02:03Z",
"direct_url": null,
"disk_format": "raw",
"id": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
"min_disk": 0,
"min_ram": 0,
"name": "fakeimage123456",
"owner": null,
"properties": {"$ref":"ImageMetaPropsPayload.json#"},
"protected": false,
"size": 25165824,
"status": "active",
"tags": [
"tag1",
"tag2"
],
"updated_at": "2011-01-01T01:02:03Z",
"virtual_size": null,
"visibility": "public"
},
"nova_object.name": "ImageMetaPayload",
"nova_object.version": "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"nova_object.namespace": "nova",
"nova_object.data": {
"hw_architecture": "x86_64"
},
"nova_object.name": "ImageMetaPropsPayload",
"nova_object.version": "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"nova_object.version": "1.0",
"nova_object.namespace": "nova",
"nova_object.name": "InstanceNUMACellPayload",
"nova_object.data": {
"cpu_pinning_raw": null,
"cpu_policy": null,
"cpu_thread_policy": null,
"cpu_topology": null,
"cpuset": [0],
"cpuset_reserved": null,
"id": 0,
"memory": 512,
"pagesize": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"nova_object.version": "1.0",
"nova_object.namespace": "nova",
"nova_object.name": "InstanceNUMATopologyPayload",
"nova_object.data": {
"cells": [
{"$ref": "InstanceNUMACellPayload.json#"}
],
"emulator_threads_policy": null,
"instance_uuid": "75cab9f7-57e2-4bd1-984f-a0383d9ee60e"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"nova_object.version": "1.0",
"nova_object.namespace": "nova",
"nova_object.name": "InstancePCIRequestsPayload",
"nova_object.data":{
"instance_uuid": "d5e6a7b7-80e5-4166-85a3-cd6115201082",
"requests": []
}
}
25 changes: 25 additions & 0 deletions doc/notification_samples/common_payloads/RequestSpecPayload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"nova_object.namespace": "nova",
"nova_object.data": {
"availability_zone": null,
"flavor": {
"$ref": "FlavorPayload.json#",
"nova_object.data": {
"extra_specs": {
"hw:numa_cpus.0": "0",
"hw:numa_mem.0": "512",
"hw:numa_nodes": "1"
}
}
},
"image": {"$ref": "ImageMetaPayload.json#"},
"instance_uuid": "d5e6a7b7-80e5-4166-85a3-cd6115201082",
"num_instances": 1,
"numa_topology": {"$ref": "InstanceNUMATopologyPayload.json#"},
"pci_requests": {"$ref": "InstancePCIRequestsPayload.json#"},
"project_id": "6f70656e737461636b20342065766572",
"user_id": "fake"
},
"nova_object.name": "RequestSpecPayload",
"nova_object.version": "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"event_type": "compute_task.build_instances.error",
"payload": {"$ref":"common_payloads/ComputeTaskPayload.json#"},
"priority": "ERROR",
"publisher_id": "nova-conductor:fake-mini"
}
11 changes: 11 additions & 0 deletions doc/notification_samples/compute_task-migrate_server-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"event_type": "compute_task.migrate_server.error",
"payload": {
"$ref":"common_payloads/ComputeTaskPayload.json#",
"nova_object.data":{
"state": "active"
}
},
"priority": "ERROR",
"publisher_id": "nova-conductor:fake-mini"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"event_type": "compute_task.rebuild_server.error",
"payload": {
"$ref": "common_payloads/ComputeTaskPayload.json#"
},
"priority": "ERROR",
"publisher_id": "nova-conductor:fake-mini"
}
36 changes: 36 additions & 0 deletions nova/compute/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from nova import notifications
from nova.notifications.objects import aggregate as aggregate_notification
from nova.notifications.objects import base as notification_base
from nova.notifications.objects import compute_task as task_notification
from nova.notifications.objects import exception as notification_exception
from nova.notifications.objects import flavor as flavor_notification
from nova.notifications.objects import instance as instance_notification
Expand Down Expand Up @@ -857,6 +858,41 @@ def notify_about_volume_usage(context, vol_usage, host):
notification.emit(context)


@rpc.if_notifications_enabled
def notify_about_compute_task_error(context, action, instance_uuid,
request_spec, state, exception, tb):
"""Send a versioned notification about compute task error.
:param context: the request context
:param action: the name of the action
:param instance_uuid: the UUID of the instance
:param request_spec: the request spec object or
the dict includes request spec information
:param state: the vm state of the instance
:param exception: the thrown exception
:param tb: the traceback
"""
if (request_spec is not None and
not isinstance(request_spec, objects.RequestSpec)):
request_spec = objects.RequestSpec.from_primitives(
context, request_spec, {})

fault, _ = _get_fault_and_priority_from_exc_and_tb(exception, tb)
payload = task_notification.ComputeTaskPayload(
instance_uuid=instance_uuid, request_spec=request_spec, state=state,
reason=fault)
notification = task_notification.ComputeTaskNotification(
priority=fields.NotificationPriority.ERROR,
publisher=notification_base.NotificationPublisher(
host=CONF.host, source=fields.NotificationSource.CONDUCTOR),
event_type=notification_base.EventType(
object='compute_task',
action=action,
phase=fields.NotificationPhase.ERROR),
payload=payload)
notification.emit(context)


def refresh_info_cache_for_instance(context, instance):
"""Refresh the info cache for an instance.
Expand Down
23 changes: 13 additions & 10 deletions nova/notifications/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class EventType(NotificationObject):
# NotificationActionField enum
# Version 1.16: CONNECT is added to NotificationActionField enum
# Version 1.17: USAGE is added to NotificationActionField enum
VERSION = '1.17'
# Version 1.18: ComputeTask related values have been added to
# NotificationActionField enum
VERSION = '1.18'

fields = {
'object': fields.StringField(nullable=False),
Expand Down Expand Up @@ -119,7 +121,7 @@ def __init__(self):
self.populated = not self.SCHEMA

@rpc.if_notifications_enabled
def populate_schema(self, **kwargs):
def populate_schema(self, set_none=True, **kwargs):
"""Populate the object based on the SCHEMA and the source objects
:param kwargs: A dict contains the source object at the key defined in
Expand All @@ -137,14 +139,15 @@ def populate_schema(self, **kwargs):
NotImplementedError,
exception.OrphanedObjectError,
ovo_exception.OrphanedObjectError):
# If it is unset or non lazy loadable in the source object
# then we cannot do anything else but try to default it in the
# payload object we are generating here.
# NOTE(gibi): This will fail if the payload field is not
# nullable, but that means that either the source object is not
# properly initialized or the payload field needs to be defined
# as nullable
setattr(self, key, None)
if set_none:
# If it is unset or non lazy loadable in the source object
# then we cannot do anything else but try to default it
# in the payload object we are generating here.
# NOTE(gibi): This will fail if the payload field is not
# nullable, but that means that either the source object
# is not properly initialized or the payload field needs
# to be defined as nullable
setattr(self, key, None)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error('Failed trying to populate attribute "%s" '
Expand Down
54 changes: 54 additions & 0 deletions nova/notifications/objects/compute_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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 nova.notifications.objects import base
from nova.notifications.objects import request_spec as reqspec_payload
from nova.objects import base as nova_base
from nova.objects import fields


@nova_base.NovaObjectRegistry.register_notification
class ComputeTaskPayload(base.NotificationPayloadBase):
# Version 1.0: Initial version
VERSION = '1.0'

fields = {
'instance_uuid': fields.UUIDField(),
# There are some cases that request_spec is None.
# e.g. Old instances can still have no RequestSpec object
# attached to them.
'request_spec': fields.ObjectField('RequestSpecPayload',
nullable=True),
'state': fields.InstanceStateField(nullable=True),
'reason': fields.ObjectField('ExceptionPayload')
}

def __init__(self, instance_uuid, request_spec, state, reason):
super(ComputeTaskPayload, self).__init__()
self.instance_uuid = instance_uuid
self.request_spec = reqspec_payload.RequestSpecPayload(
request_spec) if request_spec is not None else None
self.state = state
self.reason = reason


@base.notification_sample('compute_task-build_instances-error.json')
@base.notification_sample('compute_task-migrate_server-error.json')
@base.notification_sample('compute_task-rebuild_server-error.json')
@nova_base.NovaObjectRegistry.register_notification
class ComputeTaskNotification(base.NotificationBase):
# Version 1.0: Initial version
VERSION = '1.0'

fields = {
'payload': fields.ObjectField('ComputeTaskPayload')
}

0 comments on commit fe4e47d

Please sign in to comment.