Yevgeny Zaspitsky has uploaded a new change for review.

Change subject: core: Audit log warning about display network connectivity 
change. (CollectVdsNetworkDataVDSCommand)
......................................................................

core: Audit log warning about display network connectivity change. 
(CollectVdsNetworkDataVDSCommand)

The warning that let the user to understand that the changes in
display network will be applied not instantly, but on the next
VM restart. The change is done in CollectVdsNetworkDataVDSCommand.

Change-Id: I9949fc6ed52871ccfb1a15397e2cc722ad231b8f
Bug-Url: https://bugzilla.redhat.com/1078836
Signed-off-by: Yevgeny Zaspitsky <yzasp...@redhat.com>
---
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/VdcEventNotificationUtils.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/vdsbroker/CollectVdsNetworkDataVDSCommand.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicate.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicate.java
A 
backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicateTest.java
A 
backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicateTest.java
8 files changed, 213 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/27168/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 64b364d..641b1b7 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
@@ -634,6 +634,7 @@
     NETWORK_ACTIVATE_VM_INTERFACE_FAILURE(1013, AuditLogSeverity.ERROR),
     NETWORK_DEACTIVATE_VM_INTERFACE_SUCCESS(1014),
     NETWORK_DEACTIVATE_VM_INTERFACE_FAILURE(1015, AuditLogSeverity.ERROR),
+    NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM(1098, 
AuditLogSeverity.WARNING),
     NETWORK_UPDATE_DISPLAY_FOR_CLUSTER_WITH_ACTIVE_VM(1099, 
AuditLogSeverity.WARNING),
     NETWORK_UPDATE_DISPLAY_TO_VDS_GROUP(1100),
     NETWORK_UPDATE_DISPLAY_TO_VDS_GROUP_FAILED(1101, AuditLogSeverity.ERROR),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
index 65a7fbf..93cd371 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
@@ -38,7 +38,8 @@
         AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.VDS_HIGH_SWAP_USE);
         AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.VDS_LOW_SWAP);
         AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.HOST_INTERFACE_STATE_DOWN);
-        AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.HOST_BOND_SLAVE_STATE_DOWN);
+        AddEventNotificationEntry(EventNotificationEntity.Host,
+                AuditLogType.NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM);
         AddEventNotificationEntry(EventNotificationEntity.VirtHost, 
AuditLogType.VDS_SET_NONOPERATIONAL_DOMAIN);
         AddEventNotificationEntry(EventNotificationEntity.VirtHost, 
AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_NO_HOST_FOR_SPM);
         AddEventNotificationEntry(EventNotificationEntity.VirtHost, 
AuditLogType.SYSTEM_DEACTIVATED_STORAGE_DOMAIN);
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 35e6008..428ab31 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -515,6 +515,7 @@
 NETWORK_REMOVE_VM_INTERFACE=Interface ${InterfaceName} (${InterfaceType}) was 
removed from VM ${VmName}. (User: ${UserName})
 NETWORK_REMOVE_VM_INTERFACE_FAILED=Failed to remove Interface ${InterfaceName} 
(${InterfaceType}) from VM ${VmName}. (User: ${UserName})
 NETWORK_UPDATE_DISPLAY_FOR_CLUSTER_WITH_ACTIVE_VM=Update Display Network 
(${NetworkName}) for Cluster ${VdsGroupName} with active VMs. The change will 
be applied to those VMs after the next reboot.
+NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM=Update Display Network Host 
${VdsName} with active VMs. The change will be applied to those VMs after the 
next reboot. Running VMs might loose display connectivity until then.
 NETWORK_UPDATE_DISPLAY_TO_VDS_GROUP=Update Display Network (${NetworkName}) 
for Cluster ${VdsGroupName}. (User: ${UserName})
 NETWORK_UPDATE_DISPLAY_TO_VDS_GROUP_FAILED=Failed to update Display Network 
