##// END OF EJS Templates
Check for active configuration for status update
Juan C. Espinoza -
r329:7d210f98eba4
parent child
Show More
@@ -413,9 +413,7 class ABSConfiguration(Configuration):
413 413 self.device.status = 3
414 414 self.module_status = ''.join(status)
415 415 self.save()
416 for u in User.objects.all():
417 u.profile.abs_active = self
418 u.save()
416
419 417 return True
420 418
421 419
@@ -250,7 +250,7 def send_beam(request, id_conf, id_beam):
250 250
251 251 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
252 252
253 abs = request.user.profile.abs_active
253 abs = Configuration.objects.filter(pk=conf.device.conf_active).first()
254 254 if abs<>conf:
255 255 url = '#' if abs is None else abs.get_absolute_url()
256 256 label = 'None' if abs is None else abs.label
@@ -75,10 +75,10 DEV_TYPES = (
75 75
76 76 EXP_STATES = (
77 77 (0,'Error'), #RED
78 (1,'Configured'), #BLUE
78 (1,'Cancelled'), #YELLOW
79 79 (2,'Running'), #GREEN
80 (3,'Scheduled'), #YELLOW
81 (4,'Not Configured'), #WHITE
80 (3,'Scheduled'), #BLUE
81 (4,'Unknown'), #WHITE
82 82 )
83 83
84 84 CONF_TYPES = (
@@ -89,7 +89,6 CONF_TYPES = (
89 89 class Profile(models.Model):
90 90 user = models.OneToOneField(User, on_delete=models.CASCADE)
91 91 theme = models.CharField(max_length=30, default='spacelab')
92 abs_active = models.ForeignKey('Configuration', null=True, blank=True, verbose_name='Current ABS')
93 92
94 93
95 94 @receiver(post_save, sender=User)
@@ -137,6 +136,7 class Device(models.Model):
137 136 port_address = models.PositiveSmallIntegerField(default=2000)
138 137 description = models.TextField(blank=True, null=True)
139 138 status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES)
139 conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration')
140 140
141 141 class Meta:
142 142 db_table = 'db_devices'
@@ -423,7 +423,6 class Experiment(models.Model):
423 423 ABS-CGS-DDS-RC-JARS
424 424 '''
425 425
426 result = 2
427 426 confs = []
428 427 allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence')
429 428 rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix]
@@ -434,18 +433,16 class Experiment(models.Model):
434 433 confs.append(conf)
435 434 else:
436 435 confs = allconfs
437 #Only Configured Devices.
438 for conf in confs:
439 if conf.device.status in (0, 4):
440 result = 0
441 return result
436
437 try:
442 438 for conf in confs:
443 439 conf.stop_device()
444 440 conf.write_device()
445 441 conf.start_device()
446 time.sleep(1)
447
448 return result
442 time.sleep(0.1)
443 except:
444 return 0
445 return 2
449 446
450 447
451 448 def stop(self):
@@ -454,18 +451,14 class Experiment(models.Model):
454 451 DDS-JARS-RC-CGS-ABS
455 452 '''
456 453
457 result = 1
458
459 454 confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence')
460 455 confs=confs.exclude(device__device_type__name='cgs')
456 try:
461 457 for conf in confs:
462 if conf.device.status in (0, 4):
463 result = 0
464 continue
465 458 conf.stop_device()
466
467 return result
468
459 except:
460 return 0
461 return 1
469 462
470 463 def get_status(self):
471 464
@@ -494,11 +487,11 class Experiment(models.Model):
494 487 if self.status == 0:
495 488 color = "danger"
496 489 elif self.status == 1:
497 color = "info"
490 color = "warning"
498 491 elif self.status == 2:
499 492 color = "success"
500 493 elif self.status == 3:
501 color = "warning"
494 color = "info"
502 495
503 496 return color
504 497
@@ -37,7 +37,11
37 37 <table class="table table-bordered">
38 38 <tr>
39 39 <th>Status</th>
40 {% if dev_conf.pk == dev_conf.device.conf_active %}
40 41 <td class="text-{{dev_conf.device.status_color}}"><strong> {% if dev_conf.device.device_type.name == 'abs' %} {{connected_modules}} {% else %} {{dev_conf.device.get_status_display}}{% endif %}</strong></td>
42 {% else %}
43 <td class="text-info"><strong> Connected </strong></td>
44 {% endif %}
41 45 </tr>
42 46
43 47 {% for key in dev_conf_keys %}
@@ -67,7 +67,7
67 67 <i class="fa fa-3x fa-puzzle-piece"></i>
68 68 {%endif%}
69 69 <h4>{{item}}<br><small>{{item.device.ip_address}}</small>
70 {%if experiment.status == 3 %}
70 {%if item.pk != item.device.conf_active %}
71 71 <span class="label label-info">Configured</span>
72 72 {%else%}
73 73 <span class="label label-{{item.device.status_color}}">{{item.device.get_status_display}}</span>
@@ -1452,18 +1452,18 def dev_conf_status(request, id_conf):
1452 1452
1453 1453 conf = get_object_or_404(Configuration, pk=id_conf)
1454 1454
1455 if conf.device.device_type.name == 'abs':
1456 abs = request.user.profile.abs_active
1457 if abs<>conf:
1458 url = '#' if abs is None else abs.get_absolute_url()
1459 label = 'None' if abs is None else abs.label
1455 conf_active = Configuration.objects.filter(pk=conf.device.conf_active).first()
1456 if conf_active<>conf:
1457 url = '#' if conf_active is None else conf_active.get_absolute_url()
1458 label = 'None' if conf_active is None else conf_active.label
1460 1459 messages.warning(
1461 1460 request,
1462 mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format(
1461 mark_safe('The current configuration has not been written to device, the active configuration is <a href="{}">{}</a>'.format(
1463 1462 url,
1464 1463 label
1465 1464 ))
1466 1465 )
1466
1467 1467 return redirect(conf.get_absolute_url())
1468 1468
1469 1469 if conf.status_device():
@@ -1493,6 +1493,8 def dev_conf_write(request, id_conf):
1493 1493 conf = get_object_or_404(Configuration, pk=id_conf)
1494 1494
1495 1495 if conf.write_device():
1496 conf.device.conf_active = conf.pk
1497 conf.device.save()
1496 1498 messages.success(request, conf.message)
1497 1499 if has_been_modified(conf):
1498 1500 conf.clone(type=1, template=False)
@@ -1841,9 +1843,20 def radar_refresh(request, id_camp, id_radar):
1841 1843 campaign = get_object_or_404(Campaign, pk=id_camp)
1842 1844 experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments']
1843 1845
1844 for exp in experiments:
1845 exp.get_status()
1846 i = app.control.inspect()
1847 scheduled = i.scheduled().values[0]
1848 revoked = i.revoked().values[0]
1846 1849
1850 for exp in experiments:
1851 if exp.task in revoked:
1852 exp.status = 1
1853 elif exp.task in [t['request']['id'] for t in scheduled if 'task_start' in t['request']['name']]:
1854 exp.status = 2
1855 elif exp.task in [t['request']['id'] for t in scheduled if 'task_stop' in t['request']['name']]:
1856 exp.status = 3
1857 else:
1858 exp.status = 4
1859 exp.save()
1847 1860 return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
1848 1861
1849 1862
General Comments 0
You need to be logged in to leave comments. Login now