Add HA support

This patch set adds hostname field to Audit and Action Plan
objects to track services which execute these objects.

Change-Id: I786e419952925c380c969b12cc60f9a1004af96b
Partially-Implements: blueprint support-watcher-ha-active-active-mode
This commit is contained in:
Alexander Chadin
2018-06-26 16:21:48 +03:00
parent c9e8886631
commit e426a015ee
19 changed files with 298 additions and 17 deletions

View File

@@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from oslo_config import cfg
from oslo_log import log
from watcher.applier.action_plan import base
@@ -25,6 +26,7 @@ from watcher import notifications
from watcher import objects
from watcher.objects import fields
CONF = cfg.CONF
LOG = log.getLogger(__name__)
@@ -43,6 +45,7 @@ class DefaultActionPlanHandler(base.BaseActionPlanHandler):
if action_plan.state == objects.action_plan.State.CANCELLED:
self._update_action_from_pending_to_cancelled()
return
action_plan.hostname = CONF.host
action_plan.state = objects.action_plan.State.ONGOING
action_plan.save()
notifications.action_plan.send_action_notification(

View File

@@ -15,12 +15,19 @@
# limitations under the License.
#
from oslo_config import cfg
from oslo_log import log
from watcher.applier.loading import default
from watcher.common import context
from watcher.common import exception
from watcher import objects
CONF = cfg.CONF
LOG = log.getLogger(__name__)
class Syncer(object):
"""Syncs all available actions with the Watcher DB"""
@@ -42,3 +49,27 @@ class Syncer(object):
obj_action_desc.action_type = action_type
obj_action_desc.description = load_description
obj_action_desc.create()
self._cancel_ongoing_actionplans(ctx)
def _cancel_ongoing_actionplans(self, context):
actions_plans = objects.ActionPlan.list(
context,
filters={'state': objects.action_plan.State.ONGOING,
'hostname': CONF.host},
eager=True)
for ap in actions_plans:
ap.state = objects.action_plan.State.CANCELLED
ap.save()
filters = {'action_plan_uuid': ap.uuid,
'state__in': (objects.action.State.PENDING,
objects.action.State.ONGOING)}
actions = objects.Action.list(context, filters=filters, eager=True)
for a in actions:
a.state = objects.action.State.CANCELLED
a.save()
LOG.info("Action Plan %(uuid)s along with appropriate Actions "
"has been cancelled because it was in %(state)s state "
"when Applier had been stopped on %(hostname)s host.",
{'uuid': ap.uuid,
'state': objects.action_plan.State.ONGOING,
'hostname': ap.hostname})