From a368ba9def6a02086ddea3fe84dcf01f6095c518 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 20 Nov 2020 11:40:02 +0100 Subject: [PATCH 1/2] VR: fix logging is not working and logs are not appended to /var/log/cloud.log (#4466) --- systemvm/debian/opt/cloud/bin/configure.py | 4 ---- systemvm/debian/opt/cloud/bin/cs/__init__.py | 9 +++++++++ systemvm/debian/opt/cloud/bin/update_config.py | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/configure.py b/systemvm/debian/opt/cloud/bin/configure.py index 5d60fab2b17..01e580fce2f 100755 --- a/systemvm/debian/opt/cloud/bin/configure.py +++ b/systemvm/debian/opt/cloud/bin/configure.py @@ -1019,10 +1019,6 @@ def main(argv): # The "GLOBAL" Configuration object config = CsConfig() - logging.basicConfig(filename=config.get_logger(), - level=config.get_level(), - format=config.get_format()) - # Load stored ip addresses from disk to CsConfig() config.set_address() diff --git a/systemvm/debian/opt/cloud/bin/cs/__init__.py b/systemvm/debian/opt/cloud/bin/cs/__init__.py index 13a83393a91..dc0c3d9517d 100755 --- a/systemvm/debian/opt/cloud/bin/cs/__init__.py +++ b/systemvm/debian/opt/cloud/bin/cs/__init__.py @@ -14,3 +14,12 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + +import logging +from cs.CsConfig import CsConfig + +config = CsConfig() + +logging.basicConfig(filename=config.get_logger(), + level=config.get_level(), + format=config.get_format()) diff --git a/systemvm/debian/opt/cloud/bin/update_config.py b/systemvm/debian/opt/cloud/bin/update_config.py index c9121eb634f..518a31ca5ed 100755 --- a/systemvm/debian/opt/cloud/bin/update_config.py +++ b/systemvm/debian/opt/cloud/bin/update_config.py @@ -26,8 +26,6 @@ import os.path import configure import json -logging.basicConfig(filename='/var/log/cloud.log', level=logging.INFO, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s') - # first commandline argument should be the file to process argc = len(sys.argv) if argc != 2 and argc != 3: From d79d24261a69769a481b71e6a74e197b76fcdf58 Mon Sep 17 00:00:00 2001 From: davidjumani Date: Fri, 20 Nov 2020 16:57:47 +0530 Subject: [PATCH 2/2] Adding memoryallocatedpercentage & memoryallocatedbytes to HostsResponse & HostsForMigrationResponse (#4478) --- .../api/response/HostForMigrationResponse.java | 17 +++++++++++++++++ .../cloudstack/api/response/HostResponse.java | 17 +++++++++++++++++ .../cloud/api/query/dao/HostJoinDaoImpl.java | 12 +++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java index 8cc31097205..e4a84a3166c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java @@ -128,10 +128,19 @@ public class HostForMigrationResponse extends BaseResponse { @Param(description = "the outgoing network traffic on the host") private Long networkKbsWrite; + @Deprecated @SerializedName("memoryallocated") @Param(description = "the amount of the host's memory currently allocated") private String memoryAllocated; + @SerializedName("memoryallocatedpercentage") + @Param(description = "the amount of the host's memory currently allocated in percentage") + private String memoryAllocatedPercentage; + + @SerializedName("memoryallocatedbytes") + @Param(description = "the amount of the host's memory currently allocated in bytes") + private Long memoryAllocatedBytes; + @SerializedName("memoryused") @Param(description = "the amount of the host's memory currently used") private Long memoryUsed; @@ -314,6 +323,14 @@ public class HostForMigrationResponse extends BaseResponse { this.memoryAllocated = memoryAllocated; } + public void setMemoryAllocatedPercentage(String memoryAllocatedPercentage) { + this.memoryAllocatedPercentage = memoryAllocatedPercentage; + } + + public void setMemoryAllocatedBytes(Long memoryAllocatedBytes) { + this.memoryAllocatedBytes = memoryAllocatedBytes; + } + public void setMemoryUsed(Long memoryUsed) { this.memoryUsed = memoryUsed; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java index 61a662f0725..7b80f22b7b6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java @@ -136,10 +136,19 @@ public class HostResponse extends BaseResponse { @Param(description = "the amount of the host's memory after applying the mem.overprovisioning.factor") private String memWithOverprovisioning; + @Deprecated @SerializedName("memoryallocated") @Param(description = "the amount of the host's memory currently allocated") private long memoryAllocated; + @SerializedName("memoryallocatedpercentage") + @Param(description = "the amount of the host's memory currently allocated in percentage") + private String memoryAllocatedPercentage; + + @SerializedName("memoryallocatedbytes") + @Param(description = "the amount of the host's memory currently allocated in bytes") + private Long memoryAllocatedBytes; + @SerializedName("memoryused") @Param(description = "the amount of the host's memory currently used") private Long memoryUsed; @@ -609,6 +618,14 @@ public class HostResponse extends BaseResponse { return memoryAllocated; } + public void setMemoryAllocatedPercentage(String memoryAllocatedPercentage) { + this.memoryAllocatedPercentage = memoryAllocatedPercentage; + } + + public void setMemoryAllocatedBytes(Long memoryAllocatedBytes) { + this.memoryAllocatedBytes = memoryAllocatedBytes; + } + public Long getMemoryUsed() { return memoryUsed; } diff --git a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java index 8b4220c8838..9f5bfee0dd4 100644 --- a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java +++ b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java @@ -170,9 +170,12 @@ public class HostJoinDaoImpl extends GenericDaoBase implements Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity(); hostResponse.setMemoryTotal(host.getTotalMemory()); - Float totalMemorywithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId()); - hostResponse.setMemWithOverprovisioning(decimalFormat.format(totalMemorywithOverprovisioning)); + Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId()); + hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning)); hostResponse.setMemoryAllocated(mem); + hostResponse.setMemoryAllocatedBytes(mem); + String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%"; + hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage); String hostTags = host.getTag(); hostResponse.setHostTags(host.getTag()); @@ -321,7 +324,10 @@ public class HostJoinDaoImpl extends GenericDaoBase implements hostResponse.setMemoryTotal(host.getTotalMemory()); Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId()); hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning)); - hostResponse.setMemoryAllocated(decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%"); + String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%"; + hostResponse.setMemoryAllocated(memoryAllocatedPercentage); + hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage); + hostResponse.setMemoryAllocatedBytes(mem); String hostTags = host.getTag(); hostResponse.setHostTags(host.getTag());