Search in sources :

Example 16 with WorkflowContext

use of org.apache.inlong.manager.workflow.WorkflowContext in project incubator-inlong by apache.

the class EventListenerServiceImpl method triggerTaskEvent.

@Override
public void triggerTaskEvent(Integer taskId, TaskEvent taskEvent) {
    WorkflowContext context = workflowContextBuilder.buildContextForTask(taskId, WorkflowAction.fromTaskEvent(taskEvent));
    workflowEventNotifier.getTaskEventNotifier().notify(taskEvent, context);
}
Also used : WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext)

Example 17 with WorkflowContext

use of org.apache.inlong.manager.workflow.WorkflowContext in project incubator-inlong by apache.

the class WorkflowQueryServiceImpl method getBriefFromProcessEntity.

private WorkflowBriefDTO getBriefFromProcessEntity(WorkflowProcessEntity processEntity) {
    WorkflowProcess process = definitionRepository.get(processEntity.getName());
    if (process == null) {
        return null;
    }
    Map<String, TaskStatus> nameStatusMap = this.getTaskNameStatusMap(processEntity);
    ElementDTO elementDTO = new ElementDTO();
    StartEvent startEvent = process.getStartEvent();
    elementDTO.setName(startEvent.getName());
    elementDTO.setDisplayName(startEvent.getDisplayName());
    WorkflowContext context = WorkflowBeanUtils.buildContext(process, processEntity);
    addNext(startEvent, elementDTO, context, nameStatusMap);
    WorkflowBriefDTO briefDTO = new WorkflowBriefDTO();
    briefDTO.setName(process.getName());
    briefDTO.setDisplayName(process.getDisplayName());
    briefDTO.setType(process.getType());
    briefDTO.setStartEvent(elementDTO);
    return briefDTO;
}
Also used : WorkflowBriefDTO(org.apache.inlong.manager.common.pojo.workflow.WorkflowBriefDTO) ElementDTO(org.apache.inlong.manager.common.pojo.workflow.ElementDTO) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) StartEvent(org.apache.inlong.manager.workflow.definition.StartEvent) TaskStatus(org.apache.inlong.manager.common.enums.TaskStatus) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Example 18 with WorkflowContext

use of org.apache.inlong.manager.workflow.WorkflowContext in project incubator-inlong by apache.

the class EndEventProcessor method complete.

@Override
public boolean complete(WorkflowContext context) {
    WorkflowProcessEntity processEntity = context.getProcessEntity();
    List<WorkflowTaskEntity> tasks = taskEntityMapper.selectByProcess(processEntity.getId(), TaskStatus.PENDING);
    // If there are unfinished tasks, the process cannot be ended
    if (!CollectionUtils.isEmpty(tasks)) {
        log.warn("have pending task, end event not execute");
        return true;
    }
    WorkflowContext.ActionContext actionContext = context.getActionContext();
    processEntity.setStatus(getProcessStatus(actionContext.getAction()).name());
    processEntity.setEndTime(new Date());
    processEntityMapper.update(processEntity);
    processEventNotifier.notify(mapToEvent(actionContext.getAction()), context);
    return true;
}
Also used : WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) Date(java.util.Date)

Example 19 with WorkflowContext

use of org.apache.inlong.manager.workflow.WorkflowContext in project incubator-inlong by apache.

the class ServiceTaskProcessor method complete.

@Override
public boolean complete(WorkflowContext context) {
    WorkflowContext.ActionContext actionContext = context.getActionContext();
    Preconditions.checkTrue(SUPPORT_ACTIONS.contains(actionContext.getAction()), "serviceTask not support action: " + actionContext.getAction());
    WorkflowTaskEntity workflowTaskEntity = actionContext.getTaskEntity();
    Preconditions.checkTrue(ALLOW_COMPLETE_STATE.contains(TaskStatus.valueOf(workflowTaskEntity.getStatus())), "task status should allow complete");
    try {
        this.taskEventNotifier.notify(TaskEvent.COMPLETE, context);
        completeTaskEntity(actionContext, workflowTaskEntity, TaskStatus.COMPLETED);
        return true;
    } catch (Exception e) {
        completeTaskEntity(actionContext, workflowTaskEntity, TaskStatus.FAILED);
        this.taskEventNotifier.notify(TaskEvent.FAIL, context);
        this.processEventNotifier.notify(ProcessEvent.FAIL, context);
        return false;
    }
}
Also used : WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)

Example 20 with WorkflowContext

use of org.apache.inlong.manager.workflow.WorkflowContext in project incubator-inlong by apache.

the class ProcessEventNotifier method notify.

@Override
public void notify(String listenerName, boolean forceSync, WorkflowContext sourceContext) {
    final WorkflowContext context = sourceContext.clone();
    WorkflowProcess process = context.getProcess();
    Optional.ofNullable(this.eventListenerManager.listener(listenerName)).ifPresent(logableNotify(forceSync, context));
    Optional.ofNullable(process.listener(listenerName)).ifPresent(logableNotify(forceSync, context));
}
Also used : WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Aggregations

WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)37 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)15 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)13 Test (org.junit.Test)11 ProcessResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessResponse)9 WorkflowResult (org.apache.inlong.manager.common.pojo.workflow.WorkflowResult)9 ServiceTask (org.apache.inlong.manager.workflow.definition.ServiceTask)9 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)8 UpdateGroupProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm)8 TaskEventListener (org.apache.inlong.manager.workflow.event.task.TaskEventListener)8 WorkflowTaskEntity (org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)7 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)7 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)6 List (java.util.List)4 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)4 MockPlugin (org.apache.inlong.manager.service.mocks.MockPlugin)4 WorkflowServiceImplTest (org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest)4 Collectors (java.util.stream.Collectors)3 SneakyThrows (lombok.SneakyThrows)3 WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)3