Example #1
0
    def _update_parent_instance(cls, instance):
        subtasks = instance.subtasks
        if len(subtasks):
            data = dict()

            if all(
                    map(lambda s: s.status == consts.TASK_STATUSES.ready,
                        subtasks)):

                data['status'] = consts.TASK_STATUSES.ready
                data['progress'] = 100
                data['message'] = u'\n'.join(
                    map(lambda s: s.message,
                        filter(lambda s: s.message is not None, subtasks)))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            elif any(
                    map(lambda s: s.status == consts.TASK_STATUSES.error,
                        subtasks)):
                for subtask in subtasks:
                    if subtask.status not in (consts.TASK_STATUSES.error,
                                              consts.TASK_STATUSES.ready):
                        subtask.status = consts.TASK_STATUSES.error
                        subtask.progress = 100
                        subtask.message = "Task aborted"

                data['status'] = consts.TASK_STATUSES.error
                data['progress'] = 100
                data['message'] = u'\n'.join(list(set(map(
                    lambda s: (s.message or ""), filter(
                        lambda s: (
                            s.status == consts.TASK_STATUSES.error and not
                            # TODO(aroma): make this check less ugly
                            s.message == "Task aborted"
                        ), subtasks)))))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            elif instance.status == consts.TASK_STATUSES.pending and any(
                    map(
                        lambda s: s.status in
                        (consts.TASK_STATUSES.running, consts.TASK_STATUSES.
                         ready), subtasks)):
                instance.status = consts.TASK_STATUSES.running

            else:
                subtasks_with_progress = filter(
                    lambda s: s.progress is not None, subtasks)
                if subtasks_with_progress:
                    instance.progress = \
                        TaskHelper.calculate_parent_task_progress(
                            subtasks_with_progress
                        )
                else:
                    instance.progress = 0
Example #2
0
    def _update_parent_instance(cls, instance):
        subtasks = instance.subtasks
        if len(subtasks):
            data = dict()

            if all(map(lambda s: s.status == consts.TASK_STATUSES.ready,
                       subtasks)):

                data['status'] = consts.TASK_STATUSES.ready
                data['progress'] = 100
                data['message'] = u'\n'.join(map(
                    lambda s: s.message, filter(
                        lambda s: s.message is not None, subtasks)))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            elif any(map(lambda s: s.status == consts.TASK_STATUSES.error,
                         subtasks)):
                for subtask in subtasks:
                    if subtask.status not in (consts.TASK_STATUSES.error,
                                              consts.TASK_STATUSES.ready):
                        subtask.status = consts.TASK_STATUSES.error
                        subtask.progress = 100
                        subtask.message = "Task aborted"

                data['status'] = consts.TASK_STATUSES.error
                data['progress'] = 100
                data['message'] = u'\n'.join(list(set(map(
                    lambda s: (s.message or ""), filter(
                        lambda s: (
                            s.status == consts.TASK_STATUSES.error and not
                            # TODO(aroma): make this check less ugly
                            s.message == "Task aborted"
                        ), subtasks)))))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            elif instance.status == consts.TASK_STATUSES.pending and any(
                    map(lambda s: s.status in (consts.TASK_STATUSES.running,
                                               consts.TASK_STATUSES.ready),
                        subtasks)):
                instance.status = consts.TASK_STATUSES.running

            else:
                subtasks_with_progress = filter(
                    lambda s: s.progress is not None,
                    subtasks
                )
                if subtasks_with_progress:
                    instance.progress = \
                        TaskHelper.calculate_parent_task_progress(
                            subtasks_with_progress
                        )
                else:
                    instance.progress = 0
    def simulate_running_deployment(self, deploy_task, progress=42):
        """To exclude race condition errors in the tests we simulate deployment

        :param deploy_task: deploy task object
        :param progress: task progress value
        """
        # Updating deploy task
        TaskHelper.update_action_log(deploy_task)
        deploy_task.status = consts.TASK_STATUSES.running
        deploy_task.progress = progress
        # Updating action log
        action_log = objects.ActionLog.get_by_kwargs(task_uuid=deploy_task.uuid, action_name=deploy_task.name)
        action_log.end_timestamp = None

        self.db.commit()
    def _update_parent_instance(cls, instance):
        subtasks = instance.subtasks
        if len(subtasks):
            data = dict()

            if all(map(lambda s: s.status == 'ready', subtasks)):

                data['status'] = 'ready'
                data['progress'] = 100
                data['message'] = u'\n'.join(map(
                    lambda s: s.message, filter(
                        lambda s: s.message is not None, subtasks)))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            elif any(map(lambda s: s.status in ('error',), subtasks)):
                for subtask in subtasks:
                    if not subtask.status in ('error', 'ready'):
                        subtask.status = 'error'
                        subtask.progress = 100
                        subtask.message = 'Task aborted'

                data['status'] = 'error'
                data['progress'] = 100
                data['message'] = u'\n'.join(list(set(map(
                    lambda s: (s.message or ""), filter(
                        lambda s: (
                            s.status == 'error' and not
                            # TODO: make this check less ugly
                            s.message == 'Task aborted'
                        ), subtasks)))))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            else:
                subtasks_with_progress = filter(
                    lambda s: s.progress is not None,
                    subtasks
                )
                if subtasks_with_progress:
                    instance.progress = \
                        TaskHelper.calculate_parent_task_progress(
                            subtasks_with_progress
                        )
                else:
                    instance.progress = 0
Example #5
0
    def _update_parent_instance(cls, instance):
        subtasks = instance.subtasks
        if len(subtasks):
            data = dict()

            if all(map(lambda s: s.status == 'ready', subtasks)):
                sort_subtasks = sorted(subtasks,
                                       key=lambda s: s.timestamp,
                                       reverse=False)
                data['status'] = 'ready'
                data['progress'] = 100
                data['message'] = u'\n'.join(
                    map(lambda s: s.message,
                        filter(lambda s: s.message is not None,
                               sort_subtasks)))
                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            elif any(map(lambda s: s.status in ('error', ), subtasks)):
                for subtask in subtasks:
                    if not subtask.status in ('error', 'ready'):
                        subtask.status = 'error'
                        subtask.progress = 100
                        subtask.message = 'Task aborted'

                data['status'] = 'error'
                data['progress'] = 100
                data['message'] = u'\n'.join(list(set(map(
                    lambda s: (s.message or ""), filter(
                        lambda s: (
                            s.status == 'error' and not
                            # TODO: make this check less ugly
                            s.message == 'Task aborted'
                        ), subtasks)))))

                cls.update(instance, data)
                TaskHelper.update_action_log(instance)

            else:
                subtasks_with_progress = filter(
                    lambda s: s.progress is not None, subtasks)
                if subtasks_with_progress:
                    instance.progress = \
                        TaskHelper.calculate_parent_task_progress(
                            subtasks_with_progress
                        )
                else:
                    instance.progress = 0
Example #6
0
    def simulate_running_deployment(self, deploy_task, progress=42):
        """To exclude race condition errors in the tests we simulate deployment

        :param deploy_task: deploy task object
        :param progress: task progress value
        """
        # Updating deploy task
        TaskHelper.update_action_log(deploy_task)
        deploy_task.status = consts.TASK_STATUSES.running
        deploy_task.progress = progress
        # Updating action log
        action_log = objects.ActionLog.get_by_kwargs(
            task_uuid=deploy_task.uuid, action_name=deploy_task.name)
        action_log.end_timestamp = None

        self.db.commit()
Example #7
0
    def update_recursively(cls, instance, data):
        logger.debug("Updating task: %s", instance.uuid)
        clean_data = cls._clean_data(data)
        super(Task, cls).update(instance, data)
        if instance.parent:
            parent = instance.parent
            siblings = parent.subtasks
            status = clean_data.get('status')
            if status == consts.TASK_STATUSES.ready:
                clean_data['progress'] = 100
                instance.progress = 100
                ready_siblings_count = sum(
                    x.status == consts.TASK_STATUSES.ready for x in siblings)
                if ready_siblings_count == len(siblings):
                    parent.status = consts.TASK_STATUSES.ready
            elif status == consts.TASK_STATUSES.error:
                parent.status = consts.TASK_STATUSES.error
                for s in siblings:
                    if s.status != consts.TASK_STATUSES.ready:
                        s.status = consts.TASK_STATUSES.error
                        s.progress = 100
                        s.message = "Task aborted"
                        clean_data['progress'] = 100
                        instance.progress = 100
                TaskHelper.update_action_log(parent)
            elif status == consts.TASK_STATUSES.running:
                parent.status = consts.TASK_STATUSES.running

            if 'progress' in clean_data:
                total_progress = sum(x.progress for x in siblings)
                parent.progress = total_progress // len(siblings)

            task_status = parent.status
        else:
            task_status = instance.status

        if not instance.dry_run:
            if task_status == consts.TASK_STATUSES.ready:
                cls._update_cluster_status(instance.cluster,
                                           consts.CLUSTER_STATUSES.operational,
                                           consts.NODE_STATUSES.ready)
            elif task_status == consts.TASK_STATUSES.error:
                cls._update_cluster_status(instance.cluster,
                                           consts.CLUSTER_STATUSES.error, None)

        db().flush()