Search in sources :

Example 11 with ServiceTask

use of org.apache.inlong.manager.workflow.definition.ServiceTask 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 12 with ServiceTask

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

the class ServiceTaskProcessor method saveTaskEntity.

private WorkflowTaskEntity saveTaskEntity(ServiceTask serviceTask, WorkflowContext context) {
    WorkflowProcessEntity workflowProcessEntity = context.getProcessEntity();
    List<String> approvers = ApproverAssign.DEFAULT_SYSTEM_APPROVER.assign(context);
    WorkflowTaskEntity taskEntity = new WorkflowTaskEntity();
    taskEntity.setType(ServiceTask.class.getSimpleName());
    taskEntity.setProcessId(workflowProcessEntity.getId());
    taskEntity.setProcessName(context.getProcess().getName());
    taskEntity.setProcessDisplayName(context.getProcess().getDisplayName());
    taskEntity.setName(serviceTask.getName());
    taskEntity.setDisplayName(serviceTask.getDisplayName());
    taskEntity.setApplicant(workflowProcessEntity.getApplicant());
    taskEntity.setApprovers(StringUtils.join(approvers, WorkflowTaskEntity.APPROVERS_DELIMITER));
    taskEntity.setStatus(TaskStatus.PENDING.name());
    taskEntity.setStartTime(new Date());
    taskEntityMapper.insert(taskEntity);
    Preconditions.checkNotNull(taskEntity.getId(), "task saved failed");
    return taskEntity;
}
Also used : ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) Date(java.util.Date)

Example 13 with ServiceTask

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

the class CreateStreamWorkflowDefinition method defineProcess.

@Override
public WorkflowProcess defineProcess() {
    // Configuration process
    WorkflowProcess process = new WorkflowProcess();
    process.addListener(initGroupListener);
    process.addListener(streamFailedProcessListener);
    process.addListener(streamCompleteProcessListener);
    process.setType("Inlong stream access resource creation");
    process.setName(getProcessName().name());
    process.setDisplayName(getProcessName().getDisplayName());
    process.setFormClass(GroupResourceProcessForm.class);
    process.setVersion(1);
    process.setHidden(1);
    // Start node
    StartEvent startEvent = new StartEvent();
    process.setStartEvent(startEvent);
    // End node
    EndEvent endEvent = new EndEvent();
    process.setEndEvent(endEvent);
    ServiceTask createPulsarTopicTask = new ServiceTask();
    createPulsarTopicTask.setSkipResolver(c -> {
        GroupResourceProcessForm form = (GroupResourceProcessForm) c.getProcessForm();
        String mqType = form.getGroupInfo().getMiddlewareType();
        if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
            return false;
        }
        log.warn("no need to create pulsar topic for groupId={}, streamId={}, as the middlewareType={}", form.getInlongGroupId(), form.getInlongStreamId(), mqType);
        return true;
    });
    createPulsarTopicTask.setName("createPulsarTopic");
    createPulsarTopicTask.setDisplayName("Stream-CreatePulsarTopic");
    createPulsarTopicTask.addListener(createPulsarTopicTaskListener);
    process.addTask(createPulsarTopicTask);
    ServiceTask createPulsarSubscriptionGroupTask = new ServiceTask();
    createPulsarSubscriptionGroupTask.setSkipResolver(c -> {
        GroupResourceProcessForm form = (GroupResourceProcessForm) c.getProcessForm();
        String mqType = form.getGroupInfo().getMiddlewareType();
        if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
            return false;
        }
        log.warn("no need to create pulsar subscription for groupId={}, streamId={}, as the middlewareType={}", form.getInlongGroupId(), form.getInlongStreamId(), mqType);
        return true;
    });
    createPulsarSubscriptionGroupTask.setName("createPulsarSubscription");
    createPulsarSubscriptionGroupTask.setDisplayName("Stream-CreatePulsarSubscription");
    createPulsarSubscriptionGroupTask.addListener(createPulsarGroupTaskListener);
    process.addTask(createPulsarSubscriptionGroupTask);
    ServiceTask createHiveTableTask = new ServiceTask();
    createHiveTableTask.setSkipResolver(c -> {
        GroupResourceProcessForm form = (GroupResourceProcessForm) c.getProcessForm();
        String groupId = form.getInlongGroupId();
        String streamId = form.getInlongStreamId();
        List<String> dsForHive = sinkService.getExistsStreamIdList(groupId, Constant.SINK_HIVE, Collections.singletonList(streamId));
        if (CollectionUtils.isEmpty(dsForHive)) {
            log.warn("inlong group [{}] adn inlong stream [{}] does not have sink, skip create hive table", groupId, streamId);
            return true;
        }
        return false;
    });
    createHiveTableTask.setName("createHiveTable");
    createHiveTableTask.setDisplayName("Stream-CreateHiveTable");
    createHiveTableTask.addListener(createHiveTableListener);
    process.addTask(createHiveTableTask);
    ServiceTask pushSortConfig = new ServiceTask();
    pushSortConfig.setName("pushSortConfig");
    pushSortConfig.setDisplayName("Stream-PushSortConfig");
    pushSortConfig.addListener(pushSortConfigListener);
    process.addTask(pushSortConfig);
    startEvent.addNext(createPulsarTopicTask);
    createPulsarTopicTask.addNext(createPulsarSubscriptionGroupTask);
    createPulsarSubscriptionGroupTask.addNext(createHiveTableTask);
    createHiveTableTask.addNext(pushSortConfig);
    pushSortConfig.addNext(endEvent);
    return process;
}
Also used : ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) StartEvent(org.apache.inlong.manager.workflow.definition.StartEvent) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)

