예제 #1
0
    def get_queryset(self, *args, **kwargs):
        if docker_status():
            # https://huey.readthedocs.io/en/latest/api.html#Huey.pending
            # HUEY.pending() returns a list of task instances waiting to be run.
            # https://huey.readthedocs.io/en/latest/api.html#huey-object
            # Example hi.pending() result:
            # [storageadmin.views.rockon_helpers.rock_helpers.uninstall:
            # 7ce769d4-a468-4cd0-8706-c246d207e81c]
            # But for above task.name = "uninstall"
            hi = HUEY
            logger.debug("HUEY.pending() {}".format(hi.pending()))
            # List of pending rockon related tasks.
            pending_task_ids = [
                task.id for task in hi.pending() if task.name in
                ["start", "stop", "update", "install", "uninstall"]
            ]
            for item in hi.pending():
                logger.debug("Pending task name: {}, ID: {}".format(
                    item.name, item.id))
            logger.debug("PENDING TASK ID'S {}".format(pending_task_ids))
            # List of rockons with an associated active pending task.
            pending_rockon_ids = [
                rockon.id for rockon in RockOn.objects.all()
                if rockon.taskid in pending_task_ids
            ]
            logger.debug("PENDING ROCKON_ID'S {}".format(pending_rockon_ids))
            # https://huey.readthedocs.io/en/latest/api.html#Huey.all_results
            # HUEY.all_results()
            # dict of task-id to the serialized result data for all
            # key/value pairs in the result store.
            # https://huey.readthedocs.io/en/latest/api.html#Huey.__len__
            # HUEY.__len__ Return the number of items currently in the queue.

            # For all RockOns
            for ro in RockOn.objects.all():
                if ro.state == "installed":
                    # update current running status of installed rockons.
                    if ro.id not in pending_rockon_ids:
                        ro.status = rockon_status(ro)
                elif re.search("pending", ro.state) is not None:
                    if ro.id not in pending_rockon_ids:
                        logger.info(
                            ("Rockon ({}) state pending and no pending task: "
                             "assuming task is mid execution.").format(
                                 ro.name))
                    else:
                        logger.debug(
                            "Rockon ({}) state pending with pending task id {}."
                            .format(ro.name, ro.taskid))
                elif ro.state == "uninstall_failed":
                    ro.state = "installed"
                ro.save()
        return RockOn.objects.filter().order_by("name")
예제 #2
0
 def get_queryset(self, *args, **kwargs):
     if (docker_status()):
         pending_rids = {}
         failed_rids = {}
         for t in Task.objects.filter(
                 function_name__regex='rockon_helpers'):
             rid = pickle.loads(t.args)[0]
             if (t.retry_count == 0 and t.failed is not None):
                 failed_rids[rid] = t
             else:
                 pending_rids[rid] = t
         #Remove old failed attempts
         #@todo: we should prune all failed tasks of the past, not here though.
         for rid in pending_rids.keys():
             if (rid in failed_rids):
                 pt = pending_rids[rid]
                 ft = failed_rids[rid]
                 if (failed_rids[rid].created > pending_rids[rid].created):
                     #this should never be the case. pending tasks either
                     #succeed and get deleted or they are marked failed.
                     msg = ('Found a failed Task(%s) in the future of a '
                            'pending Task(%s).' % (ft.uuid, pt.uuid))
                     handle_exception(Exception(msg), self.request)
                 failed_rids[rid].delete()
                 logger.debug('deleted failed task')
                 del failed_rids[rid]
         for ro in RockOn.objects.all():
             if (ro.state == 'installed'):
                 # update current running status of installed rockons.
                 if (ro.id not in pending_rids):
                     ro.status = rockon_status(ro.name)
             elif (re.search('pending', ro.state) is not None):
                 if (ro.id in failed_rids):
                     #we update the status on behalf of the task runner
                     func_name = t.function_name.split('.')[-1]
                     ro.state = '%s_failed' % func_name
                 elif (ro.id not in pending_rids):
                     logger.error(
                         'Rockon(%s) is in pending state but there '
                         'is no pending or failed task for it. ' % ro.name)
                     ro.state = '%s_failed' % ro.state.split('_')[1]
                 else:
                     logger.debug('Rockon(%s) is in pending state' %
                                  ro.name)
             elif (ro.state == 'uninstall_failed'):
                 ro.state = 'installed'
             ro.save()
     return RockOn.objects.filter().order_by('name')
예제 #3
0
 def get_queryset(self, *args, **kwargs):
     if docker_status():
         pending_rids = {}
         failed_rids = {}
         for t in Task.objects.filter(
                 function_name__regex="rockon_helpers"):  # noqa E501
             rid = pickle.loads(t.args)[0]
             if t.retry_count == 0 and t.failed is not None:
                 failed_rids[rid] = t
             else:
                 pending_rids[rid] = t
         # Remove old failed attempts @todo: we should prune all failed
         # tasks of the past, not here though.
         for rid in pending_rids.keys():
             if rid in failed_rids:
                 pt = pending_rids[rid]
                 ft = failed_rids[rid]
                 if failed_rids[rid].created > pending_rids[rid].created:
                     # this should never be the case. pending tasks either
                     # succeed and get deleted or they are marked failed.
                     msg = ("Found a failed Task ({}) in the future of a "
                            "pending Task ({}).").format(ft.uuid, pt.uuid)
                     handle_exception(Exception(msg), self.request)
                 failed_rids[rid].delete()
                 del failed_rids[rid]
         for ro in RockOn.objects.all():
             if ro.state == "installed":
                 # update current running status of installed rockons.
                 if ro.id not in pending_rids:
                     ro.status = rockon_status(ro.name)
             elif re.search("pending", ro.state) is not None:
                 if ro.id in failed_rids:
                     # we update the status on behalf of the task runner
                     func_name = t.function_name.split(".")[-1]
                     ro.state = "%s_failed" % func_name
                 elif ro.id not in pending_rids:
                     logger.error(("Rockon ({}) is in pending state but "
                                   "there is no pending or failed task "
                                   "for it.").format(ro.name))
                     ro.state = "%s_failed" % ro.state.split("_")[1]
                 else:
                     logger.debug(
                         ("Rockon ({}) is in pending state.").format(
                             ro.name))
             elif ro.state == "uninstall_failed":
                 ro.state = "installed"
             ro.save()
     return RockOn.objects.filter().order_by("name")
