DaanHoogland commented on code in PR #13852:
URL: https://github.com/apache/cloudstack/pull/13852#discussion_r3759984185
##########
agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java:
##########
@@ -71,11 +76,69 @@ public static <T> T
getPropertyValue(AgentProperties.Property<T> property) {
LOGGER.debug("Property [{}] was altered. Now using the value
[{}].", name, configValue);
return (T)ConvertUtils.convert(configValue,
property.getTypeClass());
- } catch (IOException ex) {
+ } catch (RuntimeException ex) {
LOGGER.debug("Failed to get property [{}]. Using default value
[{}].", name, defaultValue, ex);
}
return defaultValue;
}
+ /**
+ * Gets the cached properties, loading them once if not already loaded.
+ * Agent properties are static configuration that don't change during
runtime.
+ *
+ * @return cached Properties object or null if file cannot be loaded
+ */
+ private static Properties getCachedProperties() {
+ Properties properties = cachedProperties;
+ if (properties == null) {
+ synchronized (AgentPropertiesFileHandler.class) {
+ properties = cachedProperties;
+ if (properties == null) {
+ loadProperties();
+ properties = cachedProperties;
+ }
+ }
+ }
+ return properties;
+ }
+
+ /**
+ * Loads properties from file and caches them for the agent's lifetime.
+ */
+ private static void loadProperties() {
+ File agentPropertiesFile =
PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE);
+
+ if (agentPropertiesFile == null) {
+ LOGGER.debug("File [{}] was not found.",
KeyStoreUtils.AGENT_PROPSFILE);
+ return;
+ }
+
+ try {
+ Properties newProperties =
PropertiesUtil.loadFromFile(agentPropertiesFile);
+ cachedProperties = newProperties;
+
+ LOGGER.info("Loaded {} properties from [{}]",
newProperties.size(), agentPropertiesFile.getAbsolutePath());
+
+ } catch (IOException ex) {
+ LOGGER.error("Failed to load properties from file [{}].",
agentPropertiesFile.getAbsolutePath(), ex);
Review Comment:
this seems FATAL to me. Any reason to keep running when this occurs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]