(${NetworkName}) for Cluster ${VdsGroupName}. (User: ${UserName})
 NETWORK_UPDATE_NETWORK_TO_VDS_INTERFACE=Update Network ${NetworkName} in Host 
${VdsName}. (User: ${UserName})
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
index 6209427..aeac301 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
@@ -3,6 +3,7 @@
 import static 
org.ovirt.engine.core.common.businessentities.network.NetworkStatus.OPERATIONAL;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -25,9 +26,12 @@
 import org.ovirt.engine.core.dao.network.InterfaceDao;
 import org.ovirt.engine.core.dao.network.NetworkQoSDao;
 import org.ovirt.engine.core.utils.NetworkUtils;
+import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 import org.ovirt.engine.core.vdsbroker.ResourceManager;
+import 
org.ovirt.engine.core.vdsbroker.vdsbroker.predicates.DisplayInterfaceEqualityPredicate;
+import 
org.ovirt.engine.core.vdsbroker.vdsbroker.predicates.IsNetworkOnInterfacePredicate;
 
 public class CollectVdsNetworkDataVDSCommand extends 
GetCapabilitiesVDSCommand<CollectHostNetworkDataVdsCommandParameters> {
     public 
CollectVdsNetworkDataVDSCommand(CollectHostNetworkDataVdsCommandParameters 
parameters) {
@@ -91,7 +95,9 @@
     public static NonOperationalReason persistAndEnforceNetworkCompliance(VDS 
vds,
             boolean skipManagementNetwork,
             Map<String, VdsNetworkInterface> nicsByName) {
-        persistTopology(vds, nicsByName);
+        List<VdsNetworkInterface> dbIfaces =
+                
DbFacade.getInstance().getInterfaceDao().getAllInterfacesForVds(vds.getId());
+        persistTopology(vds, nicsByName, dbIfaces);
 
         if (vds.getStatus() != VDSStatus.Maintenance) {
 
@@ -123,7 +129,10 @@
                 return NonOperationalReason.VM_NETWORK_IS_BRIDGELESS;
             }
 
-            logUnsynchronizedNetworks(vds, 
Entities.entitiesByName(clusterNetworks));
+            final Map<String, Network> clusterNetworksByName = 
Entities.entitiesByName(clusterNetworks);
+            final Collection<Network> dbHostNetworks = 
findNetworksOnInterfaces(dbIfaces, clusterNetworksByName);
+            logChangedDisplayNetwork(vds, dbHostNetworks, dbIfaces);
+            logUnsynchronizedNetworks(vds, clusterNetworksByName);
         }
         return NonOperationalReason.NONE;
     }
@@ -147,6 +156,64 @@
                 break;
             }
         }