예제 #4
0
 def get_queryset(self, *args, **kwargs):
     if (docker_status()):
         pending_rids = {}
         failed_rids = {}
         for t in Task.objects.filter(function_name__regex='rockon_helpers'):
             rid = pickle.loads(t.args)[0]
             if (t.retry_count == 0 and t.failed is not None):
                 failed_rids[rid] = t
             else:
                 pending_rids[rid] = t
         #Remove old failed attempts
         #@todo: we should prune all failed tasks of the past, not here though.
         for rid in pending_rids.keys():
             if (rid in failed_rids):
                 pt = pending_rids[rid]
                 ft = failed_rids[rid]
                 if (failed_rids[rid].created > pending_rids[rid].created):
                     #this should never be the case. pending tasks either
                     #succeed and get deleted or they are marked failed.
                     msg = ('Found a failed Task(%s) in the future of a '
                            'pending Task(%s).' % (ft.uuid, pt.uuid))
                     handle_exception(Exception(msg), self.request)
                 failed_rids[rid].delete()
                 logger.debug('deleted failed task')
                 del failed_rids[rid]
         for ro in RockOn.objects.all():
             if (ro.state == 'installed'):
                 # update current running status of installed rockons.
                 if (ro.id not in pending_rids):
                     ro.status = rockon_status(ro.name)
             elif (re.search('pending', ro.state) is not None):
                 if (ro.id in failed_rids):
                     #we update the status on behalf of the task runner
                     func_name = t.function_name.split('.')[-1]
                     ro.state = '%s_failed' % func_name
                 elif (ro.id not in pending_rids):
                     logger.error('Rockon(%s) is in pending state but there '
                                  'is no pending or failed task for it. '
                                  % ro.name)
                     ro.state = '%s_failed' % ro.state.split('_')[1]
                 else:
                     logger.debug('Rockon(%s) is in pending state' % ro.name)
             elif (ro.state == 'uninstall_failed'):
                 ro.state = 'installed'
             ro.save()
     return RockOn.objects.filter().order_by('name')
예제 #5
0
 def get_queryset(self, *args, **kwargs):
     if docker_status():
         pending_rids = {}
         failed_rids = {}
         for t in Task.objects.filter(function_name__regex="rockon_helpers"):
             rid = pickle.loads(t.args)[0]
             if t.retry_count == 0 and t.failed is not None:
                 failed_rids[rid] = t
             else:
                 pending_rids[rid] = t
         # Remove old failed attempts
         # @todo: we should prune all failed tasks of the past, not here though.
         for rid in pending_rids.keys():
             if rid in failed_rids:
                 pt = pending_rids[rid]
                 ft = failed_rids[rid]
                 if failed_rids[rid].created > pending_rids[rid].created:
                     # this should never be the case. pending tasks either
                     # succeed and get deleted or they are marked failed.
                     msg = "Found a failed Task(%s) in the future of a " "pending Task(%s)." % (ft.uuid, pt.uuid)
                     handle_exception(Exception(msg), self.request)
                 failed_rids[rid].delete()
                 logger.debug("deleted failed task")
                 del failed_rids[rid]
         for ro in RockOn.objects.all():
             if ro.state == "installed":
                 # update current running status of installed rockons.
                 if ro.id not in pending_rids:
                     ro.status = rockon_status(ro.name)
             elif re.search("pending", ro.state) is not None:
                 if ro.id in failed_rids:
                     # we update the status on behalf of the task runner
                     func_name = t.function_name.split(".")[-1]
                     ro.state = "%s_failed" % func_name
                 elif ro.id not in pending_rids:
                     logger.error(
                         "Rockon(%s) is in pending state but there "
                         "is no pending or failed task for it. " % ro.name
                     )
                     ro.state = "%s_failed" % ro.state.split("_")[1]
                 else:
                     logger.debug("Rockon(%s) is in pending state" % ro.name)
             elif ro.state == "uninstall_failed":
                 ro.state = "installed"
             ro.save()
     return RockOn.objects.filter().order_by("name")
예제 #6
0
 def get_queryset(self, *args, **kwargs):
     if (docker_status()):
         pending_rids = []
         for t in Task.objects.all():
             pending_rids.append(pickle.loads(t.args)[0])
         for ro in RockOn.objects.all():
             if (ro.state == 'installed'):
                 # update current running status of installed rockons.
                 ro.status = rockon_status(ro.name)
             elif (re.search('pending', ro.state) is not None and
                   ro.id not in pending_rids):
                 # reset rockons to their previosu state if they are stuck
                 # in a pending transition.
                 if (re.search('uninstall', ro.state) is not None):
                     ro.state = 'installed'
                 else:
                     ro.state = 'available'
             ro.save()
     return RockOn.objects.filter().order_by('-id')