From b67557fdf3ddab95d2834c8aa01dcc0d120685dd Mon Sep 17 00:00:00 2001 From: maxbr Date: Thu, 25 Aug 2016 12:10:55 +0200 Subject: Add a Resource detail view JIRA: RELENG-12 The resource page contains an utilization diagram, future bookings with their jira tickets and a list of servers. Change-Id: I2123ccbe96cde29a56af32b933ebbf6ba2668ed1 Signed-off-by: maxbr --- tools/pharos-dashboard/dashboard/admin.py | 3 +- tools/pharos-dashboard/dashboard/models.py | 19 ++- .../dashboard/templatetags/jenkins_filters.py | 7 +- .../dashboard/templatetags/jira_filters.py | 8 ++ tools/pharos-dashboard/dashboard/urls.py | 4 +- tools/pharos-dashboard/dashboard/views.py | 30 ++-- tools/pharos-dashboard/jenkins/models.py | 13 ++ .../templates/booking/booking_table.html | 33 +++++ .../templates/dashboard/dev_pods.html | 2 +- .../templates/dashboard/lab_owner.html | 151 --------------------- .../templates/dashboard/resource.html | 58 ++++++++ .../templates/dashboard/resource_all.html | 74 ++++++++++ .../templates/dashboard/resource_detail.html | 64 +++++++++ .../templates/dashboard/resource_utilization.html | 86 ------------ .../templates/dashboard/server_table.html | 30 ++++ 15 files changed, 322 insertions(+), 260 deletions(-) create mode 100644 tools/pharos-dashboard/dashboard/templatetags/jira_filters.py create mode 100644 tools/pharos-dashboard/templates/booking/booking_table.html delete mode 100644 tools/pharos-dashboard/templates/dashboard/lab_owner.html create mode 100644 tools/pharos-dashboard/templates/dashboard/resource.html create mode 100644 tools/pharos-dashboard/templates/dashboard/resource_all.html create mode 100644 tools/pharos-dashboard/templates/dashboard/resource_detail.html delete mode 100644 tools/pharos-dashboard/templates/dashboard/resource_utilization.html create mode 100644 tools/pharos-dashboard/templates/dashboard/server_table.html (limited to 'tools') diff --git a/tools/pharos-dashboard/dashboard/admin.py b/tools/pharos-dashboard/dashboard/admin.py index 990e63e8..71a1e7d2 100644 --- a/tools/pharos-dashboard/dashboard/admin.py +++ b/tools/pharos-dashboard/dashboard/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from dashboard.models import Resource +from dashboard.models import * admin.site.register(Resource) +admin.site.register(Server) diff --git a/tools/pharos-dashboard/dashboard/models.py b/tools/pharos-dashboard/dashboard/models.py index 971af6a2..d645cd55 100644 --- a/tools/pharos-dashboard/dashboard/models.py +++ b/tools/pharos-dashboard/dashboard/models.py @@ -1,6 +1,5 @@ from django.contrib.auth.models import User from django.db import models -from django.utils import timezone from jenkins.models import JenkinsSlave @@ -17,4 +16,20 @@ class Resource(models.Model): db_table = 'resource' def __str__(self): - return self.name \ No newline at end of file + return self.name + + +class Server(models.Model): + id = models.AutoField(primary_key=True) + resource = models.ForeignKey(Resource, on_delete=models.CASCADE) + name = models.CharField(max_length=100, blank=True) + model = models.CharField(max_length=100, blank=True) + cpu = models.CharField(max_length=100, blank=True) + ram = models.CharField(max_length=100, blank=True) + storage = models.CharField(max_length=100, blank=True) + + class Meta: + db_table = 'server' + + def __str__(self): + return self.name diff --git a/tools/pharos-dashboard/dashboard/templatetags/jenkins_filters.py b/tools/pharos-dashboard/dashboard/templatetags/jenkins_filters.py index f7e00a87..f5038ea5 100644 --- a/tools/pharos-dashboard/dashboard/templatetags/jenkins_filters.py +++ b/tools/pharos-dashboard/dashboard/templatetags/jenkins_filters.py @@ -9,7 +9,7 @@ def jenkins_job_color(job_result): return '#d9534f' if job_result == 'UNSTABLE': return '#EDD62B' - return '#646F73' # job is still building + return '#646F73' # job is still building @register.filter @@ -21,7 +21,8 @@ def jenkins_status_color(slave_status): if slave_status == 'online / idle': return '#5bc0de' + @register.filter def jenkins_job_blink(job_result): - if job_result == '': # job is still building - return 'class=blink_me' \ No newline at end of file + if job_result == '': # job is still building + return 'class=blink_me' diff --git a/tools/pharos-dashboard/dashboard/templatetags/jira_filters.py b/tools/pharos-dashboard/dashboard/templatetags/jira_filters.py new file mode 100644 index 00000000..d9c27612 --- /dev/null +++ b/tools/pharos-dashboard/dashboard/templatetags/jira_filters.py @@ -0,0 +1,8 @@ +from django.template.defaultfilters import register + +from pharos_dashboard import settings + + +@register.filter +def jira_issue_url(issue): + return settings.JIRA_URL + '/browse/' + str(issue) diff --git a/tools/pharos-dashboard/dashboard/urls.py b/tools/pharos-dashboard/dashboard/urls.py index 51d764c4..809204c1 100644 --- a/tools/pharos-dashboard/dashboard/urls.py +++ b/tools/pharos-dashboard/dashboard/urls.py @@ -21,8 +21,8 @@ urlpatterns = [ url(r'^ci_pods/$', CIPodsView.as_view(), name='ci_pods'), url(r'^dev_pods/$', DevelopmentPodsView.as_view(), name='dev_pods'), url(r'^jenkins_slaves/$', JenkinsSlavesView.as_view(), name='jenkins_slaves'), - url(r'^resource/all/', LabOwnerView.as_view(), - name='resources'), + url(r'^resource/all/$', LabOwnerView.as_view(), name='resources'), + url(r'^resource/(?P[0-9]+)/$', ResourceView.as_view(), name='resource'), url(r'^$', DevelopmentPodsView.as_view(), name="index"), ] diff --git a/tools/pharos-dashboard/dashboard/views.py b/tools/pharos-dashboard/dashboard/views.py index 56b3a510..ef1845c8 100644 --- a/tools/pharos-dashboard/dashboard/views.py +++ b/tools/pharos-dashboard/dashboard/views.py @@ -1,12 +1,12 @@ from datetime import timedelta -from django.contrib.auth.models import User +from django.shortcuts import get_object_or_404 from django.utils import timezone from django.views.generic import TemplateView from booking.models import Booking from dashboard.models import Resource -from jenkins.models import JenkinsSlave, JenkinsStatistic +from jenkins.models import JenkinsSlave class JenkinsSlavesView(TemplateView): @@ -51,25 +51,27 @@ class DevelopmentPodsView(TemplateView): return context +class ResourceView(TemplateView): + template_name = "dashboard/resource.html" + + def get_context_data(self, **kwargs): + resource = get_object_or_404(Resource, id=self.kwargs['resource_id']) + utilization = resource.slave.get_utilization(timedelta(days=7)) + bookings = Booking.objects.filter(resource=resource, end__gt=timezone.now()) + context = super(ResourceView, self).get_context_data(**kwargs) + context.update({'title': str(resource), 'resource': resource, 'utilization': utilization, 'bookings': bookings}) + return context + + class LabOwnerView(TemplateView): - template_name = "dashboard/lab_owner.html" + template_name = "dashboard/resource_all.html" def get_context_data(self, **kwargs): resources = Resource.objects.filter(slave__dev_pod=True) pods = [] for resource in resources: - utilization = {'idle': 0, 'online': 0, 'offline': 0} - # query measurement points for the last week - statistics = JenkinsStatistic.objects.filter(slave=resource.slave, - timestamp__gte=timezone.now() - timedelta( - days=7)) - - utilization['idle'] = statistics.filter(idle=True).count() - utilization['online'] = statistics.filter(online=True).count() - utilization['offline'] = statistics.filter(offline=True).count() - + utilization = resource.slave.get_utilization(timedelta(days=7)) bookings = Booking.objects.filter(resource=resource, end__gt=timezone.now()) - pods.append((resource, utilization, bookings)) context = super(LabOwnerView, self).get_context_data(**kwargs) context.update({'title': "Overview", 'pods': pods}) diff --git a/tools/pharos-dashboard/jenkins/models.py b/tools/pharos-dashboard/jenkins/models.py index 438a8827..354887ab 100644 --- a/tools/pharos-dashboard/jenkins/models.py +++ b/tools/pharos-dashboard/jenkins/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils import timezone class JenkinsSlave(models.Model): @@ -18,6 +19,18 @@ class JenkinsSlave(models.Model): last_job_installer = models.CharField(max_length=50, default='') last_job_result = models.CharField(max_length=30, default='') + def get_utilization(self, timedelta): + """ + Return a dictionary containing the count of idle, online and offline measurements in the time from + now-timedelta to now + """ + utilization = {'idle': 0, 'online': 0, 'offline': 0} + statistics = self.jenkinsstatistic_set.filter(timestamp__gte=timezone.now() - timedelta) + utilization['idle'] = statistics.filter(idle=True).count() + utilization['online'] = statistics.filter(online=True).count() + utilization['offline'] = statistics.filter(offline=True).count() + return utilization + class Meta: db_table = 'jenkins_slave' diff --git a/tools/pharos-dashboard/templates/booking/booking_table.html b/tools/pharos-dashboard/templates/booking/booking_table.html new file mode 100644 index 00000000..3d0b7575 --- /dev/null +++ b/tools/pharos-dashboard/templates/booking/booking_table.html @@ -0,0 +1,33 @@ +{% load jira_filters %} + + + + + User + Purpose + Start + End + Jira + + + +{% for booking in bookings %} + + + {{ booking.user.username }} + + + {{ booking.purpose }} + + + {{ booking.start }} + + + {{ booking.end }} + + {{ booking.get_jira_issue }} + + +{% endfor %} + \ No newline at end of file diff --git a/tools/pharos-dashboard/templates/dashboard/dev_pods.html b/tools/pharos-dashboard/templates/dashboard/dev_pods.html index 532a3a11..9c84bb91 100644 --- a/tools/pharos-dashboard/templates/dashboard/dev_pods.html +++ b/tools/pharos-dashboard/templates/dashboard/dev_pods.html @@ -18,7 +18,7 @@ {% for pod, booking in dev_pods %} - {{ pod.name }} + {{ pod.name }} {{ pod.slave.name }} diff --git a/tools/pharos-dashboard/templates/dashboard/lab_owner.html b/tools/pharos-dashboard/templates/dashboard/lab_owner.html deleted file mode 100644 index a4f428c7..00000000 --- a/tools/pharos-dashboard/templates/dashboard/lab_owner.html +++ /dev/null @@ -1,151 +0,0 @@ -{% extends "base.html" %} -{% load staticfiles %} - -{% block extrahead %} - - - - - - - - -{% endblock extrahead %} - - -{% block content %} - {% for resource, utilization, bookings in pods %} -
-
-
-
- {{ resource.name }} -
-
-
-
-
-
-
-
-
-
-
- {{ resource.name }} Bookings -
-
-
- - - - - - - - - - - - {% for booking in bookings %} - - - - - - - - {% endfor %}` - -
UserPurposeStartEndStatus
- {{ booking.user.username }} - - {{ booking.purpose }} - - {{ booking.start }} - - {{ booking.end }} - - Jira Status -
-
-
-
-
-
- {% endfor %} - -{% endblock content %} - - -{% block extrajs %} - - - - - - - - - - - - - - - - - - - -{% endblock extrajs %} \ No newline at end of file diff --git a/tools/pharos-dashboard/templates/dashboard/resource.html b/tools/pharos-dashboard/templates/dashboard/resource.html new file mode 100644 index 00000000..92d02f66 --- /dev/null +++ b/tools/pharos-dashboard/templates/dashboard/resource.html @@ -0,0 +1,58 @@ +{% extends "base.html" %} +{% load staticfiles %} + +{% block extrahead %} + + + + + + + + +{% endblock extrahead %} + + +{% block content %} + {% include "dashboard/resource_detail.html" %} +{% endblock content %} + + +{% block extrajs %} + + + + + + + + + + + + + + + + + +{% endblock extrajs %} \ No newline at end of file diff --git a/tools/pharos-dashboard/templates/dashboard/resource_all.html b/tools/pharos-dashboard/templates/dashboard/resource_all.html new file mode 100644 index 00000000..2078475f --- /dev/null +++ b/tools/pharos-dashboard/templates/dashboard/resource_all.html @@ -0,0 +1,74 @@ +{% extends "base.html" %} +{% load staticfiles %} + +{% block extrahead %} + + + + + + + + +{% endblock extrahead %} + + +{% block content %} + {% for resource, utilization, bookings in pods %} +
+
+
+
+ {{ resource.name }} +
+
+ {% include "dashboard/resource_detail.html" %} +
+
+
+
+ {% endfor %} +{% endblock content %} + + +{% block extrajs %} + + + + + + + + + + + + + + + + + +{% endblock extrajs %} \ No newline at end of file diff --git a/tools/pharos-dashboard/templates/dashboard/resource_detail.html b/tools/pharos-dashboard/templates/dashboard/resource_detail.html new file mode 100644 index 00000000..4fba4766 --- /dev/null +++ b/tools/pharos-dashboard/templates/dashboard/resource_detail.html @@ -0,0 +1,64 @@ +
+
+
+
+ Utilization +
+
+
+
+
+
+
+
+
+
+
+ Servers +
+
+
+ + {% include "dashboard/server_table.html" %} +
+
+
+
+
+
+
+
+
+
+ Bookings +
+
+
+ + {% include "booking/booking_table.html" %} +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/tools/pharos-dashboard/templates/dashboard/resource_utilization.html b/tools/pharos-dashboard/templates/dashboard/resource_utilization.html deleted file mode 100644 index fb483d60..00000000 --- a/tools/pharos-dashboard/templates/dashboard/resource_utilization.html +++ /dev/null @@ -1,86 +0,0 @@ -{% extends "base.html" %} -{% load staticfiles %} - -{% block extrahead %} - - - -{% endblock extrahead %} - - -{% block content %} -
- {% for resource, utilization in pods %} -
-
-
- {{ resource.name }} -
-
-
-
-
-
-
-
- {% endfor %} -
- -{% endblock content %} - - -{% block extrajs %} - - - - - - - - - - - -{% endblock extrajs %} \ No newline at end of file diff --git a/tools/pharos-dashboard/templates/dashboard/server_table.html b/tools/pharos-dashboard/templates/dashboard/server_table.html new file mode 100644 index 00000000..d47e5204 --- /dev/null +++ b/tools/pharos-dashboard/templates/dashboard/server_table.html @@ -0,0 +1,30 @@ + + + Server + Model + CPU + RAM + Storage + + + +{% for server in resource.server_set.all %} + + + {{ server.name }} + + + {{ server.model }} + + + {{ server.cpu }} + + + {{ server.ram }} + + + {{ server.storage }} + + +{% endfor %}` + \ No newline at end of file -- cgit 1.2.3-korg