Commit 0d6aa42f48de27b77ee982da4609dd8bd4b92973
1 parent
9cd82394
Exists in
dev
Add vuejs in agents_state (update informations every 4 secs)
Showing
7 changed files
with
91 additions
and
9 deletions
Show diff stats
CHANGELOG
1 | -20-09-2022 (AKo): v0.5.5.0 | |
1 | +28-09-2022 (AKo): v0.5.6.0 | |
2 | + - Add vuejs in agents_state (update informations every 4 secs) | |
3 | + - Add new option for agentSST : start a specific agent | |
4 | + | |
5 | +23-09-2022 (AKo): v0.5.5.0 | |
2 | 6 | - Add flexible form for sending agent cmd |
3 | 7 | - New implementation of Agent get_specific_cmds() |
4 | 8 | - Adapt agentSST to new signature of specific_cmds, add type hints to cmd functions | ... | ... |
VERSION
src/core/pyros_django/api/serializers.py
1 | -from common.models import Institute, Period, PyrosUser, SP_Period, ScienceTheme, ScientificProgram, Sequence, Plan, Album | |
1 | +from common.models import AgentSurvey, Institute, Period, PyrosUser, SP_Period, ScienceTheme, ScientificProgram, Sequence, Plan, Album, AgentCmd | |
2 | 2 | from rest_framework import serializers |
3 | - | |
4 | - | |
3 | +import datetime | |
4 | +from datetime import timezone | |
5 | 5 | |
6 | 6 | class InstituteSerializer(serializers.ModelSerializer): |
7 | 7 | class Meta: |
... | ... | @@ -97,3 +97,29 @@ class FullSequenceSerializer(serializers.ModelSerializer): |
97 | 97 | model = Sequence |
98 | 98 | fields = "__all__" |
99 | 99 | extra_fields = ["pyros_user", "albums"] |
100 | + | |
101 | + | |
102 | + | |
103 | +class AgentSurveySerializer(serializers.ModelSerializer): | |
104 | + class Meta: | |
105 | + model = AgentSurvey | |
106 | + fields = "__all__" | |
107 | + | |
108 | + is_out_of_date = serializers.SerializerMethodField() | |
109 | + running_cmd = serializers.SerializerMethodField() | |
110 | + | |
111 | + def get_is_out_of_date(self, obj): | |
112 | + datetime_now = datetime.datetime.utcnow() | |
113 | + datetime_now_minus_thirty_sec = datetime_now - datetime.timedelta(seconds=30) | |
114 | + datetime_now_minus_thirty_sec = datetime_now_minus_thirty_sec.replace(tzinfo=timezone.utc) | |
115 | + | |
116 | + if datetime_now_minus_thirty_sec >= obj.updated: | |
117 | + return True | |
118 | + else: | |
119 | + return False | |
120 | + | |
121 | + def get_running_cmd(self,obj): | |
122 | + try: | |
123 | + return AgentCmd.objects.get(state="CMD_RUNNING",sender=obj.name).full_name | |
124 | + except AgentCmd.DoesNotExist: | |
125 | + return "None" | |
100 | 126 | \ No newline at end of file | ... | ... |
src/core/pyros_django/api/urls.py
... | ... | @@ -11,6 +11,7 @@ router.register(r'plans', views.PlanViewSet) |
11 | 11 | router.register(r'full_sequences', views.FullSequenceViewSet) |
12 | 12 | router.register(r'scientific_programs', views.ScientificProgramViewSet) |
13 | 13 | router.register(r'sp_period', views.SPPeriodViewSet) |
14 | +router.register(r'agent_survey', views.AgentSurveyViewSet) | |
14 | 15 | |
15 | 16 | urlpatterns = [ |
16 | 17 | path('', include(router.urls)), | ... | ... |
src/core/pyros_django/api/views.py
... | ... | @@ -6,8 +6,8 @@ from rest_framework.permissions import IsAuthenticated, AllowAny |
6 | 6 | from rest_framework.decorators import api_view, permission_classes, action |
7 | 7 | from django.core.validators import ValidationError |
8 | 8 | from src.core.pyros_django.user_manager import views as user_views |
9 | -from api.serializers import AlbumSerializer, FullSequenceSerializer, PlanSerializer, SPPeriodSerializer, ScientificProgramSerializer, SequenceSerializer, UserSerializer | |
10 | -from common.models import PyrosUser, SP_Period, ScientificProgram, Sequence, Album, Plan, UserLevel, SP_Period_User | |
9 | +from api.serializers import AgentSurveySerializer, AlbumSerializer, FullSequenceSerializer, PlanSerializer, SPPeriodSerializer, ScientificProgramSerializer, SequenceSerializer, UserSerializer | |
10 | +from common.models import PyrosUser, SP_Period, ScientificProgram, Sequence, Album, Plan, UserLevel, SP_Period_User, AgentSurvey | |
11 | 11 | from routine_manager.functions import check_sequence_file_validity |
12 | 12 | from rest_framework.request import Request |
13 | 13 | from django.db.models import Q |
... | ... | @@ -238,3 +238,14 @@ def submit_sequence_with_json(request): |
238 | 238 | log.info( |
239 | 239 | f"User {request.user} did action submit sequence {seq} for period {seq.period} ") |
240 | 240 | return Response(response) |
241 | + | |
242 | + | |
243 | + | |
244 | +class AgentSurveyViewSet(viewsets.ModelViewSet): | |
245 | + """ | |
246 | + API endpoint that allows users to view their sequences. | |
247 | + """ | |
248 | + queryset = AgentSurvey.objects.all() | |
249 | + serializer_class = AgentSurveySerializer | |
250 | + permission_classes = [IsAuthenticated] | |
251 | + http_method_names = ["get"] | |
241 | 252 | \ No newline at end of file | ... | ... |
src/core/pyros_django/dashboard/templates/dashboard/agents_state.html
... | ... | @@ -7,13 +7,18 @@ |
7 | 7 | Agents status : |
8 | 8 | {% endblock %} |
9 | 9 | |
10 | -{% block content %} | |
10 | +{% block head %} | |
11 | 11 | <style> |
12 | 12 | .red{ |
13 | 13 | color: red; |
14 | 14 | } |
15 | 15 | </style> |
16 | 16 | |
17 | +<script src="../public/static/js/vue.min.js"></script> | |
18 | +{% endblock %} | |
19 | +{% block content %} | |
20 | + | |
21 | + | |
17 | 22 | <div class="table-responsive"> |
18 | 23 | <table |
19 | 24 | class="table table-bordered table-hover table-striped tablesorter" id="agents_state_table"> |
... | ... | @@ -28,6 +33,7 @@ |
28 | 33 | </tr> |
29 | 34 | </thead> |
30 | 35 | <tbody> |
36 | + {% comment %} | |
31 | 37 | {% for agent in agents %} |
32 | 38 | <tr> |
33 | 39 | <td> <a href={% url 'agent_detail' agent.name %}>{{ agent.name }}</a></td> |
... | ... | @@ -43,6 +49,20 @@ |
43 | 49 | <td> {{ agent.current_nb_restart }} </td> |
44 | 50 | </tr> |
45 | 51 | {% endfor %} |
52 | + {% endcomment %} | |
53 | + | |
54 | + <tr v-for="agent in agents"> | |
55 | + | |
56 | + <td> <a v-bind:href="`/dashboard/agent_detail/${agent.name}`"> [[agent.name ]]</a></td> | |
57 | + | |
58 | + <td> [[ agent.status ]]</td> | |
59 | + <td> [[ agent.mode ]]</td> | |
60 | + | |
61 | + <td v-if="agent.is_out_of_date" class="red"> [[ agent.updated ]]</td> | |
62 | + <td v-else> [[ agent.updated ]] </td> | |
63 | + <td class="running_commands"> [[agent.running_cmd]] </td> | |
64 | + <td> [[ agent.current_nb_restart ]] </td> | |
65 | + </tr> | |
46 | 66 | </tbody> |
47 | 67 | </table> |
48 | 68 | </div> |
... | ... | @@ -61,6 +81,25 @@ |
61 | 81 | }); |
62 | 82 | } |
63 | 83 | |
64 | - setInterval(refresh_command_column,5000); | |
84 | + function refresh_status_table(){ | |
85 | + | |
86 | + fetch("/api/agent_survey/?format=json").then(response => response.json()).then(function(data){ | |
87 | + console.log(data); | |
88 | + app.agents = data; | |
89 | + }); | |
90 | + } | |
91 | + $(document).ready(function() { | |
92 | + | |
93 | + refresh_status_table(); | |
94 | + //setInterval(refresh_command_column,5000); | |
95 | + setInterval(refresh_status_table,4000); | |
96 | + }); | |
97 | + var app = new Vue({ | |
98 | + delimiters:["[[","]]"], | |
99 | + el: '#agents_state_table', | |
100 | + data: { | |
101 | + agents: [] | |
102 | + } | |
103 | + }) | |
65 | 104 | </script> |
66 | 105 | {% endblock %} |
67 | 106 | \ No newline at end of file | ... | ... |
src/core/pyros_django/pyros/settings.py