Repository: aurora Updated Branches: refs/heads/master 395bd7dd9 -> 96d97bac4
Allow custom announce path. Bugs closed: AURORA-1569 Reviewed at https://reviews.apache.org/r/41809/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/96d97bac Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/96d97bac Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/96d97bac Branch: refs/heads/master Commit: 96d97bac41306d4c7326b672b2d1f94382034757 Parents: 395bd7d Author: Kunal Thakar <[email protected]> Authored: Wed Jan 6 21:07:42 2016 -0800 Committer: Bill Farner <[email protected]> Committed: Wed Jan 6 21:07:42 2016 -0800 ---------------------------------------------------------------------- docs/configuration-reference.md | 4 ++- .../python/apache/aurora/config/schema/base.py | 5 ++++ .../executor/bin/thermos_executor_main.py | 12 ++++++++- .../apache/aurora/executor/common/announcer.py | 18 +++++++++---- .../aurora/executor/common/test_announcer.py | 28 ++++++++++++++++++-- 5 files changed, 58 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/96d97bac/docs/configuration-reference.md ---------------------------------------------------------------------- diff --git a/docs/configuration-reference.md b/docs/configuration-reference.md index cf63cfa..bea99a7 100644 --- a/docs/configuration-reference.md +++ b/docs/configuration-reference.md @@ -457,13 +457,15 @@ Parameters for controlling a task's health checks via HTTP or a shell command. If the `announce` field in the Job configuration is set, each task will be registered in the ServerSet `/aurora/role/environment/jobname` in the -zookeeper ensemble configured by the executor. If no Announcer object is specified, +zookeeper ensemble configured by the executor (which can be optionally overriden by specifying +zk_path parameter). If no Announcer object is specified, no announcement will take place. For more information about ServerSets, see the [User Guide](user-guide.md). | object | type | description | ------- | :-------: | -------- | ```primary_port``` | String | Which named port to register as the primary endpoint in the ServerSet (Default: `http`) | ```portmap``` | dict | A mapping of additional endpoints to announced in the ServerSet (Default: `{ 'aurora': '{{primary_port}}' }`) +| ```zk_path``` | String | Zookeeper serverset path override (executor must be started with the --announcer-allow-custom-serverset-path parameter) ### Port aliasing with the Announcer `portmap` http://git-wip-us.apache.org/repos/asf/aurora/blob/96d97bac/src/main/python/apache/aurora/config/schema/base.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/config/schema/base.py b/src/main/python/apache/aurora/config/schema/base.py index 69182c3..7bc903c 100644 --- a/src/main/python/apache/aurora/config/schema/base.py +++ b/src/main/python/apache/aurora/config/schema/base.py @@ -97,6 +97,11 @@ class Announcer(Struct): 'aurora': '{{primary_port}}' }) + # Root of tree where annoucements are stored. If specified, this overrides the + # default path (executor must be started with --announcer-allow-custom-serverset-path for + # this setting to take effect) + zk_path = String + # The executorConfig populated inside of TaskConfig. class MesosTaskInstance(Struct): http://git-wip-us.apache.org/repos/asf/aurora/blob/96d97bac/src/main/python/apache/aurora/executor/bin/thermos_executor_main.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/executor/bin/thermos_executor_main.py b/src/main/python/apache/aurora/executor/bin/thermos_executor_main.py index 4e9b027..cfade22 100644 --- a/src/main/python/apache/aurora/executor/bin/thermos_executor_main.py +++ b/src/main/python/apache/aurora/executor/bin/thermos_executor_main.py @@ -83,6 +83,13 @@ app.add_option( help='The root of the tree into which ServerSets should be announced. The paths will ' 'be of the form $ROOT/$ROLE/$ENVIRONMENT/$JOBNAME.') +app.add_option( + '--announcer-allow-custom-serverset-path', + dest='announcer_allow_custom_serverset_path', + action='store_true', + default=False, + help='Allows setting arbitrary serverset path through the Announcer configuration.') + app.add_option( '--execute-as-user', @@ -165,7 +172,10 @@ def initialize(options): if options.announcer_ensemble is None: app.error('Must specify --announcer-ensemble if the announcer is enabled.') status_providers.append(DefaultAnnouncerCheckerProvider( - options.announcer_ensemble, options.announcer_serverset_path)) + options.announcer_ensemble, + options.announcer_serverset_path, + options.announcer_allow_custom_serverset_path + )) # Create executor stub if options.execute_as_user or options.nosetuid: http://git-wip-us.apache.org/repos/asf/aurora/blob/96d97bac/src/main/python/apache/aurora/executor/common/announcer.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/executor/common/announcer.py b/src/main/python/apache/aurora/executor/common/announcer.py index dda76f0..c89cf4c 100644 --- a/src/main/python/apache/aurora/executor/common/announcer.py +++ b/src/main/python/apache/aurora/executor/common/announcer.py @@ -20,7 +20,7 @@ from abc import abstractmethod from kazoo.client import KazooClient from kazoo.retry import KazooRetry from mesos.interface import mesos_pb2 -from twitter.common import log +from twitter.common import app, log from twitter.common.concurrent.deferred import defer from twitter.common.exceptions import ExceptionalThread from twitter.common.metrics import LambdaGauge, Observable @@ -54,8 +54,9 @@ def make_endpoints(hostname, portmap, primary_port): class AnnouncerCheckerProvider(StatusCheckerProvider): - def __init__(self, name=None): + def __init__(self, allow_custom_serverset_path=False, name=None): self.name = name + self.__allow_custom_serverset_path = allow_custom_serverset_path super(AnnouncerCheckerProvider, self).__init__() @abstractmethod @@ -83,7 +84,14 @@ class AnnouncerCheckerProvider(StatusCheckerProvider): mesos_task.announce().primary_port().get()) client = self.make_zk_client() - path = self.make_zk_path(assigned_task) + if mesos_task.announce().has_zk_path(): + if self.__allow_custom_serverset_path: + path = mesos_task.announce().zk_path().get() + else: + app.error('Executor must be started with --announcer-allow-custom-serverset-path in order ' + 'to use zk_path in the Announcer config') + else: + path = self.make_zk_path(assigned_task) initial_interval = mesos_task.health_check_config().initial_interval_secs().get() interval = mesos_task.health_check_config().interval_secs().get() @@ -103,10 +111,10 @@ class DefaultAnnouncerCheckerProvider(AnnouncerCheckerProvider): max_delay=DEFAULT_RETRY_MAX_DELAY.as_(Time.SECONDS), ) - def __init__(self, ensemble, root='/aurora'): + def __init__(self, ensemble, root='/aurora', allow_custom_serverset_path=False): self.__ensemble = ensemble self.__root = root - super(DefaultAnnouncerCheckerProvider, self).__init__() + super(DefaultAnnouncerCheckerProvider, self).__init__(allow_custom_serverset_path) def make_zk_client(self): return KazooClient(self.__ensemble, connection_retry=self.DEFAULT_RETRY_POLICY) http://git-wip-us.apache.org/repos/asf/aurora/blob/96d97bac/src/test/python/apache/aurora/executor/common/test_announcer.py ---------------------------------------------------------------------- diff --git a/src/test/python/apache/aurora/executor/common/test_announcer.py b/src/test/python/apache/aurora/executor/common/test_announcer.py index 46ad784..bb9e4b0 100644 --- a/src/test/python/apache/aurora/executor/common/test_announcer.py +++ b/src/test/python/apache/aurora/executor/common/test_announcer.py @@ -213,7 +213,7 @@ def make_assigned_task(thermos_config, assigned_ports=None): slaveHost='test-host') -def make_job(role, environment, name, primary_port, portmap): +def make_job(role, environment, name, primary_port, portmap, zk_path=None): from apache.aurora.config.schema.base import ( Announcer, Job, @@ -225,13 +225,17 @@ def make_job(role, environment, name, primary_port, portmap): name='ignore2', processes=[Process(name='ignore3', cmdline='ignore4')], resources=Resources(cpu=1, ram=1, disk=1)) + if zk_path: + announce = Announcer(primary_port=primary_port, portmap=portmap, zk_path=zk_path) + else: + announce = Announcer(primary_port=primary_port, portmap=portmap) job = Job( role=role, environment=environment, name=name, cluster='ignore1', task=task, - announce=Announcer(primary_port=primary_port, portmap=portmap)) + announce=announce) return job @@ -301,3 +305,23 @@ def test_default_announcer_provider_without_announce(): assigned_task = make_assigned_task(job) assert DefaultAnnouncerCheckerProvider('foo.bar').from_assigned_task(assigned_task, None) is None + + +@patch('apache.aurora.executor.common.announcer.ServerSet') +@patch('apache.aurora.executor.common.announcer.KazooClient') +def test_announcer_provider_with_zkpath(mock_client_provider, mock_serverset_provider): + mock_client = create_autospec(spec=KazooClient, instance=True) + mock_client_provider.return_value = mock_client + mock_serverset = create_autospec(spec=ServerSet, instance=True) + mock_serverset_provider.return_value = mock_serverset + + dap = DefaultAnnouncerCheckerProvider('zookeeper.example.com', '', True) + job = make_job('aurora', 'prod', 'proxy', 'primary', portmap={'http': 80, 'admin': 'primary'}, + zk_path='/uns/v1/sjc1-prod/us1/service/prod') + assigned_task = make_assigned_task(job, assigned_ports={'primary': 12345}) + checker = dap.from_assigned_task(assigned_task, None) + + mock_client.start_async.assert_called_once_with() + mock_serverset_provider.assert_called_once_with(mock_client, '/uns/v1/sjc1-prod/us1/service/prod') + assert checker.name() == 'announcer' + assert checker.status is None
