From bd7a667e159db44533d963d3cf003c27b25bf823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B2=BB=E5=9B=BD?= Date: Mon, 4 Mar 2024 11:27:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=98=BE=E7=A4=BAbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constants/ComponentCategories.java | 10 +++++ .../service/AbstractServiceJobFactory.java | 5 ++- .../manager/server/model/vo/ServiceVO.java | 5 ++- .../service/impl/ServiceServiceImpl.java | 39 ++++++++++++++++--- bigtop-manager-ui/src/api/service/types.ts | 5 +-- bigtop-manager-ui/src/pages/service/index.vue | 12 +++++- bigtop-manager-ui/src/store/user/index.ts | 2 +- bigtop-manager-ui/src/utils/enums.ts | 10 ++--- 8 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/constants/ComponentCategories.java diff --git a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/constants/ComponentCategories.java b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/constants/ComponentCategories.java new file mode 100644 index 0000000..aaed93a --- /dev/null +++ b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/constants/ComponentCategories.java @@ -0,0 +1,10 @@ +package org.apache.bigtop.manager.common.constants; + +public class ComponentCategories { + + public static final String MASTER = "master"; + + public static final String SLAVE = "slave"; + + public static final String CLIENT = "client"; +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/factory/service/AbstractServiceJobFactory.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/factory/service/AbstractServiceJobFactory.java index 4fdc3ef..820dba6 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/factory/service/AbstractServiceJobFactory.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/factory/service/AbstractServiceJobFactory.java @@ -1,6 +1,7 @@ package org.apache.bigtop.manager.server.command.job.factory.service; import jakarta.annotation.Resource; +import org.apache.bigtop.manager.common.constants.ComponentCategories; import org.apache.bigtop.manager.common.enums.Command; import org.apache.bigtop.manager.common.utils.JsonUtils; import org.apache.bigtop.manager.server.command.job.factory.AbstractJobFactory; @@ -125,12 +126,12 @@ public abstract class AbstractServiceJobFactory extends AbstractJobFactory { protected Boolean isMasterComponent(String componentName) { ComponentDTO componentDTO = componentNameToDTO.get(componentName); - return componentDTO.getCategory().equalsIgnoreCase("master"); + return componentDTO.getCategory().equalsIgnoreCase(ComponentCategories.MASTER); } protected Boolean isSlaveComponent(String componentName) { ComponentDTO componentDTO = componentNameToDTO.get(componentName); - return componentDTO.getCategory().equalsIgnoreCase("slave"); + return componentDTO.getCategory().equalsIgnoreCase(ComponentCategories.SLAVE); } protected List findHostnamesByComponentName(String componentName) { diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceVO.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceVO.java index e45a3f7..db5b305 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceVO.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceVO.java @@ -1,7 +1,6 @@ package org.apache.bigtop.manager.server.model.vo; import lombok.Data; -import org.apache.bigtop.manager.common.enums.MaintainState; import java.util.List; @@ -25,4 +24,8 @@ public class ServiceVO { private String serviceGroup; private List requiredServices; + + private Boolean isClient; + + private Boolean isHealthy; } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java index 62b48dc..93842bc 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java @@ -2,6 +2,7 @@ package org.apache.bigtop.manager.server.service.impl; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.bigtop.manager.common.constants.ComponentCategories; import org.apache.bigtop.manager.common.enums.MaintainState; import org.apache.bigtop.manager.server.model.dto.*; import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO; @@ -15,9 +16,7 @@ import org.apache.bigtop.manager.server.service.ServiceService; import org.apache.bigtop.manager.server.utils.StackUtils; import org.apache.commons.lang3.tuple.ImmutablePair; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -45,9 +44,39 @@ public class ServiceServiceImpl implements ServiceService { @Override public List list(Long clusterId) { - List serviceList = serviceRepository.findAllByClusterId(clusterId); + List res = new ArrayList<>(); + Map serviceMap = new HashMap<>(); + List hostComponentList = hostComponentRepository.findAllByComponentClusterId(clusterId); + Map> serviceIdToHostComponent = hostComponentList + .stream() + .collect(Collectors.groupingBy(hostComponent -> hostComponent.getComponent().getService().getId())); + + for (Map.Entry> entry : serviceIdToHostComponent.entrySet()) { + Long serviceId = entry.getKey(); + List hostComponents = entry.getValue(); + Service service = serviceMap.computeIfAbsent(serviceId, k -> hostComponents.get(0).getComponent().getService()); + ServiceVO serviceVO = ServiceMapper.INSTANCE.fromEntity2VO(service); + + boolean isHealthy = true; + boolean isClient = true; + for (HostComponent hostComponent : hostComponents) { + String category = hostComponent.getComponent().getCategory(); + if (!category.equalsIgnoreCase(ComponentCategories.CLIENT)) { + isClient = false; + } + + MaintainState expectedState = category.equalsIgnoreCase(ComponentCategories.CLIENT) ? MaintainState.INSTALLED : MaintainState.STARTED; + if (!hostComponent.getState().equals(expectedState)) { + isHealthy = false; + } + } + + serviceVO.setIsClient(isClient); + serviceVO.setIsHealthy(isHealthy); + res.add(serviceVO); + } - return ServiceMapper.INSTANCE.fromEntity2VO(serviceList); + return res; } @Override diff --git a/bigtop-manager-ui/src/api/service/types.ts b/bigtop-manager-ui/src/api/service/types.ts index 30e8543..a6cbaf5 100644 --- a/bigtop-manager-ui/src/api/service/types.ts +++ b/bigtop-manager-ui/src/api/service/types.ts @@ -15,8 +15,6 @@ * limitations under the License. */ -import { MaintainState } from '@/utils/enums.ts' - export interface ServiceVO { id?: number serviceName: string @@ -26,5 +24,6 @@ export interface ServiceVO { clusterName?: string serviceUser?: string serviceGroup?: string - state?: MaintainState + isClient?: boolean + isHealthy?: boolean } diff --git a/bigtop-manager-ui/src/pages/service/index.vue b/bigtop-manager-ui/src/pages/service/index.vue index 0fcb94c..efbd0e6 100644 --- a/bigtop-manager-ui/src/pages/service/index.vue +++ b/bigtop-manager-ui/src/pages/service/index.vue @@ -100,6 +100,14 @@ await componentStore.loadHostComponents() } + const isHealthy = (item: HostComponentVO) => { + if (item.category === 'client') { + return item.state === 'Installed' + } else { + return item.state === 'Started' + } + } + onMounted(() => { initServiceMeta() }) @@ -163,11 +171,11 @@

{{ item.hostname }}

diff --git a/bigtop-manager-ui/src/store/user/index.ts b/bigtop-manager-ui/src/store/user/index.ts index 95de5f4..ab80f92 100644 --- a/bigtop-manager-ui/src/store/user/index.ts +++ b/bigtop-manager-ui/src/store/user/index.ts @@ -49,7 +49,7 @@ export const useUserStore = defineStore( if (route.meta?.title === 'Services') { menuItem.children = [] installedServices.value.forEach((service) => { - const color = service.state === 'STARTED' ? '#52c41a' : '#f5222d' + const color = service.isHealthy ? '#52c41a' : '#f5222d' menuItem.children?.push({ key: service.serviceName, to: '/services/' + service.serviceName, diff --git a/bigtop-manager-ui/src/utils/enums.ts b/bigtop-manager-ui/src/utils/enums.ts index e78e76e..c447ab9 100644 --- a/bigtop-manager-ui/src/utils/enums.ts +++ b/bigtop-manager-ui/src/utils/enums.ts @@ -16,8 +16,8 @@ */ export type MaintainState = - | 'UNINSTALLED' - | 'INSTALLED' - | 'MAINTAINED' - | 'STARTED' - | 'STOPPED' + | 'Uninstalled' + | 'Installed' + | 'Maintained' + | 'Started' + | 'Stopped' -- Gitee From da3a1d378db546fa23154b03fd630b410ae4ea4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B2=BB=E5=9B=BD?= Date: Mon, 4 Mar 2024 11:34:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E9=99=A4serviceMap=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/server/service/impl/ServiceServiceImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java index 93842bc..88d3692 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ServiceServiceImpl.java @@ -45,16 +45,14 @@ public class ServiceServiceImpl implements ServiceService { @Override public List list(Long clusterId) { List res = new ArrayList<>(); - Map serviceMap = new HashMap<>(); List hostComponentList = hostComponentRepository.findAllByComponentClusterId(clusterId); Map> serviceIdToHostComponent = hostComponentList .stream() .collect(Collectors.groupingBy(hostComponent -> hostComponent.getComponent().getService().getId())); for (Map.Entry> entry : serviceIdToHostComponent.entrySet()) { - Long serviceId = entry.getKey(); List hostComponents = entry.getValue(); - Service service = serviceMap.computeIfAbsent(serviceId, k -> hostComponents.get(0).getComponent().getService()); + Service service = hostComponents.get(0).getComponent().getService(); ServiceVO serviceVO = ServiceMapper.INSTANCE.fromEntity2VO(service); boolean isHealthy = true; -- Gitee