Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
service: Added bus-uri and exchange-name to config files
Browse files Browse the repository at this point in the history
Service configuration files can now include the bus-uri, bus_exchange,
and any other set of information needed to run the service.
  • Loading branch information
ashcrow authored and mbarnes committed Apr 5, 2017
1 parent 45845ce commit 3c78f25
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 28 deletions.
1 change: 1 addition & 0 deletions conf/clusterexec.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"bus_uri": "redis://127.0.0.1:6379",
"debug": false
}
1 change: 1 addition & 0 deletions conf/containermgr.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"bus_uri": "redis://127.0.0.1:6379",
"container_handlers": [
{
"name": "OpenshiftA1",
Expand Down
3 changes: 2 additions & 1 deletion conf/investigator.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"debug": false
"debug": false,
"bus_uri": "redis://127.0.0.1:6379"
}
1 change: 1 addition & 0 deletions conf/storage.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"bus_uri": "redis://127.0.0.1:6379",
"storage_handlers": [
{
"type": "etcd",
Expand Down
1 change: 1 addition & 0 deletions conf/watcher.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"bus_uri": "redis://127.0.0.1:6379",
"debug": false
}
15 changes: 10 additions & 5 deletions src/commissaire_service/clusterexec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from commissaire.models import (
ClusterDeploy, ClusterUpgrade, ClusterRestart)
from commissaire.storage.client import StorageClient
from commissaire.util.config import read_config_file
from commissaire.util.date import formatted_dt
from commissaire.util.ssh import TemporarySSHKey

Expand All @@ -34,6 +33,9 @@ class ClusterExecService(CommissaireService):
Executes operations over a cluster by way of remote shell commands.
"""

#: Default configuration file
_default_config_file = '/etc/commissaire/clusterexec.conf'

def __init__(self, exchange_name, connection_url, config_file=None):
"""
Creates a new ClusterExecService. If config_file is omitted,
Expand All @@ -49,11 +51,14 @@ def __init__(self, exchange_name, connection_url, config_file=None):
queue_kwargs = [
{'routing_key': 'jobs.clusterexec.*'}
]
super().__init__(exchange_name, connection_url, queue_kwargs)
self.storage = StorageClient(self)

# Apply any logging configuration for this service.
read_config_file(config_file, '/etc/commissaire/clusterexec.conf')
super().__init__(
exchange_name,
connection_url,
queue_kwargs,
config_file=config_file)

self.storage = StorageClient(self)

def _execute(self, message, model_instance, command_args,
finished_hosts_key):
Expand Down
15 changes: 10 additions & 5 deletions src/commissaire_service/containermgr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from commissaire.bus import ContainerManagerError
from commissaire.containermgr import ContainerManagerBase
from commissaire.storage.client import StorageClient
from commissaire.util.config import read_config_file, import_plugin
from commissaire.util.config import import_plugin

from commissaire_service.service import (
CommissaireService, add_service_arguments)
Expand All @@ -29,6 +29,9 @@ class ContainerManagerService(CommissaireService):
Provides access to Container Managers.
"""

#: Default configuration file
_default_config_file = '/etc/commissaire/containermgr.conf'

def __init__(self, exchange_name, connection_url, config_file=None):
"""
Creates a new ContainerManagerService. If config_file is omitted,
Expand All @@ -46,13 +49,15 @@ def __init__(self, exchange_name, connection_url, config_file=None):
'routing_key': 'container.*',
'exclusive': False,
}]
super().__init__(exchange_name, connection_url, queue_kwargs)
super().__init__(
exchange_name,
connection_url,
queue_kwargs,
config_file=config_file)

self.storage = StorageClient(self)
self.managers = {}

# Apply any logging configuration for this service.
read_config_file(config_file, '/etc/commissaire/containermgr.conf')

def refresh_managers(self):
"""
Fetches all ContainerManagerConfig records from the storage service,
Expand Down
16 changes: 11 additions & 5 deletions src/commissaire_service/investigator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from commissaire.models import Cluster, Host, Network
from commissaire.storage.client import StorageClient
from commissaire.util.config import ConfigurationError, read_config_file
from commissaire.util.config import ConfigurationError
from commissaire.util.date import formatted_dt
from commissaire.util.ssh import TemporarySSHKey

Expand All @@ -34,6 +34,9 @@ class InvestigatorService(CommissaireService):
Investigates new hosts to retrieve and store facts.
"""

#: Default configuration file
_default_config_file = '/etc/commissaire/investigator.conf'

def __init__(self, exchange_name, connection_url, config_file=None):
"""
Creates a new InvestigatorService. If config_file is omitted,
Expand All @@ -49,11 +52,14 @@ def __init__(self, exchange_name, connection_url, config_file=None):
queue_kwargs = [
{'routing_key': 'jobs.investigate'}
]
super().__init__(exchange_name, connection_url, queue_kwargs)
self.storage = StorageClient(self)

# Apply any logging configuration for this service.
read_config_file(config_file, '/etc/commissaire/investigator.conf')
super().__init__(
exchange_name,
connection_url,
queue_kwargs,
config_files=config_file)

self.storage = StorageClient(self)

def _get_etcd_config(self):
"""
Expand Down
26 changes: 25 additions & 1 deletion src/commissaire_service/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from commissaire import constants as C
from commissaire.bus import BusMixin, RemoteProcedureCallError
from commissaire.util.config import read_config_file

