Noam Slomianko has uploaded a new change for review.

Change subject: engine: Report when vm gets less the Guaranteed memory
......................................................................

engine: Report when vm gets less the Guaranteed memory

Currently vm might get less then the guaranteed memory.
In they future they will be migrated, but for now we will only log the issue.

Change-Id: I47d32f291f39f0ab51c4e5d20a34ab01b47db562
Bug-Url: https://bugzilla.redhat.com/967574
Signed-off-by: Noam Slomianko <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatistics.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
7 files changed, 81 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/49/16949/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
index ed2e139..dd7817d 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
@@ -378,6 +378,8 @@
     VM_PAUSED_EPERM(146),
     VM_POWER_DOWN_FAILED(147),
 
+    VM_MEMORY_UNDER_GUARANTEED_VALUE(148, 
AuditLogTimeInterval.MINUTE.getValue() * 15),
+
     USER_ADD_VM_POOL(300),
     USER_ADD_VM_POOL_FAILED(301),
     USER_ADD_VM_POOL_WITH_VMS(302),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatistics.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatistics.java
index cf74869..b9e69e7 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatistics.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatistics.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.common.businessentities;
 
+import java.beans.Transient;
 import java.util.ArrayList;
 
 import 
org.ovirt.engine.core.common.businessentities.comparators.BusinessEntityGuidComparator;
@@ -130,6 +131,17 @@
         this.usage_mem_percentField = value;
     }
 
+    // NOT PRESISTED
+    private Integer currentMemory;
+
+    public Integer getCurrentMemory() {
+        return currentMemory;
+    }
+
+    public void setCurrentMemory(Integer value) {
+        currentMemory = value;
+    }
+
     private String disksUsage;
 
     /**
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
index f13a5ce..c8e52c0 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
@@ -505,6 +505,7 @@
         severities.put(AuditLogType.VM_PAUSED_EIO, AuditLogSeverity.ERROR);
         severities.put(AuditLogType.VM_PAUSED_EPERM, AuditLogSeverity.ERROR);
         severities.put(AuditLogType.VM_POWER_DOWN_FAILED, 
AuditLogSeverity.WARNING);
+        severities.put(AuditLogType.VM_MEMORY_UNDER_GUARANTEED_VALUE, 
AuditLogSeverity.WARNING);
         severities.put(AuditLogType.USER_RUN_VM, AuditLogSeverity.NORMAL);
         severities.put(AuditLogType.USER_RUN_VM_AS_STATELESS, 
AuditLogSeverity.NORMAL);
         severities.put(AuditLogType.USER_FAILED_RUN_VM, 
AuditLogSeverity.ERROR);
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
index cf3c426..7910392 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -305,6 +305,7 @@
 VM_PAUSED_EIO=VM ${VmName} has paused due to storage I/O problem.
 VM_PAUSED_EPERM=VM ${VmName} has paused due to storage permissions problem.
 VM_POWER_DOWN_FAILED=Shutdown of VM ${VmName} failed.
+VM_MEMORY_UNDER_GUARANTEED_VALUE=VM ${VmName} has less then the guaranteed 
memory
 VDS_INSTALL=Host ${VdsName} installed
 VDS_INSTALL_FAILED=Host ${VdsName} installation failed. 
${FailedInstallMessage}.
 VDS_INITIALIZING=Host ${VdsName} is initializing. Message: ${ErrorMessage}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index c950df4..8154371 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -83,7 +83,7 @@
 import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.entities.VmInternalData;
 
-@SuppressWarnings({ "synthetic-access", "unchecked" ,"rawtypes"})
+@SuppressWarnings({ "synthetic-access", "unchecked", "rawtypes" })
 public class VdsUpdateRunTimeInfo {
     private Map<Guid, VmInternalData> _runningVms;
     private final Map<Guid, VmDynamic> _vmDynamicToSave = new HashMap<Guid, 
VmDynamic>();
@@ -225,8 +225,9 @@
      * @param dao
      *            The DAO used for updating.
      */
