haibo-duan commented on code in PR #4868:
URL: https://github.com/apache/inlong/pull/4868#discussion_r933953732
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sort/CreateSortConfigListener.java:
##########
@@ -18,96 +18,195 @@
package org.apache.inlong.manager.service.sort;
import com.google.common.collect.Lists;
-import org.apache.commons.collections.CollectionUtils;
+import com.google.common.collect.Maps;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.common.enums.DataTypeEnum;
import org.apache.inlong.manager.common.consts.InlongConstants;
+import org.apache.inlong.manager.common.enums.ClusterType;
import org.apache.inlong.manager.common.enums.GroupOperateType;
+import org.apache.inlong.manager.common.enums.MQType;
+import org.apache.inlong.manager.common.enums.SourceType;
import org.apache.inlong.manager.common.exceptions.WorkflowListenerException;
+import org.apache.inlong.manager.common.pojo.cluster.ClusterInfo;
+import org.apache.inlong.manager.common.pojo.cluster.pulsar.PulsarClusterInfo;
import org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo;
import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
import org.apache.inlong.manager.common.pojo.sink.StreamSink;
+import org.apache.inlong.manager.common.pojo.source.StreamSource;
+import org.apache.inlong.manager.common.pojo.source.kafka.KafkaSource;
+import org.apache.inlong.manager.common.pojo.source.pulsar.PulsarSource;
+import org.apache.inlong.manager.common.pojo.stream.InlongStreamInfo;
import
org.apache.inlong.manager.common.pojo.workflow.form.process.GroupResourceProcessForm;
+import org.apache.inlong.manager.service.cluster.InlongClusterService;
import org.apache.inlong.manager.service.sink.StreamSinkService;
-import org.apache.inlong.manager.service.sort.util.DataFlowUtils;
+import org.apache.inlong.manager.service.sort.util.ExtractNodeUtils;
+import org.apache.inlong.manager.service.sort.util.LoadNodeUtils;
+import org.apache.inlong.manager.service.source.StreamSourceService;
import org.apache.inlong.manager.workflow.WorkflowContext;
import org.apache.inlong.manager.workflow.event.ListenerResult;
import org.apache.inlong.manager.workflow.event.task.SortOperateListener;
import org.apache.inlong.manager.workflow.event.task.TaskEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.inlong.sort.protocol.GroupInfo;
+import org.apache.inlong.sort.protocol.StreamInfo;
+import org.apache.inlong.sort.protocol.enums.PulsarScanStartupMode;
+import org.apache.inlong.sort.protocol.node.Node;
+import org.apache.inlong.sort.protocol.transformation.relation.NodeRelation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
-/**
- * Create sort config when disable the ZooKeeper
- */
-@Deprecated
@Component
+@Slf4j
public class CreateSortConfigListener implements SortOperateListener {
- private static final Logger LOGGER =
LoggerFactory.getLogger(CreateSortConfigListener.class);
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); //
thread safe
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Autowired
- private StreamSinkService streamSinkService;
+ private StreamSourceService sourceService;
+ @Autowired
+ private StreamSinkService sinkService;
@Autowired
- private DataFlowUtils dataFlowUtils;
+ private InlongClusterService clusterService;
@Override
public TaskEvent event() {
return TaskEvent.COMPLETE;
}
+ @SneakyThrows
@Override
- public ListenerResult listen(WorkflowContext context) throws
WorkflowListenerException {
- LOGGER.info("Create sort config for groupId={}",
context.getProcessForm().getInlongGroupId());
+ public ListenerResult listen(WorkflowContext context) {
+ log.info("Create sort config V2 for groupId={}",
context.getProcessForm().getInlongGroupId());
GroupResourceProcessForm form = (GroupResourceProcessForm)
context.getProcessForm();
GroupOperateType groupOperateType = form.getGroupOperateType();
if (groupOperateType == GroupOperateType.SUSPEND || groupOperateType
== GroupOperateType.DELETE) {
return ListenerResult.success();
}
InlongGroupInfo groupInfo = form.getGroupInfo();
- String groupId = groupInfo.getInlongGroupId();
- if (StringUtils.isEmpty(groupId)) {
- LOGGER.warn("GroupId is null for context={}", context);
+ List<InlongStreamInfo> streamInfos = form.getStreamInfos();
+ int sinkCount = streamInfos.stream()
+ .map(s -> s.getSinkList() == null ? 0 : s.getSinkList().size())
+ .reduce(0, Integer::sum);
+ if (sinkCount == 0) {
+ log.warn("not any sink for group {} found, skip creating sort
config", groupInfo.getInlongGroupId());
return ListenerResult.success();
}
- List<StreamSink> streamSinks = streamSinkService.listSink(groupId,
null);
- if (CollectionUtils.isEmpty(streamSinks)) {
- LOGGER.warn("Sink not found by groupId={}", groupId);
- return ListenerResult.success();
+ GroupInfo configInfo = createGroupInfo(groupInfo, streamInfos);
+ String dataFlows = OBJECT_MAPPER.writeValueAsString(configInfo);
+ addExtInfo(groupInfo, InlongConstants.DATA_FLOW, dataFlows);
+ return ListenerResult.success();
+ }
+
+ private void addExtInfo(InlongGroupInfo groupInfo, String key, String
value) {
+ if (groupInfo.getExtList() == null) {
+ groupInfo.setExtList(Lists.newArrayList());
}
+ InlongGroupExtInfo extInfo = new InlongGroupExtInfo();
+ extInfo.setInlongGroupId(groupInfo.getInlongGroupId());
+ extInfo.setKeyName(key);
+ extInfo.setKeyValue(value);
+ upsertExtInfo(groupInfo, extInfo);
+ }
- try {
- // TODO Support more than one sinks under a stream
- // Map<String, DataFlowInfo> dataFlowInfoMap =
streamSinks.stream().map(sink -> {
- // DataFlowInfo flowInfo =
dataFlowUtils.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(InlongConstants.DATA_FLOW);
- // extInfo.setKeyValue(dataFlows);
- if (groupInfo.getExtList() == null) {
- groupInfo.setExtList(Lists.newArrayList());
- }
- upsertDataFlow(groupInfo, extInfo);
- } catch (Exception e) {
- LOGGER.error("create sort config failed for sink list={} ",
streamSinks, e);
- throw new WorkflowListenerException("create sort config failed: "
+ e.getMessage());
+ /**
+ * TODO need support TubeMQ
+ */
+ private GroupInfo createGroupInfo(InlongGroupInfo groupInfo,
List<InlongStreamInfo> streamInfoList) {
+ String groupId = groupInfo.getInlongGroupId();
+ List<StreamSink> streamSinks = sinkService.listSink(groupId, null);
+ Map<String, List<StreamSink>> sinkMap = streamSinks.stream()
+ .collect(Collectors.groupingBy(StreamSink::getInlongStreamId,
HashMap::new,
+ Collectors.toCollection(ArrayList::new)));
+ Map<String, List<StreamSource>> sourceMap =
createPulsarSources(groupInfo, streamInfoList);
+
+ List<StreamInfo> streamInfos = new ArrayList<>();
+ for (InlongStreamInfo inlongStream : streamInfoList) {
+ String streamId = inlongStream.getInlongStreamId();
+ StreamInfo streamInfo = new StreamInfo(streamId,
+ createNodesForStream(sourceMap.get(streamId),
sinkMap.get(streamId)),
+ createNodeRelationsForStream(sourceMap.get(streamId),
sinkMap.get(streamId)));
+ streamInfos.add(streamInfo);
}
- return ListenerResult.success();
+
+ return new GroupInfo(groupId, streamInfos);
+ }
+
+ private Map<String, List<StreamSource>> createPulsarSources(
Review Comment:
java doc
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sort/CreateSortConfigListenerV0.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.service.sort;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.consts.InlongConstants;
+import org.apache.inlong.manager.common.enums.GroupOperateType;
+import org.apache.inlong.manager.common.exceptions.WorkflowListenerException;
+import org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo;
+import org.apache.inlong.manager.common.pojo.group.InlongGroupInfo;
+import org.apache.inlong.manager.common.pojo.sink.StreamSink;
+import
org.apache.inlong.manager.common.pojo.workflow.form.process.GroupResourceProcessForm;
+import org.apache.inlong.manager.service.cluster.InlongClusterService;
+import org.apache.inlong.manager.service.sink.StreamSinkService;
+import org.apache.inlong.manager.service.source.StreamSourceService;
+import org.apache.inlong.manager.workflow.WorkflowContext;
+import org.apache.inlong.manager.workflow.event.ListenerResult;
+import org.apache.inlong.manager.workflow.event.task.SortOperateListener;
+import org.apache.inlong.manager.workflow.event.task.TaskEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Deprecated
+@Service
+public class CreateSortConfigListenerV0 implements SortOperateListener {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(CreateSortConfigListenerV0.class);
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); //
thread safe
+
+ @Autowired
+ private StreamSourceService sourceService;
+ @Autowired
+ private StreamSinkService sinkService;
+ @Autowired
+ private InlongClusterService clusterService;
+
+ @Override
+ public TaskEvent event() {
+ return TaskEvent.COMPLETE;
+ }
+
+ @Override
+ public ListenerResult listen(WorkflowContext context) throws Exception {
+ LOGGER.info("Create sort config for groupId={}",
context.getProcessForm().getInlongGroupId());
+ GroupResourceProcessForm form = (GroupResourceProcessForm)
context.getProcessForm();
+ GroupOperateType groupOperateType = form.getGroupOperateType();
+ if (groupOperateType == GroupOperateType.SUSPEND || groupOperateType
== GroupOperateType.DELETE) {
+ return ListenerResult.success();
+ }
+ InlongGroupInfo groupInfo = form.getGroupInfo();
+ String groupId = groupInfo.getInlongGroupId();
+ if (StringUtils.isEmpty(groupId)) {
+ LOGGER.warn("GroupId is null for context={}", context);
+ return ListenerResult.success();
+ }
+ List<StreamSink> streamSinks = sinkService.listSink(groupId, null);
+ if (CollectionUtils.isEmpty(streamSinks)) {
+ LOGGER.warn("Sink not found by groupId={}", groupId);
+ return ListenerResult.success();
+ }
+
+ try {
+ // TODO Support more than one sinks under a stream
+ // Map<String, DataFlowInfo> dataFlowInfoMap =
streamSinks.stream().map(sink -> {
+ // DataFlowInfo flowInfo =
dataFlowUtils.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(InlongConstants.DATA_FLOW);
+ // extInfo.setKeyValue(dataFlows);
+ if (groupInfo.getExtList() == null) {
+ groupInfo.setExtList(Lists.newArrayList());
+ }
+ upsertDataFlow(groupInfo, extInfo);
+ } catch (Exception e) {
+ LOGGER.error("create sort config failed for sink list={} ",
streamSinks, e);
+ throw new WorkflowListenerException("create sort config failed: "
+ e.getMessage());
+ }
+ return ListenerResult.success();
+ }
+
+ private void upsertDataFlow(InlongGroupInfo groupInfo, InlongGroupExtInfo
extInfo) {
Review Comment:
java doc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]