from kombu import Connection, Exchange, Producer, Queue
from kombu.mixins import ConsumerMixin
Expand Down Expand Up @@ -73,6 +74,7 @@ class ServiceManager:
"""
Multiprocessed Service Manager.
"""

def __init__(self, service_class, process_count, exchange_name,
connection_url, qkwargs, **kwargs):
"""
Expand Down Expand Up @@ -143,7 +145,12 @@ class CommissaireService(ConsumerMixin, BusMixin):
Commissaire service class.
"""

def __init__(self, exchange_name, connection_url, qkwargs):
#: Default configuration file if none is specified. Subclasses
#: should override this.
_default_config_file = C.DEFAULT_CONFIGURATION_FILE

def __init__(
self, exchange_name, connection_url, qkwargs, config_file=None):
"""
Initializes a new Service instance.
Expand All @@ -153,10 +160,27 @@ def __init__(self, exchange_name, connection_url, qkwargs):
:type connection_url: str
:param qkwargs: One or more dicts keyword arguments for queue creation
:type qkwargs: list
:param config_file: Path to the configuration file location.
:type config_file: str or None
"""
name = self.__class__.__name__
self.logger = logging.getLogger(name)
self.logger.debug('Initializing {}'.format(name))

# If we are given no default, use the global one
# Read the configuration file
self._config_data = read_config_file(
config_file, self._default_config_file)

if connection_url is None and 'bus_uri' in self._config_data:
connection_url = self._config_data.get('bus_uri')
self.logger.debug(
'Using connection_url=%s from config file', connection_url)
if exchange_name is None and 'exchange_name' in self._config_data:
self.logger.debug(
'Using exchange_name=%s from config file', exchange_name)
exchange_name = self._config_data.get('bus_exchange')

self.connection = Connection(connection_url)
self._channel = self.connection.channel()
self._exchange = Exchange(
Expand Down
17 changes: 11 additions & 6 deletions src/commissaire_service/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

from commissaire import constants as C
from commissaire.storage import StoreHandlerBase
from commissaire.util.config import (
ConfigurationError, read_config_file, import_plugin)
from commissaire.util.config import (ConfigurationError, import_plugin)

from commissaire_service.service import (
CommissaireService, add_service_arguments)
Expand All @@ -34,6 +33,9 @@ class StorageService(CommissaireService):
Provides access to data stores to other services.
"""

#: Default configuration file
_default_config_file = '/etc/commissaire/storage.conf'

def __init__(self, exchange_name, connection_url, config_file=None):
"""
Creates a new StorageService and sets up StoreHandler instances
Expand All @@ -50,7 +52,12 @@ def __init__(self, exchange_name, connection_url, config_file=None):
queue_kwargs = [
{'routing_key': 'storage.*'},
]
super().__init__(exchange_name, connection_url, queue_kwargs)

super().__init__(
exchange_name,
connection_url,
queue_kwargs,
config_file=config_file)

self._manager = StoreHandlerManager()

Expand All @@ -59,9 +66,7 @@ def __init__(self, exchange_name, connection_url, config_file=None):
if isinstance(v, type) and
issubclass(v, models.Model)}

config_data = read_config_file(
config_file, '/etc/commissaire/storage.conf')
store_handlers = config_data.get('storage_handlers', [])
store_handlers = self._config_data.get('storage_handlers', [])

# Configure store handlers from user data.
if len(store_handlers) == 0:
Expand Down
15 changes: 10 additions & 5 deletions src/commissaire_service/watcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from commissaire import constants as C
from commissaire.models import WatcherRecord
from commissaire.storage.client import StorageClient
from commissaire.util.config import read_config_file
from commissaire.util.date import formatted_dt
from commissaire.util.ssh import TemporarySSHKey

Expand All @@ -38,6 +37,9 @@ class WatcherService(CommissaireService):
Periodically connects to hosts to check their status.
"""

#: Default configuration file
_default_config_file = '/etc/commissaire/watcher.conf'

def __init__(self, exchange_name, connection_url, config_file=None):
"""
Creates a new WatcherService. If config_file is omitted,
Expand All @@ -57,11 +59,14 @@ def __init__(self, exchange_name, connection_url, config_file=None):
}]
# Store the last address seen for backoff
self.last_address = None
super().__init__(exchange_name, connection_url, queue_kwargs)
self.storage = StorageClient(self)

# Apply any logging configuration for this service.
read_config_file(config_file, '/etc/commissaire/watcher.conf')
super().__init__(
exchange_name,
connection_url,
queue_kwargs,
config_file=config_file)

self.storage = StorageClient(self)

def on_message(self, body, message):
"""
Expand Down

0 comments on commit 3c78f25

Please sign in to comment.