Example #1
0
File: jobs.py Project: hysds/mozart
 def get(self):
     """Paginated list submitted jobs"""
     jobs = mozart_es.query(index=JOB_STATUS_INDEX, _source=False)
     return {
         'success': True,
         'message': "",
         'result': sorted([job["_id"] for job in jobs])
     }
Example #2
0
    def get(self):
        """Retrieve user rule(s)"""
        _id = request.args.get("id", None)
        _rule_name = request.args.get("rule_name", None)
        user_rules_index = app.config['USER_RULES_INDEX']

        if _id:
            rule = mozart_es.get_by_id(index=user_rules_index, id=_id, ignore=404)
            if rule.get("found", False) is False:
                return {
                    'success': False,
                    'message': rule['message']
                }, 404
            else:
                rule = {**rule, **rule["_source"]}
                rule.pop("_source", None)
                return {
                    'success': True,
                    'rule': rule
                }
        elif _rule_name:
            result = mozart_es.search(index=user_rules_index, q="rule_name:{}".format(_rule_name), ignore=404)
            if result.get("hits", {}).get("total", {}).get("value", 0) == 0:
                return {
                    "success": False,
                    "message": "rule {} not found".format(_rule_name)
                }, 404
            rule = result.get("hits").get("hits")[0]
            rule = {**rule, **rule["_source"]}
            rule.pop("_source", None)
            return {
                "success": True,
                "rule": rule
            }

        user_rules = mozart_es.query(index=user_rules_index)

        parsed_user_rules = []
        for rule in user_rules:
            rule_copy = rule.copy()
            rule_temp = {**rule_copy, **rule['_source']}
            rule_temp.pop('_source')
            parsed_user_rules.append(rule_temp)

        return {
            'success': True,
            'rules': parsed_user_rules
        }
Example #3
0
File: jobs.py Project: hysds/mozart
    def get(self):
        """List available on demand jobs"""
        query = {
            "_source": ["id", "job-specification", "label", "job-version"],
            "sort": [{"label.keyword": {"order": "asc"}}],
            "query": {
                "exists": {
                    "field": "job-specification"
                }
            }
        }

        documents = mozart_es.query(index=HYSDS_IOS_INDEX, body=query)
        documents = [{
            'hysds_io': row['_source']['id'],
            'job_spec': row['_source']['job-specification'],
            'version': row['_source']['job-version'],
            'label': row['_source']['label']
        } for row in documents]

        return {
            'success': True,
            'result': documents
        }
Example #4
0
 def get(self):
     """Gets a list of Job Type specifications"""
     query = {"query": {"match_all": {}}}
     job_specs = mozart_es.query(index=JOB_SPECS_INDEX, body=query)
     ids = [job_spec['_id'] for job_spec in job_specs]
     return {'success': True, 'message': "", 'result': ids}
Example #5
0
 def get(self):
     """List HySDS IO specifications"""
     hysds_ios = mozart_es.query(index=HYSDS_IOS_INDEX, _source=False)
     ids = [hysds_io['_id'] for hysds_io in hysds_ios]
     return {'success': True, 'message': "", 'result': ids}
Example #6
0
    def get(self):
        """Get a list of containers managed by Mozart"""
        containers = mozart_es.query(index=CONTAINERS_INDEX, _source=False)
        ids = [container['_id'] for container in containers]

        return {'success': True, 'message': "", 'result': ids}