From 67df6668465f4e0d169891c00bf53b713f43c618 Mon Sep 17 00:00:00 2001 From: Stephan Krug Date: Wed, 9 Nov 2022 16:04:20 -0300 Subject: [PATCH 1/2] Add and improve logs --- .../model/impl/DefaultModuleDefinitionSet.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 5dab5d7bd349..2c3d30e9d3b3 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 @@ -97,16 +97,17 @@ protected void startContexts() { @Override public void with(ModuleDefinition def, Stack parents) { try { + log.debug(String.format("Trying to obtain module [%s] context.", def.getName())); ApplicationContext context = getApplicationContext(def.getName()); try { Runnable runnable = context.getBean("moduleStartup", Runnable.class); - log.info("Starting module [" + def.getName() + "]"); + log.info(String.format("Starting module [%s].", def.getName())); runnable.run(); } catch (BeansException e) { - // Ignore + log.error(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage()), e); } } catch (EmptyStackException e) { - // The root context is already loaded, so ignore the exception + log.error(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage()), e); } } }); @@ -117,10 +118,14 @@ protected void loadContexts() { @Override public void with(ModuleDefinition def, Stack parents) { try { + log.debug(String.format("Trying to obtain module [%s] context.", def.getName())); ApplicationContext parent = getApplicationContext(parents.peek().getName()); + log.debug(String.format("Trying to load module [%s] context.", def.getName())); loadContext(def, parent); } catch (EmptyStackException e) { - // The root context is already loaded, so ignore the exception + log.error(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage()), e); + } catch (BeansException e) { + log.error(String.format("Failed to load module [%s] due to: [%s].", def.getName(), e.getMessage()), e); } } }); From f67c580e65d2643c1e162bacf58daf8ce04d871e Mon Sep 17 00:00:00 2001 From: Stephan Krug Date: Mon, 28 Nov 2022 15:36:04 -0300 Subject: [PATCH 2/2] Fix unnecessary calls --- .../model/impl/DefaultModuleDefinitionSet.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 2c3d30e9d3b3..ec9bbc0cd972 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 @@ -97,14 +97,15 @@ protected void startContexts() { @Override public void with(ModuleDefinition def, Stack parents) { try { - log.debug(String.format("Trying to obtain module [%s] context.", def.getName())); - ApplicationContext context = getApplicationContext(def.getName()); + String moduleDefinitionName = def.getName(); + log.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); + ApplicationContext context = getApplicationContext(moduleDefinitionName); try { Runnable runnable = context.getBean("moduleStartup", Runnable.class); - log.info(String.format("Starting module [%s].", def.getName())); + log.info(String.format("Starting module [%s].", moduleDefinitionName)); runnable.run(); } catch (BeansException e) { - log.error(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage()), e); + log.error(String.format("Failed to start module [%s] due to: [%s].", moduleDefinitionName, e.getMessage()), e); } } catch (EmptyStackException e) { log.error(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage()), e); @@ -118,9 +119,10 @@ protected void loadContexts() { @Override public void with(ModuleDefinition def, Stack parents) { try { - log.debug(String.format("Trying to obtain module [%s] context.", def.getName())); + String moduleDefinitionName = def.getName(); + log.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); ApplicationContext parent = getApplicationContext(parents.peek().getName()); - log.debug(String.format("Trying to load module [%s] context.", def.getName())); + log.debug(String.format("Trying to load module [%s] context.", moduleDefinitionName)); loadContext(def, parent); } catch (EmptyStackException e) { log.error(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage()), e);