+    }
+
+    private static void logChangedDisplayNetwork(
+            VDS vds,
+            Collection<Network> engineHostNetworks,
+            Collection<VdsNetworkInterface> engineInterfaces) {
+
+        if (isVmRunningOnHost(vds.getId())) {
+            final Network engineDisplayNetwork = 
findDisplayNetwork(engineHostNetworks);
+
+            final IsNetworkOnInterfacePredicate isNetworkOnInterfacePredicate =
+                    new 
IsNetworkOnInterfacePredicate(engineDisplayNetwork.getName());
+            final VdsNetworkInterface vdsmDisplayInterface = 
LinqUtils.firstOrNull(
+                    vds.getInterfaces(),
+                    isNetworkOnInterfacePredicate);
+            final VdsNetworkInterface engineDisplayInterface = 
LinqUtils.firstOrNull(
+                    engineInterfaces,
+                    isNetworkOnInterfacePredicate);
+            final DisplayInterfaceEqualityPredicate 
displayIneterfaceEqualityPredicate =
+                    new 
DisplayInterfaceEqualityPredicate(engineDisplayInterface);
+            if (vdsmDisplayInterface == null // the display interface is't on 
host anymore
+                    || 
!displayIneterfaceEqualityPredicate.eval(vdsmDisplayInterface)) {
+                final AuditLogableBase loggable = new AuditLogableBase();
+                loggable.setVdsId(vds.getId());
+                AuditLogDirector.log(loggable, 
AuditLogType.NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM);
+            }
+        }
+    }
+
+    private static boolean isVmRunningOnHost(Guid hostId) {
+        return 
!DbFacade.getInstance().getVmDao().getAllRunningForVds(hostId).isEmpty();
+    }
+
+    private static Collection<Network> findNetworksOnInterfaces(
+            Collection<VdsNetworkInterface> ifaces,
+            Map<String, Network> clusterNetworksByName) {
+        final Collection<Network> networks = new ArrayList<Network>();
+        for (VdsNetworkInterface iface : ifaces) {
+            final String interfaceNetworkName = iface.getNetworkName();
+            if (clusterNetworksByName.containsKey(interfaceNetworkName)) {
+                final Network network = 
clusterNetworksByName.get(interfaceNetworkName);
+                networks.add(network);
+            }
+        }
+        return networks;
+    }
+
+    private static Network findDisplayNetwork(Collection<Network> networks) {
+        Network managementNetwork = null;
+        for (Network network : networks) {
+            if (network.getCluster().isDisplay()) {
+                return network;
+            }
+            if (NetworkUtils.isManagementNetwork(network)) {
+                managementNetwork = network;
+            }
+        }
+        return managementNetwork;
     }
 
     private static void logUnsynchronizedNetworks(VDS vds, Map<String, 
Network> networks) {
@@ -174,9 +241,11 @@
         }
     }
 
