Rest API to query the trial info, with the given trial_id.

    The url pattern should be like this:

    curl http://<server>:<port>/query_trial?trial_id=<trial_id>

    The response may be:

    {
        "app_url": "None",
        "trial_status": "TERMINATED",
        "params": {'a': 1, 'b': 2},
        "job_id": "asynchyperband_test",
        "end_time": "2018-07-19 20:49:44",
        "start_time": "2018-07-19 20:49:40",
        "trial_id": "2067R2ZD",
    }

def query_trial(request):
    """Rest API to query the trial info, with the given trial_id.

    The url pattern should be like this:

    curl http://<server>:<port>/query_trial?trial_id=<trial_id>

    The response may be:

    {
        "app_url": "None",
        "trial_status": "TERMINATED",
        "params": {'a': 1, 'b': 2},
        "job_id": "asynchyperband_test",
        "end_time": "2018-07-19 20:49:44",
        "start_time": "2018-07-19 20:49:40",
        "trial_id": "2067R2ZD",
    }
    """
    trial_id = request.GET.get("trial_id")
    trials = TrialRecord.objects \
        .filter(trial_id=trial_id) \
        .order_by("-start_time")
    if len(trials) == 0:
        resp = "Unkonwn trial id %s.\n" % trials
    else:
        trial = trials[0]
        result = {
            "trial_id": trial.trial_id,
            "job_id": trial.job_id,
            "trial_status": trial.trial_status,
            "start_time": trial.start_time,
            "end_time": trial.end_time,
            "params": trial.params
        }
        resp = json.dumps(result)
    return HttpResponse(resp, content_type="application/json;charset=utf-8")