From 3fc28122be6c6971b600bfc51d248db8a1b2747e Mon Sep 17 00:00:00 2001 From: Zhiguo Wu Date: Wed, 19 Feb 2025 21:49:00 +0800 Subject: [PATCH] BIGTOP-4372: Adjust APIs related to cluster management for UI needs (#180) --- .../grpc/interceptor/TaskInterceptor.java | 2 +- .../grpc/interceptor/TaskInterceptorTest.java | 16 ++---- .../validator/ClusterRestartValidator.java | 56 +++++++++++++++++++ .../validator/ClusterStartValidator.java | 56 +++++++++++++++++++ .../validator/ClusterStopValidator.java | 56 +++++++++++++++++++ .../server/controller/ServiceController.java | 17 ++++++ .../server/controller/StackController.java | 9 ++- .../server/enums/ApiExceptionEnum.java | 1 + .../manager/server/enums/LocaleKeys.java | 1 + .../bigtop/manager/server/model/vo/JobVO.java | 2 + .../server/model/vo/ServiceClusterVO.java | 35 ++++++++++++ .../server/model/vo/ServiceUserVO.java | 33 +++++++++++ .../server/service/ServiceService.java | 8 +++ .../manager/server/service/StackService.java | 7 +-- .../server/service/impl/JobServiceImpl.java | 19 ++++++- .../service/impl/ServiceServiceImpl.java | 33 +++++++++++ .../server/service/impl/StackServiceImpl.java | 40 +++++++++---- .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + 19 files changed, 361 insertions(+), 32 deletions(-) create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterRestartValidator.java create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStartValidator.java create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStopValidator.java create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceClusterVO.java create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceUserVO.java diff --git a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptor.java b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptor.java index c25505090..43f382ed6 100644 --- a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptor.java +++ b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptor.java @@ -107,7 +107,7 @@ protected Boolean isTaskRequest(Object obj) { // Every task will have taskId, but TaskLogRequest have it also, so we need to exclude it Class clazz = obj.getClass(); - if (clazz.isInstance(TaskLogRequest.class)) { + if (TaskLogRequest.class.isAssignableFrom(clazz)) { return false; } diff --git a/bigtop-manager-agent/src/test/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptorTest.java b/bigtop-manager-agent/src/test/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptorTest.java index f9425578e..7b53c4850 100644 --- a/bigtop-manager-agent/src/test/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptorTest.java +++ b/bigtop-manager-agent/src/test/java/org/apache/bigtop/manager/agent/grpc/interceptor/TaskInterceptorTest.java @@ -19,6 +19,7 @@ package org.apache.bigtop.manager.agent.grpc.interceptor; import org.apache.bigtop.manager.common.utils.ProjectPathUtils; +import org.apache.bigtop.manager.grpc.generated.TaskLogRequest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -91,16 +92,17 @@ public void testTruncateLogFileFileDoesNotExist() throws IOException { } @Test - public void testIsTaskRequestTaskRequest() { - TaskLogRequest taskLogRequest = new TaskLogRequest(); + public void testIsTaskLogRequestTaskRequest() { + TaskLogRequest taskLogRequest = + TaskLogRequest.newBuilder().setTaskId(1L).build(); Boolean result = taskInterceptor.isTaskRequest(taskLogRequest); - assertTrue(result); + assertFalse(result); } @Test - public void testIsTaskRequestTaskWithGetTaskIdMethod() { + public void testIsTaskRequestTaskRequest() { Task task = new Task(); Boolean result = taskInterceptor.isTaskRequest(task); @@ -129,10 +131,4 @@ public Long getTaskId() { return 1L; } } - - private static class TaskLogRequest { - public Long getTaskId() { - return 1L; - } - } } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterRestartValidator.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterRestartValidator.java new file mode 100644 index 000000000..3a399f8be --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterRestartValidator.java @@ -0,0 +1,56 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.command.validator; + +import org.apache.bigtop.manager.common.enums.Command; +import org.apache.bigtop.manager.dao.po.ServicePO; +import org.apache.bigtop.manager.dao.repository.ServiceDao; +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.commons.collections4.CollectionUtils; + +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.util.List; + +@Component +public class ClusterRestartValidator implements CommandValidator { + + @Resource + private ServiceDao serviceDao; + + @Override + public List getCommandIdentifiers() { + return List.of(new CommandIdentifier(CommandLevel.CLUSTER, Command.RESTART)); + } + + @Override + public void validate(ValidatorContext context) { + Long clusterId = context.getCommandDTO().getClusterId(); + List servicePOList = serviceDao.findByClusterId(clusterId); + + if (CollectionUtils.isEmpty(servicePOList)) { + throw new ApiException(ApiExceptionEnum.CLUSTER_HAS_NO_SERVICES); + } + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStartValidator.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStartValidator.java new file mode 100644 index 000000000..e86774301 --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStartValidator.java @@ -0,0 +1,56 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.command.validator; + +import org.apache.bigtop.manager.common.enums.Command; +import org.apache.bigtop.manager.dao.po.ServicePO; +import org.apache.bigtop.manager.dao.repository.ServiceDao; +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.commons.collections4.CollectionUtils; + +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.util.List; + +@Component +public class ClusterStartValidator implements CommandValidator { + + @Resource + private ServiceDao serviceDao; + + @Override + public List getCommandIdentifiers() { + return List.of(new CommandIdentifier(CommandLevel.CLUSTER, Command.START)); + } + + @Override + public void validate(ValidatorContext context) { + Long clusterId = context.getCommandDTO().getClusterId(); + List servicePOList = serviceDao.findByClusterId(clusterId); + + if (CollectionUtils.isEmpty(servicePOList)) { + throw new ApiException(ApiExceptionEnum.CLUSTER_HAS_NO_SERVICES); + } + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStopValidator.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStopValidator.java new file mode 100644 index 000000000..d4d6e999f --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/validator/ClusterStopValidator.java @@ -0,0 +1,56 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.command.validator; + +import org.apache.bigtop.manager.common.enums.Command; +import org.apache.bigtop.manager.dao.po.ServicePO; +import org.apache.bigtop.manager.dao.repository.ServiceDao; +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.commons.collections4.CollectionUtils; + +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.util.List; + +@Component +public class ClusterStopValidator implements CommandValidator { + + @Resource + private ServiceDao serviceDao; + + @Override + public List getCommandIdentifiers() { + return List.of(new CommandIdentifier(CommandLevel.CLUSTER, Command.STOP)); + } + + @Override + public void validate(ValidatorContext context) { + Long clusterId = context.getCommandDTO().getClusterId(); + List servicePOList = serviceDao.findByClusterId(clusterId); + + if (CollectionUtils.isEmpty(servicePOList)) { + throw new ApiException(ApiExceptionEnum.CLUSTER_HAS_NO_SERVICES); + } + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ServiceController.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ServiceController.java index a52f1c32d..0af7912b6 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ServiceController.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ServiceController.java @@ -24,6 +24,7 @@ import org.apache.bigtop.manager.server.model.vo.PageVO; import org.apache.bigtop.manager.server.model.vo.ServiceConfigSnapshotVO; import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO; +import org.apache.bigtop.manager.server.model.vo.ServiceUserVO; import org.apache.bigtop.manager.server.model.vo.ServiceVO; import org.apache.bigtop.manager.server.service.ServiceService; import org.apache.bigtop.manager.server.utils.ResponseEntity; @@ -72,6 +73,22 @@ public ResponseEntity> list(ServiceQuery query) { return ResponseEntity.success(serviceService.list(query)); } + @Parameters({ + @Parameter(in = ParameterIn.QUERY, name = "pageNum", schema = @Schema(type = "integer", defaultValue = "1")), + @Parameter(in = ParameterIn.QUERY, name = "pageSize", schema = @Schema(type = "integer", defaultValue = "10")), + @Parameter(in = ParameterIn.QUERY, name = "orderBy", schema = @Schema(type = "string", defaultValue = "id")), + @Parameter( + in = ParameterIn.QUERY, + name = "sort", + description = "asc/desc", + schema = @Schema(type = "string", defaultValue = "asc")) + }) + @Operation(summary = "service user list", description = "List service users") + @GetMapping("/users") + public ResponseEntity> serviceUsers(@PathVariable Long clusterId) { + return ResponseEntity.success(serviceService.serviceUsers(clusterId)); + } + @Operation(summary = "get", description = "Get a service") @GetMapping("/{id}") public ResponseEntity get(@PathVariable Long clusterId, @PathVariable Long id) { diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/StackController.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/StackController.java index 0df4f53d4..b2fe0a67a 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/StackController.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/StackController.java @@ -18,13 +18,12 @@ */ package org.apache.bigtop.manager.server.controller; -import org.apache.bigtop.manager.server.model.vo.ClusterVO; +import org.apache.bigtop.manager.server.model.vo.ServiceClusterVO; import org.apache.bigtop.manager.server.model.vo.StackVO; import org.apache.bigtop.manager.server.service.StackService; import org.apache.bigtop.manager.server.utils.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -49,8 +48,8 @@ public ResponseEntity> list() { } @Operation(summary = "service clusters", description = "Get service clusters") - @GetMapping("/services/{serviceName}/clusters") - public ResponseEntity> serviceClusters(@PathVariable String serviceName) { - return ResponseEntity.success(stackService.serviceClusters(serviceName)); + @GetMapping("/services/clusters") + public ResponseEntity> serviceClusters() { + return ResponseEntity.success(stackService.serviceClusters()); } } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnum.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnum.java index 16191a1cd..429fe5977 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnum.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnum.java @@ -35,6 +35,7 @@ public enum ApiExceptionEnum { CLUSTER_EXISTS(11001, LocaleKeys.CLUSTER_EXISTS), CLUSTER_HAS_HOSTS(11002, LocaleKeys.CLUSTER_HAS_HOSTS), CLUSTER_HAS_SERVICES(11003, LocaleKeys.CLUSTER_HAS_SERVICES), + CLUSTER_HAS_NO_SERVICES(11004, LocaleKeys.CLUSTER_HAS_NO_SERVICES), // Host Exceptions -- 12000 ~ 12999 HOST_NOT_FOUND(12000, LocaleKeys.HOST_NOT_FOUND), diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/LocaleKeys.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/LocaleKeys.java index e9762433f..c2fd671cc 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/LocaleKeys.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/LocaleKeys.java @@ -38,6 +38,7 @@ public enum LocaleKeys { CLUSTER_EXISTS("cluster.exists"), CLUSTER_HAS_HOSTS("cluster.has.hosts"), CLUSTER_HAS_SERVICES("cluster.has.services"), + CLUSTER_HAS_NO_SERVICES("cluster.has.no.services"), HOST_NOT_FOUND("host.not.found"), HOST_ASSIGNED("host.assigned"), diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/JobVO.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/JobVO.java index ef554a1e3..dbc9af5ee 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/JobVO.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/JobVO.java @@ -35,5 +35,7 @@ public class JobVO { private String updateTime; + private Integer progress; + private List stages; } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceClusterVO.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceClusterVO.java new file mode 100644 index 000000000..a8d9fe873 --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceClusterVO.java @@ -0,0 +1,35 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ServiceClusterVO { + + private String serviceName; + + private List clusters; +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceUserVO.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceUserVO.java new file mode 100644 index 000000000..45c5a343a --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/ServiceUserVO.java @@ -0,0 +1,33 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.model.vo; + +import lombok.Data; + +@Data +public class ServiceUserVO { + + private String displayName; + + private String user; + + private String userGroup; + + private String desc; +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/ServiceService.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/ServiceService.java index 736795746..dfbfda62c 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/ServiceService.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/ServiceService.java @@ -24,6 +24,7 @@ import org.apache.bigtop.manager.server.model.vo.PageVO; import org.apache.bigtop.manager.server.model.vo.ServiceConfigSnapshotVO; import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO; +import org.apache.bigtop.manager.server.model.vo.ServiceUserVO; import org.apache.bigtop.manager.server.model.vo.ServiceVO; import java.util.List; @@ -37,6 +38,13 @@ public interface ServiceService { */ PageVO list(ServiceQuery query); + /** + * Get service users. + * + * @return service users + */ + PageVO serviceUsers(Long clusterId); + /** * Get a service. * diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/StackService.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/StackService.java index bf1040788..1e31bcf3f 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/StackService.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/StackService.java @@ -18,7 +18,7 @@ */ package org.apache.bigtop.manager.server.service; -import org.apache.bigtop.manager.server.model.vo.ClusterVO; +import org.apache.bigtop.manager.server.model.vo.ServiceClusterVO; import org.apache.bigtop.manager.server.model.vo.StackVO; import java.util.List; @@ -35,8 +35,7 @@ public interface StackService { /** * Get service clusters. * - * @param serviceName Service name - * @return Clusters + * @return Service clusters */ - List serviceClusters(String serviceName); + List serviceClusters(); } diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java index fa3a6999d..2a208f97c 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/JobServiceImpl.java @@ -54,6 +54,8 @@ import com.github.pagehelper.PageInfo; import jakarta.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; @@ -78,8 +80,23 @@ public PageVO jobs(Long clusterId) { try (Page ignored = PageHelper.startPage(pageQuery.getPageNum(), pageQuery.getPageSize(), pageQuery.getOrderBy())) { List jobPOList = jobDao.findByClusterId(clusterId); + List jobVOList = new ArrayList<>(); + for (JobPO jobPO : jobPOList) { + List stagePOList = stageDao.findByJobId(jobPO.getId()); + List runningStagePOList = stagePOList.stream() + .filter(stagePO -> List.of(JobState.PROCESSING, JobState.SUCCESSFUL) + .contains(JobState.fromString(stagePO.getState()))) + .toList(); + JobVO jobVO = JobConverter.INSTANCE.fromPO2VO(jobPO); + jobVO.setProgress(new BigDecimal(runningStagePOList.size()) + .divide(new BigDecimal(stagePOList.size()), 2, RoundingMode.HALF_UP) + .multiply(new BigDecimal(100)) + .intValue()); + jobVOList.add(jobVO); + } + PageInfo pageInfo = new PageInfo<>(jobPOList); - return PageVO.of(pageInfo); + return PageVO.of(jobVOList, pageInfo.getTotal()); } finally { PageHelper.clearPage(); } 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 9c99ddbff..af9c0a87e 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 @@ -19,12 +19,14 @@ package org.apache.bigtop.manager.server.service.impl; import org.apache.bigtop.manager.common.utils.JsonUtils; +import org.apache.bigtop.manager.dao.po.ClusterPO; import org.apache.bigtop.manager.dao.po.ComponentPO; import org.apache.bigtop.manager.dao.po.ServiceConfigPO; import org.apache.bigtop.manager.dao.po.ServiceConfigSnapshotPO; import org.apache.bigtop.manager.dao.po.ServicePO; import org.apache.bigtop.manager.dao.query.ComponentQuery; import org.apache.bigtop.manager.dao.query.ServiceQuery; +import org.apache.bigtop.manager.dao.repository.ClusterDao; import org.apache.bigtop.manager.dao.repository.ComponentDao; import org.apache.bigtop.manager.dao.repository.ServiceConfigDao; import org.apache.bigtop.manager.dao.repository.ServiceConfigSnapshotDao; @@ -41,6 +43,7 @@ import org.apache.bigtop.manager.server.model.vo.PageVO; import org.apache.bigtop.manager.server.model.vo.ServiceConfigSnapshotVO; import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO; +import org.apache.bigtop.manager.server.model.vo.ServiceUserVO; import org.apache.bigtop.manager.server.model.vo.ServiceVO; import org.apache.bigtop.manager.server.service.ServiceService; import org.apache.bigtop.manager.server.utils.PageUtils; @@ -57,6 +60,7 @@ import lombok.extern.slf4j.Slf4j; import jakarta.annotation.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -65,6 +69,9 @@ @Service public class ServiceServiceImpl implements ServiceService { + @Resource + private ClusterDao clusterDao; + @Resource private ServiceDao serviceDao; @@ -90,6 +97,32 @@ public PageVO list(ServiceQuery query) { } } + @Override + public PageVO serviceUsers(Long clusterId) { + PageQuery pageQuery = PageUtils.getPageQuery(); + try (Page ignored = + PageHelper.startPage(pageQuery.getPageNum(), pageQuery.getPageSize(), pageQuery.getOrderBy())) { + ServiceQuery query = ServiceQuery.builder().clusterId(clusterId).build(); + List servicePOList = serviceDao.findByQuery(query); + + ClusterPO clusterPO = clusterDao.findById(clusterId); + List res = new ArrayList<>(); + for (ServicePO servicePO : servicePOList) { + ServiceUserVO serviceUserVO = new ServiceUserVO(); + serviceUserVO.setDisplayName(servicePO.getDisplayName()); + serviceUserVO.setUser(servicePO.getUser()); + serviceUserVO.setUserGroup(clusterPO.getUserGroup()); + serviceUserVO.setDesc(servicePO.getDesc()); + res.add(serviceUserVO); + } + + PageInfo pageInfo = new PageInfo<>(servicePOList); + return PageVO.of(res, pageInfo.getTotal()); + } finally { + PageHelper.clearPage(); + } + } + @Override public ServiceVO get(Long id) { return ServiceConverter.INSTANCE.fromPO2VO(serviceDao.findById(id)); diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/StackServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/StackServiceImpl.java index 08517a52f..472a78e8e 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/StackServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/StackServiceImpl.java @@ -18,9 +18,7 @@ */ package org.apache.bigtop.manager.server.service.impl; -import org.apache.bigtop.manager.dao.po.ClusterPO; import org.apache.bigtop.manager.dao.po.ServicePO; -import org.apache.bigtop.manager.dao.query.ServiceQuery; import org.apache.bigtop.manager.dao.repository.ClusterDao; import org.apache.bigtop.manager.dao.repository.ServiceDao; import org.apache.bigtop.manager.server.model.converter.ClusterConverter; @@ -29,10 +27,13 @@ import org.apache.bigtop.manager.server.model.dto.ServiceDTO; import org.apache.bigtop.manager.server.model.dto.StackDTO; import org.apache.bigtop.manager.server.model.vo.ClusterVO; +import org.apache.bigtop.manager.server.model.vo.ServiceClusterVO; import org.apache.bigtop.manager.server.model.vo.StackVO; import org.apache.bigtop.manager.server.service.StackService; import org.apache.bigtop.manager.server.utils.StackUtils; +import org.apache.commons.collections4.CollectionUtils; + import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; @@ -41,6 +42,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; @Slf4j @Service @@ -72,16 +75,31 @@ public List list() { } @Override - public List serviceClusters(String serviceName) { - ServiceQuery query = ServiceQuery.builder().name(serviceName).build(); - List servicePOList = serviceDao.findByQuery(query); - if (servicePOList.isEmpty()) { - return new ArrayList<>(); + public List serviceClusters() { + List res = new ArrayList<>(); + // ID - ClusterVO map + Map clusterVOMap = ClusterConverter.INSTANCE.fromPO2VO(clusterDao.findAll()).stream() + .collect(Collectors.toMap(ClusterVO::getId, Function.identity())); + // Name - ServicePO map + Map> servicePONameMap = + serviceDao.findAll().stream().collect(Collectors.groupingBy(ServicePO::getName)); + List serviceDTOList = StackUtils.getAllStacks().stream() + .map(StackUtils::getServiceDTOList) + .flatMap(List::stream) + .toList(); + for (ServiceDTO serviceDTO : serviceDTOList) { + List clusterVOList = new ArrayList<>(); + List servicePOList = servicePONameMap.get(serviceDTO.getName()); + if (!CollectionUtils.isEmpty(servicePOList)) { + for (ServicePO servicePO : servicePOList) { + ClusterVO clusterVO = clusterVOMap.get(servicePO.getClusterId()); + clusterVOList.add(clusterVO); + } + } + + res.add(new ServiceClusterVO(serviceDTO.getName(), clusterVOList)); } - List clusterIds = - servicePOList.stream().map(ServicePO::getClusterId).toList(); - List clusterPOList = clusterDao.findByIds(clusterIds); - return ClusterConverter.INSTANCE.fromPO2VO(clusterPOList); + return res; } } diff --git a/bigtop-manager-server/src/main/resources/i18n/messages_en_US.properties b/bigtop-manager-server/src/main/resources/i18n/messages_en_US.properties index 07bfd6e75..c83cf2b41 100644 --- a/bigtop-manager-server/src/main/resources/i18n/messages_en_US.properties +++ b/bigtop-manager-server/src/main/resources/i18n/messages_en_US.properties @@ -32,6 +32,7 @@ cluster.not.found=Cluster not exist cluster.exists=Cluster already exists cluster.has.hosts=Cluster still has hosts, please remove them first cluster.has.services=Cluster still has services, please remove them first +cluster.has.no.services=Cluster has no services, please add one first host.not.found=Host not exist host.assigned=Hosts [{0}] already assigned to another cluster diff --git a/bigtop-manager-server/src/main/resources/i18n/messages_zh_CN.properties b/bigtop-manager-server/src/main/resources/i18n/messages_zh_CN.properties index ed7ecbc1e..7b4b92d0c 100644 --- a/bigtop-manager-server/src/main/resources/i18n/messages_zh_CN.properties +++ b/bigtop-manager-server/src/main/resources/i18n/messages_zh_CN.properties @@ -32,6 +32,7 @@ cluster.not.found=集群不存在 cluster.exists=集群已存在 cluster.has.hosts=集群上仍有主机,请先移除 cluster.has.services=集群上仍有服务,请先移除 +cluster.has.no.services=集群上没有服务,请先添加 host.not.found=主机不存在 host.assigned=主机 [{0}] 已属于其他集群