def trigger_try_jobs(auth_config, changelist, options, masters, category):
    rietveld_url = settings.GetDefaultServerUrl()
    rietveld_host = urlparse.urlparse(rietveld_url).hostname
    authenticator = auth.get_authenticator_for_host(rietveld_host, auth_config)
    http = authenticator.authorize(httplib2.Http())
    http.force_exception_to_status_code = True
    issue_props = changelist.GetIssueProperties()
    issue = changelist.GetIssue()
    patchset = changelist.GetMostRecentPatchset()
    properties = _get_properties_from_options(options)
    buildbucket_put_url = 'https://{hostname}/_ah/api/buildbucket/v1/builds/batch'.format(hostname=options.buildbucket_host)
    buildset = 'patch/rietveld/{hostname}/{issue}/{patch}'.format(hostname=rietveld_host, issue=issue, patch=patchset)
    batch_req_body = {'builds': []}
    print_text = []
    print_text.append('Tried jobs on:')
    for (master, builders_and_tests) in sorted(masters.iteritems()):
        print_text.append(('Master: %s' % master))
        bucket = _prefix_master(master)
        for (builder, tests) in sorted(builders_and_tests.iteritems()):
            print_text.append(('  %s: %s' % (builder, tests)))
            parameters = {'builder_name': builder, 'changes': [{'author': {'email': issue_props['owner_email']}, 'revision': options.revision}], 'properties': {'category': category, 'issue': issue, 'master': master, 'patch_project': issue_props['project'], 'patch_storage': 'rietveld', 'patchset': patchset, 'reason': options.name, 'rietveld': rietveld_url}}
            if ('presubmit' in builder.lower()):
                parameters['properties']['dry_run'] = 'true'
            if tests:
                parameters['properties']['testfilter'] = tests
            if properties:
                parameters['properties'].update(properties)
            if options.clobber:
                parameters['properties']['clobber'] = True
            batch_req_body['builds'].append({'bucket': bucket, 'parameters_json': json.dumps(parameters), 'client_operation_id': str(uuid.uuid4()), 'tags': [('builder:%s' % builder), ('buildset:%s' % buildset), ('master:%s' % master), 'user_agent:git_cl_try']})
    _buildbucket_retry('triggering tryjobs', http, buildbucket_put_url, 'PUT', body=json.dumps(batch_req_body), headers={'Content-Type': 'application/json'})
    print_text.append('To see results here, run:        git cl try-results')
    print_text.append('To see results in browser, run:  git cl web')
    print('\n'.join(print_text))
def trigger_try_jobs(auth_config, changelist, options, masters, category):
    rietveld_url = settings.GetDefaultServerUrl()
    rietveld_host = urlparse.urlparse(rietveld_url).hostname
    authenticator = auth.get_authenticator_for_host(rietveld_host, auth_config)
    http = authenticator.authorize(httplib2.Http())
    http.force_exception_to_status_code = True
    issue_props = changelist.GetIssueProperties()
    issue = changelist.GetIssue()
    patchset = changelist.GetMostRecentPatchset()
    properties = _get_properties_from_options(options)
    buildbucket_put_url = 'https://{hostname}/_ah/api/buildbucket/v1/builds/batch'.format(hostname=options.buildbucket_host)
    buildset = 'patch/rietveld/{hostname}/{issue}/{patch}'.format(hostname=rietveld_host, issue=issue, patch=patchset)
    batch_req_body = {'builds': []}
    print_text = []
    print_text.append('Tried jobs on:')
    for (master, builders_and_tests) in sorted(masters.iteritems()):
        print_text.append(('Master: %s' % master))
        bucket = _prefix_master(master)
        for (builder, tests) in sorted(builders_and_tests.iteritems()):
            print_text.append(('  %s: %s' % (builder, tests)))
            parameters = {'builder_name': builder, 'changes': [{'author': {'email': issue_props['owner_email']}, 'revision': options.revision}], 'properties': {'category': category, 'issue': issue, 'master': master, 'patch_project': issue_props['project'], 'patch_storage': 'rietveld', 'patchset': patchset, 'reason': options.name, 'rietveld': rietveld_url}}
            if ('presubmit' in builder.lower()):
                parameters['properties']['dry_run'] = 'true'
            if tests:
                parameters['properties']['testfilter'] = tests
            if properties:
                parameters['properties'].update(properties)
            if options.clobber:
                parameters['properties']['clobber'] = True
            batch_req_body['builds'].append({'bucket': bucket, 'parameters_json': json.dumps(parameters), 'client_operation_id': str(uuid.uuid4()), 'tags': [('builder:%s' % builder), ('buildset:%s' % buildset), ('master:%s' % master), 'user_agent:git_cl_try']})
    _buildbucket_retry('triggering tryjobs', http, buildbucket_put_url, 'PUT', body=json.dumps(batch_req_body), headers={'Content-Type': 'application/json'})
    print_text.append('To see results here, run:        git cl try-results')
    print_text.append('To see results in browser, run:  git cl web')
    print('\n'.join(print_text))