status.py 2.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Copyright (c) 2017, Daniele Venzano
#
# 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.

"""Main points of entry for the Zoe web interface."""

18
from zoe_api.web.request_handler import ZoeWebRequestHandler
Daniele Venzano's avatar
Daniele Venzano committed
19
from zoe_api.exceptions import ZoeException
20
from zoe_lib.config import get_conf
21 22


23
class StatusEndpointWeb(ZoeWebRequestHandler):
24 25 26 27
    """Handler class"""

    def get(self):
        """Status and statistics page."""
28
        if self.current_user is None or not self.current_user.role.can_see_status:
29
            return
30

31
        stats = self.api_endpoint.statistics_scheduler()
32 33
        if stats is None:
            raise ZoeException('Cannot retrieve statistics from the Zoe master')
34 35 36

        executions_in_queue = {}
        for exec_id in stats['queue']:
37
            executions_in_queue[exec_id] = self.api_endpoint.execution_by_id(None, exec_id)
38
        for exec_id in stats['running_queue']:
39
            executions_in_queue[exec_id] = self.api_endpoint.execution_by_id(None, exec_id)
40 41
        for exec_id in stats['termination_queue']:
            executions_in_queue[exec_id] = self.api_endpoint.execution_by_id(None, exec_id)
42

43 44 45
        services_per_node = {}
        for node in stats['platform_stats']['nodes']:
            services_per_node[node['name']] = self.api_endpoint.sql.services.select(backend_host=node['name'], backend_status='started')
46 47 48 49 50 51
            for service in services_per_node[node['name']]:
                if service.id not in node['service_stats']:
                    node['service_stats'][service.id] = {
                        'mem_limit': 0,
                        'core_limit': 0
                    }
52 53

        max_service_count = max([len(services_per_node[name]) for name in services_per_node])
54

55 56
        template_vars = {
            "stats": stats,
57
            "executions_in_queue": executions_in_queue,
58
            "services_per_node": services_per_node,
59 60
            "max_service_count": max_service_count,
            'eurecom': get_conf().eurecom
61 62
        }

Daniele Venzano's avatar
Daniele Venzano committed
63
        self.render('status.jinja2', **template_vars)