GutoVeronezi commented on code in PR #6348:
URL: https://github.com/apache/cloudstack/pull/6348#discussion_r870728418


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:
##########
@@ -1020,80 +939,54 @@ public boolean configure(final String name, final 
Map<String, Object> params) th
             }
         }
 
-        configureLocalStorage(params);
+        configureLocalStorage();
 
         /* Directory to use for Qemu sockets like for the Qemu Guest Agent */
-        _qemuSocketsPath = new File("/var/lib/libvirt/qemu");
-        String _qemuSocketsPathVar = (String)params.get("qemu.sockets.path");
-        if (_qemuSocketsPathVar != null && 
StringUtils.isNotBlank(_qemuSocketsPathVar)) {
-            _qemuSocketsPath = new File(_qemuSocketsPathVar);
-        }
+        String _qemuSocketsPathVar = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.QEMU_SOCKETS_PATH);
+        _qemuSocketsPath = new File(_qemuSocketsPathVar);
 
-        value = (String)params.get("scripts.timeout");
+        // This value is never set. Default value is always used.
+        String value = (String)params.get("scripts.timeout");
         _timeout = Duration.standardSeconds(NumbersUtil.parseInt(value, 30 * 
60));
 
-        value = (String)params.get("stop.script.timeout");
-        _stopTimeout = NumbersUtil.parseInt(value, 120) * 1000;
+        _stopTimeout = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.STOP_SCRIPT_TIMEOUT)
 * 1000;
 
-        value = (String)params.get("cmds.timeout");
-        _cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000;
+        _cmdsTimeout = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CMDS_TIMEOUT) * 
1000;
 
-        value = (String) params.get("vm.memballoon.disable");
-        if (Boolean.parseBoolean(value)) {
-            _noMemBalloon = true;
-        }
+        _noMemBalloon = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_DISABLE);
+
+        _manualCpuSpeed = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_CPU_MANUAL_SPEED_MHZ);
 
-        value = (String)params.get("host.cpu.manual.speed.mhz");
-        _manualCpuSpeed = NumbersUtil.parseInt(value, 0);
+        _videoHw = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_VIDEO_HARDWARE);
 
-        _videoHw = (String) params.get("vm.video.hardware");
-        value = (String) params.get("vm.video.ram");
-        _videoRam = NumbersUtil.parseInt(value, 0);
+        _videoRam = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_VIDEO_RAM);
 
-        value = (String)params.get("host.reserved.mem.mb");
         // Reserve 1GB unless admin overrides
-        _dom0MinMem = NumbersUtil.parseInt(value, 1024) * 1024* 1024L;
+        _dom0MinMem = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_RESERVED_MEM_MB)
 * 1024 * 1024L;

Review Comment:
   We could use `ByteScaleUtils` to do the byte calculation.



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:
##########
@@ -1020,80 +939,54 @@ public boolean configure(final String name, final 
Map<String, Object> params) th
             }
         }
 
-        configureLocalStorage(params);
+        configureLocalStorage();
 
         /* Directory to use for Qemu sockets like for the Qemu Guest Agent */
-        _qemuSocketsPath = new File("/var/lib/libvirt/qemu");
-        String _qemuSocketsPathVar = (String)params.get("qemu.sockets.path");
-        if (_qemuSocketsPathVar != null && 
StringUtils.isNotBlank(_qemuSocketsPathVar)) {
-            _qemuSocketsPath = new File(_qemuSocketsPathVar);
-        }
+        String _qemuSocketsPathVar = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.QEMU_SOCKETS_PATH);
+        _qemuSocketsPath = new File(_qemuSocketsPathVar);
 
-        value = (String)params.get("scripts.timeout");
+        // This value is never set. Default value is always used.
+        String value = (String)params.get("scripts.timeout");
         _timeout = Duration.standardSeconds(NumbersUtil.parseInt(value, 30 * 
60));
 
