Search in sources :

Example 1 with WorkflowContext

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

the class CreateHiveTableListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) {
    GroupResourceProcessForm form = (GroupResourceProcessForm) context.getProcessForm();
    String groupId = form.getInlongGroupId();
    log.info("begin to create hive table for groupId={}", groupId);
    List<SinkForSortDTO> configList = sinkMapper.selectAllConfig(groupId, null);
    List<SinkForSortDTO> needCreateList = configList.stream().filter(sinkForSortDTO -> sinkForSortDTO.getEnableCreateResource() == 1).collect(Collectors.toList());
    if (hiveTableOperator == null) {
        hiveTableOperator = (IHiveTableOperator) SpringContextUtils.getBean(IHiveTableOperator.BEAN_NAME, DefaultHiveTableOperator.class.getName());
    }
    hiveTableOperator.createHiveResource(groupId, needCreateList);
    String result = "success to create hive table for group [" + groupId + "]";
    log.info(result);
    return ListenerResult.success(result);
}
Also used : StreamSinkEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper) SinkForSortDTO(org.apache.inlong.manager.common.pojo.sink.SinkForSortDTO) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) SpringContextUtils(org.apache.inlong.manager.service.utils.SpringContextUtils) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) List(java.util.List) ListenerResult(org.apache.inlong.manager.workflow.event.ListenerResult) Slf4j(lombok.extern.slf4j.Slf4j) SinkOperateListener(org.apache.inlong.manager.workflow.event.task.SinkOperateListener) TaskEvent(org.apache.inlong.manager.workflow.event.task.TaskEvent) Service(org.springframework.stereotype.Service) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) SinkForSortDTO(org.apache.inlong.manager.common.pojo.sink.SinkForSortDTO)

Example 2 with WorkflowContext

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

the class CreateSortConfigListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws Exception {
    LOGGER.info("Create sort config for context={}", context);
    ProcessForm form = context.getProcessForm();
    if (form instanceof UpdateGroupProcessForm) {
        UpdateGroupProcessForm updateGroupProcessForm = (UpdateGroupProcessForm) form;
        OperateType operateType = updateGroupProcessForm.getOperateType();
        if (operateType == OperateType.SUSPEND || operateType == OperateType.DELETE) {
            return ListenerResult.success();
        }
    }
    InlongGroupInfo groupInfo = this.getGroupInfo(form);
    String groupId = groupInfo.getInlongGroupId();
    if (StringUtils.isEmpty(groupId)) {
        LOGGER.warn("GroupId is null for context={}", context);
        return ListenerResult.success();
    }
    List<SinkResponse> sinkResponseList = streamSinkService.listSink(groupId, null);
    if (CollectionUtils.isEmpty(sinkResponseList)) {
        LOGGER.warn("Sink not found by groupId={}", groupId);
        return ListenerResult.success();
    }
    Map<String, DataFlowInfo> dataFlowInfoMap = sinkResponseList.stream().map(sink -> {
        DataFlowInfo flowInfo = commonOperateService.createDataFlow(groupInfo, sink);
        return Pair.of(sink.getInlongStreamId(), flowInfo);
    }).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
    String dataFlows = OBJECT_MAPPER.writeValueAsString(dataFlowInfoMap);
    InlongGroupExtInfo extInfo = new InlongGroupExtInfo();
    extInfo.setInlongGroupId(groupId);
    extInfo.setKeyName(InlongGroupSettings.DATA_FLOW);
    extInfo.setKeyValue(dataFlows);
    if (groupInfo.getExtList() == null) {
        groupInfo.setExtList(Lists.newArrayList());
    }
    upsertDataFlow(groupInfo, extInfo);
    return ListenerResult.success();
}
Also used : ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) CommonOperateService(org.apache.inlong.manager.service.CommonOperateService) StreamSinkService(org.apache.inlong.manager.service.sink.StreamSinkService) TaskEvent(org.apache.inlong.manager.workflow.event.task.TaskEvent) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper) Map(java.util.Map) OperateType(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) InlongGroupSettings(org.apache.inlong.manager.common.settings.InlongGroupSettings) Logger(org.slf4j.Logger) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) Collectors(java.util.stream.Collectors) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) ListenerResult(org.apache.inlong.manager.workflow.event.ListenerResult) Component(org.springframework.stereotype.Component) List(java.util.List) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) SortOperateListener(org.apache.inlong.manager.workflow.event.task.SortOperateListener) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) OperateType(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo)

Example 3 with WorkflowContext

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

the class DisableZkForSortTest method testCreateSortConfigInCreateWorkflow.

