Search in sources :

Example 6 with TaskEventListener

use of org.apache.inlong.manager.workflow.event.task.TaskEventListener in project incubator-inlong by apache.

the class EventListenerServiceImpl method executeTaskEventListener.

@Override
public void executeTaskEventListener(Integer taskId, String listener) {
    WorkflowContext context = workflowContextBuilder.buildContextForTask(taskId, null);
    TaskEventListener eventListener = getTaskEventListener((WorkflowTask) context.getCurrentElement(), listener);
    context.getActionContext().setAction(WorkflowAction.fromTaskEvent(eventListener.event()));
    workflowEventNotifier.getTaskEventNotifier().notify(listener, true, context);
}
Also used : TaskEventListener(org.apache.inlong.manager.workflow.event.task.TaskEventListener) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext)

Example 7 with TaskEventListener

use of org.apache.inlong.manager.workflow.event.task.TaskEventListener in project incubator-inlong by apache.

the class WorkflowServiceImplTest method testStopProcess.

@Test
public void testStopProcess() {
    InlongGroupInfo groupInfo = initGroupForm(Constant.MIDDLEWARE_PULSAR);
    groupInfo.setStatus(GroupState.CONFIG_SUCCESSFUL.getCode());
    groupService.update(groupInfo.genRequest(), OPERATOR);
    groupInfo.setStatus(GroupState.SUSPENDED.getCode());
    groupService.update(groupInfo.genRequest(), OPERATOR);
    UpdateGroupProcessForm form = new UpdateGroupProcessForm();
    form.setGroupInfo(groupInfo);
    form.setOperateType(OperateType.DELETE);
    taskListenerFactory.acceptPlugin(new MockPlugin());
    WorkflowContext context = workflowEngine.processService().start(ProcessName.DELETE_GROUP_PROCESS.name(), applicant, form);
    WorkflowResult result = WorkflowBeanUtils.result(context);
    ProcessResponse view = result.getProcessInfo();
    Assert.assertSame(view.getStatus(), ProcessStatus.COMPLETED);
    WorkflowProcess process = context.getProcess();
    WorkflowTask deleteSort = process.getTaskByName("deleteSort");
    Assert.assertTrue(deleteSort instanceof ServiceTask);
    List<TaskEventListener> listeners = Lists.newArrayList(deleteSort.getNameToListenerMap().values());
    Assert.assertEquals(1, listeners.size());
    Assert.assertTrue(listeners.get(0) instanceof MockDeleteSortListener);
    WorkflowTask deleteSourceTask = process.getTaskByName("deleteSource");
    Assert.assertTrue(deleteSourceTask instanceof ServiceTask);
    listeners = Lists.newArrayList(deleteSourceTask.getNameToListenerMap().values());
    Assert.assertEquals(2, listeners.size());
}
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) TaskEventListener(org.apache.inlong.manager.workflow.event.task.TaskEventListener) MockPlugin(org.apache.inlong.manager.service.mocks.MockPlugin) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) 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) MockDeleteSortListener(org.apache.inlong.manager.service.mocks.MockDeleteSortListener) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest)

Example 8 with TaskEventListener

use of org.apache.inlong.manager.workflow.event.task.TaskEventListener in project incubator-inlong by apache.

the class WorkflowServiceImplTest method testStartCreateTubeWorkflow.

@Test
public void testStartCreateTubeWorkflow() {
    initGroupForm(Constant.MIDDLEWARE_TUBE);
    mockTaskListenerFactory();
    WorkflowContext context = workflowEngine.processService().start(processName.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("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 CreateTubeTopicTaskListener);
    Assert.assertTrue(listeners.get(1) instanceof CreateTubeGroupTaskListener);
}
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) CreateTubeTopicTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreateTubeTopicTaskListener) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) CreateTubeGroupTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreateTubeGroupTaskListener) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) ProcessResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessResponse) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest)

Example 9 with TaskEventListener

use of org.apache.inlong.manager.workflow.event.task.TaskEventListener in project incubator-inlong by apache.

the class EventListenerServiceImpl method getTaskEventListener.

private TaskEventListener getTaskEventListener(WorkflowTask task, String listenerName) {
    TaskEventListener listener = task.listener(listenerName);
    if (listener != null) {
        return listener;
    }
    listener = listenerManagerFactory.getTaskListenerManager().listener(listenerName);
    Preconditions.checkNotNull(listener, "task listener not exist with name: " + listenerName);
    return listener;
}
Also used : TaskEventListener(org.apache.inlong.manager.workflow.event.task.TaskEventListener)

Aggregations

TaskEventListener (org.apache.inlong.manager.workflow.event.task.TaskEventListener)9 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)8 ProcessResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessResponse)7 WorkflowResult (org.apache.inlong.manager.common.pojo.workflow.WorkflowResult)7 ServiceTask (org.apache.inlong.manager.workflow.definition.ServiceTask)7 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)7 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)7 Test (org.junit.Test)7 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)5 UpdateGroupProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm)5 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)5 MockPlugin (org.apache.inlong.manager.service.mocks.MockPlugin)4 InlongStreamInfo (org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)2 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)2 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)2 WorkflowServiceImplTest (org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest)2 MockDeleteSortListener (org.apache.inlong.manager.service.mocks.MockDeleteSortListener)1 MockRestartSortListener (org.apache.inlong.manager.service.mocks.MockRestartSortListener)1 MockStopSortListener (org.apache.inlong.manager.service.mocks.MockStopSortListener)1 CreatePulsarGroupTaskListener (org.apache.inlong.manager.service.thirdparty.mq.CreatePulsarGroupTaskListener)1