Martin Mucha has uploaded a new change for review. Change subject: core,restapi: added reported differences element to api.xsd + returning reported differences from GetNetworkAttachment queries ......................................................................
core,restapi: added reported differences element to api.xsd + returning reported differences from GetNetworkAttachment queries • added reported_configurations element to NetworkAttachment complex type <0, 1>. Each element of ReportedConfigurations type can have zero to N subelements of ReportedConfiguration type. • GetNetworkAttachmentsByHostIdQuery and GetNetworkAttachmentsByHostNicIdQuery returns NetworkAttachments changed so they returns populated by reported configuration. Change-Id: Ia7f83d268e250c24c4eeee6bff832426699ad95d Bug-Url: https://bugzilla.redhat.com/?????? Signed-off-by: Martin Mucha <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/FillReportedConfigurations.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostIdQuery.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostNicIdQuery.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/QosDaoCache.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkAttachment.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/ReportedConfigurations.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/NetworkAttachmentMapper.java A backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ReportedConfigurationsMapper.java A backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterface.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java A backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterfaceTest.java M backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetupNetworksVDSCommandTest.java M frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml 15 files changed, 646 insertions(+), 59 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/37407/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/FillReportedConfigurations.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/FillReportedConfigurations.java new file mode 100644 index 0000000..a8a81309 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/FillReportedConfigurations.java @@ -0,0 +1,51 @@ +package org.ovirt.engine.core.bll.network.host; + +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.BusinessEntityMap; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.network.InterfaceDao; +import org.ovirt.engine.core.dao.network.NetworkDao; +import org.ovirt.engine.core.utils.NetworkInSyncWithVdsNetworkInterface; + +public class FillReportedConfigurations { + + private BusinessEntityMap<VdsNetworkInterface> vdsNetworkInterfaceMap; + private BusinessEntityMap<Network> networkMap; + private final QosDaoCache qosDaoCache; + + public FillReportedConfigurations(Guid hostId) { + DbFacade dbFacade = DbFacade.getInstance(); + + InterfaceDao interfaceDao = dbFacade.getInterfaceDao(); + NetworkDao networkDao = dbFacade.getNetworkDao(); + VdsDAO vdsDao = dbFacade.getVdsDao(); + qosDaoCache = new QosDaoCache(dbFacade.getHostNetworkQosDao()); + + VDS host = vdsDao.get(hostId); + vdsNetworkInterfaceMap = new BusinessEntityMap<>(interfaceDao.getAllInterfacesForVds(hostId)); + networkMap = new BusinessEntityMap<>(networkDao.getAllForCluster(host.getVdsGroupId())); + } + + public void fillReportedConfigurations(List<NetworkAttachment> networkAttachments) { + for (NetworkAttachment networkAttachment : networkAttachments) { + fillReportedConfiguration(networkAttachment); + } + } + + public void fillReportedConfiguration(NetworkAttachment networkAttachment) { + Network network = networkMap.get(networkAttachment.getNetworkId()); + VdsNetworkInterface iface = vdsNetworkInterfaceMap.get(networkAttachment.getNicId()); + HostNetworkQos networkQos = qosDaoCache.get(network.getQosId()); + + networkAttachment.setReportedConfigurations( + new NetworkInSyncWithVdsNetworkInterface(iface, network, networkQos).reportConfigurationsOnHost()); + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostIdQuery.java index 09661e1..21a8585 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostIdQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostIdQuery.java @@ -1,7 +1,12 @@ package org.ovirt.engine.core.bll.network.host; +import java.util.List; + import org.ovirt.engine.core.bll.QueriesCommandBase; +import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.network.NetworkAttachmentDao; public class GetNetworkAttachmentsByHostIdQuery<P extends IdQueryParameters> extends QueriesCommandBase<P> { public GetNetworkAttachmentsByHostIdQuery(P parameters) { @@ -10,8 +15,13 @@ @Override protected void executeQueryCommand() { - // TODO populate reported configuration - getQueryReturnValue().setReturnValue(getDbFacade().getNetworkAttachmentDao() - .getAllForHost(getParameters().getId())); + NetworkAttachmentDao networkAttachmentDao = getDbFacade().getNetworkAttachmentDao(); + Guid hostId = getParameters().getId(); + + List<NetworkAttachment> networkAttachments = networkAttachmentDao.getAllForHost(hostId); + new FillReportedConfigurations(hostId).fillReportedConfigurations(networkAttachments); + getQueryReturnValue().setReturnValue(networkAttachments); } + + } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostNicIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostNicIdQuery.java index deb0032..84aa183 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostNicIdQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/GetNetworkAttachmentsByHostNicIdQuery.java @@ -1,7 +1,12 @@ package org.ovirt.engine.core.bll.network.host; +import java.util.List; + import org.ovirt.engine.core.bll.QueriesCommandBase; +import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.network.NetworkAttachmentDao; public class GetNetworkAttachmentsByHostNicIdQuery<P extends IdQueryParameters> extends QueriesCommandBase<P> { public GetNetworkAttachmentsByHostNicIdQuery(P parameters) { @@ -10,8 +15,13 @@ @Override protected void executeQueryCommand() { - // TODO populate reported configuration - getQueryReturnValue().setReturnValue(getDbFacade().getNetworkAttachmentDao() - .getAllForNic(getParameters().getId())); + NetworkAttachmentDao networkAttachmentDao = getDbFacade().getNetworkAttachmentDao(); + Guid nicId = getParameters().getId(); + + Guid hostId = getDbFacade().getInterfaceDao().get(nicId).getVdsId(); + + List<NetworkAttachment> networkAttachments = networkAttachmentDao.getAllForNic(nicId); + new FillReportedConfigurations(hostId).fillReportedConfigurations(networkAttachments); + getQueryReturnValue().setReturnValue(networkAttachments); } } 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 ae89f12..988d331 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,7 +3,6 @@ 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; @@ -47,7 +46,6 @@ 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; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -414,28 +412,6 @@ } 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/bll/src/main/java/org/ovirt/engine/core/bll/network/host/QosDaoCache.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/QosDaoCache.java new file mode 100644 index 0000000..da6159c --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/QosDaoCache.java @@ -0,0 +1,30 @@ +package org.ovirt.engine.core.bll.network.host; + +import java.util.HashMap; +import java.util.Map; + +import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.network.HostNetworkQosDao; + +public 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 f691733..5eed3ef 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,8 +29,8 @@ private IpConfiguration ipConfiguration; private Map<String, String> properties; - private boolean overrideConfiguration; + private ReportedConfigurations reportedConfigurations; public Guid getId() { return id; @@ -97,6 +97,14 @@ this.overrideConfiguration = overrideConfiguration; } + public void setReportedConfigurations(ReportedConfigurations reportedConfigurations) { + this.reportedConfigurations = reportedConfigurations; + } + + public ReportedConfigurations getReportedConfigurations() { + return reportedConfigurations; + } + @Override public int hashCode() { final int prime = 31; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/ReportedConfigurations.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/ReportedConfigurations.java new file mode 100644 index 0000000..a97f5bc --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/ReportedConfigurations.java @@ -0,0 +1,137 @@ +package org.ovirt.engine.core.common.businessentities.network; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Reported configuration related to sole network. + */ +public class ReportedConfigurations implements Serializable { + private static final long serialVersionUID = -6086888024266749566L; + + private boolean networkInSync; + + /* + * all reported configurations, with flag whether each configuration is in sync or not. + */ + private List<ReportedConfiguration> reportedConfigurationList = new ArrayList<>(); + + public ReportedConfigurations add(Type type, String value, boolean inSync) { + reportedConfigurationList.add(new ReportedConfiguration(type, value, inSync)); + return this; + } + + public ReportedConfigurations add(Type type, Integer value, boolean inSync) { + reportedConfigurationList.add(new ReportedConfiguration(type, value == null ? "null" : value.toString(), inSync)); + return this; + } + + public ReportedConfigurations add(Type type, boolean value, boolean inSync) { + reportedConfigurationList.add(new ReportedConfiguration(type, Boolean.toString(value), inSync)); + return this; + } + + public List<ReportedConfiguration> getReportedConfigurationList() { + return reportedConfigurationList; + } + + + /** + * all network configuration is in sync with host. + */ + public boolean isNetworkInSync() { + return networkInSync; + } + + public void setNetworkInSync(boolean networkInSync) { + this.networkInSync = networkInSync; + } + + public enum Type { + MTU("mtu"), + BRIDGED("bridged"), + VLAN("vlan"), + OUT_AVERAGE_LINK_SHARE("outAverageLinkShare"), + OUT_AVERAGE_UPPER_LIMIT("outAverageUpperLimit"), + OUT_AVERAGE_REAL_TIME("outAverageRealTime"); + + private final String name; + + Type(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + public static class ReportedConfiguration { + private Type type; + private String value; + private boolean inSync; + + public ReportedConfiguration() { + } + + public ReportedConfiguration(Type type, String value, boolean inSync) { + this.type = type; + this.value = value; + this.inSync = inSync; + } + + + public Type getType() { + return type; + } + + public void setType(Type name) { + this.type = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public boolean isInSync() { + return inSync; + } + + public void setInSync(boolean inSync) { + this.inSync = inSync; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof ReportedConfiguration)) + return false; + + ReportedConfiguration that = (ReportedConfiguration) o; + + if (inSync != that.inSync) + return false; + if (type != that.type) + return false; + if (value != null ? !value.equals(that.value) : that.value != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = type != null ? type.hashCode() : 0; + result = 31 * result + (value != null ? value.hashCode() : 0); + result = 31 * result + (inSync ? 1 : 0); + return result; + } + } + +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 1b19155..f051c86 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -3872,6 +3872,7 @@ <xs:element ref="ip_configuration" minOccurs="0" maxOccurs="1"/> <xs:element ref="properties" minOccurs="0" maxOccurs="1"/> <xs:element name="override_configuration" type="xs:boolean" minOccurs="0" maxOccurs="1"/> + <xs:element name="reported_configurations" type="ReportedConfigurations" minOccurs="0"/> <xs:element ref="host" minOccurs="0" maxOccurs="1"/> </xs:sequence> </xs:extension> @@ -3896,6 +3897,21 @@ </xs:complexContent> </xs:complexType> + <xs:complexType name="ReportedConfigurations"> + <xs:sequence> + <xs:element name="in_sync" type="xs:boolean"/> + <xs:element name="reportedConfiguration" type="ReportedConfiguration" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + + <xs:complexType name="ReportedConfiguration"> + <xs:sequence> + <xs:element name="name" type="xs:string"/> + <xs:element name="value" type="xs:string"/> + <xs:element name="in_sync" type="xs:boolean"/> + </xs:sequence> + </xs:complexType> + <xs:element name="ip_configuration" type="IpConfiguration"/> <xs:complexType name="IpConfiguration"> 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 687a7c6..77e26ae 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 @@ -103,6 +103,7 @@ } model.setOverrideConfiguration(entity.isOverrideConfiguration()); + model.setReportedConfigurations(ReportedConfigurationsMapper.map(entity.getReportedConfigurations(), null)); IpConfiguration ipConfiguration = entity.getIpConfiguration(); if (ipConfiguration != null) { diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ReportedConfigurationsMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ReportedConfigurationsMapper.java new file mode 100644 index 0000000..f20781c --- /dev/null +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ReportedConfigurationsMapper.java @@ -0,0 +1,31 @@ +package org.ovirt.engine.api.restapi.types; + +import java.util.List; + +import org.ovirt.engine.api.model.ReportedConfiguration; +import org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations; + +public class ReportedConfigurationsMapper { + + @Mapping(from = ReportedConfigurations.class, to = org.ovirt.engine.api.model.ReportedConfigurations.class) + public static org.ovirt.engine.api.model.ReportedConfigurations map(ReportedConfigurations entity, + org.ovirt.engine.api.model.ReportedConfigurations template) { + + org.ovirt.engine.api.model.ReportedConfigurations model = + template == null ? new org.ovirt.engine.api.model.ReportedConfigurations() : template; + + model.setInSync(entity.isNetworkInSync()); + List<ReportedConfiguration> reportedConfigurationList = model.getReportedConfiguration(); + for (ReportedConfigurations.ReportedConfiguration reportedConfiguration : entity.getReportedConfigurationList()) { + + ReportedConfiguration conf = new ReportedConfiguration(); + conf.setInSync(reportedConfiguration.isInSync()); + conf.setName(reportedConfiguration.getType().getName()); + conf.setValue(reportedConfiguration.getValue()); + reportedConfigurationList.add(conf); + } + + + return model; + } +} diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterface.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterface.java new file mode 100644 index 0000000..1fbf3ac --- /dev/null +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterface.java @@ -0,0 +1,103 @@ +package org.ovirt.engine.core.utils; + +import java.util.Objects; + +import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations; +import org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations.Type; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; +import org.ovirt.engine.core.common.utils.ObjectUtils; + +public class NetworkInSyncWithVdsNetworkInterface { + + private final VdsNetworkInterface iface; + private final Network network; + private final HostNetworkQos ifaceQos; + private final HostNetworkQos networkQos; + + public NetworkInSyncWithVdsNetworkInterface(VdsNetworkInterface iface, Network network, HostNetworkQos networkQos) { + this.iface = iface; + this.network = network; + this.networkQos = networkQos; + + ifaceQos = iface.getQos(); + } + + public NetworkInSyncWithVdsNetworkInterface(VdsNetworkInterface iface, + Network network, + HostNetworkQos ifaceQos, + HostNetworkQos networkQos) { + this.iface = iface; + this.network = network; + this.ifaceQos = ifaceQos; + this.networkQos = networkQos; + } + + public boolean isNetworkInSync() { + return isNetworkMtuInSync() + && isNetworkVlanIdInSync() + && isNetworkBridgedFlagInSync() + && (qosParametersEqual() || iface.isQosOverridden()); + } + + public ReportedConfigurations reportConfigurationsOnHost () { + ReportedConfigurations result = new ReportedConfigurations(); + + result.setNetworkInSync(isNetworkInSync()); + + result.add(Type.MTU, iface.getMtu(), isNetworkMtuInSync()); + result.add(Type.BRIDGED, iface.isBridged(), isNetworkBridgedFlagInSync()); + result.add(Type.VLAN, iface.getVlanId(), isNetworkVlanIdInSync()); + + boolean reportHostQos = ifaceQos != null; + if (reportHostQos) { + //TODO MM: lets say, that Qos is overridden, so whole network is 'inSync' while following parameters are 'out of sync'. Can be little bit confusing. + result.add(Type.OUT_AVERAGE_LINK_SHARE, ifaceQos.getOutAverageLinkshare(), isOutAverageLinkShareInSync()); + result.add(Type.OUT_AVERAGE_UPPER_LIMIT, ifaceQos.getOutAverageUpperlimit(), isOutAverageUpperLimitInSync()); + result.add(Type.OUT_AVERAGE_REAL_TIME, ifaceQos.getOutAverageRealtime(), isOutAverageRealTimeInSync()); + } + + return result; + } + + private boolean isNetworkBridgedFlagInSync() { + return iface.isBridged() == network.isVmNetwork(); + } + + private boolean isNetworkVlanIdInSync() { + return Objects.equals(iface.getVlanId(), network.getVlanId()); + } + + private boolean isNetworkMtuInSync() { + boolean networkValueSetToDefaultMtu = network.getMtu() == 0; + boolean ifaceValueSetToDefaultMtu = iface.getMtu() == NetworkUtils.getDefaultMtu(); + boolean bothUsesDefaultValue = networkValueSetToDefaultMtu && ifaceValueSetToDefaultMtu; + return (bothUsesDefaultValue || iface.getMtu() == network.getMtu()); + } + + public boolean qosParametersEqual() { + if (ifaceQos == networkQos) { + return true; + } + + if (ifaceQos == null || networkQos == null) { + return false; + } + + return isOutAverageLinkShareInSync() && isOutAverageUpperLimitInSync() && isOutAverageRealTimeInSync(); + } + + private boolean isOutAverageRealTimeInSync() { + return ObjectUtils.objectsEqual(ifaceQos.getOutAverageRealtime(), networkQos.getOutAverageRealtime()); + } + + private boolean isOutAverageUpperLimitInSync() { + return ObjectUtils.objectsEqual(ifaceQos.getOutAverageUpperlimit(), networkQos.getOutAverageUpperlimit()); + } + + private boolean isOutAverageLinkShareInSync() { + return ObjectUtils.objectsEqual(ifaceQos.getOutAverageLinkshare(), networkQos.getOutAverageLinkshare()); + } + +} diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java index ac915f5..a28f5de 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import org.apache.commons.codec.digest.DigestUtils; @@ -17,7 +16,6 @@ import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.common.utils.ObjectUtils; public final class NetworkUtils { public static final String OS_REFERENCE_TO_MACHINE_NAME = "HOSTNAME"; @@ -120,14 +118,14 @@ */ public static VdsNetworkInterface.NetworkImplementationDetails calculateNetworkImplementationDetails( Network network, - HostNetworkQos qos, + HostNetworkQos networkQos, VdsNetworkInterface iface) { if (StringUtils.isEmpty(iface.getNetworkName())) { return null; } if (network != null) { - if (isNetworkInSync(iface, network, qos)) { + if (new NetworkInSyncWithVdsNetworkInterface(iface, network, networkQos).isNetworkInSync()) { return new VdsNetworkInterface.NetworkImplementationDetails(true, true); } else { return new VdsNetworkInterface.NetworkImplementationDetails(false, true); @@ -154,28 +152,8 @@ } } - public static boolean isNetworkInSync(VdsNetworkInterface iface, Network network, HostNetworkQos qos) { - return ((network.getMtu() == 0 && iface.getMtu() == getDefaultMtu()) || iface.getMtu() == network.getMtu()) - && Objects.equals(iface.getVlanId(), network.getVlanId()) - && iface.isBridged() == network.isVmNetwork() - && (isQosInSync(iface, qos) || iface.isQosOverridden()); - } - - private static boolean isQosInSync(VdsNetworkInterface iface, HostNetworkQos networkQos) { - HostNetworkQos ifaceQos = iface.getQos(); - return qosParametersEqual(ifaceQos, networkQos); - } - - public static boolean qosParametersEqual(HostNetworkQos qos, HostNetworkQos otherQos) { - if (qos == otherQos) { - return true; - } else if (qos == null || otherQos == null) { - return false; - } else { - return ObjectUtils.objectsEqual(qos.getOutAverageLinkshare(), otherQos.getOutAverageLinkshare()) - && ObjectUtils.objectsEqual(qos.getOutAverageUpperlimit(), otherQos.getOutAverageUpperlimit()) - && ObjectUtils.objectsEqual(qos.getOutAverageRealtime(), otherQos.getOutAverageRealtime()); - } + public static boolean isNetworkInSync(VdsNetworkInterface iface, Network network, HostNetworkQos networkQos) { + return new NetworkInSyncWithVdsNetworkInterface(iface, network, networkQos).isNetworkInSync(); } /** diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterfaceTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterfaceTest.java new file mode 100644 index 0000000..97a3d50 --- /dev/null +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkInSyncWithVdsNetworkInterfaceTest.java @@ -0,0 +1,235 @@ +package org.ovirt.engine.core.utils; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations; +import org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations.ReportedConfiguration; +import org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations.Type; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; +import org.ovirt.engine.core.common.config.ConfigValues; + +public class NetworkInSyncWithVdsNetworkInterfaceTest { + + private VdsNetworkInterface iface; + private Network network; + private HostNetworkQos ifaceQos; + private HostNetworkQos networkQos; + + @ClassRule + public static MockConfigRule mcr = new MockConfigRule(mockConfig(ConfigValues.DefaultMTU, 1500)); + + @Before + public void setUp() throws Exception { + ifaceQos = new HostNetworkQos(); + networkQos = new HostNetworkQos(); + iface = new VdsNetworkInterface(); + network = new Network(); + + iface.setQos(ifaceQos); + } + + @Test + public void testIsNetworkInSyncWhenMtuDifferent() throws Exception { + iface.setMtu(1); + network.setMtu(2); + assertThat(createTestedInstance().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenMtuSameViaDefault() throws Exception { + NetworkInSyncWithVdsNetworkInterface testedInstanceWithSameNonQosValues = + createTestedInstanceWithSameNonQosValues(); + + iface.setMtu(1500); + network.setMtu(0); + + assertThat(testedInstanceWithSameNonQosValues.isNetworkInSync(), is(true)); + } + + + + @Test + public void testIsNetworkInSyncWhenVlanIdDifferent() throws Exception { + iface.setMtu(1); + network.setMtu(1); + + iface.setVlanId(1); + network.setVlanId(2); + assertThat(createTestedInstance().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenBridgedFlagDifferent() throws Exception { + iface.setMtu(1); + network.setMtu(1); + + iface.setVlanId(1); + network.setVlanId(1); + + iface.setBridged(true); + network.setVmNetwork(false); + assertThat(createTestedInstance().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenIfaceQosEqual() throws Exception { + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + @Test + public void testIsNetworkInSyncWhenIfaceQosIsNull() throws Exception { + iface.setQos(null); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenNetworkQosIsNull() throws Exception { + networkQos = null; + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenBothQosIsNull() throws Exception { + iface.setQos(null); + networkQos = null; + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + @Test + public void testIsNetworkInSyncWhenIfaceQosIsNullIfaceQosOverridden() throws Exception { + iface.setQos(null); + iface.setQosOverridden(true); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + @Test + public void testIsNetworkInSyncWhenNetworkQosIsNullIfaceQosOverridden() throws Exception { + networkQos = null; + iface.setQosOverridden(true); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + @Test + public void testIsNetworkInSyncWhenAverageLinkShareDifferent() throws Exception { + ifaceQos.setOutAverageLinkshare(1); + networkQos.setOutAverageLinkshare(2); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenAverageLinkShareDifferentIfaceQosOverridden() throws Exception { + ifaceQos.setOutAverageLinkshare(1); + networkQos.setOutAverageLinkshare(2); + iface.setQosOverridden(true); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + @Test + public void testIsNetworkInSyncWhenAverageUpperLimitDifferent() throws Exception { + ifaceQos.setOutAverageUpperlimit(1); + networkQos.setOutAverageUpperlimit(2); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenAverageUpperLimitDifferentIfaceQosOverridden() throws Exception { + ifaceQos.setOutAverageUpperlimit(1); + networkQos.setOutAverageUpperlimit(2); + iface.setQosOverridden(true); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + @Test + public void testIsNetworkInSyncWhenAverageRealTimeDifferent() throws Exception { + ifaceQos.setOutAverageRealtime(1); + networkQos.setOutAverageRealtime(2); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); + } + + @Test + public void testIsNetworkInSyncWhenAverageRealTimeDifferentIfaceQosOverridden() throws Exception { + ifaceQos.setOutAverageRealtime(1); + networkQos.setOutAverageRealtime(2); + iface.setQosOverridden(true); + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(true)); + } + + public NetworkInSyncWithVdsNetworkInterface createTestedInstanceWithSameNonQosValues() { + iface.setMtu(1); + network.setMtu(1); + + iface.setVlanId(1); + network.setVlanId(1); + + iface.setBridged(true); + network.setVmNetwork(true); + return createTestedInstance(); + } + + public NetworkInSyncWithVdsNetworkInterface createTestedInstance() { + return new NetworkInSyncWithVdsNetworkInterface(iface, network, networkQos); + } + + @Test + public void testReportConfigurationsOnHost() throws Exception { + NetworkInSyncWithVdsNetworkInterface testedInstanceWithSameNonQosValues = + createTestedInstanceWithSameNonQosValues(); + ifaceQos.setOutAverageLinkshare(1); + ifaceQos.setOutAverageUpperlimit(1); + ifaceQos.setOutAverageRealtime(1); + + ReportedConfigurations reportedConfigurations = testedInstanceWithSameNonQosValues.reportConfigurationsOnHost(); + + + assertThat(reportedConfigurations.isNetworkInSync(), is(false)); + List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); + + List<ReportedConfiguration> expectedReportedConfigurations = Arrays.asList( + new ReportedConfiguration(Type.MTU, Integer.toString(iface.getMtu()), true), + new ReportedConfiguration(Type.BRIDGED, Boolean.toString(iface.isBridged()), true), + new ReportedConfiguration(Type.VLAN, Integer.toString(iface.getVlanId()), true), + + new ReportedConfiguration(Type.OUT_AVERAGE_LINK_SHARE, ifaceQos.getOutAverageLinkshare().toString(), false), + new ReportedConfiguration(Type.OUT_AVERAGE_UPPER_LIMIT, ifaceQos.getOutAverageUpperlimit().toString(), false), + new ReportedConfiguration(Type.OUT_AVERAGE_REAL_TIME, ifaceQos.getOutAverageRealtime().toString(), false) + ); + + assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); + assertThat(reportedConfigurationList.size(), is(6)); + } + @Test + public void testReportConfigurationsOnHostWhenIfaceQosIsNull() throws Exception { + ifaceQos = null; + iface.setQos(null); + NetworkInSyncWithVdsNetworkInterface testedInstanceWithSameNonQosValues = + createTestedInstanceWithSameNonQosValues(); + networkQos.setOutAverageLinkshare(1); + networkQos.setOutAverageUpperlimit(1); + networkQos.setOutAverageRealtime(1); + + ReportedConfigurations reportedConfigurations = testedInstanceWithSameNonQosValues.reportConfigurationsOnHost(); + + assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); + assertThat(reportedConfigurations.isNetworkInSync(), is(false)); + List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); + + List<ReportedConfiguration> expectedReportedConfigurations = Arrays.asList( + new ReportedConfiguration(Type.MTU, Integer.toString(iface.getMtu()), true), + new ReportedConfiguration(Type.BRIDGED, Boolean.toString(iface.isBridged()), true), + new ReportedConfiguration(Type.VLAN, Integer.toString(iface.getVlanId()), true) + ); + + assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); + assertThat(reportedConfigurationList.size(), is(3)); + } +} diff --git a/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetupNetworksVDSCommandTest.java b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetupNetworksVDSCommandTest.java index 267823d..801947b 100644 --- a/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetupNetworksVDSCommandTest.java +++ b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SetupNetworksVDSCommandTest.java @@ -38,7 +38,7 @@ import org.ovirt.engine.core.dao.VdsStaticDAO; import org.ovirt.engine.core.dao.network.HostNetworkQosDao; import org.ovirt.engine.core.utils.MockConfigRule; -import org.ovirt.engine.core.utils.NetworkUtils; +import org.ovirt.engine.core.utils.NetworkInSyncWithVdsNetworkInterface; import org.ovirt.engine.core.utils.RandomUtils; @RunWith(MockitoJUnitRunner.class) @@ -188,7 +188,7 @@ verifyMethodPassedToHost(); Map<String, Object> networkStruct = assertNeworkWasSent(network); HostNetworkQos result = new HostNetworkQosMapper(networkStruct).deserialize(); - assertTrue(NetworkUtils.qosParametersEqual(expectedQos, result)); + assertTrue(new NetworkInSyncWithVdsNetworkInterface(iface, network, result, expectedQos).qosParametersEqual()); } private void qos(Network network, VdsNetworkInterface iface, HostNetworkQos expectedQos) { diff --git a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml index 502859c..9816a18 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml +++ b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml @@ -91,6 +91,7 @@ <include name="common/businessentities/network/ExternalSubnet.java" /> <include name="common/businessentities/network/IpConfiguration.java" /> <include name="common/businessentities/network/NetworkAttachment.java" /> + <include name="common/businessentities/network/ReportedConfigurations.java" /> <include name="common/businessentities/Commented.java" /> <include name="common/businessentities/Reasoned.java" /> -- To view, visit http://gerrit.ovirt.org/37407 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia7f83d268e250c24c4eeee6bff832426699ad95d 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
