This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git
The following commit(s) were added to refs/heads/main by this push:
new c9ba15ab BIGTOP-4448: Duplicate checks should be added when adding
hosts (#230)
c9ba15ab is described below
commit c9ba15ab33cee1021fe852e99b4e6b0c49bb8413
Author: Dansanyo <[email protected]>
AuthorDate: Thu Jun 26 14:58:57 2025 +0800
BIGTOP-4448: Duplicate checks should be added when adding hosts (#230)
---
.../server/command/validator/ClusterAddValidator.java | 17 +++++++++++++++++
.../manager/server/controller/HostController.java | 7 +++++++
.../bigtop/manager/server/service/HostService.java | 6 ++++++
.../manager/server/service/impl/HostServiceImpl.java | 13 +++++++++++++
4 files changed, 43 insertions(+)
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterAddValidator.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterAddValidator.java
index a00a38f5..63cbb3f7 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterAddValidator.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterAddValidator.java
@@ -20,13 +20,17 @@ package org.apache.bigtop.manager.server.command.validator;
import org.apache.bigtop.manager.common.enums.Command;
import org.apache.bigtop.manager.dao.po.ClusterPO;
+import org.apache.bigtop.manager.dao.po.HostPO;
import org.apache.bigtop.manager.dao.repository.ClusterDao;
+import org.apache.bigtop.manager.dao.repository.HostDao;
import org.apache.bigtop.manager.server.command.CommandIdentifier;
import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
import org.apache.bigtop.manager.server.enums.CommandLevel;
import org.apache.bigtop.manager.server.exception.ApiException;
import org.apache.bigtop.manager.server.model.dto.command.ClusterCommandDTO;
+import org.apache.commons.collections4.CollectionUtils;
+
import org.springframework.stereotype.Component;
import jakarta.annotation.Resource;
@@ -38,6 +42,9 @@ public class ClusterAddValidator implements CommandValidator {
@Resource
private ClusterDao clusterDao;
+ @Resource
+ private HostDao hostDao;
+
@Override
public List<CommandIdentifier> getCommandIdentifiers() {
return List.of(new CommandIdentifier(CommandLevel.CLUSTER,
Command.ADD));
@@ -53,5 +60,15 @@ public class ClusterAddValidator implements CommandValidator
{
if (clusterPO != null) {
throw new ApiException(ApiExceptionEnum.CLUSTER_EXISTS,
clusterName);
}
+
+ List<String> hostnames = clusterCommand.getHosts().stream()
+ .flatMap(hostCommandDTO ->
hostCommandDTO.getHostnames().stream())
+ .toList();
+ List<HostPO> hostPOList = hostDao.findAllByHostnames(hostnames);
+ if (CollectionUtils.isNotEmpty(hostPOList)) {
+ List<String> existsHostnames =
+ hostPOList.stream().map(HostPO::getHostname).toList();
+ throw new ApiException(ApiExceptionEnum.HOST_ASSIGNED,
String.join(",", existsHostnames));
+ }
}
}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
index 7521ab07..e7b63b9f 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
@@ -133,4 +133,11 @@ public class HostController {
public ResponseEntity<List<InstalledStatusVO>> installedStatus() {
return ResponseEntity.success(hostService.installedStatus());
}
+
+ @Operation(summary = "check-duplicate", description = "check hostname
duplicate")
+ @PostMapping("/check-duplicate")
+ public ResponseEntity<Boolean> checkDuplicate(@RequestBody @Validated
HostReq hostReq) {
+ HostDTO hostDTO = HostConverter.INSTANCE.fromReq2DTO(hostReq);
+ return ResponseEntity.success(hostService.checkDuplicate(hostDTO));
+ }
}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/HostService.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/HostService.java
index d0503b05..8ddc391f 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/HostService.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/HostService.java
@@ -102,4 +102,10 @@ public interface HostService {
* @return installed status
*/
List<InstalledStatusVO> installedStatus();
+
+ /**
+ * validate host exists
+ * @param hostDTO hostnames
+ */
+ Boolean checkDuplicate(HostDTO hostDTO);
}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java
index 4fd2ade6..58b1ce5b 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java
@@ -46,6 +46,8 @@ import org.apache.bigtop.manager.server.service.HostService;
import org.apache.bigtop.manager.server.utils.PageUtils;
import org.apache.bigtop.manager.server.utils.RemoteSSHUtils;
+import org.apache.commons.collections4.CollectionUtils;
+
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@@ -252,6 +254,17 @@ public class HostServiceImpl implements HostService {
return installedStatus;
}
+ @Override
+ public Boolean checkDuplicate(HostDTO hostDTO) {
+ List<HostPO> existsHostList =
hostDao.findAllByHostnames(hostDTO.getHostnames());
+ if (CollectionUtils.isNotEmpty(existsHostList)) {
+ List<String> existsHostnames =
+ existsHostList.stream().map(HostPO::getHostname).toList();
+ throw new ApiException(ApiExceptionEnum.HOST_ASSIGNED,
String.join(",", existsHostnames));
+ }
+ return true;
+ }
+
public void installDependencies(HostDTO hostDTO, String hostname,
InstalledStatusVO installedStatusVO) {
String path = hostDTO.getAgentDir();
String repoUrl = toolDao.findByName("agent").getBaseUrl();