From d831f373b2c97d45db0739cb781ba47e41905cff Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Tue, 19 May 2026 08:13:24 +0200 Subject: [PATCH 1/2] framework/spring: throw RuntimeException when fail to start or load a module --- .../spring/lifecycle/CloudStackExtendedLifeCycle.java | 1 + .../module/model/impl/DefaultModuleDefinitionSet.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java index 170e3b40e94c..eb987695970c 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java @@ -74,6 +74,7 @@ public void with(ComponentLifecycle lifecycle) { lifecycle.start(); } catch (Exception e) { logger.error("Error on starting bean {} - {}", lifecycle.getName(), e.getMessage(), e); + throw new CloudRuntimeException("Failed to start bean [" + lifecycle.getName() + "]", e); } if (lifecycle instanceof ManagementBean) { diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java index 2a6d0b63e5c2..418f9e556751 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java @@ -116,6 +116,7 @@ public void with(ModuleDefinition def, Stack parents) { if (logger.isDebugEnabled()) { logger.debug(String.format("module start failure of module [%s] was due to: ", moduleDefinitionName), e); } + throw new RuntimeException(String.format("Failed to start module [%s]", moduleDefinitionName), e); } } catch (EmptyStackException e) { logger.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); @@ -147,10 +148,11 @@ public void with(ModuleDefinition def, Stack parents) { logger.debug("Failed to obtain module context: ", e); } } catch (BeansException e) { - logger.warn(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage())); + logger.warn(String.format("Failed to load module [%s] due to: [%s].", def.getName(), e.getMessage())); if (logger.isDebugEnabled()) { - logger.debug(String.format("module start failure of module [%s] was due to: ", def.getName()), e); + logger.debug(String.format("module load failure of module [%s] was due to: ", def.getName()), e); } + throw new RuntimeException(String.format("Failed to load module [%s]", def.getName()), e); } } }); From e9ca574c96f078a25afb5141deeb29acf590c5da Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Wed, 20 May 2026 08:37:35 +0200 Subject: [PATCH 2/2] apply suggestion --- .../lifecycle/CloudStackExtendedLifeCycle.java | 4 ++-- .../model/impl/DefaultModuleDefinitionSet.java | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java index eb987695970c..bd3e424f7673 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java @@ -73,8 +73,8 @@ public void with(ComponentLifecycle lifecycle) { try { lifecycle.start(); } catch (Exception e) { - logger.error("Error on starting bean {} - {}", lifecycle.getName(), e.getMessage(), e); - throw new CloudRuntimeException("Failed to start bean [" + lifecycle.getName() + "]", e); + logger.error("Error on starting bean [{}] due to: {}", lifecycle.getName(), e); + throw new CloudRuntimeException("Failed to start bean [" + lifecycle.getName() + "]"); } if (lifecycle instanceof ManagementBean) { diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java index 418f9e556751..78693f72140c 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java @@ -112,11 +112,8 @@ public void with(ModuleDefinition def, Stack parents) { logger.debug(String.format("Could not get module [%s] context bean.", moduleDefinitionName)); } } catch (BeansException e) { - logger.warn(String.format("Failed to start module [%s] due to: [%s].", moduleDefinitionName, e.getMessage())); - if (logger.isDebugEnabled()) { - logger.debug(String.format("module start failure of module [%s] was due to: ", moduleDefinitionName), e); - } - throw new RuntimeException(String.format("Failed to start module [%s]", moduleDefinitionName), e); + logger.error("Failed to start module [{}] due to: {}", def.getName(), e); + throw new RuntimeException(String.format("Failed to start module [%s]", def.getName())); } } catch (EmptyStackException e) { logger.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); @@ -148,11 +145,8 @@ public void with(ModuleDefinition def, Stack parents) { logger.debug("Failed to obtain module context: ", e); } } catch (BeansException e) { - logger.warn(String.format("Failed to load module [%s] due to: [%s].", def.getName(), e.getMessage())); - if (logger.isDebugEnabled()) { - logger.debug(String.format("module load failure of module [%s] was due to: ", def.getName()), e); - } - throw new RuntimeException(String.format("Failed to load module [%s]", def.getName()), e); + logger.error("Failed to load module [{}] due to: {}", def.getName(), e); + throw new RuntimeException(String.format("Failed to load module [%s]", def.getName())); } } });