Moti Asayag has uploaded a new change for review. Change subject: engine: Persist labels changes on interfaces ......................................................................
engine: Persist labels changes on interfaces In case setup-networks detects there were no changes that involve host configuration, the labels should be persisted in case they were changed. Change-Id: I401677887fa36e8a851e8d0544df7a288a257d9a Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java 2 files changed, 42 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/12/22912/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java index 35e9d7b..19234b7 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java @@ -83,6 +83,10 @@ @Override protected void executeCommand() { if (noChangesDetected()) { + if (!getModifiedLabeledInterfaces().isEmpty()) { + updateModifiedLabeledInterfaces(); + } + setSucceeded(true); return; } @@ -123,6 +127,17 @@ } } + private void updateModifiedLabeledInterfaces() { + TransactionSupport.executeInNewTransaction(new TransactionMethod<T>() { + + @Override + public T runInTransaction() { + getDbFacade().getInterfaceDao().massUpdateInterfacesForVds(getModifiedLabeledInterfaces()); + return null; + } + }); + } + private boolean noChangesDetected() { return getNetworks().isEmpty() && getRemovedNetworks().isEmpty() && getBonds().isEmpty() && getRemovedBonds().isEmpty(); @@ -148,6 +163,10 @@ return helper.getNetworks(); } + private List<VdsNetworkInterface> getModifiedLabeledInterfaces() { + return helper.getModifiedLabeledInterfaces(); + } + /** * use FutureTask to poll the vdsm (with getCapabilities) while setupNetworks task is not done. during the poll task * try to fetch the setupNetwork task answer with a timeout equal to getConnectitivtyTimeout defined in the command diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java index 9908608..8664318 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java @@ -2,12 +2,14 @@ import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.network.VmInterfaceManager; @@ -34,6 +36,7 @@ private List<String> removedNetworks = new ArrayList<String>(); private Map<String, VdsNetworkInterface> modifiedBonds = new HashMap<String, VdsNetworkInterface>(); private Set<String> removedBonds = new HashSet<String>(); + private List<VdsNetworkInterface> modifiedLabeledInterfaces = new ArrayList<>(); /** All interface`s names that were processed by the helper. */ private Set<String> ifaceNames = new HashSet<String>(); @@ -87,10 +90,26 @@ validateBondSlavesCount(); extractRemovedNetworks(); extractRemovedBonds(); + extractModifiedLabeledInterfaces(); detectSlaveChanges(); validateMTU(); return translateViolations(); + } + + private void extractModifiedLabeledInterfaces() { + for (VdsNetworkInterface nic : params.getInterfaces()) { + VdsNetworkInterface existingNic = getExistingIfaces().get(nic.getName()); + if (existingNic != null) { + Set<String> newLabels = nic.getLabels() == null ? Collections.<String> emptySet() : nic.getLabels(); + Set<String> existingLabels = + existingNic.getLabels() == null ? Collections.<String> emptySet() : existingNic.getLabels(); + if (!CollectionUtils.isEqualCollection(newLabels, existingLabels)) { + existingNic.setLabels(newLabels); + modifiedLabeledInterfaces.add(existingNic); + } + } + } } /** @@ -586,6 +605,10 @@ return removedBonds; } + public List<VdsNetworkInterface> getModifiedLabeledInterfaces() { + return modifiedLabeledInterfaces; + } + public VmInterfaceManager getVmInterfaceManager() { return new VmInterfaceManager(); } -- To view, visit http://gerrit.ovirt.org/22912 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I401677887fa36e8a851e8d0544df7a288a257d9a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches