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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations