Beispiel #1
0
 def workload_create(self, task_uuid, subtask_uuid, name, description,
                     position, runner, runner_type, hooks, contexts, sla,
                     args):
     workload = models.Workload(task_uuid=task_uuid,
                                subtask_uuid=subtask_uuid,
                                name=name,
                                description=description,
                                position=position,
                                runner=runner,
                                runner_type=runner_type,
                                hooks=hooks,
                                contexts=contexts or {},
                                sla=sla,
                                args=args)
     workload.save()
     return workload
Beispiel #2
0
 def workload_create(self, task_uuid, subtask_uuid, key):
     workload = models.Workload(task_uuid=task_uuid,
                                subtask_uuid=subtask_uuid)
     workload.update({
         "name": key["name"],
         "position": key["pos"],
         "runner": key["kw"]["runner"],
         "runner_type": key["kw"]["runner"]["type"],
         "context": key["kw"].get("context", {}),
         "sla": key["kw"].get("sla", {}),
         "args": key["kw"].get("args", {}),
         "context_execution": {},
         "statistics": {},
     })
     workload.save()
     return workload
Beispiel #3
0
 def workload_create(self, task_uuid, subtask_uuid, name, description,
                     position, runner, runner_type, hooks, context, sla,
                     args, context_execution, statistics):
     workload = models.Workload(task_uuid=task_uuid,
                                subtask_uuid=subtask_uuid,
                                name=name,
                                description=description,
                                position=position,
                                runner=runner,
                                runner_type=runner_type,
                                hooks=hooks,
                                context=context,
                                sla=sla,
                                args=args,
                                context_execution=context_execution,
                                statistics=statistics)
     workload.save()
     return workload
Beispiel #4
0
    def task_result_create(self, task_uuid, key, data):
        raw_data = data.get("raw", [])
        iter_count = len(raw_data)

        failed_iter_count = 0
        max_duration = 0
        min_duration = 0

        success = True

        for d in raw_data:
            if d.get("error"):
                failed_iter_count += 1

            duration = d.get("duration", 0)

            if duration > max_duration:
                max_duration = duration

            if min_duration and min_duration > duration:
                min_duration = duration

        sla = data.get("sla", [])
        # TODO(ikhudoshyn): if no SLA was specified and there are
        # failed iterations is it success?
        # NOTE(ikhudoshyn): we call it 'pass_sla'
        # for the sake of consistency with other models
        # so if no SLAs were specified, then we assume pass_sla == True
        success = all([s.get("success") for s in sla])

        now = timeutils.utcnow()
        delta = dt.timedelta(seconds=data.get("full_duration", 0))
        start = now - delta

        subtask = models.Subtask()
        subtask.update({"task_uuid": task_uuid})
        subtask.save()

        workload = models.Workload()
        workload.update({
            "task_uuid": task_uuid,
            "subtask_uuid": subtask.uuid,
            "name": key["name"],
            "position": key["pos"],
            "runner": key["kw"]["runner"],
            "runner_type": key["kw"]["runner"]["type"],
            "context": key["kw"].get("context", {}),
            "hooks": data.get("hooks", []),
            "sla": key["kw"].get("sla", {}),
            "args": key["kw"].get("args", {}),
            "sla_results": {"sla": sla},
            "context_execution": {},
            "load_duration": data.get("load_duration", 0),
            "full_duration": data.get("full_duration", 0),
            "min_duration": min_duration,
            "max_duration": max_duration,
            "total_iteration_count": iter_count,
            "failed_iteration_count": failed_iter_count,
            # TODO(ikhudoshyn)
            "start_time": start,
            "statistics": {},
            "pass_sla": success
        })
        workload.save()

        workload_data = models.WorkloadData()
        workload_data.update({
            "task_uuid": task_uuid,
            "workload_uuid": workload.uuid,
            "chunk_order": 0,
            "iteration_count": iter_count,
            "failed_iteration_count": failed_iter_count,
            "chunk_data": {"raw": raw_data},
            # TODO(ikhudoshyn)
            "chunk_size": 0,
            "compressed_chunk_size": 0,
            "started_at": start,
            "finished_at": now
        })

        # TODO(ikhudoshyn): create workload and workload data in
        # one transaction
        workload_data.save()

        # TODO(ikhudoshyn): if pass_sla is False,
        # then update task's and subtask's pass_sla

        # TODO(ikhudoshyn): update task.task_duration
        # and subtask.duration

        return self._make_old_task_result(workload, workload_data)