def construct_base_payload()

in pygenie/adapter/genie_3.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'))
                att = to_attachment(dep)
                if isinstance(att, list):
                    attachments.extend(att)
                else:
                    attachments.append(att)
            else:
                dependencies.append(dep)

        description = job.get('description')
        if isinstance(description, dict):
            description = json.dumps(description)

        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 = {
            'applications': job.get('application_ids'),
            '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') or job.default_command_tags,
            'dependencies': [d for d in dependencies if d not in {'', None}],
            'description': description,
            'disableLogArchival': not job.get('archive'),
            'email': job.get('email'),
            'group': job.get('group'),
            'id': job.get('job_id'),
            'name': job.get('job_name'),
            'setupFile': job.get('setup_file'),
            'tags': job.get('tags'),
            'timeout': job.get('timeout'),
            'user': job.get('username'),
            'version': job.get('job_version')
        }

        if job.get('genie_cpu'):
            payload['cpu'] = job.get('genie_cpu')
        if job.get('genie_memory'):
            payload['memory'] = job.get('genie_memory')
        if job.get('genie_grouping'):
            payload['grouping'] = job.get('genie_grouping')
        if job.get('genie_grouping_instance'):
            payload['groupingInstance'] = job.get('genie_grouping_instance')
        if job.get('metadata'):
            payload['metadata'] = job.get('metadata')

        return payload