Search in sources :

Example 1 with Element

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

the class ProcessorExecutorImpl method executeSkipAndNext.

private void executeSkipAndNext(Element element, WorkflowContext context) {
    if (!(element instanceof SkippableElement)) {
        throw new WorkflowException("element not instance of skip element " + element.getDisplayName());
    }
    if (!(element instanceof NextableElement)) {
        throw new WorkflowException("element not instance of nextable element " + element.getDisplayName());
    }
    ElementProcessor processor = this.getProcessor(element.getClass());
    if (!(processor instanceof SkipableElementProcessor)) {
        throw new WorkflowException("element processor not instance of skip processor " + element.getDisplayName());
    }
    // Execute skip logic
    SkipableElementProcessor skipableProcessor = (SkipableElementProcessor) processor;
    skipableProcessor.skip(element, context);
    // Execute next
    context.getActionContext().setAction(((NextableElement) element).defaultNextAction());
    List<Element> nextElements = processor.next(element, context);
    nextElements.forEach(next -> executeStart(next, context));
}
Also used : SkipableElementProcessor(org.apache.inlong.manager.workflow.processor.SkipableElementProcessor) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) SkippableElement(org.apache.inlong.manager.workflow.definition.SkippableElement) SkippableElement(org.apache.inlong.manager.workflow.definition.SkippableElement) ElementProcessor(org.apache.inlong.manager.workflow.processor.ElementProcessor) SkipableElementProcessor(org.apache.inlong.manager.workflow.processor.SkipableElementProcessor)

Example 2 with Element

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

the class ProcessorExecutorImpl method executeComplete.

@Override
public void executeComplete(Element element, WorkflowContext context) {
    ElementProcessor processor = this.getProcessor(element.getClass());
    context.setCurrentElement(element);
    boolean completed = processor.complete(context);
    if (!completed) {
        return;
    }
    List<Element> nextElements = processor.next(element, context);
    nextElements.forEach(next -> executeStart(next, context));
}
Also used : Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) SkippableElement(org.apache.inlong.manager.workflow.definition.SkippableElement) ElementProcessor(org.apache.inlong.manager.workflow.processor.ElementProcessor) SkipableElementProcessor(org.apache.inlong.manager.workflow.processor.SkipableElementProcessor)

Example 3 with Element

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

the class WorkflowQueryServiceImpl method addNext.

private void addNext(NextableElement nextableElement, ElementDTO elementDTO, WorkflowContext context, Map<String, TaskStatus> nameToStatusMap) {
    for (Element element : nextableElement.getNextList(context)) {
        ElementDTO nextElement = new ElementDTO();
        nextElement.setName(element.getName());
        nextElement.setDisplayName(element.getDisplayName());
        if (element instanceof UserTask) {
            nextElement.setApprovers(((UserTask) element).getApproverAssign().assign(context));
            nextElement.setStatus(nameToStatusMap.get(element.getName()));
        }
        elementDTO.getNext().add(nextElement);
        if (!(element instanceof NextableElement)) {
            continue;
        }
        addNext((NextableElement) element, nextElement, context, nameToStatusMap);
    }
}
Also used : NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) ElementDTO(org.apache.inlong.manager.common.pojo.workflow.ElementDTO) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) UserTask(org.apache.inlong.manager.workflow.definition.UserTask)

Example 4 with Element

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

the class AbstractNextableElementProcessor method next.

@Override
public List<Element> next(T element, WorkflowContext context) {
    WorkflowContext.ActionContext actionContext = context.getActionContext();
    List<Element> nextElements = element.getNextList(actionContext.getAction(), context);
    Preconditions.checkNotEmpty(nextElements, "not found next element ");
    Element endEvent = nextElements.stream().filter(EndEvent.class::isInstance).findFirst().orElse(null);
    if (endEvent == null) {
        return nextElements;
    }
    List<Element> notEndEventElements = nextElements.stream().filter(ele -> !(ele instanceof EndEvent)).collect(Collectors.toList());
    if (CollectionUtils.isEmpty(notEndEventElements)) {
        return Collections.singletonList(endEvent);
    }
    throw new WorkflowException("process definition error, find endEvent and not endEvent at the same time");
}
Also used : List(java.util.List) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent) Preconditions(org.apache.inlong.manager.common.util.Preconditions) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) CollectionUtils(org.springframework.util.CollectionUtils) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent)

Example 5 with Element

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

the class LogableEventListener method buildEventLog.

protected WorkflowEventLogEntity buildEventLog(WorkflowContext context) {
    WorkflowProcessEntity workflowProcessEntity = context.getProcessEntity();
    Element currentElement = context.getCurrentElement();
    WorkflowEventLogEntity logEntity = new WorkflowEventLogEntity();
    logEntity.setProcessId(workflowProcessEntity.getId());
    logEntity.setProcessName(workflowProcessEntity.getName());
    logEntity.setProcessDisplayName(workflowProcessEntity.getDisplayName());
    logEntity.setInlongGroupId(context.getProcessForm().getInlongGroupId());
    logEntity.setElementName(currentElement.getName());
    logEntity.setElementDisplayName(currentElement.getDisplayName());
    logEntity.setEventType(event().getClass().getSimpleName());
    logEntity.setEvent(event().name());
    logEntity.setListener(eventListener.name());
    logEntity.setStatus(EventStatus.EXECUTING.getStatus());
    logEntity.setAsync(async() ? 1 : 0);
    logEntity.setIp(NetworkUtils.getLocalIp());
    logEntity.setStartTime(new Date());
    return logEntity;
}
Also used : Element(org.apache.inlong.manager.workflow.definition.Element) WorkflowEventLogEntity(org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) Date(java.util.Date)

Aggregations

Element (org.apache.inlong.manager.workflow.definition.Element)5 NextableElement (org.apache.inlong.manager.workflow.definition.NextableElement)4 WorkflowException (org.apache.inlong.manager.common.exceptions.WorkflowException)2 SkippableElement (org.apache.inlong.manager.workflow.definition.SkippableElement)2 ElementProcessor (org.apache.inlong.manager.workflow.processor.ElementProcessor)2 SkipableElementProcessor (org.apache.inlong.manager.workflow.processor.SkipableElementProcessor)2 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ElementDTO (org.apache.inlong.manager.common.pojo.workflow.ElementDTO)1 Preconditions (org.apache.inlong.manager.common.util.Preconditions)1 WorkflowEventLogEntity (org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity)1 WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)1 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)1 EndEvent (org.apache.inlong.manager.workflow.definition.EndEvent)1 UserTask (org.apache.inlong.manager.workflow.definition.UserTask)1 CollectionUtils (org.springframework.util.CollectionUtils)1