Martin Mucha has uploaded a new change for review.

Change subject: override configuration
......................................................................

override configuration

core: add 'overrideConfiguration' field so user can explicitely express his 
intention.

Change-Id: I6e966a1cb51aee4743b0a40e4ea82d7f961e7bac
Signed-off-by: Martin Mucha <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkAttachment.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/NetworkAttachmentMapper.java
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
8 files changed, 110 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/37242/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java
index 4a7a1b0..ae89f12 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -25,6 +26,7 @@
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.network.Bond;
+import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos;
 import org.ovirt.engine.core.common.businessentities.network.IpConfiguration;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment;
@@ -43,6 +45,7 @@
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dao.network.HostNetworkQosDao;
 import org.ovirt.engine.core.utils.NetworkUtils;
@@ -66,6 +69,8 @@
     private List<VdsNetworkInterface> existingNics;
     private List<NetworkAttachment> existingAttachments;
     private List<HostNetwork> networksToConfigure;
+    private BusinessEntityMap<VdsNetworkInterface> 
existingNicsBusinessEntityMap;
+    private final QosDaoCache qosDaoCache = new 
QosDaoCache(getDbFacade().getHostNetworkQosDao());
 
     public HostSetupNetworksCommand(T parameters) {
         this(parameters, null);
@@ -110,16 +115,21 @@
                         getNetworkBusinessEntityMap());
         FailingValidationResults<String> validationResults = 
validator.validate();
 
