This is an automated email from the ASF dual-hosted git repository.

houyu 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 6819e1aa BIGTOP-4492: Improve service remove API (#262)
6819e1aa is described below

commit 6819e1aa699d9079fabac18e4de962bf79b13030
Author: Zhiguo Wu <[email protected]>
AuthorDate: Thu Sep 11 21:56:54 2025 +0800

    BIGTOP-4492: Improve service remove API (#262)
---
 .../manager/server/enums/ApiExceptionEnum.java     |  1 +
 .../bigtop/manager/server/enums/LocaleKeys.java    |  1 +
 .../server/service/impl/ServiceServiceImpl.java    | 41 ++++++++++++++++++++--
 .../main/resources/i18n/messages_en_US.properties  |  1 +
 .../main/resources/i18n/messages_zh_CN.properties  |  1 +
 5 files changed, 43 insertions(+), 2 deletions(-)

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 b379d15b..20fe46b7 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
@@ -59,6 +59,7 @@ public enum ApiExceptionEnum {
     SERVICE_NOT_FOUND(14000, LocaleKeys.SERVICE_NOT_FOUND),
     SERVICE_REQUIRED_NOT_FOUND(14001, LocaleKeys.SERVICE_REQUIRED_NOT_FOUND),
     SERVICE_HAS_COMPONENTS(14002, LocaleKeys.SERVICE_HAS_COMPONENTS),
+    SERVICE_IS_RUNNING(14003, LocaleKeys.SERVICE_IS_RUNNING),
 
     // Component Exceptions -- 15000 ~ 15999
     COMPONENT_NOT_FOUND(15000, LocaleKeys.COMPONENT_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 5279b55f..30f53749 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
@@ -59,6 +59,7 @@ public enum LocaleKeys {
     SERVICE_NOT_FOUND("service.not.found"),
     SERVICE_REQUIRED_NOT_FOUND("service.required.not.found"),
     SERVICE_HAS_COMPONENTS("service.has.components"),
+    SERVICE_IS_RUNNING("service.is.running"),
 
     COMPONENT_NOT_FOUND("component.not.found"),
     COMPONENT_IS_RUNNING("component.is.running"),
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 3ee0b874..eeb10968 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
@@ -32,6 +32,7 @@ import 
org.apache.bigtop.manager.dao.repository.ServiceConfigDao;
 import org.apache.bigtop.manager.dao.repository.ServiceConfigSnapshotDao;
 import org.apache.bigtop.manager.dao.repository.ServiceDao;
 import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
+import org.apache.bigtop.manager.server.enums.HealthyStatusEnum;
 import org.apache.bigtop.manager.server.exception.ApiException;
 import org.apache.bigtop.manager.server.model.converter.ComponentConverter;
 import org.apache.bigtop.manager.server.model.converter.ServiceConfigConverter;
@@ -55,6 +56,7 @@ import org.apache.bigtop.manager.server.utils.StackUtils;
 import org.apache.commons.collections4.CollectionUtils;
 
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
@@ -66,6 +68,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 @Slf4j
 @Service
@@ -140,13 +143,47 @@ public class ServiceServiceImpl implements ServiceService 
{
     }
 
     @Override
+    @Transactional
     public Boolean remove(Long id) {
+        ServicePO servicePO = serviceDao.findById(id);
+        if (servicePO == null) {
+            throw new ApiException(ApiExceptionEnum.SERVICE_NOT_FOUND);
+        }
+
+        // Check service status - only allow deletion when service is stopped
+        if (!Objects.equals(servicePO.getStatus(), 
HealthyStatusEnum.UNHEALTHY.getCode())) {
+            throw new ApiException(ApiExceptionEnum.SERVICE_IS_RUNNING);
+        }
+
         ComponentQuery query = ComponentQuery.builder().serviceId(id).build();
         List<ComponentPO> componentPOList = componentDao.findByQuery(query);
-        if (CollectionUtils.isNotEmpty(componentPOList)) {
-            throw new ApiException(ApiExceptionEnum.SERVICE_HAS_COMPONENTS);
+
+        // Check all components status - only allow deletion when all 
components are stopped
+        // Skip client components as they are always healthy
+        for (ComponentPO componentPO : componentPOList) {
+            if (StackUtils.isClientComponent(componentPO.getName())) {
+                continue;
+            }
+            if (!Objects.equals(componentPO.getStatus(), 
HealthyStatusEnum.UNHEALTHY.getCode())) {
+                throw new ApiException(ApiExceptionEnum.SERVICE_IS_RUNNING);
+            }
         }
 
+        // Delete all components first
+        componentDao.deleteByIds(
+                componentPOList.stream().map(ComponentPO::getId).toList());
+
+        // Delete all service configurations
+        List<ServiceConfigPO> configPOList = 
serviceConfigDao.findByServiceId(id);
+        serviceConfigDao.deleteByIds(
+                configPOList.stream().map(ServiceConfigPO::getId).toList());
+
+        // Delete all service config snapshots
+        List<ServiceConfigSnapshotPO> snapshotPOList = 
serviceConfigSnapshotDao.findByServiceId(id);
+        serviceConfigSnapshotDao.deleteByIds(
+                
snapshotPOList.stream().map(ServiceConfigSnapshotPO::getId).toList());
+
+        // Finally delete the service
         return serviceDao.deleteById(id);
     }
 
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 7b565abb..2540c225 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
@@ -53,6 +53,7 @@ stack.not.found=Stack not exist
 service.not.found=Service not exist
 service.required.not.found=Required Service [{0}] not exist
 service.has.components=Service still has components, please remove them first
+service.is.running=Service is running, please stop it first
 
 component.not.found=Component not exist
 component.is.running=Component is running, please stop it first
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 73e31063..2092345b 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
@@ -53,6 +53,7 @@ stack.not.found=组件栈不存在
 service.not.found=服务不存在
 service.required.not.found=依赖服务 [{0}] 不存在
 service.has.components=服务上仍有组件,请先移除
+service.is.running=服务正在运行,请先停止
 
 component.not.found=组件不存在
 component.is.running=组件正在运行,请先停止

Reply via email to