[autotest] Add job history support.

Add a module to be used to collect job history. For example, all special tasks
executed before and after the test job.
Add an rpc get_job_history to afe to get dictionary of the job and its special
tasks' start/end time.

Update AFE to add a button to show job history.

BUG=chromium:394445
TEST=local setup
./site_utils/job_history.py --job_id=4113
http://dshi.mtv.corp.google.com/afe/#tab_id=view_job&object_id=4113

Change-Id: I0da2e77aaf7e2a38158efd6a64d4f924cf0c803d
Reviewed-on: https://chromium-review.googlesource.com/210091
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index fa6cb15..78048d1 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -24,6 +24,7 @@
 from autotest_lib.server.cros.dynamic_suite import job_status
 from autotest_lib.server.cros.dynamic_suite import tools
 from autotest_lib.server.hosts import moblab_host
+from autotest_lib.site_utils import job_history
 
 
 _CONFIG = global_config.global_config
@@ -251,3 +252,17 @@
     if not os.path.exists(boto_key):
         raise error.RPCException('Boto key: %s does not exist!' % boto_key)
     shutil.copyfile(boto_key, moblab_host.MOBLAB_BOTO_LOCATION)
+
+
+def get_job_history(**filter_data):
+    """Get history of the job, including the special tasks executed for the job
+
+    @param filter_data: filter for the call, should at least include
+                        {'job_id': [job id]}
+    @returns: JSON string of the job's history, including the information such
+              as the hosts run the job and the special tasks executed before
+              and after the job.
+    """
+    job_id = filter_data['job_id']
+    job_info = job_history.get_job_info(job_id)
+    return _rpc_utils().prepare_for_serialization(job_info.get_history())