aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zma...@apache.org
Subject aurora git commit: Added support for {{mesos.hostname}} in configuration files.
Date Wed, 02 Sep 2015 21:47:48 GMT
Repository: aurora
Updated Branches:
  refs/heads/master c87113337 -> 85f93a70d


Added support for {{mesos.hostname}} in configuration files.

Bugs closed: AURORA-1261

Reviewed at https://reviews.apache.org/r/37801/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/85f93a70
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/85f93a70
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/85f93a70

Branch: refs/heads/master
Commit: 85f93a70dbb00d742cb9137b08799090f6e930db
Parents: c871133
Author: Steve Niemitz <sniemitz@twitter.com>
Authored: Wed Sep 2 14:47:21 2015 -0700
Committer: Zameer Manji <zmanji@apache.org>
Committed: Wed Sep 2 14:47:21 2015 -0700

----------------------------------------------------------------------
 src/main/python/apache/aurora/config/schema/base.py        | 1 +
 src/main/python/apache/aurora/config/thrift.py             | 9 +++++----
 src/main/python/apache/aurora/executor/common/task_info.py | 4 +++-
 src/test/python/apache/aurora/config/test_base.py          | 4 ++--
 src/test/python/apache/aurora/config/test_thrift.py        | 9 ++++++++-
 5 files changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/85f93a70/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 f8a1f05..398f737 100644
--- a/src/main/python/apache/aurora/config/schema/base.py
+++ b/src/main/python/apache/aurora/config/schema/base.py
@@ -22,6 +22,7 @@ from apache.thermos.config.schema import *
 class MesosContext(Struct):
   # The instance id (i.e. replica id, shard id) in the context of a task
   instance    = Required(Integer)
+  hostname    = Required(String)
 
 
 class UpdateConfig(Struct):

http://git-wip-us.apache.org/repos/asf/aurora/blob/85f93a70/src/main/python/apache/aurora/config/thrift.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/config/thrift.py b/src/main/python/apache/aurora/config/thrift.py
index f69977c..b40a7fd 100644
--- a/src/main/python/apache/aurora/config/thrift.py
+++ b/src/main/python/apache/aurora/config/thrift.py
@@ -78,8 +78,8 @@ def constraints_to_thrift(constraints):
   return result
 
 
-def task_instance_from_job(job, instance):
-  instance_context = MesosContext(instance=instance)
+def task_instance_from_job(job, instance, hostname):
+  instance_context = MesosContext(instance=instance, hostname=hostname)
   health_check_config = HealthCheckConfig()
   if job.has_health_check_config():
     health_check_config = job.health_check_config()
@@ -168,6 +168,7 @@ def assert_valid_field(field, identifier):
 
 
 MESOS_INSTANCE_REF = Ref.from_address('mesos.instance')
+MESOS_HOSTNAME_REF = Ref.from_address('mesos.hostname')
 THERMOS_PORT_SCOPE_REF = Ref.from_address('thermos.ports')
 THERMOS_TASK_ID_REF = Ref.from_address('thermos.task_id')
 
@@ -229,7 +230,7 @@ def convert(job, metadata=frozenset(), ports=frozenset()):
   underlying, refs = job.interpolate()
 
   # need to fake an instance id for the sake of schema checking
-  underlying_checked = underlying.bind(mesos={'instance': 31337})
+  underlying_checked = underlying.bind(mesos={'instance': 31337, 'hostname': ''})
   try:
     ThermosTaskValidator.assert_valid_task(underlying_checked.task())
   except ThermosTaskValidator.InvalidTaskError as e:
@@ -239,7 +240,7 @@ def convert(job, metadata=frozenset(), ports=frozenset()):
 
   unbound = []
   for ref in refs:
-    if ref == THERMOS_TASK_ID_REF or ref == MESOS_INSTANCE_REF or (
+    if ref in (THERMOS_TASK_ID_REF, MESOS_INSTANCE_REF, MESOS_HOSTNAME_REF) or (
         Ref.subscope(THERMOS_PORT_SCOPE_REF, ref)):
       continue
     unbound.append(ref)

http://git-wip-us.apache.org/repos/asf/aurora/blob/85f93a70/src/main/python/apache/aurora/executor/common/task_info.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/executor/common/task_info.py b/src/main/python/apache/aurora/executor/common/task_info.py
index 0829475..4ef49e3 100644
--- a/src/main/python/apache/aurora/executor/common/task_info.py
+++ b/src/main/python/apache/aurora/executor/common/task_info.py
@@ -75,7 +75,9 @@ def mesos_task_instance_from_assigned_task(assigned_task):
 
   # This is a MesosJob
   task_instance = task_instance_from_job(
-      MesosJob.json_loads(thermos_task), assigned_task.instanceId)
+      MesosJob.json_loads(thermos_task),
+      assigned_task.instanceId,
+      assigned_task.slaveHost)
 
   try:
     ThermosTaskValidator.assert_valid_task(task_instance.task())

http://git-wip-us.apache.org/repos/asf/aurora/blob/85f93a70/src/test/python/apache/aurora/config/test_base.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/config/test_base.py b/src/test/python/apache/aurora/config/test_base.py
index 5a58dd0..b354f08 100644
--- a/src/test/python/apache/aurora/config/test_base.py
+++ b/src/test/python/apache/aurora/config/test_base.py
@@ -55,7 +55,7 @@ HELLO_WORLD = Job(
   cluster = 'smf1-test',
   task = Task(
     name = 'main',
-    processes = [Process(name = 'hello_world', cmdline = 'echo {{mesos.instance}}')],
+    processes = [Process(name='hello_world', cmdline='echo {{mesos.instance}} {{mesos.hostname}}')],
     resources = Resources(cpu = 0.1, ram = 64 * 1048576, disk = 64 * 1048576),
   )
 )
@@ -93,7 +93,7 @@ REIFIED_CONFIG = Job(
   cluster='smf1-test',
   task=Task(
     name='main',
-    processes=[Process(name='hello_world', cmdline='echo {{mesos.instance}}')],
+    processes=[Process(name='hello_world', cmdline='echo {{mesos.instance}} {{mesos.hostname}}')],
     resources=Resources(cpu=0.1, ram=64 * 1048576, disk=64 * 1048576),
   )
 )

http://git-wip-us.apache.org/repos/asf/aurora/blob/85f93a70/src/test/python/apache/aurora/config/test_thrift.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/config/test_thrift.py b/src/test/python/apache/aurora/config/test_thrift.py
index 0c0432c..1bd7459 100644
--- a/src/test/python/apache/aurora/config/test_thrift.py
+++ b/src/test/python/apache/aurora/config/test_thrift.py
@@ -197,7 +197,8 @@ def test_metadata_in_config():
 
 
 def test_task_instance_from_job():
-  instance = task_instance_from_job(Job(health_check_config=HealthCheckConfig(interval_secs=30)),
0)
+  instance = task_instance_from_job(
+      Job(health_check_config=HealthCheckConfig(interval_secs=30)), 0, '')
   assert instance is not None
 
 
@@ -207,3 +208,9 @@ def test_identifier_validation():
     assert matcher.match(identifier)
   for identifier in INVALID_IDENTIFIERS:
     assert not matcher.match(identifier)
+
+
+def test_mesos_hostname_in_task():
+  hw = HELLO_WORLD(task=Task(name="{{mesos.hostname}}"))
+  instance = task_instance_from_job(hw, 0, 'test_host')
+  assert str(instance.task().name()) == 'test_host'


Mime
View raw message