-    private static void persistTopology(VDS vds, Map<String, 
VdsNetworkInterface> nicsByName) {
+    private static void persistTopology(
+            VDS vds,
+            Map<String, VdsNetworkInterface> nicsByName,
+            List<VdsNetworkInterface> dbIfaces) {
         InterfaceDao interfaceDAO = DbFacade.getInstance().getInterfaceDao();
-        List<VdsNetworkInterface> dbIfaces = 
interfaceDAO.getAllInterfacesForVds(vds.getId());
         List<String> updatedIfaces = new ArrayList<String>();
         List<VdsNetworkInterface> dbIfacesToBatch = new ArrayList<>();
         Map<String, VdsNetworkInterface> hostNicsByNames = 
Entities.entitiesByName(vds.getInterfaces());
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicate.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicate.java
new file mode 100644
index 0000000..8225381
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicate.java
@@ -0,0 +1,28 @@
+package org.ovirt.engine.core.vdsbroker.vdsbroker.predicates;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+import org.ovirt.engine.core.utils.linq.Predicate;
+
+public final class DisplayInterfaceEqualityPredicate implements 
Predicate<VdsNetworkInterface> {
+    private final VdsNetworkInterface iface;
+
+    public DisplayInterfaceEqualityPredicate(VdsNetworkInterface iface) {
+        this.iface = iface;
+    }
+
+    @Override
+    public boolean eval(VdsNetworkInterface otherIface) {
+        if (iface == otherIface) {
+            return true;
+        }
+        if (otherIface == null) {
+            return false;
+        }
+        // at this stage both of the objects are not null
+        EqualsBuilder eb = new EqualsBuilder();
+        eb.append(iface.getName(), otherIface.getName());
+        eb.append(iface.getAddress(), otherIface.getAddress());
+        return eb.isEquals();
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicate.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicate.java
new file mode 100644
index 0000000..e41f426
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicate.java
@@ -0,0 +1,17 @@
+package org.ovirt.engine.core.vdsbroker.vdsbroker.predicates;
+
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+import org.ovirt.engine.core.utils.linq.Predicate;
+
+public final class IsNetworkOnInterfacePredicate implements 
Predicate<VdsNetworkInterface> {
+    private final String networkName;
+
+    public IsNetworkOnInterfacePredicate(String networkName) {
+        this.networkName = networkName;
+    }
+
+    @Override
+    public boolean eval(VdsNetworkInterface vdsNetworkInterface) {
+        return networkName.equals(vdsNetworkInterface.getNetworkName());
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicateTest.java
 
b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicateTest.java
new file mode 100644
index 0000000..722c703
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/DisplayInterfaceEqualityPredicateTest.java
@@ -0,0 +1,56 @@
+package org.ovirt.engine.core.vdsbroker.vdsbroker.predicates;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DisplayInterfaceEqualityPredicateTest {
+    private static final String TEST_INTERFACE_NAME = "interface name";
+    private static final String TEST_INTERFACE_ADDRESS = "interface address";
+
+    @Mock
+    private VdsNetworkInterface mockIface;
+    @Mock
+    private VdsNetworkInterface mockOtherIface;
+
+    private DisplayInterfaceEqualityPredicate underTest;
+
+    @Before
+    public void setUp() throws Exception {
+        Mockito.when(mockIface.getName()).thenReturn(TEST_INTERFACE_NAME);
+        
Mockito.when(mockIface.getAddress()).thenReturn(TEST_INTERFACE_ADDRESS);
+        underTest = new DisplayInterfaceEqualityPredicate(mockIface);
+    }
+
+    @Test
+    public void testEvalPositive() throws Exception {
+        Mockito.when(mockOtherIface.getName()).thenReturn(TEST_INTERFACE_NAME);
+        
Mockito.when(mockOtherIface.getAddress()).thenReturn(TEST_INTERFACE_ADDRESS);
+
+        Assert.assertTrue(underTest.eval(mockOtherIface));
+    }
+
+    @Test
+    public void testEvalDifferentName() throws Exception {
+        Mockito.when(mockOtherIface.getName()).thenReturn("not" + 
TEST_INTERFACE_NAME);
+        
Mockito.when(mockOtherIface.getAddress()).thenReturn(TEST_INTERFACE_ADDRESS);
+
+        Assert.assertFalse(underTest.eval(mockOtherIface));
+    }
+
+    @Test
+    public void testEvalDifferentAddress() throws Exception {
+        Mockito.when(mockOtherIface.getName()).thenReturn(TEST_INTERFACE_NAME);
+        Mockito.when(mockOtherIface.getAddress()).thenReturn("not" + 
TEST_INTERFACE_ADDRESS);
+
+        Assert.assertFalse(underTest.eval(mockOtherIface));
+    }
+
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicateTest.java
 
b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicateTest.java
new file mode 100644
index 0000000..fcc9d67
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/predicates/IsNetworkOnInterfacePredicateTest.java
@@ -0,0 +1,35 @@
+package org.ovirt.engine.core.vdsbroker.vdsbroker.predicates;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+
+@RunWith(MockitoJUnitRunner.class)
+public class IsNetworkOnInterfacePredicateTest {
+
+    private static final String TEST_NETWORK_NAME = "network name";
+    @Mock
+    private VdsNetworkInterface mockVdsNetworkInterface;
+
+    @Test
+    public void testEvalPositive() throws Exception {
+        
Mockito.when(mockVdsNetworkInterface.getNetworkName()).thenReturn(TEST_NETWORK_NAME);
+
+        final IsNetworkOnInterfacePredicate underTest = new 
IsNetworkOnInterfacePredicate(TEST_NETWORK_NAME);
+
+        Assert.assertTrue(underTest.eval(mockVdsNetworkInterface));
+    }
+
+    @Test
+    public void testEvalNegaitive() throws Exception {
+        
Mockito.when(mockVdsNetworkInterface.getNetworkName()).thenReturn("not" + 
TEST_NETWORK_NAME);
+
+        final IsNetworkOnInterfacePredicate underTest = new 
IsNetworkOnInterfacePredicate(TEST_NETWORK_NAME);
+
+        Assert.assertFalse(underTest.eval(mockVdsNetworkInterface));
+    }
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9949fc6ed52871ccfb1a15397e2cc722ad231b8f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yevgeny Zaspitsky <yzasp...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to