Example #1
0
def request_pause(ac_ex_db):
    wf_ac_ex_id = str(ac_ex_db.id)
    LOG.info('[%s] Processing pause request for workflow.', wf_ac_ex_id)

    wf_ex_dbs = wf_db_access.WorkflowExecution.query(
        action_execution=str(ac_ex_db.id))

    if not wf_ex_dbs:
        raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))

    if len(wf_ex_dbs) > 1:
        raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))

    wf_ex_db = wf_ex_dbs[0]

    if wf_ex_db.status in states.COMPLETED_STATES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    conductor = deserialize_conductor(wf_ex_db)

    if conductor.get_workflow_state() in states.COMPLETED_STATES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    conductor.request_workflow_state(states.PAUSED)

    # Write the updated workflow state and task flow to the database.
    wf_ex_db.status = conductor.get_workflow_state()
    wf_ex_db.flow = conductor.flow.serialize()
    wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)

    LOG.info('[%s] Completed processing pause request for workflow.',
             wf_ac_ex_id)

    return wf_ex_db
Example #2
0
def request_resume(ac_ex_db):
    wf_ac_ex_id = str(ac_ex_db.id)
    LOG.info('[%s] Processing resume request for workflow.', wf_ac_ex_id)

    wf_ex_dbs = wf_db_access.WorkflowExecution.query(
        action_execution=str(ac_ex_db.id))

    if not wf_ex_dbs:
        raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))

    if len(wf_ex_dbs) > 1:
        raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))

    wf_ex_db = wf_ex_dbs[0]

    if wf_ex_db.status in statuses.COMPLETED_STATUSES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    if wf_ex_db.status in statuses.RUNNING_STATUSES:
        msg = '[%s] Workflow execution "%s" is not resumed because it is already active.'
        LOG.info(msg, wf_ac_ex_id, str(wf_ex_db.id))
        return

    conductor = deserialize_conductor(wf_ex_db)

    if conductor.get_workflow_status() in statuses.COMPLETED_STATUSES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    if conductor.get_workflow_status() in statuses.RUNNING_STATUSES:
        msg = '[%s] Workflow execution "%s" is not resumed because it is already active.'
        LOG.info(msg, wf_ac_ex_id, str(wf_ex_db.id))
        return

    conductor.request_workflow_status(statuses.RESUMING)

    # Write the updated workflow status and task flow to the database.
    wf_ex_db.status = conductor.get_workflow_status()
    wf_ex_db.state = conductor.workflow_state.serialize()
    wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)
    wf_ex_db = wf_db_access.WorkflowExecution.get_by_id(str(wf_ex_db.id))

    # Publish status change.
    wf_db_access.WorkflowExecution.publish_status(wf_ex_db)

    LOG.info('[%s] Completed processing resume request for workflow.',
             wf_ac_ex_id)

    return wf_ex_db
Example #3
0
def request_cancellation(ac_ex_db):
    wf_ac_ex_id = str(ac_ex_db.id)
    LOG.info('[%s] Processing cancelation request for workflow.', wf_ac_ex_id)

    wf_ex_dbs = wf_db_access.WorkflowExecution.query(
        action_execution=str(ac_ex_db.id))

    if not wf_ex_dbs:
        raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))

    if len(wf_ex_dbs) > 1:
        raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))

    wf_ex_db = wf_ex_dbs[0]

    if wf_ex_db.status in statuses.COMPLETED_STATUSES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    conductor = deserialize_conductor(wf_ex_db)

    if conductor.get_workflow_status() in statuses.COMPLETED_STATUSES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    conductor.request_workflow_status(statuses.CANCELED)

    # Write the updated workflow status and task flow to the database.
    wf_ex_db.status = conductor.get_workflow_status()
    wf_ex_db.state = conductor.workflow_state.serialize()
    wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)

    # Cascade the cancellation up to the root of the workflow.
    root_ac_ex_db = ac_svc.get_root_execution(ac_ex_db)

    if root_ac_ex_db != ac_ex_db and root_ac_ex_db.status not in ac_const.LIVEACTION_CANCEL_STATES:
        LOG.info('[%s] Cascading cancelation request to parent workflow.',
                 wf_ac_ex_id)
        root_lv_ac_db = lv_db_access.LiveAction.get(
            id=root_ac_ex_db.liveaction['id'])
        ac_svc.request_cancellation(root_lv_ac_db, None)

    LOG.debug('[%s] %s', wf_ac_ex_id, conductor.serialize())
    LOG.info('[%s] Completed processing cancelation request for workflow.',
             wf_ac_ex_id)

    return wf_ex_db
Example #4
0
def request_resume(ac_ex_db):
    wf_ex_dbs = wf_db_access.WorkflowExecution.query(
        action_execution=str(ac_ex_db.id))

    if not wf_ex_dbs:
        raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))

    if len(wf_ex_dbs) > 1:
        raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))

    wf_ex_db = wf_ex_dbs[0]

    if wf_ex_db.status in states.COMPLETED_STATES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    if wf_ex_db.status in states.RUNNING_STATES:
        raise wf_exc.WorkflowExecutionIsRunningException(str(wf_ex_db.id))

    conductor = deserialize_conductor(wf_ex_db)

    if conductor.get_workflow_state() in states.COMPLETED_STATES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    if conductor.get_workflow_state() in states.RUNNING_STATES:
        raise wf_exc.WorkflowExecutionIsRunningException(str(wf_ex_db.id))

    conductor.set_workflow_state(states.RESUMING)

    # Write the updated workflow state and task flow to the database.
    wf_ex_db.status = conductor.get_workflow_state()
    wf_ex_db.flow = conductor.flow.serialize()
    wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)

    # Publish state change.
    wf_db_access.WorkflowExecution.publish_status(wf_ex_db)

    return wf_ex_db
Example #5
0
def request_cancellation(ac_ex_db):
    wf_ex_dbs = wf_db_access.WorkflowExecution.query(
        action_execution=str(ac_ex_db.id))

    if not wf_ex_dbs:
        raise wf_exc.WorkflowExecutionNotFoundException(str(ac_ex_db.id))

    if len(wf_ex_dbs) > 1:
        raise wf_exc.AmbiguousWorkflowExecutionException(str(ac_ex_db.id))

    wf_ex_db = wf_ex_dbs[0]

    if wf_ex_db.status in states.COMPLETED_STATES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    conductor = deserialize_conductor(wf_ex_db)

    if conductor.get_workflow_state() in states.COMPLETED_STATES:
        raise wf_exc.WorkflowExecutionIsCompletedException(str(wf_ex_db.id))

    conductor.set_workflow_state(states.CANCELED)

    # Write the updated workflow state and task flow to the database.
    wf_ex_db.status = conductor.get_workflow_state()
    wf_ex_db.flow = conductor.flow.serialize()
    wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False)

    # Cascade the cancellation up to the root of the workflow.
    root_ac_ex_db = ac_svc.get_root_execution(ac_ex_db)

    if root_ac_ex_db != ac_ex_db and root_ac_ex_db.status not in ac_const.LIVEACTION_CANCEL_STATES:
        root_lv_ac_db = lv_db_access.LiveAction.get(
            id=root_ac_ex_db.liveaction['id'])
        ac_svc.request_cancellation(root_lv_ac_db, None)

    return wf_ex_db