-    private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends 
Serializable & Comparable<? super ID>> void updateAllInTransaction(final 
Collection<T> entities, final MassOperationsDao<T, ID> dao) {
-        updateAllInTransaction(null, entities,dao);
+    private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends 
Serializable & Comparable<? super ID>> void updateAllInTransaction(final 
Collection<T> entities,
+            final MassOperationsDao<T, ID> dao) {
+        updateAllInTransaction(null, entities, dao);
     }
 
     /**
@@ -244,22 +245,21 @@
      */
 
     private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends 
Serializable & Comparable<? super ID>> void updateAllInTransaction
-        (final String procedureName, final Collection<T> entities, final 
MassOperationsDao<T, ID> dao) {
-    final List<T> sortedList = new ArrayList<T>(entities);
-    Collections.sort(sortedList);
-    if (!entities.isEmpty()) {
-        TransactionSupport.executeInScope(TransactionScopeOption.Required,
-            new TransactionMethod<Void>() {
+            (final String procedureName, final Collection<T> entities, final 
MassOperationsDao<T, ID> dao) {
+        final List<T> sortedList = new ArrayList<T>(entities);
+        Collections.sort(sortedList);
+        if (!entities.isEmpty()) {
+            TransactionSupport.executeInScope(TransactionScopeOption.Required,
+                    new TransactionMethod<Void>() {
 
-                @Override
-                public Void runInTransaction() {
+                        @Override
+                        public Void runInTransaction() {
                             dao.updateAll(procedureName, sortedList);
-                    return null;
-                }
-            });
+                            return null;
+                        }
+                    });
+        }
     }
-}
-
 
     /**
      * check if value is less than configurable threshold , if yes , generated 
event log message
@@ -269,7 +269,8 @@
     private void checkVdsMemoryThreshold(VdsStatistics stat) {
 
         Integer minAvailableThreshold = 
Config.GetValue(ConfigValues.LogPhysicalMemoryThresholdInMB);
-        Integer maxUsedPercentageThreshold = 
Config.GetValue(ConfigValues.LogMaxPhysicalMemoryUsedThresholdInPercentage);
+        Integer maxUsedPercentageThreshold =
+                
Config.GetValue(ConfigValues.LogMaxPhysicalMemoryUsedThresholdInPercentage);
 
         if (stat.getMemFree() == null || stat.getusage_mem_percent() == null) {
             return;
@@ -962,6 +963,8 @@
 
             proceedDownVms();
 
+            guaranteedMemoryCheck();
+
             // update repository and check if there are any vm in cache that 
not
             // in vdsm
             updateRepository(running);
@@ -1098,6 +1101,7 @@
 
     /**
      * gets VM full information for the given list of VMs
+     *
      * @param vmsToUpdate
      * @return
      */
@@ -1115,7 +1119,7 @@
         String deviceType = getDeviceType(device);
 
         if (shouldLogDeviceDetails(deviceType)) {
-            Map<String,Object> deviceInfo = device;
+            Map<String, Object> deviceInfo = device;
             log.infoFormat(message + ": {2}", 
StringUtils.defaultString(deviceType), vmId, deviceInfo);
         } else {
             log.infoFormat(message, StringUtils.defaultString(deviceType), 
vmId);
@@ -1124,6 +1128,7 @@
 
     /**
      * Actually process the VM device update in DB.
+     *
      * @param vm
      */
     private void processVmDevices(Map vm) {
@@ -1162,6 +1167,7 @@
 
     /**
      * Removes unmanaged devices from DB if were removed by libvirt. Empties 
device address with isPlugged = false
+     *
      * @param vmId
      * @param processedDevices
      */
@@ -1195,6 +1201,7 @@
 
     /**
      * Adds new devices recognized by libvirt
+     *
      * @param vmId
      * @param device
      */
@@ -1229,6 +1236,7 @@
 
     /**
      * gets the device id from the structure returned by VDSM device ids are 
stored in specParams map
+     *
      * @param device
      * @return
      */
@@ -1239,6 +1247,7 @@
 
     /**
      * gets the device type from the structure returned by VDSM
+     *
      * @param device
      * @return
      */
@@ -1259,7 +1268,7 @@
 
                 if (vmToUpdate == null
                         || (vmToUpdate.getStatus() != runningVm.getStatus() &&
-                            !(vmToUpdate.getStatus() == 
VMStatus.PreparingForHibernate && runningVm.getStatus() == VMStatus.Up))) {
+                        !(vmToUpdate.getStatus() == 
VMStatus.PreparingForHibernate && runningVm.getStatus() == VMStatus.Up))) {
                     GetVmStatsVDSCommand<GetVmStatsVDSCommandParameters> 
command =
                             new 
GetVmStatsVDSCommand<GetVmStatsVDSCommandParameters>(new 
GetVmStatsVDSCommandParameters(
                                     _vds, runningVm.getId()));
@@ -1288,11 +1297,24 @@
                 AuditLogableBase auditLogable = new AuditLogableBase();
                 auditLogable.setVmId(vmDynamic.getId());
                 auditLogable.addCustomValue("wdaction", 
vmDynamic.getLastWatchdogAction());
-                //for the interpretation of vdsm's response see 
http://docs.python.org/2/library/time.html
+                // for the interpretation of vdsm's response see 
http://docs.python.org/2/library/time.html
                 auditLogable.addCustomValue("wdevent",
                         ObjectUtils.toString(new 
Date(vmDynamic.getLastWatchdogEvent().longValue() * 1000)));
                 AuditLogDirector.log(auditLogable, 
AuditLogType.WATCHDOG_EVENT);
             }
+        }
+    }
+
+    private void guaranteedMemoryCheck() {
+        for (VmInternalData vmInternalData : _runningVms.values()) {
+            VM savedVm = _vmDict.get(vmInternalData.getVmDynamic().getId());
+            if (vmInternalData.getVmStatistics().getCurrentMemory() != null &&
+                    savedVm.getMinAllocatedMem() > 
vmInternalData.getVmStatistics().getCurrentMemory()) {
+                AuditLogableBase auditLogable = new AuditLogableBase();
+                auditLogable.setVmId(savedVm.getId());
+                AuditLogDirector.log(auditLogable, 
AuditLogType.VM_MEMORY_UNDER_GUARANTEED_VALUE);
+            }
+
         }
     }
 
@@ -1301,7 +1323,6 @@
         return vmTo != null && lastWatchdogEvent != null
                 && (vmTo.getLastWatchdogEvent() == null || 
vmTo.getLastWatchdogEvent() < lastWatchdogEvent);
     }
