forked from apache/inlong
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-8960][Manager] Automatically assign sort cluster after creati…
…ng stream sinks (apache#9001)
- Loading branch information
1 parent
0b3ef6a
commit c3319b3
Showing
13 changed files
with
265 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
.../java/org/apache/inlong/manager/pojo/cluster/sortstandalone/SortStandaloneClusterDTO.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...g/apache/inlong/manager/service/resource/sink/AbstractStandaloneSinkResourceOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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.resource.sink; | ||
|
||
import org.apache.inlong.manager.common.consts.InlongConstants; | ||
import org.apache.inlong.manager.common.util.Preconditions; | ||
import org.apache.inlong.manager.dao.entity.InlongClusterEntity; | ||
import org.apache.inlong.manager.dao.entity.InlongGroupEntity; | ||
import org.apache.inlong.manager.dao.entity.StreamSinkEntity; | ||
import org.apache.inlong.manager.dao.mapper.InlongClusterEntityMapper; | ||
import org.apache.inlong.manager.dao.mapper.InlongGroupEntityMapper; | ||
import org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper; | ||
import org.apache.inlong.manager.pojo.sink.SinkInfo; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.Sets; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class AbstractStandaloneSinkResourceOperator implements SinkResourceOperator { | ||
|
||
@Autowired | ||
private InlongClusterEntityMapper clusterEntityMapper; | ||
@Autowired | ||
private StreamSinkEntityMapper sinkEntityMapper; | ||
@Autowired | ||
private InlongGroupEntityMapper groupEntityMapper; | ||
|
||
private Random rand = new Random(); | ||
|
||
@VisibleForTesting | ||
protected void assignCluster(SinkInfo sinkInfo) { | ||
if (StringUtils.isNotBlank(sinkInfo.getInlongClusterName())) { | ||
return; | ||
} | ||
|
||
String targetCluster = assignOneCluster(sinkInfo); | ||
Preconditions.expectNotBlank(targetCluster, | ||
String.format("find no proper cluster assign to group=%s, stream=%s, sink type=%s, data node=%s ", | ||
sinkInfo.getInlongGroupId(), sinkInfo.getInlongStreamId(), sinkInfo.getSinkType(), | ||
sinkInfo.getDataNodeName())); | ||
|
||
StreamSinkEntity sink = sinkEntityMapper.selectByPrimaryKey(sinkInfo.getId()); | ||
sink.setInlongClusterName(targetCluster); | ||
sinkEntityMapper.updateByIdSelective(sink); | ||
} | ||
|
||
private String assignOneCluster(SinkInfo sinkInfo) { | ||
return StringUtils | ||
.firstNonBlank(assignFromExist(sinkInfo.getDataNodeName()), | ||
assignFromRelated(sinkInfo.getSinkType(), sinkInfo.getInlongGroupId())); | ||
} | ||
|
||
private String assignFromExist(String dataNodeName) { | ||
return sinkEntityMapper.selectAssignedCluster(dataNodeName); | ||
} | ||
|
||
private String assignFromRelated(String sinkType, String groupId) { | ||
InlongGroupEntity group = groupEntityMapper.selectByGroupId(groupId); | ||
List<InlongClusterEntity> clusters = clusterEntityMapper | ||
.selectStandaloneClusterByType(sinkType).stream() | ||
.filter(cluster -> checkCluster(cluster.getClusterTags(), group.getInlongClusterTag())) | ||
.collect(Collectors.toList()); | ||
|
||
return CollectionUtils.isEmpty(clusters) ? null : clusters.get(rand.nextInt(clusters.size())).getName(); | ||
|
||
} | ||
|
||
private boolean checkCluster(String clusterTags, String targetTag) { | ||
return StringUtils.isBlank(clusterTags) | ||
|| Sets.newHashSet(clusterTags.split(InlongConstants.COMMA)).contains(targetTag); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.