Example 14 with ServiceTask

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

the class RestartGroupWorkflowDefinition method defineProcess.

@Override
public WorkflowProcess defineProcess() {
    // Configuration process
    WorkflowProcess process = new WorkflowProcess();
    process.addListener(updateGroupListener);
    process.addListener(updateGroupCompleteListener);
    process.setType("Group Resource Restart");
    process.setName(getProcessName().name());
    process.setDisplayName(getProcessName().getDisplayName());
    process.setFormClass(UpdateGroupProcessForm.class);
    process.setVersion(1);
    process.setHidden(1);
    // Start node
    StartEvent startEvent = new StartEvent();
    process.setStartEvent(startEvent);
    // restart sort
    ServiceTask restartSortTask = new ServiceTask();
    restartSortTask.setName("restartSort");
    restartSortTask.setDisplayName("Group-RestartSort");
    restartSortTask.addServiceTaskType(ServiceTaskType.RESTART_SORT);
    restartSortTask.addListenerProvider(serviceTaskListenerFactory);
    process.addTask(restartSortTask);
    // restart datasource
    ServiceTask restartDataSourceTask = new ServiceTask();
    restartDataSourceTask.setName("restartSource");
    restartDataSourceTask.setDisplayName("Group-RestartSource");
    restartDataSourceTask.addServiceTaskType(ServiceTaskType.RESTART_SOURCE);
    restartDataSourceTask.addListenerProvider(serviceTaskListenerFactory);
    process.addTask(restartDataSourceTask);
    // End node
    EndEvent endEvent = new EndEvent();
    process.setEndEvent(endEvent);
    startEvent.addNext(restartSortTask);
    restartSortTask.addNext(restartDataSourceTask);
    restartDataSourceTask.addNext(endEvent);
    return process;
}
Also used : ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) StartEvent(org.apache.inlong.manager.workflow.definition.StartEvent) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Example 15 with ServiceTask

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

the class DataSourceListenerTest method testRestartSource.

@Test
public void testRestartSource() {
    // testFrozenSource();
    groupInfo = initGroupForm("PULSAR");
    groupInfo.setStatus(GroupState.CONFIG_SUCCESSFUL.getCode());
    groupService.update(groupInfo.genRequest(), OPERATOR);
    groupInfo.setStatus(GroupState.SUSPENDED.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.RESTART);
    WorkflowContext context = workflowEngine.processService().start(ProcessName.RESTART_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("restartSource");
    Assert.assertTrue(task instanceof ServiceTask);
    SourceResponse sourceResponse = streamSourceService.get(sourceId, SourceType.BINLOG.toString());
    Assert.assertSame(SourceState.forCode(sourceResponse.getStatus()), SourceState.TO_BE_ISSUED_ACTIVE);
}
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)

Aggregations

ServiceTask (org.apache.inlong.manager.workflow.definition.ServiceTask)15 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)14 ProcessResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessResponse)9 WorkflowResult (org.apache.inlong.manager.common.pojo.workflow.WorkflowResult)9 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)9 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)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 EndEvent (org.apache.inlong.manager.workflow.definition.EndEvent)5 StartEvent (org.apache.inlong.manager.workflow.definition.StartEvent)5 MockPlugin (org.apache.inlong.manager.service.mocks.MockPlugin)4 WorkflowServiceImplTest (org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest)4 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)3 SourceResponse (org.apache.inlong.manager.common.pojo.source.SourceResponse)2 InlongStreamInfo (org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo)2 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)2 Date (java.util.Date)1