From 6213292adc58b350dd38609d2840b9e1b6a504a9 Mon Sep 17 00:00:00 2001 From: zhaoyi <2498974539@qq.com> Date: Tue, 29 Aug 2023 16:44:21 +0800 Subject: [PATCH 1/5] commit content --- .../src/main/java/com/datasophon/api/enums/Status.java | 1 + .../datasophon/api/service/impl/ServiceInstallServiceImpl.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java b/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java index 9b7fee38..08845488 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java +++ b/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java @@ -85,6 +85,7 @@ public enum Status { NEED_SAME_ROLE_GROUP(10039, "All instances of the same service on the same machine need to be within the same role group", "同一个服务在同一台机器上的所有实例需要在同一个角色组内"), + ODD_NUMBER_ARE_REQUIRED_FOR_DORISFE(10040, "The Number of DorisFE must be an odd number.", "DorisFE个数必须是奇数"), ; private final int code; diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java index ac30dbf1..0b11e382 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java @@ -703,6 +703,9 @@ private void serviceValidation(ServiceRoleHostMapping serviceRoleHostMapping) { if ("ZkServer".equals(serviceRole) && (hosts.size() & 1) == 0) { throw new ServiceException(Status.ODD_NUMBER_ARE_REQUIRED_FOR_ZKSERVER.getMsg()); } + if ("DorisFE".equals(serviceRole) && (hosts.size() & 1) == 0) { + throw new ServiceException(Status.ODD_NUMBER_ARE_REQUIRED_FOR_DORISFE.getMsg()); + } } private List listServiceConfigByServiceInstance( From 463aefb0cd45a00969a0dd71998cffbf9a960f1a Mon Sep 17 00:00:00 2001 From: zhaoyi <2498974539@qq.com> Date: Thu, 31 Aug 2023 16:41:55 +0800 Subject: [PATCH 2/5] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E5=8E=9F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=82=B9=202=E3=80=81=E5=A2=9E=E5=8A=A0Doris?= =?UTF-8?q?FE=E3=80=81DorisFEObserver=20=E4=B8=8D=E8=83=BD=E5=9C=A8?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E5=8F=B0=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/check/CheckBasicServiceRule.java | 51 +++++++++++++++++++ .../datasophon/api/check/CheckDorisRule.java | 47 +++++++++++++++++ .../com/datasophon/api/check/CheckRule.java | 9 ++++ .../java/com/datasophon/api/enums/Status.java | 2 + .../impl/ServiceInstallServiceImpl.java | 18 ++++++- 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java create mode 100644 datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java create mode 100644 datasophon-service/src/main/java/com/datasophon/api/check/CheckRule.java diff --git a/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java b/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java new file mode 100644 index 00000000..32c14838 --- /dev/null +++ b/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java @@ -0,0 +1,51 @@ +package com.datasophon.api.check; + +import com.datasophon.api.enums.Status; +import com.datasophon.api.exceptions.ServiceException; +import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.common.model.ServiceRoleHostMapping; +import com.datasophon.common.utils.CollectionUtils; +import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class CheckBasicServiceRule extends CheckRule{ + private static final List MUST_AT_SAME_NODE_BASIC_SERVICE = + Arrays.asList("Grafana", "AlertManager", "Prometheus"); + + @Autowired + private ClusterServiceRoleInstanceService roleInstanceService; + + @Override + public void checkeNodeRule(Integer clusterId, List list) { + Set hostnameSet = + list.stream() + .filter(s -> MUST_AT_SAME_NODE_BASIC_SERVICE.contains(s.getServiceRole())) + .map(ServiceRoleHostMapping::getHosts) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + if (CollectionUtils.isEmpty(hostnameSet)) { + return; + } + + Set installedHostnameSet = + roleInstanceService.lambdaQuery() + .eq(ClusterServiceRoleInstanceEntity::getClusterId, clusterId) + .in( + ClusterServiceRoleInstanceEntity::getServiceName, + MUST_AT_SAME_NODE_BASIC_SERVICE) + .list().stream() + .map(ClusterServiceRoleInstanceEntity::getHostname) + .collect(Collectors.toSet()); + hostnameSet.addAll(installedHostnameSet); + + if (hostnameSet.size() > 1) { + throw new ServiceException(Status.BASIC_SERVICE_SELECT_MOST_ONE_HOST.getMsg()); + } + } +} diff --git a/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java b/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java new file mode 100644 index 00000000..b2bd104d --- /dev/null +++ b/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java @@ -0,0 +1,47 @@ +package com.datasophon.api.check; + +import com.datasophon.api.enums.Status; +import com.datasophon.api.exceptions.ServiceException; +import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.common.model.ServiceRoleHostMapping; +import com.datasophon.common.utils.CollectionUtils; +import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; +import java.util.stream.Collectors; + +public class CheckDorisRule extends CheckRule{ + private static final List MUST_AT_NOT_SAME_NODE_DORIS = + Arrays.asList("DorisFE","DorisFEObserver"); + + @Autowired + private ClusterServiceRoleInstanceService roleInstanceService; + + @Override + public void checkeNodeRule(Integer clusterId, List list) { + Set hostnameSet = + list.stream() + .filter(s -> MUST_AT_NOT_SAME_NODE_DORIS.contains(s.getServiceRole())) + .map(ServiceRoleHostMapping::getHosts) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + if (CollectionUtils.isEmpty(hostnameSet)) { + return; + } + + + Map roleHostMap = roleInstanceService.lambdaQuery() + .eq(ClusterServiceRoleInstanceEntity::getClusterId, clusterId) + .in( + ClusterServiceRoleInstanceEntity::getServiceName, + MUST_AT_NOT_SAME_NODE_DORIS) + .list().stream() + .collect(Collectors.toMap(ClusterServiceRoleInstanceEntity::getHostname, + ClusterServiceRoleInstanceEntity::getServiceRoleName)); + + if (roleHostMap.size() < 2) { + throw new ServiceException(Status.DORIS_FE_OBSERVER_NUST_IN_DIFFERENCE_NODE.getMsg()); + } + } +} diff --git a/datasophon-service/src/main/java/com/datasophon/api/check/CheckRule.java b/datasophon-service/src/main/java/com/datasophon/api/check/CheckRule.java new file mode 100644 index 00000000..d0c3116c --- /dev/null +++ b/datasophon-service/src/main/java/com/datasophon/api/check/CheckRule.java @@ -0,0 +1,9 @@ +package com.datasophon.api.check; + +import com.datasophon.common.model.ServiceRoleHostMapping; + +import java.util.List; + +public abstract class CheckRule { + public abstract void checkeNodeRule(Integer clusterId, List list); +} diff --git a/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java b/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java index 08845488..a020ab17 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java +++ b/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java @@ -86,6 +86,8 @@ public enum Status { "All instances of the same service on the same machine need to be within the same role group", "同一个服务在同一台机器上的所有实例需要在同一个角色组内"), ODD_NUMBER_ARE_REQUIRED_FOR_DORISFE(10040, "The Number of DorisFE must be an odd number.", "DorisFE个数必须是奇数"), + DORIS_FE_OBSERVER_NUST_IN_DIFFERENCE_NODE(10041,"The DorisFE and DorisFEObserver must in difference node.", + "DorisFE和DorisFEObserver必须分布在不同节点"), ; private final int code; diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java index 0b11e382..2c9a8929 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java @@ -23,6 +23,9 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.datasophon.api.check.CheckBasicServiceRule; +import com.datasophon.api.check.CheckDorisRule; +import com.datasophon.api.check.CheckRule; import com.datasophon.api.enums.Status; import com.datasophon.api.exceptions.ServiceException; import com.datasophon.api.load.GlobalVariables; @@ -274,7 +277,7 @@ public Result saveServiceConfig( @Override public Result saveServiceRoleHostMapping(Integer clusterId, List list) { - checkOnSameNode(clusterId, list); + checkRules(clusterId, list); ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); String hostMapKey = @@ -307,6 +310,19 @@ public Result saveServiceRoleHostMapping(Integer clusterId, List list) { + List checkRules = new ArrayList<>(); + checkRules.add(new CheckBasicServiceRule()); + checkRules.add(new CheckDorisRule()); + checkRules.forEach(e->{ + e.checkeNodeRule(clusterId,list); + }); + } + + @Override public Result saveHostServiceRoleMapping(Integer clusterId, List list) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); From 63a0b704e8024da6448d812a1cc1890bc9e0dee4 Mon Sep 17 00:00:00 2001 From: zhaoyi <2498974539@qq.com> Date: Thu, 31 Aug 2023 16:45:41 +0800 Subject: [PATCH 3/5] =?UTF-8?q?1=E3=80=81=E8=B0=83=E6=95=B4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ServiceInstallServiceImpl.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java index 2c9a8929..03148306 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java @@ -673,33 +673,6 @@ private void buildConfig( roleGroupConfig.setConfigFileJsonMd5(SecureUtil.md5(configFileJson)); } - private void checkOnSameNode(Integer clusterId, List list) { - Set hostnameSet = - list.stream() - .filter(s -> MUST_AT_SAME_NODE_BASIC_SERVICE.contains(s.getServiceRole())) - .map(ServiceRoleHostMapping::getHosts) - .flatMap(Collection::stream) - .collect(Collectors.toSet()); - if (CollectionUtils.isEmpty(hostnameSet)) { - return; - } - - Set installedHostnameSet = - roleInstanceService.lambdaQuery() - .eq(ClusterServiceRoleInstanceEntity::getClusterId, clusterId) - .in( - ClusterServiceRoleInstanceEntity::getServiceName, - MUST_AT_SAME_NODE_BASIC_SERVICE) - .list().stream() - .map(ClusterServiceRoleInstanceEntity::getHostname) - .collect(Collectors.toSet()); - hostnameSet.addAll(installedHostnameSet); - - if (hostnameSet.size() > 1) { - throw new ServiceException(Status.BASIC_SERVICE_SELECT_MOST_ONE_HOST.getMsg()); - } - } - private void serviceValidation(ServiceRoleHostMapping serviceRoleHostMapping) { String serviceRole = serviceRoleHostMapping.getServiceRole(); List hosts = serviceRoleHostMapping.getHosts(); From 70adae3078132d03f67be9125d6d55ac7096db7d Mon Sep 17 00:00:00 2001 From: zhaoyi <2498974539@qq.com> Date: Sun, 8 Oct 2023 13:57:57 +0800 Subject: [PATCH 4/5] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/datasophon/api/check/CheckBasicServiceRule.java | 6 +++++- .../main/java/com/datasophon/api/check/CheckDorisRule.java | 4 ++++ .../api/service/impl/ServiceInstallServiceImpl.java | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java b/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java index 32c14838..0c9d1f37 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java +++ b/datasophon-service/src/main/java/com/datasophon/api/check/CheckBasicServiceRule.java @@ -18,9 +18,13 @@ public class CheckBasicServiceRule extends CheckRule{ private static final List MUST_AT_SAME_NODE_BASIC_SERVICE = Arrays.asList("Grafana", "AlertManager", "Prometheus"); - @Autowired + private ClusterServiceRoleInstanceService roleInstanceService; + public CheckBasicServiceRule(ClusterServiceRoleInstanceService roleInstanceService) { + this.roleInstanceService = roleInstanceService; + } + @Override public void checkeNodeRule(Integer clusterId, List list) { Set hostnameSet = diff --git a/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java b/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java index b2bd104d..9c1fc436 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java +++ b/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java @@ -18,6 +18,10 @@ public class CheckDorisRule extends CheckRule{ @Autowired private ClusterServiceRoleInstanceService roleInstanceService; + public CheckDorisRule(ClusterServiceRoleInstanceService roleInstanceService) { + this.roleInstanceService = roleInstanceService; + } + @Override public void checkeNodeRule(Integer clusterId, List list) { Set hostnameSet = diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java index 166d32af..6dad5601 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java @@ -315,8 +315,8 @@ public Result saveServiceRoleHostMapping(Integer clusterId, List list) { List checkRules = new ArrayList<>(); - checkRules.add(new CheckBasicServiceRule()); - checkRules.add(new CheckDorisRule()); + checkRules.add(new CheckBasicServiceRule(roleInstanceService)); + checkRules.add(new CheckDorisRule(roleInstanceService)); checkRules.forEach(e->{ e.checkeNodeRule(clusterId,list); }); From df672a9b6b43462ae013e0b3c3976cabbc05800d Mon Sep 17 00:00:00 2001 From: zhaoyi <2498974539@qq.com> Date: Sun, 8 Oct 2023 14:32:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1=E3=80=81=E5=88=A0=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/datasophon/api/check/CheckDorisRule.java | 1 - 1 file changed, 1 deletion(-) diff --git a/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java b/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java index 9c1fc436..4c579ac0 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java +++ b/datasophon-service/src/main/java/com/datasophon/api/check/CheckDorisRule.java @@ -15,7 +15,6 @@ public class CheckDorisRule extends CheckRule{ private static final List MUST_AT_NOT_SAME_NODE_DORIS = Arrays.asList("DorisFE","DorisFEObserver"); - @Autowired private ClusterServiceRoleInstanceService roleInstanceService; public CheckDorisRule(ClusterServiceRoleInstanceService roleInstanceService) {