-        value = (String)params.get("stop.script.timeout");
-        _stopTimeout = NumbersUtil.parseInt(value, 120) * 1000;
+        _stopTimeout = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.STOP_SCRIPT_TIMEOUT)
 * 1000;
 
-        value = (String)params.get("cmds.timeout");
-        _cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000;
+        _cmdsTimeout = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CMDS_TIMEOUT) * 
1000;
 
-        value = (String) params.get("vm.memballoon.disable");
-        if (Boolean.parseBoolean(value)) {
-            _noMemBalloon = true;
-        }
+        _noMemBalloon = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_DISABLE);
+
+        _manualCpuSpeed = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_CPU_MANUAL_SPEED_MHZ);
 
-        value = (String)params.get("host.cpu.manual.speed.mhz");
-        _manualCpuSpeed = NumbersUtil.parseInt(value, 0);
+        _videoHw = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_VIDEO_HARDWARE);
 
-        _videoHw = (String) params.get("vm.video.hardware");
-        value = (String) params.get("vm.video.ram");
-        _videoRam = NumbersUtil.parseInt(value, 0);
+        _videoRam = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_VIDEO_RAM);
 
-        value = (String)params.get("host.reserved.mem.mb");
         // Reserve 1GB unless admin overrides
-        _dom0MinMem = NumbersUtil.parseInt(value, 1024) * 1024* 1024L;
+        _dom0MinMem = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_RESERVED_MEM_MB)
 * 1024 * 1024L;
 
-        value = (String)params.get("host.overcommit.mem.mb");
         // Support overcommit memory for host if host uses ZSWAP, KSM and 
other memory
         // compressing technologies
-        _dom0OvercommitMem = NumbersUtil.parseInt(value, 0) * 1024 * 1024L;
+        _dom0OvercommitMem = 
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_OVERCOMMIT_MEM_MB)
 * 1024 * 1024L;

Review Comment:
   We could use `ByteScaleUtils` to do the byte calculation.



##########
agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java:
##########
@@ -45,24 +46,34 @@ public static <T> T 
getPropertyValue(AgentProperties.Property<T> property) {
 
         File agentPropertiesFile = 
PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE);
 
-        if (agentPropertiesFile != null) {
-            try {
-                String configValue = 
PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name);
-                if (StringUtils.isNotBlank(configValue)) {
-                    if (defaultValue instanceof Integer) {
-                        ConvertUtils.register(new 
IntegerConverter(defaultValue), Integer.class);
-                    }
+        if (agentPropertiesFile == null) {
+            logger.debug(String.format("File [%s] was not found, we will use 
default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, 
name, defaultValue));
+
+            return defaultValue;
+        }
+
+        try {
+            String configValue = 
PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name);
+            if (StringUtils.isBlank(configValue)) {
+                logger.debug(String.format("Property [%s] has empty or null 
value. Using default value [%s].", name, defaultValue));
+
+                return defaultValue;
+                }
 
-                    return (T)ConvertUtils.convert(configValue, 
defaultValue.getClass());
-                } else {
-                    logger.debug(String.format("Property [%s] has empty or 
null value. Using default value [%s].", name, defaultValue));
+            if (defaultValue instanceof Integer) {
+                ConvertUtils.register(new IntegerConverter(defaultValue), 
Integer.class);
                 }
+
+            if (defaultValue instanceof Long) {
+                ConvertUtils.register(new LongConverter(defaultValue), 
Long.class);
+                }
+
+            logger.debug(String.format("Property [%s] was altered. Now using 
the value [%s].", name, configValue));
+            return (T)ConvertUtils.convert(configValue, 
property.getTypeClass());
+
             } catch (IOException ex) {
                 logger.debug(String.format("Failed to get property [%s]. Using 
default value [%s].", name, defaultValue), ex);
             }

Review Comment:
   @paulazomig, I think this code block needs some adjusts regarding 
indentation.



-- 
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]

Reply via email to