Lior Vernia has uploaded a new change for review. Change subject: engine: Added sorting to host NICs query ......................................................................
engine: Added sorting to host NICs query NICs are now sorted as part of the query, to enable easy and efficient processing in different UI clients. The exact details of the sort ordering are documented in the code, but note that LexoNumericComparator is used to sort strings sensibly. Change-Id: I2cb5b00230d7957dd3375b093e73d2a4a51d72b9 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=883269 Signed-off-by: Lior Vernia <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetVdsInterfacesByVdsIdQuery.java 1 file changed, 49 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/11997/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetVdsInterfacesByVdsIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetVdsInterfacesByVdsIdQuery.java index b660c28..881d4ee 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetVdsInterfacesByVdsIdQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetVdsInterfacesByVdsIdQuery.java @@ -1,6 +1,8 @@ package org.ovirt.engine.core.bll.network.host; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -11,6 +13,7 @@ import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.utils.LexoNumericComparator; import org.ovirt.engine.core.utils.NetworkUtils; import org.ovirt.engine.core.utils.linq.LinqUtils; import org.ovirt.engine.core.utils.linq.Predicate; @@ -63,6 +66,52 @@ } } + Collections.sort(interfaces, new Comparator<VdsNetworkInterface>() { + + private boolean isBond(VdsNetworkInterface nic) { + return (nic.getBonded() != null && nic.getBonded()); + } + + private String extractBondName(VdsNetworkInterface nic) { + if (isBond(nic)) { + return nic.getName(); + } else { + return nic.getBondName(); + } + } + + /** + * Ordering NICs with this compare function will result in the following order: + * + * 1. Bonds (sorted by name) + * 1. Bond itself + * 2. NICs that are contained in bond (sorted by name) + * 2. NICs (sorted by name) + * + * It's worth noting that when sorting by name using LexoNumericComparator, VLAN NICs will automatically + * follow their "parent NIC" (although when bonds are concerned, contained NICs will appear between the + * "parent bond" and the VLAN bond). + */ + @Override + public int compare(VdsNetworkInterface nic1, VdsNetworkInterface nic2) { + int compRes = LexoNumericComparator.comp(extractBondName(nic1), extractBondName(nic2)); + if (compRes != 0) { + if (extractBondName(nic1) == null) { + return 1; + } + if (extractBondName(nic2) == null) { + return -1; + } + return compRes; + } + if (isBond(nic1) != isBond(nic2)) { + return isBond(nic1) ? -1 : 1; + } + return LexoNumericComparator.comp(nic1.getName(), nic2.getName()); + } + + }); + getQueryReturnValue().setReturnValue(interfaces); } } -- To view, visit http://gerrit.ovirt.org/11997 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2cb5b00230d7957dd3375b093e73d2a4a51d72b9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
