Alona Kaplan has uploaded a new change for review.

Change subject: core: event on interface status change
......................................................................

core: event on interface status change

When the status of the interface/bond is changed an event should be
reported in the following cases-
1. There is a network or label on the interface/bond
2. The interface is a slave of a bond and 1 is true for the parent bond.

There won't be more than one event per interface each 30 minutes.

Change-Id: I76953e4b52e35d2e18b6bc68051fa7dd6f3db129
Bug-Url: https://bugzilla.redhat.com/1079719
Bug-Url: https://bugzilla.redhat.com/987299
Signed-off-by: Alona Kaplan <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.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
3 files changed, 69 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/04/26104/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 398ca7e..9e7846a 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
@@ -108,6 +108,11 @@
     HOST_REFRESHED_CAPABILITIES(606),
     HOST_REFRESH_CAPABILITIES_FAILED(607, AuditLogSeverity.ERROR),
 
+    HOST_IFACE_DOWN(608, AuditLogSeverity.WARNING, 
AuditLogTimeInterval.MINUTE.getValue() * 30),
+    HOST_IFACE_UP(609, AuditLogSeverity.NORMAL, 
AuditLogTimeInterval.MINUTE.getValue() * 30),
+    HOST_BOND_DOWN(610, AuditLogSeverity.WARNING, 
AuditLogTimeInterval.MINUTE.getValue() * 30),
+    HOST_BOND_UP(611, AuditLogSeverity.NORMAL, 
AuditLogTimeInterval.MINUTE.getValue() * 30),
+
     // Disk alignment audit logs
     DISK_ALIGNMENT_SCAN_START(700),
     DISK_ALIGNMENT_SCAN_FAILURE(701, AuditLogSeverity.WARNING),
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 768ad1c..6619e46 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -218,6 +218,10 @@
 VDS_ACTIVATE_FAILED_ASYNC=Failed to autorecover Host ${VdsName}.
 HOST_REFRESHED_CAPABILITIES=Successfully refreshed the capabilities of host 
${VdsName}.
 HOST_REFRESH_CAPABILITIES_FAILED=Failed to refresh the capabilities of host 
${VdsName}.
+HOST_IFACE_DOWN=Interface '${InterfaceName}' on host ${VdsName}, changed state 
to down
+HOST_IFACE_UP=Interface '${InterfaceName}' on host ${VdsName}, changed state 
to up
+HOST_BOND_DOWN=Bond '${InterfaceName}' on host ${VdsName}, changed state to 
down
+HOST_BOND_UP=Bond '${InterfaceName}' on host ${VdsName}, changed state to up
 VDS_DETECTED=Status of host ${VdsName} was set to ${HostStatus}.
 VDS_FAILURE=Host ${VdsName} is non responsive.
 VDS_MAINTENANCE=Host ${VdsName} was switched to Maintenance Mode.
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 12d7781..8ecd681 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
@@ -642,6 +642,7 @@
         List<String> brokenNics = new ArrayList<String>();
 
         try {
+            reportNicStatusChanges();
             Pair<List<String>, List<String>> problematicNics = 
determineProblematicNics(_vds.getInterfaces(),
                     
getDbFacade().getNetworkDao().getAllForCluster(_vds.getVdsGroupId()));
             brokenNics.addAll(problematicNics.getFirst());
@@ -749,6 +750,65 @@
         return new Pair<List<String>, List<String>>(brokenNics, networks);
     }
 
+    private void reportNicStatusChanges() {
+        List<VdsNetworkInterface> interfaces = _vds.getInterfaces();
+        Set<VdsNetworkInterface> slaves = new HashSet<>();
+        Map<String, InterfaceStatus> monitoredInterfaces = new HashMap<String, 
InterfaceStatus>();
+
+        for (VdsNetworkInterface iface : interfaces) {
+            if (iface.getBondName() != null) {
+                slaves.add(iface);
+            }
+
+            String parentIfaceName =
+                    iface.getVlanId() == null ? iface.getName() : 
NetworkUtils.stripVlan(iface.getName());
+
+            // If the parent interface already marked as monitored- no need to 
check it again
+            if (monitoredInterfaces.containsKey(parentIfaceName)) {
+                continue;
+            }
+
+            // The status of the interface should be monitored only if it has 
networks attached to it or has labels
+            if (StringUtils.isNotEmpty(iface.getNetworkName())
+                    || (iface.getLabels() != null && 
!iface.getLabels().isEmpty())) {
+                VdsNetworkInterface parentIface = iface;
+                // If vlan find the parent interface
+                if (iface.getVlanId() != null) {
+                    for (VdsNetworkInterface tmpIface : interfaces) {
+                        if (parentIfaceName.equals(tmpIface.getName())) {
+                            parentIface = tmpIface;
+                        }
+                    }
+                }
+                monitoredInterfaces.put(parentIface.getName(), 
parentIface.getStatistics().getStatus());
+            }
+        }
+
+        // Slaves should be monitored if the bond is monitored
+        for (VdsNetworkInterface slave : slaves) {
+            if (monitoredInterfaces.containsKey(slave.getBondName())) {
+                monitoredInterfaces.put(slave.getName(), 
slave.getStatistics().getStatus());
+            }
+        }
+
+        for (VdsNetworkInterface oldIface : 
getDbFacade().getInterfaceDao().getAllInterfacesForVds(_vds.getId())) {
+            InterfaceStatus status = 
monitoredInterfaces.get(oldIface.getName());
+            if (status != null && oldIface.getStatistics().getStatus() != 
InterfaceStatus.NONE
+                    && oldIface.getStatistics().getStatus() != status) {
+                AuditLogableBase logable = new AuditLogableBase(_vds.getId());
+                logable.setCustomId(oldIface.getName());
+                logable.addCustomValue("InterfaceName", oldIface.getName());
+                if (oldIface.getBonded() != null && oldIface.getBonded()) {
+                    auditLog(logable, status == InterfaceStatus.UP ? 
AuditLogType.HOST_BOND_UP
+                            : AuditLogType.HOST_BOND_DOWN);
+                } else {
+                    auditLog(logable, status == InterfaceStatus.UP ? 
AuditLogType.HOST_IFACE_UP
+                            : AuditLogType.HOST_IFACE_DOWN);
+                }
+            }
+        }
+    }
+
     private static void populate(Map<String, Boolean> bondsWithStatus,
             List<VdsNetworkInterface> interfaces,
             List<Network> clusterNetworks,


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

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

Reply via email to