Exemplo n.º 1
0
def create_task_update_model(status):
    """Creates and returns a task update model for the given Mesos task status

    :param status: The task status
    :type status: :class:`mesos_pb2.TaskStatus`
    :returns: The task update model
    :rtype: :class:`job.models.TaskUpdate`
    """

    task_update = TaskUpdate()
    task_update.task_id = get_status_task_id(status)
    task_update.job_exe_id = RunningJobExecution.get_job_exe_id(
        task_update.task_id)
    task_update.status = get_status_state(status)
    task_update.timestamp = get_status_timestamp(status)
    task_update.source = get_status_source(status)
    task_update.reason = get_status_reason(status)
    task_update.message = get_status_message(status)

    return task_update
Exemplo n.º 2
0
def create_task_update_model(status):
    """Creates and returns a task update model for the given Mesos task status

    :param status: The task status in TaskStatus JSON format
    :type status: dict
    :returns: The task update model
    :rtype: :class:`job.models.TaskUpdate`
    """

    task_update = TaskUpdate()
    task_update.task_id = get_status_task_id(status)
    task_update.status = get_status_state(status)
    task_update.timestamp = get_status_timestamp(status)
    task_update.source = get_status_source(status)
    task_update.reason = get_status_reason(status)
    task_update.message = get_status_message(status)

    return task_update
Exemplo n.º 3
0
def create_task_update_model(status):
    """Creates and returns a task update model for the given Mesos task status

    :param status: The task status
    :type status: :class:`mesos_pb2.TaskStatus`
    :returns: The task update model
    :rtype: :class:`job.models.TaskUpdate`
    """

    task_update = TaskUpdate()
    task_update.task_id = get_status_task_id(status)
    task_update.job_exe_id = RunningJobExecution.get_job_exe_id(task_update.task_id)
    task_update.status = get_status_state(status)
    task_update.timestamp = get_status_timestamp(status)
    task_update.source = get_status_source(status)
    task_update.reason = get_status_reason(status)
    task_update.message = get_status_message(status)

    return task_update
Exemplo n.º 4
0
def create_task_status_update(task_id,
                              agent_id,
                              status,
                              when,
                              exit_code=None,
                              reason=None,
                              source=None,
                              message=None,
                              data=None):
    """Creates a job model for unit testing

    :param task_id: The unique ID of the task
    :type task_id: string
    :param agent_id: The agent ID for the task
    :type agent_id: string
    :param status: The status of the task
    :type status: string
    :param when: The timestamp of the update
    :type when: :class:`datetime.datetime`
    :param exit_code: The task's exit code
    :type exit_code: int
    :param reason: The reason
    :type reason: string
    :param source: The source
    :type source: string
    :param message: The message
    :type message: string
    :param data: The data dict
    :type data: dict
    :returns: The task status update
    :rtype: :class:`job.tasks.update.TaskStatusUpdate`
    """

    if data is None:
        data = {}

    task_update_model = TaskUpdate()
    task_update_model.task_id = task_id
    task_update_model.timestamp = when
    task_update_model.message = message
    task_update_model.source = source
    task_update_model.reason = reason
    update = TaskStatusUpdate(task_update_model, agent_id, data)
    update.status = status
    if exit_code is not None:
        update.exit_code = exit_code
    return update
Exemplo n.º 5
0
    def test_update_job_exe_dup(self):
        """Tests running the database update to remove job execution duplicates"""

        # Create jobs with duplicate job executions
        job_type = job_test_utils.create_job_type()
        job_1 = job_test_utils.create_job(job_type=job_type, num_exes=2)
        job_2 = job_test_utils.create_job(job_type=job_type, num_exes=3)
        job_3 = job_test_utils.create_job(job_type=job_type, num_exes=2)

        # Job 1
        job_exe_1 = job_test_utils.create_job_exe(job=job_1,
                                                  status='COMPLETED',
                                                  exe_num=1)
        job_exe_2 = job_test_utils.create_job_exe(job=job_1,
                                                  status='COMPLETED',
                                                  exe_num=1)
        job_exe_3 = job_test_utils.create_job_exe(job=job_1,
                                                  status='COMPLETED',
                                                  exe_num=2)
        job_exe_4 = job_test_utils.create_job_exe(job=job_1,
                                                  status='COMPLETED',
                                                  exe_num=2)

        # Job 2
        job_exe_5 = job_test_utils.create_job_exe(job=job_2,
                                                  status='COMPLETED',
                                                  exe_num=1)
        job_exe_6 = job_test_utils.create_job_exe(job=job_2,
                                                  status='COMPLETED',
                                                  exe_num=2)
        job_exe_7 = job_test_utils.create_job_exe(job=job_2,
                                                  status='COMPLETED',
                                                  exe_num=2)
        job_exe_8 = job_test_utils.create_job_exe(job=job_2,
                                                  status='COMPLETED',
                                                  exe_num=3)

        # Job 3
        job_exe_9 = job_test_utils.create_job_exe(job=job_3,
                                                  status='COMPLETED',
                                                  exe_num=1)

        # Create some task updates to make sure they get deleted as well
        task_updates = []
        task_updates.append(
            TaskUpdate(job_exe=job_exe_1, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_1, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_2, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_2, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_3, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_3, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_4, task_id='1234', status='foo'))
        task_updates.append(
            TaskUpdate(job_exe=job_exe_4, task_id='1234', status='foo'))
        TaskUpdate.objects.bulk_create(task_updates)

        # Run update
        updater = DatabaseUpdater()
        updater.update()

        expected_job_exe_ids = {
            job_exe_1.id, job_exe_3.id, job_exe_5.id, job_exe_6.id,
            job_exe_8.id, job_exe_9.id
        }
        actual_job_exe_ids = set()
        for job_exe in JobExecution.objects.all().only('id'):
            actual_job_exe_ids.add(job_exe.id)
        self.assertSetEqual(expected_job_exe_ids, actual_job_exe_ids)