From d5886f92f3ddd6edf94303d02c88c6c30ec3c850 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Tue, 27 Apr 2021 10:43:40 -0300 Subject: [PATCH 1/8] Extract hardcoded string to var --- .../java/org/apache/cloudstack/utils/linux/KVMHostInfo.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index 1f28304806a7..94d9235dab24 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -42,6 +42,8 @@ public class KVMHostInfo { private long overCommitMemory; private List capabilities = new ArrayList<>(); + public static String CPU_INFO_MAX_FREQ_FILE_NAME = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; + public KVMHostInfo(long reservedMemory, long overCommitMemory) { this.reservedMemory = reservedMemory; this.overCommitMemory = overCommitMemory; @@ -78,8 +80,7 @@ public List getCapabilities() { } protected static long getCpuSpeed(final NodeInfo nodeInfo) { - try (final Reader reader = new FileReader( - "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")) { + try (final Reader reader = new FileReader(CPU_INFO_MAX_FREQ_FILE_NAME)) { return Long.parseLong(IOUtils.toString(reader).trim()) / 1000; } catch (IOException | NumberFormatException e) { LOGGER.info("Could not read cpuinfo_max_freq, falling back on libvirt"); From 468d696831690cb5fd4785495b29f28da13872fb Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Tue, 27 Apr 2021 10:46:40 -0300 Subject: [PATCH 2/8] Add logs --- .../apache/cloudstack/utils/linux/KVMHostInfo.java | 13 +++++++++---- .../com/cloud/resource/ResourceManagerImpl.java | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index 94d9235dab24..d91194bd6781 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -80,10 +80,12 @@ public List getCapabilities() { } protected static long getCpuSpeed(final NodeInfo nodeInfo) { - try (final Reader reader = new FileReader(CPU_INFO_MAX_FREQ_FILE_NAME)) { - return Long.parseLong(IOUtils.toString(reader).trim()) / 1000; + try (Reader reader = new FileReader(CPU_INFO_MAX_FREQ_FILE_NAME)) { + Long cpuInfoMaxFreq = Long.parseLong(IOUtils.toString(reader).trim()); + LOGGER.info(String.format("Retrieved value [%s] from file [%s]. Using the value divided by 1000 [%s] as CPU speed value.", cpuInfoMaxFreq, CPU_INFO_MAX_FREQ_FILE_NAME, cpuInfoMaxFreq / 1000)); + return cpuInfoMaxFreq / 1000; } catch (IOException | NumberFormatException e) { - LOGGER.info("Could not read cpuinfo_max_freq, falling back on libvirt"); + LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using using the value [%s] provided by the Libvirt.", CPU_INFO_MAX_FREQ_FILE_NAME, nodeInfo.mhz), e); return nodeInfo.mhz; } } @@ -126,7 +128,10 @@ private void getHostInfoFromLibvirt() { */ this.capabilities.add("snapshot"); conn.close(); - } catch (final LibvirtException e) { + + LOGGER.info(String.format("Fetched the following host's information {\"cpus\": %s, \"cpuSpeed\": %s, \"cpuSockets\": %s, \"cpuNodes\": %s, \"capabilities\": \"%s\"}.", + hosts.cpus,this.cpuSpeed, hosts.sockets, hosts.nodes, this.capabilities.toString())); + } catch (LibvirtException e) { LOGGER.error("Caught libvirt exception while fetching host information", e); } } diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index a3b9df8fb1c9..75cf82ff0333 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -2436,6 +2436,9 @@ public HostVO fillRoutingHostVO(final HostVO host, final StartupRoutingCommand s host.setHypervisorType(hyType); host.setHypervisorVersion(ssCmd.getHypervisorVersion()); host.setGpuGroups(ssCmd.getGpuGroupDetails()); + + s_logger.info(String.format("Filling %s with the following information retrieved from the agent {\"cpus\": %s, \"cpuSpeed\": %s, \"cpuSockets\": %s, " + + "\"totalMemory\": \"%s\"}.", host.toString(), ssCmd.getCpus(), ssCmd.getSpeed(), ssCmd.getCpuSockets(), ssCmd.getCapabilities(), ssCmd.getMemory())); return host; } From 891342392c30f2ef30c3f1d2c59a992a0bd9735c Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Tue, 27 Apr 2021 15:21:45 -0300 Subject: [PATCH 3/8] Rename constant --- .../org/apache/cloudstack/utils/linux/KVMHostInfo.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index d91194bd6781..a2c59be56785 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -42,7 +42,7 @@ public class KVMHostInfo { private long overCommitMemory; private List capabilities = new ArrayList<>(); - public static String CPU_INFO_MAX_FREQ_FILE_NAME = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; + public static String cpuInfoMaxFreqFileName = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; public KVMHostInfo(long reservedMemory, long overCommitMemory) { this.reservedMemory = reservedMemory; @@ -80,12 +80,12 @@ public List getCapabilities() { } protected static long getCpuSpeed(final NodeInfo nodeInfo) { - try (Reader reader = new FileReader(CPU_INFO_MAX_FREQ_FILE_NAME)) { + try (Reader reader = new FileReader(cpuInfoMaxFreqFileName)) { Long cpuInfoMaxFreq = Long.parseLong(IOUtils.toString(reader).trim()); - LOGGER.info(String.format("Retrieved value [%s] from file [%s]. Using the value divided by 1000 [%s] as CPU speed value.", cpuInfoMaxFreq, CPU_INFO_MAX_FREQ_FILE_NAME, cpuInfoMaxFreq / 1000)); + LOGGER.info(String.format("Retrieved value [%s] from file [%s]. Using the value divided by 1000 [%s] as CPU speed value.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000)); return cpuInfoMaxFreq / 1000; } catch (IOException | NumberFormatException e) { - LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using using the value [%s] provided by the Libvirt.", CPU_INFO_MAX_FREQ_FILE_NAME, nodeInfo.mhz), e); + LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using using the value [%s] provided by the Libvirt.", cpuInfoMaxFreqFileName, nodeInfo.mhz), e); return nodeInfo.mhz; } } From 1747c74762f644e45ae165afaa2961f07145d0cf Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Wed, 28 Apr 2021 14:42:13 -0300 Subject: [PATCH 4/8] Remove repeated word --- .../java/org/apache/cloudstack/utils/linux/KVMHostInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index a2c59be56785..d4554556f7d0 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -85,7 +85,7 @@ protected static long getCpuSpeed(final NodeInfo nodeInfo) { LOGGER.info(String.format("Retrieved value [%s] from file [%s]. Using the value divided by 1000 [%s] as CPU speed value.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000)); return cpuInfoMaxFreq / 1000; } catch (IOException | NumberFormatException e) { - LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using using the value [%s] provided by the Libvirt.", cpuInfoMaxFreqFileName, nodeInfo.mhz), e); + LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using the value [%s] provided by the Libvirt.", cpuInfoMaxFreqFileName, nodeInfo.mhz), e); return nodeInfo.mhz; } } From 87d876adbe71308f701dd9d1565f265deb81fba4 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 30 Apr 2021 17:10:36 -0300 Subject: [PATCH 5/8] Change getCpuSpeed's log --- .../java/org/apache/cloudstack/utils/linux/KVMHostInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index d4554556f7d0..fea30b950ff6 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -82,7 +82,7 @@ public List getCapabilities() { protected static long getCpuSpeed(final NodeInfo nodeInfo) { try (Reader reader = new FileReader(cpuInfoMaxFreqFileName)) { Long cpuInfoMaxFreq = Long.parseLong(IOUtils.toString(reader).trim()); - LOGGER.info(String.format("Retrieved value [%s] from file [%s]. Using the value divided by 1000 [%s] as CPU speed value.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000)); + LOGGER.info(String.format("Retrieved value [%s] from file [%s]. This corresponds to a CPU speed of [%s] MHz.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000)); return cpuInfoMaxFreq / 1000; } catch (IOException | NumberFormatException e) { LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using the value [%s] provided by the Libvirt.", cpuInfoMaxFreqFileName, nodeInfo.mhz), e); From 692ea371f4e24510d5fd55c775659dd5bf075550 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Wed, 5 May 2021 15:50:39 -0300 Subject: [PATCH 6/8] Fix space betwen params Co-authored-by: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com> --- .../java/org/apache/cloudstack/utils/linux/KVMHostInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index fea30b950ff6..4af39730e184 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -130,7 +130,7 @@ private void getHostInfoFromLibvirt() { conn.close(); LOGGER.info(String.format("Fetched the following host's information {\"cpus\": %s, \"cpuSpeed\": %s, \"cpuSockets\": %s, \"cpuNodes\": %s, \"capabilities\": \"%s\"}.", - hosts.cpus,this.cpuSpeed, hosts.sockets, hosts.nodes, this.capabilities.toString())); + hosts.cpus, this.cpuSpeed, hosts.sockets, hosts.nodes, this.capabilities.toString())); } catch (LibvirtException e) { LOGGER.error("Caught libvirt exception while fetching host information", e); } From f20e1275de2f7f9f364794ba47937c3342344586 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 4 Jun 2021 14:44:43 -0300 Subject: [PATCH 7/8] Remove repeated log --- .../java/org/apache/cloudstack/utils/linux/KVMHostInfo.java | 5 +---- .../main/java/com/cloud/resource/ResourceManagerImpl.java | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index 4af39730e184..f20c71a8fdc3 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -128,10 +128,7 @@ private void getHostInfoFromLibvirt() { */ this.capabilities.add("snapshot"); conn.close(); - - LOGGER.info(String.format("Fetched the following host's information {\"cpus\": %s, \"cpuSpeed\": %s, \"cpuSockets\": %s, \"cpuNodes\": %s, \"capabilities\": \"%s\"}.", - hosts.cpus, this.cpuSpeed, hosts.sockets, hosts.nodes, this.capabilities.toString())); - } catch (LibvirtException e) { + } catch (final LibvirtException e) { LOGGER.error("Caught libvirt exception while fetching host information", e); } } diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index 75cf82ff0333..a3b9df8fb1c9 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -2436,9 +2436,6 @@ public HostVO fillRoutingHostVO(final HostVO host, final StartupRoutingCommand s host.setHypervisorType(hyType); host.setHypervisorVersion(ssCmd.getHypervisorVersion()); host.setGpuGroups(ssCmd.getGpuGroupDetails()); - - s_logger.info(String.format("Filling %s with the following information retrieved from the agent {\"cpus\": %s, \"cpuSpeed\": %s, \"cpuSockets\": %s, " - + "\"totalMemory\": \"%s\"}.", host.toString(), ssCmd.getCpus(), ssCmd.getSpeed(), ssCmd.getCpuSockets(), ssCmd.getCapabilities(), ssCmd.getMemory())); return host; } From fb4822bf24b06d6cbfb55e958e606d5b75e040ac Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> Date: Thu, 10 Jun 2021 11:27:30 -0300 Subject: [PATCH 8/8] Change var's access --- .../java/org/apache/cloudstack/utils/linux/KVMHostInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index f20c71a8fdc3..60e98f58e72c 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -42,7 +42,7 @@ public class KVMHostInfo { private long overCommitMemory; private List capabilities = new ArrayList<>(); - public static String cpuInfoMaxFreqFileName = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; + private static String cpuInfoMaxFreqFileName = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; public KVMHostInfo(long reservedMemory, long overCommitMemory) { this.reservedMemory = reservedMemory;