info.py 2.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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.

"""
API endpoint that deliver backend configuration details.
"""

from flask_restplus import Resource, fields

21
from nomad import config, parsing, normalizing, datamodel, gitinfo
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

from .app import api


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
})

domain_model = api.model('Domain', {
    'name': fields.String,
    'quantities': fields.List(fields.Nested(model=domain_quantity_model)),
    'aggregations_names': fields.List(fields.String),
    'metrics_names': fields.List(fields.String)
})

42
43
44
45
46
47
git_info_model = api.model('GitInfo', {
    'ref': fields.String,
    'version': fields.String,
    'log': fields.String
})

48
49
50
info_model = api.model('Info', {
    'parsers': fields.List(fields.String),
    'normalizers': fields.List(fields.String),
51
52
53
54
    'domain': fields.Nested(model=domain_model),
    'version': fields.String,
    'release': fields.String,
    'git': fields.Nested(model=git_info_model)
55
56
57
58
59
60
61
62
63
64
})


@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):
        """ Return information about the nomad backend and its configuration. """
        return {
65
            'parsers': [key[8:] for key in parsing.parser_dict.keys()],
66
            'normalizers': [normalizer.__name__ for normalizer in normalizing.normalizers],
67
68
            'domain': {
                'name': datamodel.Domain.instance.name,
69
                'quantities': [quantity for quantity in datamodel.Domain.instance.quantities.values()],
70
71
72
73
74
75
76
77
78
79
                'metrics_names': datamodel.Domain.instance.metrics_names,
                'aggregations_names': datamodel.Domain.instance.aggregations_names
            },
            'version': config.version,
            'release': config.release,
            'git': {
                'ref': gitinfo.ref,
                'version': gitinfo.version,
                'log': gitinfo.log
            }
80
        }, 200