in pygenie/adapter/genie_2.py [0:0]
def construct_base_payload(job):
"""Returns a base payload for the job."""
# do this first because some jobs will apply some logic (like manipulating
# dependencies) which need to be done before proceeding with building the
# payload
command_args = job.cmd_args
attachments = list()
dependencies = list()
for dep in job.get('dependencies'):
if is_attachment(dep):
# attachment is an adhoc script so do parameter substitution
if isinstance(dep, dict) \
and dep.get('data') \
and hasattr(job, 'DEFAULT_SCRIPT_NAME') \
and dep.get('name') == job.DEFAULT_SCRIPT_NAME:
dep['data'] = substitute(dep['data'], job.get('parameters'))
attachments.append(to_attachment(dep))
else:
dependencies.append(dep)
cluster_tag_mapping = job.get('cluster_tag_mapping')
clusters = [
dict(tags=cluster_tag_mapping.get(priority))
for priority in sorted(cluster_tag_mapping.keys())
]
payload = {
'attachments': attachments,
'clusterCriterias': [i for i in clusters if i.get('tags')],
'commandArgs': job.get('command_arguments') or command_args,
'commandCriteria': job.get('command_tags'),
'description': job.get('description'),
'disableLogArchival': not job.get('archive'),
'email': job.get('email'),
'envPropFile': job.get('setup_file'),
'fileDependencies': dependencies,
'group': job.get('group'),
'id': job.get('job_id'),
'name': job.get('job_name'),
'tags': job.get('tags'),
'user': job.get('username'),
'version': job.get('job_version')
}
# command tags not set, use default
if not payload.get('commandCriteria'):
payload['commandCriteria'] = job.default_command_tags
# cluster tags not set, use default
if not [c.get('tags') for c in payload.get('clusterCriterias', []) \
if len(c.get('tags') or []) > 0]:
payload['clusterCriterias'] = [{'tags': job.default_cluster_tags}]
return payload