Merge pull request #29 from xujyan/yan/executor_info

Fill in ExecutorInfo.name and ExecutorInfo.source.
diff --git a/mysos/scheduler/launcher.py b/mysos/scheduler/launcher.py
index 6167546..e545d06 100644
--- a/mysos/scheduler/launcher.py
+++ b/mysos/scheduler/launcher.py
@@ -16,6 +16,9 @@
 from twitter.common.zookeeper.serverset.endpoint import Endpoint, ServiceInstance
 
 
+EXECUTOR_NAME = 'mysos.executor'
+
+
 class MySQLClusterLauncher(object):
   """
     Responsible for launching and maintaining a MySQL cluster.
@@ -46,6 +49,7 @@
       installer_args=None,
       backup_store_args=None,
       executor_environ=None,
+      executor_source_prefix=None,
       framework_role='*',
       query_interval=Amount(1, Time.SECONDS)):
     """
@@ -62,6 +66,7 @@
       :param installer_args: See flags.
       :param backup_store_args: See flags.
       :param executor_environ: See flags.
+      :param executor_source_prefix: See flags.
       :param framework_role: See flags.
       :param query_interval: See MySQLMasterElector. Use the default value for production and allow
                              tests to use a different value.
@@ -88,6 +93,7 @@
     self._installer_args = installer_args
     self._backup_store_args = backup_store_args
     self._executor_environ = executor_environ
+    self._executor_source_prefix = executor_source_prefix
 
     # Used by the elector.
     self._query_interval = query_interval
@@ -266,6 +272,13 @@
     task.name = task_id
 
     task.executor.executor_id.value = task_id  # Use task_id as executor_id.
+    task.executor.name = EXECUTOR_NAME
+
+    source = [self._cluster.name, str(server_id)]
+    if self._executor_source_prefix and self._executor_source_prefix.strip('.'):
+      source = [self._executor_source_prefix.strip('.')] + source
+
+    task.executor.source = '.'.join(source)
     task.executor.command.value = self._executor_cmd
 
     if self._executor_environ:  # Could be 'None' since it's an optional argument.
diff --git a/mysos/scheduler/mysos_scheduler.py b/mysos/scheduler/mysos_scheduler.py
index 7ff6a25..72a1945 100644
--- a/mysos/scheduler/mysos_scheduler.py
+++ b/mysos/scheduler/mysos_scheduler.py
@@ -159,6 +159,17 @@
            "option is not provided"
   )
 
+  app.add_option(
+      '--executor_source_prefix',
+      dest='executor_source_prefix',
+      default=None,
+      help="Mysos uses the 'source' field in ExecutorInfo (See Mesos documentation) to group tasks "
+           "to support metrics tracking by external utilities. The format of ExecutorInfo.source "
+           "is '<prefix>.<cluster_name>.<server_id>'. This flag specifies the prefix to use in the "
+           "'source' field. e.g., it can be '<availability_zone>.<mesos_cluster>'. There is no "
+           "preceding period if <prefix> is empty"
+  )
+
   def main(args, options):
     log.info("Options in use: %s", options)
 
@@ -273,6 +284,7 @@
         installer_args=options.installer_args,
         backup_store_args=options.backup_store_args,
         executor_environ=options.executor_environ,
+        executor_source_prefix=options.executor_source_prefix,
         framework_role=options.framework_role)
 
     if fw_principal and fw_secret:
diff --git a/mysos/scheduler/scheduler.py b/mysos/scheduler/scheduler.py
index 8c1e36d..567562f 100644
--- a/mysos/scheduler/scheduler.py
+++ b/mysos/scheduler/scheduler.py
@@ -55,6 +55,7 @@
       installer_args=None,
       backup_store_args=None,
       executor_environ=None,
+      executor_source_prefix=None,
       framework_role='*'):
     """
       :param state: The Scheduler object.
@@ -70,6 +71,7 @@
       :param installer_args: See flags.
       :param backup_store_args: See flags.
       :param executor_environ: See flags.
+      :param executor_source_prefix: See flags.
       :param kazoo: The Kazoo client for communicating MySQL cluster information between the
                     scheduler and the executors.
       :param zk_url: ZooKeeper URL for used by the scheduler and the executors to access ZooKeeper.
@@ -93,6 +95,7 @@
     self._installer_args = installer_args
     self._backup_store_args = backup_store_args
     self._executor_environ = executor_environ
+    self._executor_source_prefix = executor_source_prefix
 
     self._driver = None  # Will be set by registered().
 
@@ -184,6 +187,7 @@
           installer_args=self._installer_args,
           backup_store_args=self._backup_store_args,
           executor_environ=self._executor_environ,
+          executor_source_prefix=self._executor_source_prefix,
           framework_role=self._framework_role)
 
       return get_cluster_path(self._discover_zk_url, cluster_name), password
@@ -284,10 +288,11 @@
           self._election_timeout,
           self._admin_keypath,
           self._scheduler_key,
-          self._installer_args,
-          self._backup_store_args,
-          self._executor_environ,
-          self._framework_role)
+          installer_args=self._installer_args,
+          backup_store_args=self._backup_store_args,
+          executor_environ=self._executor_environ,
+          executor_source_prefix=self._executor_source_prefix,
+          framework_role=self._framework_role)
 
     log.info("Recovered %s clusters" % len(self._launchers))
 
diff --git a/vagrant/bin/mysos_scheduler.sh b/vagrant/bin/mysos_scheduler.sh
index 500dc66..395aa6b 100755
--- a/vagrant/bin/mysos_scheduler.sh
+++ b/vagrant/bin/mysos_scheduler.sh
@@ -29,4 +29,5 @@
     --framework_role=mysos \
     --framework_authentication_file=/home/vagrant/mysos/vagrant/etc/fw_auth_keyfile.yml \
     --scheduler_keypath=/home/vagrant/mysos/vagrant/etc/scheduler_keyfile.txt \
+    --executor_source_prefix='vagrant.devcluster' \
     --executor_environ='[{"name": "MYSOS_DEFAULTS_FILE", "value": "/etc/mysql/conf.d/my5.6.cnf"}]'