info.py 3.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15
'''
16
API endpoint that deliver backend configuration details.
17
'''
18
19
20

from flask_restplus import Resource, fields

21
from nomad import config, parsing, normalizing, datamodel, gitinfo
22

Markus Scheidgen's avatar
Markus Scheidgen committed
23
from .api import api
24
25
26
27
28
29
30
31
32
33
34


ns = api.namespace('info', description='Access to nomad configuration details.')

domain_quantity_model = api.model('DomainQuantity', {
    'name': fields.String,
    'description': fields.String,
    'multi': fields.Boolean,
    'order_default': fields.Boolean
})

35
36
metainfo_model = api.model('Metainfo', {
    'all_package': fields.String(description='Name of the metainfo package that references all available packages, i.e. the complete metainfo.'),
37
    'root_section': fields.String(description='Name of the topmost section, e.g. section_run for computational material science data.')
38
39
})

40
41
42
43
domain_model = api.model('Domain', {
    'name': fields.String,
    'quantities': fields.List(fields.Nested(model=domain_quantity_model)),
    'aggregations_names': fields.List(fields.String),
44
45
    'metrics_names': fields.List(fields.String),
    'metainfo': fields.Nested(model=metainfo_model)
46
47
})

48
49
50
git_info_model = api.model('GitInfo', {
    'ref': fields.String,
    'version': fields.String,
Markus Scheidgen's avatar
Markus Scheidgen committed
51
    'commit': fields.String,
52
53
54
    'log': fields.String
})

55
56
info_model = api.model('Info', {
    'parsers': fields.List(fields.String),
57
    'codes': fields.List(fields.String),
58
    'normalizers': fields.List(fields.String),
59
    'domains': fields.List(fields.Nested(model=domain_model)),
60
61
    'version': fields.String,
    'release': fields.String,
62
63
    'git': fields.Nested(model=git_info_model),
    'oasis': fields.Boolean
64
65
66
67
68
69
70
71
})


@ns.route('/')
class InfoResource(Resource):
    @api.doc('get_info')
    @api.marshal_with(info_model, skip_none=True, code=200, description='Info send')
    def get(self):
72
        ''' Return information about the nomad backend and its configuration. '''
73
74
75
76
77
        codes = [
            parser.code_name
            for parser in parsing.parser_dict.values()
            if isinstance(parser, parsing.MatchingParser) and parser.domain == 'dft']

78
        return {
79
80
81
            'parsers': [
                key[key.index('/') + 1:]
                for key in parsing.parser_dict.keys()],
82
            'codes': sorted(set(codes), key=lambda x: x.lower()),
83
            'normalizers': [normalizer.__name__ for normalizer in normalizing.normalizers],
84
85
            'domains': [
                {
86
                    'name': domain_name,
87
                    'metainfo': {
88
89
                        'all_package': domain['metainfo_all_package'],
                        'root_section': domain['root_section']
90
                    }
91
                }
92
                for domain_name, domain in datamodel.domains.items()
93
            ],
94
95
96
97
98
            'version': config.version,
            'release': config.release,
            'git': {
                'ref': gitinfo.ref,
                'version': gitinfo.version,
99
                'commit': gitinfo.commit,
100
                'log': gitinfo.log
101
102
            },
            'oasis': config.keycloak.oasis
103
        }, 200