diff options
author | Ed Cranford <ed.cranford@rackspace.com> | 2013-08-22 10:01:42 -0500 |
---|---|---|
committer | Ed Cranford <ed.cranford@rackspace.com> | 2013-11-26 11:52:00 -0600 |
commit | 384576675f8205aa3985c1f576ce767e43b9944d (patch) | |
tree | cb40e84d1130fd3f35e7649e4977447c501b720a /trove/conductor | |
parent | 5755ede7a23096700fb7c17e69348106e8dd77a6 (diff) | |
download | trove-384576675f8205aa3985c1f576ce767e43b9944d.tar.gz |
Conductor proxies host db access for guests
Previously, instances updated their status by
updating the database on the host directly.
Necessarily, each instance would need access to the
database to stay updated.
Trove's new conductor service eliminates that need by
working as a proxy for those instances. By sending a heartbeat
to conductor via RPC, conductor updates the database
on the host on behalf of the instance.
As backups also made use of the host database, the backup
code has been refactored to take richer inputs to remove
the need to query the host database, and now conductor is
also used to submit updates to backup states.
Implements: blueprint trove-conductor
Change-Id: I4cb34baedd0e3a50051f9e66de95c9028c66e4b5
Diffstat (limited to 'trove/conductor')
-rw-r--r-- | trove/conductor/__init__.py | 16 | ||||
-rw-r--r-- | trove/conductor/api.py | 52 | ||||
-rw-r--r-- | trove/conductor/manager.py | 68 |
3 files changed, 136 insertions, 0 deletions
diff --git a/trove/conductor/__init__.py b/trove/conductor/__init__.py new file mode 100644 index 00000000..9c2513da --- /dev/null +++ b/trove/conductor/__init__.py @@ -0,0 +1,16 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 Rackspace Hosting +# All Rights Reserved. +# +# 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. diff --git a/trove/conductor/api.py b/trove/conductor/api.py new file mode 100644 index 00000000..d0a93abc --- /dev/null +++ b/trove/conductor/api.py @@ -0,0 +1,52 @@ +# Copyright 2013 OpenStack Foundation +# +# 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 traceback +import sys + +from trove.common import cfg +from trove.openstack.common.rpc import proxy +from trove.openstack.common import log as logging + + +CONF = cfg.CONF +LOG = logging.getLogger(__name__) +RPC_API_VERSION = "1.0" + + +class API(proxy.RpcProxy): + """API for interacting with trove conductor.""" + + def __init__(self, context): + self.context = context + super(API, self).__init__(self._get_routing_key(), RPC_API_VERSION) + + def _get_routing_key(self): + """Create the routing key for conductor.""" + return CONF.conductor_queue + + def heartbeat(self, instance_id, payload): + LOG.debug("Making async call to cast heartbeat for instance: %s" + % instance_id) + self.cast(self.context, self.make_msg("heartbeat", + instance_id=instance_id, + payload=payload)) + + def update_backup(self, instance_id, backup_id, **backup_fields): + LOG.debug("Making async call to cast update_backup for instance: %s" + % instance_id) + self.cast(self.context, self.make_msg("update_backup", + instance_id=instance_id, + backup_id=backup_id, + **backup_fields)) diff --git a/trove/conductor/manager.py b/trove/conductor/manager.py new file mode 100644 index 00000000..1d4b2271 --- /dev/null +++ b/trove/conductor/manager.py @@ -0,0 +1,68 @@ +# Copyright 2013 OpenStack Foundation +# +# 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 trove.backup import models as bkup_models +from trove.common.context import TroveContext +from trove.common.instance import ServiceStatus +from trove.instance import models as t_models +from trove.openstack.common import periodic_task +from trove.openstack.common import log as logging +from trove.common import cfg + +LOG = logging.getLogger(__name__) +RPC_API_VERSION = "1.0" +CONF = cfg.CONF + + +class Manager(periodic_task.PeriodicTasks): + + def __init__(self): + super(Manager, self).__init__() + self.admin_context = TroveContext( + user=CONF.nova_proxy_admin_user, + auth_token=CONF.nova_proxy_admin_pass, + tenant=CONF.nova_proxy_admin_tenant_name) + + def heartbeat(self, context, instance_id, payload): + LOG.debug("Instance ID: %s" % str(instance_id)) + LOG.debug("Payload: %s" % str(payload)) + status = t_models.InstanceServiceStatus.find_by( + instance_id=instance_id) + if payload.get('service_status') is not None: + status.set_status(ServiceStatus.from_description( + payload['service_status'])) + status.save() + + def update_backup(self, context, instance_id, backup_id, + **backup_fields): + LOG.debug("Instance ID: %s" % str(instance_id)) + LOG.debug("Backup ID: %s" % str(backup_id)) + backup = bkup_models.DBBackup.find_by(id=backup_id) + # TODO(datsun180b): use context to verify tenant matches + + # Some verification based on IDs + if backup_id != backup.id: + LOG.error("Backup IDs mismatch! Expected %s, found %s" % + (backup_id, backup.id)) + return + if instance_id != backup.instance_id: + LOG.error("Backup instance IDs mismatch! Expected %s, found %s" % + (instance_id, backup.instance_id)) + return + + for k, v in backup_fields.items(): + if hasattr(backup, k): + LOG.debug("Backup %s: %s" % (k, v)) + setattr(backup, k, v) + backup.save() |