Allow the key prefixes in etcd to be configurable.
This commit is contained in:
parent
35ba2a6c1f
commit
a4b0c8698d
1 changed files with 15 additions and 12 deletions
|
@ -21,10 +21,9 @@ from util.morecollections import AttrDict
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
ETCD_BUILDER_PREFIX = 'building/'
|
||||
ETCD_REALM_PREFIX = 'realm/'
|
||||
ETCD_DISABLE_TIMEOUT = 0
|
||||
|
||||
|
||||
class EtcdAction(object):
|
||||
GET = 'get'
|
||||
SET = 'set'
|
||||
|
@ -52,6 +51,9 @@ class EphemeralBuilderManager(BaseManager):
|
|||
self._async_thread_executor = None
|
||||
self._etcd_client = None
|
||||
|
||||
self._etcd_realm_prefix = None
|
||||
self._etcd_builder_prefix = None
|
||||
|
||||
self._component_to_job = {}
|
||||
self._job_uuid_to_component = {}
|
||||
self._component_to_builder = {}
|
||||
|
@ -131,7 +133,7 @@ class EphemeralBuilderManager(BaseManager):
|
|||
@coroutine
|
||||
def _register_existing_realms(self):
|
||||
try:
|
||||
all_realms = yield From(self._etcd_client.read(ETCD_REALM_PREFIX, recursive=True))
|
||||
all_realms = yield From(self._etcd_client.read(self._etcd_realm_prefix, recursive=True))
|
||||
for realm in all_realms.children:
|
||||
if not realm.dir:
|
||||
self._register_realm(json.loads(realm.value))
|
||||
|
@ -161,8 +163,11 @@ class EphemeralBuilderManager(BaseManager):
|
|||
protocol=etcd_protocol),
|
||||
executor=self._async_thread_executor)
|
||||
|
||||
self._watch_etcd(ETCD_BUILDER_PREFIX, self._handle_builder_expiration)
|
||||
self._watch_etcd(ETCD_REALM_PREFIX, self._handle_realm_change)
|
||||
self._etcd_builder_prefix = self._manager_config.get('ETCD_BUILDER_PREFIX', 'building/')
|
||||
self._watch_etcd(self._etcd_builder_prefix, self._handle_builder_expiration)
|
||||
|
||||
self._etcd_realm_prefix = self._manager_config.get('ETCD_REALM_PREFIX', 'realm/')
|
||||
self._watch_etcd(self._etcd_realm_prefix, self._handle_realm_change)
|
||||
|
||||
# Load components for all realms currently known to the cluster
|
||||
async(self._register_existing_realms())
|
||||
|
@ -192,7 +197,7 @@ class EphemeralBuilderManager(BaseManager):
|
|||
# Check if there are worker slots avialable by checking the number of jobs in etcd
|
||||
allowed_worker_count = self._manager_config.get('ALLOWED_WORKER_COUNT', 1)
|
||||
try:
|
||||
building = yield From(self._etcd_client.read(ETCD_BUILDER_PREFIX, recursive=True))
|
||||
building = yield From(self._etcd_client.read(self._etcd_builder_prefix, recursive=True))
|
||||
workers_alive = sum(1 for child in building.children if not child.dir)
|
||||
except KeyError:
|
||||
workers_alive = 0
|
||||
|
@ -307,17 +312,15 @@ class EphemeralBuilderManager(BaseManager):
|
|||
|
||||
self.job_heartbeat_callback(build_job)
|
||||
|
||||
@staticmethod
|
||||
def _etcd_job_key(build_job):
|
||||
def _etcd_job_key(self, build_job):
|
||||
""" Create a key which is used to track a job in etcd.
|
||||
"""
|
||||
return os.path.join(ETCD_BUILDER_PREFIX, build_job.job_details['build_uuid'])
|
||||
return os.path.join(self._etcd_builder_prefix, build_job.job_details['build_uuid'])
|
||||
|
||||
@staticmethod
|
||||
def _etcd_realm_key(realm):
|
||||
def _etcd_realm_key(self, realm):
|
||||
""" Create a key which is used to track an incoming connection on a realm.
|
||||
"""
|
||||
return os.path.join(ETCD_REALM_PREFIX, realm)
|
||||
return os.path.join(self._etcd_realm_prefix, realm)
|
||||
|
||||
def num_workers(self):
|
||||
""" Return the number of workers we're managing locally.
|
||||
|
|
Reference in a new issue