Merge decision engine services into a single one

The decision engine process was built based on 2
services: a service that handle rpc requests and a
scheduler to trigger watcher periodic tasks.
With the new version of oslo.service, a new threading
backend was added, based on cotyledon service manager,
which starts a new process for each service tha it
manages. These two services can't run in different
process since they need access to a shared in-memory
representation of the cluster (cluster data models)
This patch proposes creating a Decision Engine Service
which includes everything in a single main service.

Change-Id: I335a97ca14b6e023fef055978a56aefebf22d433
Signed-off-by: Douglas Viroel <viroel@gmail.com>
This commit is contained in:
Douglas Viroel
2025-06-12 15:50:30 -03:00
parent 1ab5babbb6
commit 081cd5fae9
3 changed files with 130 additions and 7 deletions

View File

@@ -0,0 +1,59 @@
# Copyright 2025 Red Hat, Inc.
#
# 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 watcher.common import service as watcher_service
from watcher.decision_engine import manager
from watcher.decision_engine import scheduling
class DecisionEngineService(watcher_service.Service):
"""Decision Engine Service that runs on a host.
The decision engine service holds a RPC server, a notification
listener server, a heartbeat service and starts a background scheduling
service to run watcher periodic jobs.
"""
def __init__(self):
super().__init__(manager.DecisionEngineManager)
# Background scheduler starts the cluster model collector periodic
# task, an one shot task to cancel ongoing audits and a periodic
# check for expired action plans
self._bg_scheduler = None
@property
def bg_scheduler(self):
if self._bg_scheduler is None:
self._bg_scheduler = scheduling.DecisionEngineSchedulingService()
return self._bg_scheduler
def start(self):
"""Start service."""
super().start()
self.bg_scheduler.start()
def stop(self):
"""Stop service."""
super().stop()
self.bg_scheduler.stop()
def wait(self):
"""Wait for service to complete."""
super().wait()
self.bg_scheduler.wait()
def reset(self):
"""Reset service."""
super().reset()
self.bg_scheduler.reset()