Exemple #1
0
def taskdetail_get(td_id):
    """Gets a TaskDetail with matching td_id, if it exists"""
    # Try to get the TaskDetail
    try:
        ld_td = taskdetails[td_id]
    # Raise NotFound exception if it is not there
    except KeyError:
        raise exception.NotFound("No TaskDetail found with id "
                                 "%s." % (td_id, ))

    # Acquire a read lock
    with ld_td.acquire_lock(read=True):
        # Get the Task this TaskDetail represents
        tsk = ld_td.task

        # Update TaskDetail to return
        retVal = taskdetail.TaskDetail(ld_td.name, tsk, ld_td.uuid)
        retVal.updated_at = ld_td.updated_at
        retVal.state = ld_td.state
        retVal.results = ld_td.results
        retVal.exception = ld_td.exception
        retVal.stacktrace = ld_td.stacktrace
        retVal.meta = ld_td.meta

    return retVal
Exemple #2
0
def _convert_td_to_external(td):
    # Convert from sqlalchemy model -> external model, this allows us
    # to change the internal sqlalchemy model easily by forcing a defined
    # interface (that isn't the sqlalchemy model itself).
    td_c = taskdetail.TaskDetail(td.name, uuid=td.uuid, backend='sqlalchemy')
    td_c.state = td.state
    td_c.results = td.results
    td_c.exception = td.exception
    td_c.stacktrace = td.stacktrace
    td_c.meta = td.meta
    td_c.version = td.version
    return td_c
Exemple #3
0
    def add_task(self, uuid, task_name):
        """Add the task to storage

        Task becomes known to storage by that name and uuid.
        Task state is set to PENDING.
        """
        # TODO(imelnikov): check that task with same uuid or
        #   task name does not exist
        td = taskdetail.TaskDetail(name=task_name, uuid=uuid)
        td.state = states.PENDING
        self._flowdetail.add(td)
        self._flowdetail.save()
        td.save()
    def test_sequential_flow_two_tasks_with_resumption(self):
        flow = lf.Flow('lf-2-r').add(
            TestTask(self.values, name='task1', provides='x1'),
            TestTask(self.values, name='task2', provides='x2'))

        # Create FlowDetail as if we already run task1
        fd = storage.temporary_flow_detail()
        td = taskdetail.TaskDetail(name='task1', uuid='42')
        td.state = states.SUCCESS
        td.results = 17
        fd.add(td)
        fd.save()
        td.save()

        engine = self._make_engine(flow, fd)
        engine.run()
        self.assertEquals(self.values, ['task2'])
        self.assertEquals(engine.storage.fetch_all(), {'x1': 17, 'x2': 5})
Exemple #5
0
    def test_logbook_add_task_detail(self):
        lb_id = uuidutils.generate_uuid()
        lb_name = 'lb-%s' % (lb_id)
        lb = logbook.LogBook(name=lb_name,
                             uuid=lb_id,
                             backend=self._get_backend())

        fd = flowdetail.FlowDetail('test', uuid=uuidutils.generate_uuid())
        td = taskdetail.TaskDetail("detail-1", uuid=uuidutils.generate_uuid())
        fd.add(td)
        lb.add(fd)
        lb.save()

        lb2 = logbook.load(lb_id, backend=self._get_backend())
        self.assertEquals(1, len(lb2))
        tasks = 0
        for fd in lb:
            tasks += len(fd)
        self.assertEquals(1, tasks)
Exemple #6
0
    def test_task_detail_save(self):
        lb_id = uuidutils.generate_uuid()
        lb_name = 'lb-%s' % (lb_id)
        lb = logbook.LogBook(name=lb_name,
                             uuid=lb_id,
                             backend=self._get_backend())

        fd = flowdetail.FlowDetail('test', uuid=uuidutils.generate_uuid())
        lb.add(fd)
        td = taskdetail.TaskDetail("detail-1", uuid=uuidutils.generate_uuid())
        fd.add(td)

        # Ensure we can't save it since its owning logbook hasn't been
        # saved.
        self.assertRaises(exc.NotFound, fd.save)
        self.assertRaises(exc.NotFound, td.save)

        # Ok now we should be able to save it
        lb.save()
        fd.save()
        td.save()
    def test_taskdetail_save(self):
        # Create a generic taskdetail to save
        td_id = uuidutils.generate_uuid()
        td_name = 'td-%s' % (td_id)
        tsk = self.tsks[0]
        td = taskdetail.TaskDetail(td_name, tsk, td_id)

        # Save the generic taskdetail to the backend and record uuid/name
        b_api.taskdetail_save(td)
        self.td_names.append(td_name)
        self.td_ids.append(td_id)

        # Get the created taskdetail and check for default attributes
        actual = b_api.taskdetail_get(td_id)

        self.assertIsNotNone(actual)
        self.assertIsNone(actual.state)
        self.assertIsNone(actual.results)
        self.assertIsNone(actual.exception)
        self.assertIsNone(actual.stacktrace)
        self.assertIsNone(actual.meta)

        # Change the generic taskdetail's attributes
        td.state = 'SUCCESS'
        td.exception = 'ERROR'
        td.stacktrace = 'STACKTRACE'
        td.meta = 'META'

        # Save the changed taskdetail
        b_api.taskdetail_save(td)

        # Get the updated taskdetail and check for updated attributes
        actual = b_api.taskdetail_get(td_id)

        self.assertEquals(actual.state, 'SUCCESS')
        self.assertIsNone(actual.results)
        self.assertEquals(actual.exception, 'ERROR')
        self.assertEquals(actual.stacktrace, 'STACKTRACE')
        self.assertEquals(actual.meta, 'META')
Exemple #8
0
def taskdetail_get(td_id):
    """Gets a TaskDetail with matching td_id, if it exists"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the TaskDetail model
        td = _taskdetail_get_model(td_id, session=session)

    # Create a generic type Task to return as part of the TaskDetail
    tsk = None

    # Create a generic type TaskDetail to return
    retVal = taskdetail.TaskDetail(td.name, tsk, td.taskdetail_id)
    # Update the TaskDetail to reflect the data in the database
    retVal.updated_at = td.updated_at
    retVal.state = td.state
    retVal.results = td.results
    retVal.exception = td.exception
    retVal.stacktrace = td.stacktrace
    retVal.meta = td.meta

    return retVal