-
 
     /**
      * Delete all vms with status Down
@@ -1324,7 +1345,8 @@
                     ResourceManager.getInstance().InternalSetVmStatus(vmTo, 
VMStatus.Suspended);
                 }
 
-                clearVm(vmTo, vmInternalData.getVmDynamic().getExitStatus(), 
vmInternalData.getVmDynamic().getExitMessage());
+                clearVm(vmTo, vmInternalData.getVmDynamic().getExitStatus(), 
vmInternalData.getVmDynamic()
+                        .getExitMessage());
             }
 
             VmStatistics vmStatistics = 
getDbFacade().getVmStatisticsDao().get(vm.getId());
@@ -1424,7 +1446,10 @@
                     }
                 }
                 // set vm status to down if source vm crushed
-                ResourceManager.getInstance().InternalSetVmStatus(curVm, 
VMStatus.Down, vmDynamic.getExitStatus(), vmDynamic.getExitMessage());
+                ResourceManager.getInstance().InternalSetVmStatus(curVm,
+                        VMStatus.Down,
+                        vmDynamic.getExitStatus(),
+                        vmDynamic.getExitMessage());
                 addVmDynamicToList(curVm.getDynamicData());
                 addVmStatisticsToList(curVm.getStatisticsData());
                 addVmInterfaceStatisticsToList(curVm.getInterfaces());
@@ -1673,7 +1698,8 @@
 
         // if the VM's status on source host was MigratingFrom and now the VM 
is running and its status
         // is not MigratingFrom, it means the migration failed
-        if (oldVmStatus == VMStatus.MigratingFrom && currentVmStatus != 
VMStatus.MigratingFrom && currentVmStatus.isRunning()) {
+        if (oldVmStatus == VMStatus.MigratingFrom && currentVmStatus != 
VMStatus.MigratingFrom
+                && currentVmStatus.isRunning()) {
             _vmsToRerun.add(runningVm.getId());
             log.infoFormat("Adding VM {0} to re-run list", runningVm.getId());
             vmToUpdate.setMigratingToVds(null);
@@ -1907,7 +1933,7 @@
     }
 
     private void clearVm(VM vm, VmExitStatus exitStatus, String exitMessage) {
-        if (vm.getStatus() != VMStatus.MigratingFrom ) {
+        if (vm.getStatus() != VMStatus.MigratingFrom) {
             // we must check that vm.getStatus() != VMStatus.Down because if 
it was set to down
             // the exit status and message were set, and we don't want to 
override them here.
             // we will add it to _vmDynamicToSave though because it might been 
removed from it in #updateRepository
@@ -1925,6 +1951,7 @@
 
     /**
      * An access method for test usages
+     *
      * @return The devices to be added to the database
      */
     protected List<VmDevice> getNewVmDevices() {
@@ -1933,6 +1960,7 @@
 
     /**
      * An access method for test usages
+     *
      * @return The devices to be removed from the database
      */
     protected List<VmDeviceId> getRemovedVmDevices() {
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
index 9adfc8f..a571b34 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
@@ -306,9 +306,18 @@
 
         // ------------- vm memory statistics -----------------------
         vm.setusage_mem_percent(AssignIntValue(xmlRpcStruct, 
VdsProperties.vm_usage_mem_percent));
+        vm.setCurrentMemory(getCurrMemory(xmlRpcStruct));
 
     }
 
+    private static Integer getCurrMemory(Map<String, Object> xmlRpcStruct) {
+        Map<String, Object> balloonInfo = (Map<String, Object>) 
xmlRpcStruct.get(VdsProperties.vm_balloonInfo);
+        if (balloonInfo != null) {
+            return AssignIntValue(balloonInfo, VdsProperties.vm_balloon_cur);
+        }
+        return null;
+    }
+
     public static void updateVDSDynamicData(VDS vds, Map<String, Object> 
xmlRpcStruct) {
         updateNetworkData(vds, xmlRpcStruct);
 
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
index bcb812a..8d8ddaf 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
@@ -192,6 +192,9 @@
     public static final String session = "session";
     public static final String spiceSslCipherSuite = "spiceSslCipherSuite";
 
+    public static final String vm_balloonInfo = "balloonInfo";
+    public static final String vm_balloon_cur = "balloon_cur";
+
     public static final String DriveC = "hda"; // drive C:
     public static final String DriveE = "hdb"; // drive E: (D: is the CD-ROM)
     public static final String DriveF = "hdc"; // drive F:


-- 
To view, visit http://gerrit.ovirt.org/16949
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I47d32f291f39f0ab51c4e5d20a34ab01b47db562
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Noam Slomianko <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to