From 54e0cd3b02961f27e34d046c592d2f1debaf7868 Mon Sep 17 00:00:00 2001 From: fuweng11 <76141879+fuweng11@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:20:29 +0800 Subject: [PATCH] [INLONG-11375][Manager] Add a restriction that an IP can only belong to one cluster (#11376) --- .../service/cluster/InlongClusterServiceImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java index c97971900e..2b18ba582f 100644 --- a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java +++ b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java @@ -714,6 +714,19 @@ public Integer saveNode(ClusterNodeRequest request, String operator) { LOGGER.error(errMsg); throw new BusinessException(errMsg); } + + // check ip if belongs to two different clusters at the same time + List existList = + clusterNodeMapper.selectByIpAndType(request.getIp(), request.getType()); + if (CollectionUtils.isNotEmpty(existList)) { + InlongClusterEntity currentCluster = clusterMapper.selectById(existList.get(0).getParentId()); + InlongClusterEntity targetCluster = clusterMapper.selectById(request.getParentId()); + if (!Objects.equals(currentCluster.getId(), targetCluster.getId())) { + throw new BusinessException( + String.format("current ip can not belong to cluster %s and %s at the same time", + currentCluster.getName(), targetCluster.getName())); + } + } InlongClusterNodeOperator instance = clusterNodeOperatorFactory.getInstance(request.getType()); Integer id = instance.saveOpt(request, operator); if (request.getIsInstall()) {