Exemplo n.º 1
0
 def get(self, request):
     cluster_ds = DataSource()
     return Response(
         data={
             'scheduler_status':
             'active' if bool(
                 cluster_ds.get_cluster_data("is_scheduler_workable")
             ) else 'inactive',
             'shared_storage_status':
             'active' if bool(
                 cluster_ds.get_cluster_data("is_cluster_fs_workable")
             ) else 'inactive'
         })
Exemplo n.º 2
0
def test_get_metric_data_invalid_type(mocker, float_influxdb_data):
    mocker.patch('django.core.cache.cache.get',
                 return_value=float_influxdb_data)
    result = DataSource().get_metric_data(physical_type="invalid_type",
                                          name="test_rack",
                                          metric="energy")
    assert result == 0
Exemplo n.º 3
0
def test_cluster_data(mocker, float_influxdb_data):
    mock = mocker.patch('django.core.cache.cache.get',
                        return_value=float_influxdb_data)

    result = DataSource().get_cluster_data("mem_used_kb")
    mock.assert_called_once_with("select last(value) from hour.cluster_mem")
    assert result == 107.14
Exemplo n.º 4
0
def test_get_metric_data_node(mocker, string_influxdb_data):
    mock = mocker.patch('django.core.cache.cache.get',
                        return_value=string_influxdb_data)

    result = DataSource().get_metric_data(physical_type="node",
                                          name="test_node",
                                          metric="power_status")

    mock.assert_called_with("select last(value) from node_active "
                            "where host = 'test_node' "
                            "and time > now() - 60s")
    assert result == "on"
Exemplo n.º 5
0
def test_cluster_data_invalid(mocker, float_influxdb_data):
    mocker.patch('django.core.cache.cache.get',
                 return_value=float_influxdb_data)
    result = DataSource().get_cluster_data("invalid_metric")
    assert result == 0
Exemplo n.º 6
0
def test_get_latest_data_none(mocker):
    mocker.patch('django.core.cache.cache.get', return_value=None)
    assert DataSource()._get_latest_data("", "test_metric") == 0
Exemplo n.º 7
0
def test_get_latest_data_string(mocker, string_influxdb_data):
    mocker.patch('django.core.cache.cache.get',
                 return_value=string_influxdb_data)
    assert DataSource()._get_latest_data("", "node_active") == "on"
Exemplo n.º 8
0
def test_get_latest_data_float(mocker, float_influxdb_data):
    mocker.patch('django.core.cache.cache.get',
                 return_value=float_influxdb_data)
    assert DataSource()._get_latest_data("", "cluster_mem") == 107.14
Exemplo n.º 9
0
 def energy(self):
     from antilles.cluster.datasource import DataSource
     return DataSource().get_metric_data(physical_type="rack",
                                         name=self.name,
                                         metric="energy")
Exemplo n.º 10
0
    def get(self, request):
        running_jobs = Job.objects.filter(status='running')
        running_jobs_num = running_jobs.count()
        cluster_ds = DataSource()
        preference = self.get_node_status_preference(request.user)

        return Response(
            data={
                'name':
                settings.DOMAIN,
                'is_scheduler_workable':
                cluster_ds.get_cluster_data("is_scheduler_workable"),
                'is_cluster_fs_workable':
                cluster_ds.get_cluster_data("is_cluster_fs_workable"),
                'nodes':
                self._get_node_statics(preference),
                'processors': {
                    'total':
                    cluster_ds.get_cluster_data("cpu_num"),
                    'used':
                    running_jobs.aggregate(used=Sum('cpuscount'))['used']
                    if running_jobs_num > 0 else 0
                },
                'gpu': {
                    'total': cluster_ds.get_cluster_data("gpu_total_num"),
                    'used': cluster_ds.get_cluster_data("gpu_use_num")
                },
                'memory': {
                    'total': cluster_ds.get_cluster_data("mem_total_kb"),
                    'used': cluster_ds.get_cluster_data("mem_used_kb")
                },
                'diskspace': {
                    'total': cluster_ds.get_cluster_data("disk_total_gb"),
                    'used': cluster_ds.get_cluster_data("disk_used_gb")
                },
                'throughput': {
                    'in': cluster_ds.get_cluster_data("network_in_bytes"),
                    'out': cluster_ds.get_cluster_data("network_out_bytes")
                }
            })
Exemplo n.º 11
0
EPL-1.0 license for commercial use. Full text of both licenses can be found in
COPYING.BSD and COPYING.EPL files.
"""

import logging

from rest_framework.response import Response
from rest_framework.views import APIView

from antilles.cluster.datasource import DataSource
from antilles.cluster.models import Rack
from antilles.user.permissions import AsOperatorRole

logger = logging.getLogger(__name__)

cluster_ds = DataSource()


class RackDetailView(APIView):
    permission_classes = (AsOperatorRole, )

    def get(self, request, pk):
        rack = Rack.objects.get(id=pk)
        chassises = [{
            'id': chassis.pk,
            'name': chassis.name,
            'machinetype': chassis.machine_type,
            'location': chassis.location
        } for chassis in rack.chassis_set.iterator()]

        nodes = [self.get_statics(node) for node in rack.node_set.iterator()]