@Test
public void testCreateSortConfigInCreateWorkflow() {
    InlongGroupInfo groupInfo = initGroupForm("PULSAR");
    groupInfo.setStatus(GroupState.CONFIG_SUCCESSFUL.getCode());
    groupInfo.setZookeeperEnabled(0);
    groupService.update(groupInfo.genRequest(), OPERATOR);
    InlongStreamInfo streamInfo = createStreamInfo(groupInfo);
    createHiveSink(streamInfo);
    createKafkaSource(streamInfo);
    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("initSort");
    Assert.assertTrue(task instanceof ServiceTask);
    Assert.assertEquals(1, task.getNameToListenerMap().size());
    List<TaskEventListener> listeners = Lists.newArrayList(task.getNameToListenerMap().values());
    Assert.assertTrue(listeners.get(0) instanceof CreateSortConfigListener);
    ProcessForm form = context.getProcessForm();
    InlongGroupInfo curGroupRequest = ((GroupResourceProcessForm) form).getGroupInfo();
    Assert.assertTrue(curGroupRequest.getExtList().size() == 1);
}
Also used : WorkflowResult(org.apache.inlong.manager.common.pojo.workflow.WorkflowResult) ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) ProcessResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessResponse) TaskEventListener(org.apache.inlong.manager.workflow.event.task.TaskEventListener) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo) WorkflowServiceImplTest(org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest) Test(org.junit.Test)

Example 4 with WorkflowContext

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

the class DisableZkForSortTest method testCreateSortConfigInUpdateWorkflow.

@Test
public void testCreateSortConfigInUpdateWorkflow() {
    InlongGroupInfo groupInfo = initGroupForm("PULSAR");
    groupInfo.setZookeeperEnabled(0);
    groupInfo.setStatus(GroupState.CONFIG_SUCCESSFUL.getCode());
    groupService.update(groupInfo.genRequest(), OPERATOR);
    InlongStreamInfo streamInfo = createStreamInfo(groupInfo);
    createHiveSink(streamInfo);
    createKafkaSource(streamInfo);
    UpdateGroupProcessForm form = new UpdateGroupProcessForm();
    form.setGroupInfo(groupInfo);
    form.setOperateType(OperateType.SUSPEND);
    taskListenerFactory.acceptPlugin(new MockPlugin());
    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("stopSort");
    Assert.assertTrue(task instanceof ServiceTask);
    Assert.assertEquals(2, task.getNameToListenerMap().size());
    List<TaskEventListener> listeners = Lists.newArrayList(task.getNameToListenerMap().values());
    Assert.assertTrue(listeners.get(1) instanceof CreateSortConfigListener);
    ProcessForm currentProcessForm = context.getProcessForm();
    InlongGroupInfo curGroupRequest = ((UpdateGroupProcessForm) currentProcessForm).getGroupInfo();
    Assert.assertTrue(curGroupRequest.getExtList().size() == 1);
}
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) MockPlugin(org.apache.inlong.manager.service.mocks.MockPlugin) ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) ProcessResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessResponse) TaskEventListener(org.apache.inlong.manager.workflow.event.task.TaskEventListener) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) InlongStreamInfo(org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo) WorkflowServiceImplTest(org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest) Test(org.junit.Test)

Example 5 with WorkflowContext

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

the class ServiceTaskListenerFactoryTest method testGetQueueOperateListener.

@Test
public void testGetQueueOperateListener() {
    WorkflowContext context = new WorkflowContext();
    GroupResourceProcessForm processForm = new GroupResourceProcessForm();
    InlongGroupInfo groupInfo = new InlongGroupInfo();
    // check pulsar listener
    groupInfo.setMiddlewareType(Constant.MIDDLEWARE_PULSAR);
    processForm.setGroupInfo(groupInfo);
    context.setProcessForm(processForm);
    List<QueueOperateListener> queueOperateListeners = serviceTaskListenerFactory.getQueueOperateListener(context);
    Assert.assertEquals(2, queueOperateListeners.size());
    Assert.assertTrue(queueOperateListeners.get(0) instanceof CreatePulsarResourceTaskListener);
    Assert.assertTrue(queueOperateListeners.get(1) instanceof CreatePulsarGroupTaskListener);
    // check tube listener
    groupInfo.setMiddlewareType(Constant.MIDDLEWARE_TUBE);
    queueOperateListeners = serviceTaskListenerFactory.getQueueOperateListener(context);
    Assert.assertEquals(2, queueOperateListeners.size());
    Assert.assertTrue(queueOperateListeners.get(0) instanceof CreateTubeTopicTaskListener);
    Assert.assertTrue(queueOperateListeners.get(1) instanceof CreateTubeGroupTaskListener);
}
Also used : QueueOperateListener(org.apache.inlong.manager.workflow.event.task.QueueOperateListener) CreateTubeTopicTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreateTubeTopicTaskListener) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) CreatePulsarGroupTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreatePulsarGroupTaskListener) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) CreateTubeGroupTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreateTubeGroupTaskListener) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) CreatePulsarResourceTaskListener(org.apache.inlong.manager.service.thirdparty.mq.CreatePulsarResourceTaskListener) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest)

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