-        if (validationResults.isValid()) {
-            return true;
+        if (!validationResults.isValid()) {
+            List<String> validationMessages = 
validationResults.translateToListOfViolationMessagesWithCausesString();
+            for (String msg : validationMessages) {
+                addCanDoActionMessage(msg);
+            }
+
+            return false;
         }
 
-        List<String> validationMessages = 
validationResults.translateToListOfViolationMessagesWithCausesString();
-        for (String msg : validationMessages) {
-            addCanDoActionMessage(msg);
+        if (!checkForOutOfSyncNetworks()) {
+            return false;
         }
 
-        return false;
+        return true;
+
     }
 
     protected boolean hostStatusLegalForSetupNetworks(VDS vds) {
@@ -159,6 +169,44 @@
         } catch (TimeoutException e) {
             log.debug("Host Setup networks command timed out for {} seconds", 
timeout);
         }
+    }
+
+    private boolean checkForOutOfSyncNetworks() {
+        BusinessEntityMap<VdsNetworkInterface> existingNicsBusinessEntityMap = 
getExistingNicsBusinessEntityMap();
+        boolean success = true;
+
+        for (NetworkAttachment networkAttachment : 
getParameters().getNetworkAttachments()) {
+            boolean doNotCheckForOutOfSync = 
networkAttachment.isOverrideConfiguration();
+            if (doNotCheckForOutOfSync) {
+                continue;
+            }
+
+            VdsNetworkInterface vdsNetworkInterface = 
existingNicsBusinessEntityMap.get(networkAttachment.getNicId());
+            Network network = 
getNetworkBusinessEntityMap().get(networkAttachment.getNetworkId());
+            HostNetworkQos qos = qosDaoCache.get(network.getQosId());
+
+            Map<Guid, NetworkAttachment> existingNetworkAttachmentMap =
+                    Entities.businessEntitiesById(getExistingAttachments());
+
+
+            boolean networkInSync = 
NetworkUtils.isNetworkInSync(vdsNetworkInterface, network, qos);
+            if (!networkInSync) {
+                NetworkAttachment existingNetworkAttachment = 
existingNetworkAttachmentMap.get(networkAttachment.getId());
+                boolean networkMoved = networkMoved(networkAttachment, 
existingNetworkAttachment);
+                addCanDoActionMessage(networkMoved ?
+                        VdcBllMessages.MOVING_NETWORKS_MAKES_IT_OUT_OF_SYNC :
+                        VdcBllMessages.NETWORKS_NOT_IN_SYNC);
+                success = false;
+            }
+        }
+
+        return success;
+    }
+
+    private boolean networkMoved(NetworkAttachment updatedNetworkAttachment, 
NetworkAttachment originalNetworkAttachment) {
+        return 
!originalNetworkAttachment.getNicId().equals(updatedNetworkAttachment.getNicId())
 ||
+                
!originalNetworkAttachment.getNetworkId().equals(updatedNetworkAttachment.getNetworkId());
+
     }
 
     private FutureVDSCall<VDSReturnValue> invokeSetupNetworksCommand(int 
timeout) {
@@ -225,13 +273,13 @@
     private List<VdsNetworkInterface> getExistingNics() {
         if (existingNics == null) {
             existingNics = 
getDbFacade().getInterfaceDao().getAllInterfacesForVds(getVdsId());
-            HostNetworkQosDao qosDao = getDbFacade().getHostNetworkQosDao();
 
             for (VdsNetworkInterface iface : existingNics) {
                 Network network = 
getNetworkBusinessEntityMap().get(iface.getNetworkName());
-                
iface.setNetworkImplementationDetails(NetworkUtils.calculateNetworkImplementationDetails(network,
-                        network == null ? null : 
qosDao.get(network.getQosId()),
-                        iface));
+                HostNetworkQos hostNetworkQos = network == null ? null : 
qosDaoCache.get(network.getQosId());
+                VdsNetworkInterface.NetworkImplementationDetails 
networkImplementationDetails =
+                        
NetworkUtils.calculateNetworkImplementationDetails(network, hostNetworkQos, 
iface);
+                
iface.setNetworkImplementationDetails(networkImplementationDetails);
             }
         }
 
@@ -260,7 +308,7 @@
     private List<HostNetwork> getNetworks() {
         if (networksToConfigure == null) {
             networksToConfigure = new 
ArrayList<>(getParameters().getNetworkAttachments().size());
-            BusinessEntityMap<VdsNetworkInterface> nics = new 
BusinessEntityMap<>(getExistingNics());
+            BusinessEntityMap<VdsNetworkInterface> nics = 
getExistingNicsBusinessEntityMap();
 
             for (NetworkAttachment attachment : 
getParameters().getNetworkAttachments()) {
                 Network network = 
getNetworkBusinessEntityMap().get(attachment.getNetworkId());
@@ -276,6 +324,14 @@
         }
 
         return networksToConfigure;
+    }
+
+    private BusinessEntityMap<VdsNetworkInterface> 
getExistingNicsBusinessEntityMap() {
+        if (existingNicsBusinessEntityMap == null) {
+            existingNicsBusinessEntityMap = new 
BusinessEntityMap<>(getExistingNics());
+        }
+
+        return existingNicsBusinessEntityMap;
     }
 
     private boolean defaultRouteSupported() {
@@ -360,4 +416,26 @@
         return networkBusinessEntityMap;
     }
 
+    public static class QosDaoCache {
+
+        private final HostNetworkQosDao qosDao;
+        private final Map<Guid, HostNetworkQos> cache = new HashMap<>();
+
+        public QosDaoCache(HostNetworkQosDao qosDao) {
+            this.qosDao = qosDao;
+
+        }
+
+        public HostNetworkQos get(Guid qosId) {
+            if (cache.containsKey(qosId)) {
+                return cache.get(qosId);
+            }
+
+            HostNetworkQos result = qosDao.get(qosId);
+            cache.put(qosId, result);
+
+            return result;
+        }
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkAttachment.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkAttachment.java
index bb96a8f..ef478e2 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkAttachment.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkAttachment.java
@@ -29,6 +29,8 @@
     private IpConfiguration ipConfiguration;
     private Map<String, String> properties;
 
+    private boolean overrideConfiguration;
+
     public Guid getId() {
         return id;
     }
@@ -150,4 +152,12 @@
                 + ", ipConfiguration=" + ipConfiguration
                 + ", properties=" + properties + "]";
     }
+
+    public boolean isOverrideConfiguration() {
+        return overrideConfiguration;
+    }
+
+    public void setOverrideConfiguration(boolean overrideConfiguration) {
+        this.overrideConfiguration = overrideConfiguration;
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 656d32d..1489332 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -535,6 +535,7 @@
     NETWORK_CLUSTER_HAVE_NOT_EXISTING_DATA_CENTER_NETWORK(ErrorType.CONFLICT),
     NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER(ErrorType.CONFLICT),
     NETWORKS_NOT_IN_SYNC(ErrorType.CONFLICT),
+    MOVING_NETWORKS_MAKES_IT_OUT_OF_SYNC(ErrorType.CONFLICT),
     NETWORK_INTERFACES_ALREADY_SPECIFIED(ErrorType.CONFLICT),
     NETWORKS_ALREADY_ATTACHED_TO_IFACES(ErrorType.CONFLICT),
     NETWORK_INTERFACES_DONT_EXIST(ErrorType.BAD_PARAMETERS),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 10e7620..2622af3 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -589,6 +589,7 @@
        -Please remove those Networks first.
 NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER=The specified Logical Network doesn't 
exist in the current Cluster.
 NETWORKS_NOT_IN_SYNC=Cannot ${action} ${type}. The following Networks' 
definitions on the Network Interfaces are different than those on the Logical 
Networks. Please synchronize the Network Interfaces before editing the 
networks: ${NETWORKS_NOT_IN_SYNC}.
+MOVING_NETWORKS_MAKES_IT_OUT_OF_SYNC=Cannot ${action} ${type}. After moving 
the network, the following Networks' definitions on the Network Interfaces will 
be different than those on the Logical Networks. Please synchronize the Network 
Interfaces before editing the networks: ${NETWORKS_NOT_IN_SYNC}.
 NETWORK_INTERFACES_ALREADY_SPECIFIED=Cannot ${action} ${type}. The following 
Network Interfaces were specified more than once: 
${NETWORK_INTERFACES_ALREADY_SPECIFIED_LIST}.
 ACTION_TYPE_FAILED_EXTERNAL_NETWORKS_CANNOT_BE_PROVISIONED=Cannot ${action} 
${type}. The following external networks cannot be configured on host via 
'Setup Networks': 
${ACTION_TYPE_FAILED_EXTERNAL_NETWORKS_CANNOT_BE_PROVISIONED_LIST}.
 NETWORKS_ALREADY_ATTACHED_TO_IFACES=Cannot ${action} ${type}. The following 
Logical Networks are attached to more than one Network Interface: 
${NETWORKS_ALREADY_ATTACHED_TO_IFACES_LIST}.
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/NetworkAttachmentMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/NetworkAttachmentMapper.java
index 06b1e12..23369f8 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/NetworkAttachmentMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/NetworkAttachmentMapper.java
@@ -40,6 +40,10 @@
             
entity.setProperties(CustomPropertiesParser.toMap(model.getProperties()));
         }
 
+        if (model.isSetOverrideConfiguration()) {
+            entity.setOverrideConfiguration(model.isOverrideConfiguration());
+        }
+
         if (model.isSetIpConfiguration() && 
model.getIpConfiguration().isSetIPv4Configuration()) {
             IPv4S ipv4configuration = 
model.getIpConfiguration().getIPv4Configuration();
             if (ipv4configuration != null) {
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 9b480c3..5555164 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -1621,6 +1621,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. The following Networks' 
definitions on the Network Interfaces are different than those on the Logical 
Networks. Please synchronize the Network Interfaces before editing the 
networks: ${NETWORKS_NOT_IN_SYNC}.")
     String NETWORKS_NOT_IN_SYNC();
 
+    @DefaultStringValue("Cannot ${action} ${type}. After moving the network, 
the following Networks' definitions on the Network Interfaces will be different 
than those on the Logical Networks. Please synchronize the Network Interfaces 
before editing the networks: ${NETWORKS_NOT_IN_SYNC}.")
+    String MOVING_NETWORKS_MAKES_IT_OUT_OF_SYNC();
+
     @DefaultStringValue("Cannot ${action} ${type}. The following Network 
Interfaces were specified more than once: 
${NETWORK_INTERFACES_ALREADY_SPECIFIED_LIST}.")
     String NETWORK_INTERFACES_ALREADY_SPECIFIED();
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index f93a2cb..f2809cb 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -552,6 +552,7 @@
        -Please remove those Networks first.
 NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER=The specified Logical Network doesn't 
exist in the current Cluster.
 NETWORKS_NOT_IN_SYNC=Cannot ${action} ${type}. The following Networks' 
definitions on the Network Interfaces are different than those on the Logical 
Networks. Please synchronize the Network Interfaces before editing the 
networks: ${NETWORKS_NOT_IN_SYNC}.
+MOVING_NETWORKS_MAKES_IT_OUT_OF_SYNC=Cannot ${action} ${type}. After moving 
the network, the following Networks' definitions on the Network Interfaces will 
be different than those on the Logical Networks. Please synchronize the Network 
Interfaces before editing the networks: ${NETWORKS_NOT_IN_SYNC}.
 NETWORK_INTERFACES_ALREADY_SPECIFIED=Cannot ${action} ${type}. The following 
Network Interfaces were specified more than once: 
${NETWORK_INTERFACES_ALREADY_SPECIFIED_LIST}.
 ACTION_TYPE_FAILED_EXTERNAL_NETWORKS_CANNOT_BE_PROVISIONED=Cannot ${action} 
${type}. The following external networks cannot be configured on host via 
'Setup Networks': 
${ACTION_TYPE_FAILED_EXTERNAL_NETWORKS_CANNOT_BE_PROVISIONED_LIST}.
 NETWORKS_ALREADY_ATTACHED_TO_IFACES=Cannot ${action} ${type}. The following 
Logical Networks are attached to more than one Network Interface: 
${NETWORKS_ALREADY_ATTACHED_TO_IFACES_LIST}.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index f4c8595..f9eab2d 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -594,6 +594,7 @@
        -Please remove those Networks first.
 NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER=The specified Logical Network doesn't 
exist in the current Cluster.
 NETWORKS_NOT_IN_SYNC=Cannot ${action} ${type}. The following Networks' 
definitions on the Network Interfaces are different than those on the Logical 
Networks. Please synchronize the Network Interfaces before editing the 
networks: ${NETWORKS_NOT_IN_SYNC}.
+MOVING_NETWORKS_MAKES_IT_OUT_OF_SYNC=Cannot ${action} ${type}. After moving 
the network, the following Networks' definitions on the Network Interfaces will 
be different than those on the Logical Networks. Please synchronize the Network 
Interfaces before editing the networks: ${NETWORKS_NOT_IN_SYNC}.
 NETWORK_INTERFACES_ALREADY_SPECIFIED=Cannot ${action} ${type}. The following 
Network Interfaces were specified more than once: 
${NETWORK_INTERFACES_ALREADY_SPECIFIED_LIST}.
 ACTION_TYPE_FAILED_EXTERNAL_NETWORKS_CANNOT_BE_PROVISIONED=Cannot ${action} 
${type}. The following external networks cannot be configured on host via 
'Setup Networks': 
${ACTION_TYPE_FAILED_EXTERNAL_NETWORKS_CANNOT_BE_PROVISIONED_LIST}.
 NETWORKS_ALREADY_ATTACHED_TO_IFACES=Cannot ${action} ${type}. The following 
Logical Networks are attached to more than one Network Interface: 
${NETWORKS_ALREADY_ATTACHED_TO_IFACES_LIST}.


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

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

Reply via email to