Search in sources :

Example 6 with WorkflowTask

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

the class WorkflowServiceImplTest method testStartCreatePulsarWorkflow.

@Test
public void testStartCreatePulsarWorkflow() {
    initGroupForm(Constant.MIDDLEWARE_PULSAR);
    mockTaskListenerFactory();
    WorkflowContext context = workflowEngine.processService().start(processName.name(), applicant, form);
    WorkflowResult result = WorkflowBeanUtils.result(context);
    ProcessResponse view = result.getProcessInfo();
    Assert.assertSame(view.getStatus(), ProcessStatus.COMPLETED);
    WorkflowProcess process = context.getProcess();
    WorkflowTask task = process.getTaskByName("initMQ");
    Assert.assertTrue(task instanceof ServiceTask);
    Assert.assertEquals(2, task.getNameToListenerMap().size());
    List<TaskEventListener> listeners = Lists.newArrayList(task.getNameToListenerMap().values());
    Assert.assertTrue(listeners.get(0) instanceof CreatePulsarGroupTaskListener);
    Assert.assertTrue(listeners.get(1) instanceof CreatePulsarResourceTaskListener);
}
Also used : WorkflowResult(org.apache.inlong.manager.common.pojo.workflow.WorkflowResult) ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) TaskEventListener(org.apache.inlong.manager.workflow.event.task.TaskEventListener) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) CreatePulsarGroupTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreatePulsarGroupTaskListener) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) ProcessResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessResponse) CreatePulsarResourceTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreatePulsarResourceTaskListener) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest)

Example 7 with WorkflowTask

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

the class ProcessorExecutorImpl method executeStart.

@Override
public void executeStart(Element element, WorkflowContext context) {
    ElementProcessor processor = this.getProcessor(element.getClass());
    context.setCurrentElement(element);
    // If the current component needs to be skipped, proceed directly to the next one
    if (isSkipCurrentElement(element, context)) {
        executeSkipAndNext(element, context);
        return;
    }
    processor.create(element, context);
    if (processor.pendingForAction(context)) {
        return;
    }
    // If it is a continuous task execution transaction isolation
    if (element instanceof WorkflowTask) {
        transactionHelper.execute(executeCompleteInTransaction(element, context), TransactionDefinition.PROPAGATION_NESTED);
        return;
    }
    executeComplete(element, context);
}
Also used : ElementProcessor(org.apache.inlong.manager.workflow.processor.ElementProcessor) SkipableElementProcessor(org.apache.inlong.manager.workflow.processor.SkipableElementProcessor) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask)

Example 8 with WorkflowTask

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

the class DataSourceListenerTest method testFrozenSource.

@Test
public void testFrozenSource() {
    groupInfo = initGroupForm("PULSAR");
    groupInfo.setStatus(GroupState.CONFIG_SUCCESSFUL.getCode());
    groupService.update(groupInfo.genRequest(), OPERATOR);
    final int sourceId = createBinlogSource(groupInfo);
    streamSourceService.updateStatus(groupInfo.getInlongGroupId(), null, SourceState.SOURCE_NORMAL.getCode(), OPERATOR);
    form = new UpdateGroupProcessForm();
    form.setGroupInfo(groupInfo);
    form.setOperateType(OperateType.SUSPEND);
    WorkflowContext context = workflowEngine.processService().start(ProcessName.SUSPEND_GROUP_PROCESS.name(), applicant, form);
    WorkflowResult result = WorkflowBeanUtils.result(context);
    ProcessResponse response = result.getProcessInfo();
    Assert.assertSame(response.getStatus(), ProcessStatus.COMPLETED);
    WorkflowProcess process = context.getProcess();
    WorkflowTask task = process.getTaskByName("stopSource");
    Assert.assertTrue(task instanceof ServiceTask);
    SourceResponse sourceResponse = streamSourceService.get(sourceId, SourceType.BINLOG.toString());
    Assert.assertSame(SourceState.forCode(sourceResponse.getStatus()), SourceState.TO_BE_ISSUED_FROZEN);
}
Also used : UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) WorkflowResult(org.apache.inlong.manager.common.pojo.workflow.WorkflowResult) ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) SourceResponse(org.apache.inlong.manager.common.pojo.source.SourceResponse) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) ProcessResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessResponse) Test(org.junit.Test) WorkflowServiceImplTest(org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest)

Example 9 with WorkflowTask

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

the class WorkflowFormParserUtils method parseTaskForm.

/**
 * Parse the task form in JSON string format into a WorkflowTask instance
 */
public static <T extends TaskForm> T parseTaskForm(WorkflowTaskEntity workflowTaskEntity, WorkflowProcess process) throws FormParseException {
    Preconditions.checkNotNull(workflowTaskEntity, "workflowTaskEntity cannot be null");
    Preconditions.checkNotNull(process, "process cannot be null");
    if (StringUtils.isEmpty(workflowTaskEntity.getFormData())) {
        return null;
    }
    WorkflowTask task = process.getTaskByName(workflowTaskEntity.getName());
    Preconditions.checkNotNull(task, "user task not exist " + workflowTaskEntity.getName());
    Preconditions.checkTrue(task instanceof UserTask, "task should be userTask " + workflowTaskEntity.getName());
    UserTask userTask = (UserTask) task;
    try {
        JavaType javaType = JsonUtils.MAPPER.constructType(userTask.getFormClass());
        return JsonUtils.parse(workflowTaskEntity.getFormData(), javaType);
    } catch (Exception e) {
        log.error("task form parse failed, form is: {}", workflowTaskEntity.getFormData(), e);
        throw new FormParseException("task form parse failed");
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) FormParseException(org.apache.inlong.manager.common.exceptions.FormParseException) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) FormParseException(org.apache.inlong.manager.common.exceptions.FormParseException)

Example 10 with WorkflowTask

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

the class TaskEventNotifier method notify.

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

Aggregations

WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)18 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)13 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)13 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 Test (org.junit.Test)9 UpdateGroupProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm)7 TaskEventListener (org.apache.inlong.manager.workflow.event.task.TaskEventListener)7 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)5 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)5 MockPlugin (org.apache.inlong.manager.service.mocks.MockPlugin)4 WorkflowServiceImplTest (org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest)4 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)3 WorkflowApproverEntity (org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)3 WorkflowTaskEntity (org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)3 SourceResponse (org.apache.inlong.manager.common.pojo.source.SourceResponse)2 InlongStreamInfo (org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)2 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)2 WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)2