Martin Mucha has uploaded a new change for review. Change subject: core: removed NetworkBy class ......................................................................
core: removed NetworkBy class probably direct usage of BusinessEntityMap is just ok. Change-Id: I1b1cc2856ef3b3048863be6a693d320ca532f89d Signed-off-by: Martin Mucha <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksValidator.java D backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkBy.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java 6 files changed, 35 insertions(+), 54 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/44/36144/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java index 8fc6b50..f0be972 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java @@ -11,6 +11,7 @@ import org.ovirt.engine.core.common.action.NetworkAttachmentParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.BusinessEntityMap; import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; @@ -75,9 +76,11 @@ private boolean validateCrossAttachments() { List<NetworkAttachment> expectedAttachments = getDbFacade().getNetworkAttachmentDao().getAllForHost(getVdsId()); expectedAttachments.add(getParameters().getNetworkAttachment()); + final List<org.ovirt.engine.core.common.businessentities.network.Network> networks = getNetworkDAO().getAllForCluster( + getVdsGroupId()); NetworkAttachmentsValidator crossAttachmentsValidator = new NetworkAttachmentsValidator(expectedAttachments, - new NetworkBy(getNetworkDAO().getAllForCluster(getVdsGroupId()))); + new BusinessEntityMap<>(networks)); return validate(crossAttachmentsValidator.validateNetworkExclusiveOnNics()); } 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 e1bc777..e8ea387 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 @@ -58,7 +58,7 @@ Arrays.asList(VDSStatus.Maintenance, VDSStatus.Up, VDSStatus.NonOperational); private static final Logger log = LoggerFactory.getLogger(HostSetupNetworksCommand.class); private HostSetupNetworksValidator validator; - private NetworkBy networkBy; + private BusinessEntityMap<Network> networkMap; private Set<String> removedNetworks; private Set<String> removedBonds; @@ -107,7 +107,7 @@ getParameters(), getExistingNics(), getExistingAttachments(), - networkBy()); + networkMap()); List<String> validationMessages = validator.validate(); if (!validationMessages.isEmpty()) { @@ -227,7 +227,7 @@ HostNetworkQosDao qosDao = getDbFacade().getHostNetworkQosDao(); for (VdsNetworkInterface iface : existingNics) { - Network network = networkBy().iface(iface); + Network network = networkMap().get(iface.getNetworkName()); iface.setNetworkImplementationDetails(NetworkUtils.calculateNetworkImplementationDetails(network, network == null ? null : qosDao.get(network.getQosId()), iface)); @@ -249,7 +249,7 @@ if (removedNetworks == null) { removedNetworks = new HashSet<>(getParameters().getRemovedNetworkAttachments().size()); for (NetworkAttachment attachment : getParameters().getRemovedNetworkAttachments()) { - removedNetworks.add(networkBy().attachment(attachment).getName()); + removedNetworks.add(networkMap().get(attachment.getNetworkId()).getName()); } } @@ -262,7 +262,7 @@ BusinessEntityMap<VdsNetworkInterface> nics = new BusinessEntityMap<>(getExistingNics()); for (NetworkAttachment attachment : getParameters().getNetworkAttachments()) { - Network network = networkBy().attachment(attachment); + Network network = networkMap().get(attachment.getNetworkId()); HostNetwork networkToConfigure = new HostNetwork(network, attachment); networkToConfigure.setBonding(isBonding(attachment, nics)); @@ -320,7 +320,7 @@ private List<Network> getModifiedNetworks() { List<Network> modifiedNetworks = new ArrayList<>(getParameters().getNetworkAttachments().size()); for (NetworkAttachment attachment : getParameters().getNetworkAttachments()) { - modifiedNetworks.add(networkBy().attachment(attachment)); + modifiedNetworks.add(networkMap().get(attachment.getNetworkId())); } return modifiedNetworks; @@ -350,12 +350,13 @@ }); } - private NetworkBy networkBy() { - if (networkBy == null) { - networkBy = new NetworkBy(getNetworkDAO().getAllForCluster(getVdsGroupId())); + private BusinessEntityMap<Network> networkMap() { + if (networkMap == null) { + final List<Network> networks = getNetworkDAO().getAllForCluster(getVdsGroupId()); + networkMap = new BusinessEntityMap<>(networks); } - return networkBy; + return networkMap; } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksValidator.java index 9f216ee..b824f58 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostSetupNetworksValidator.java @@ -47,7 +47,7 @@ private Map<String, VdsNetworkInterface> existingIfaces; private List<NetworkAttachment> existingAttachments; private boolean networkCustomPropertiesSupported; - private NetworkBy networkBy; + private BusinessEntityMap<Network> networkBy; private final Map<Guid, NetworkAttachment> attachmentsById; private final BusinessEntityMap<Bond> removedBonds; @@ -55,7 +55,7 @@ HostSetupNetworksParameters params, List<VdsNetworkInterface> existingNics, List<NetworkAttachment> existingAttachments, - NetworkBy networkBy) { + BusinessEntityMap<Network> networkBy) { this.host = host; this.params = params; this.existingAttachments = existingAttachments; @@ -112,7 +112,7 @@ Set<Guid> networkIds = new HashSet<>(attachmentsToConfigure.size()); for (NetworkAttachment attachment : attachmentsToConfigure) { if (networkIds.contains(attachment.getNetworkId())) { - Network network = networkBy.attachment(attachment); + Network network = networkBy.get(attachment.getNetworkId()); addViolation(VdcBllMessages.NETWORKS_ALREADY_ATTACHED_TO_IFACES, network.getName()); passed = false; } else { @@ -125,9 +125,9 @@ private boolean validateNotRemovingUsedNetworkByVms() { boolean passed = true; - Collection<String> removedNetworks = new HashSet<String>(); + Collection<String> removedNetworks = new HashSet<>(); for (NetworkAttachment removedAttachment : params.getRemovedNetworkAttachments()) { - removedNetworks.add(networkBy.attachment(removedAttachment).getName()); + removedNetworks.add(networkBy.get(removedAttachment.getNetworkId()).getName()); } List<String> vmNames = getVmInterfaceManager().findActiveVmsUsingNetworks(host.getId(), removedNetworks); @@ -328,7 +328,7 @@ private boolean notRemovingLabeledNetworks(NetworkAttachment attachment, Map<String, VdsNetworkInterface> existingNics) { - Network removedNetwork = networkBy.attachment(attachment); + Network removedNetwork = networkBy.get(attachment.getNetworkId()); if (!NetworkUtils.isLabeled(removedNetwork)) { return true; } @@ -392,14 +392,14 @@ nicsToNetworks.put(nicName, new ArrayList<Network>()); } - Network networkToConfigure = networkBy.attachment(attachment); + Network networkToConfigure = networkBy.get(attachment.getNetworkId()); nicsToNetworks.get(nicName).add(networkToConfigure); } return nicsToNetworks; } private void reportMtuDifferences(List<Network> ifaceNetworks) { - List<String> mtuDiffNetworks = new ArrayList<String>(); + List<String> mtuDiffNetworks = new ArrayList<>(); for (Network net : ifaceNetworks) { mtuDiffNetworks.add(String.format("%s(%s)", net.getName(), @@ -417,10 +417,10 @@ util.convertProperties(Config.<String> getValue(ConfigValues.PreDefinedNetworkCustomProperties, version)); validProperties.putAll(util.convertProperties(Config.<String> getValue(ConfigValues.UserDefinedNetworkCustomProperties, version))); - Map<String, String> validPropertiesNonVm = new HashMap<String, String>(validProperties); + Map<String, String> validPropertiesNonVm = new HashMap<>(validProperties); validPropertiesNonVm.remove("bridge_opts"); for (NetworkAttachment attachment : params.getNetworkAttachments()) { - Network network = networkBy.attachment(attachment); + Network network = networkBy.get(attachment.getNetworkId()); if (attachment.hasProperties()) { if (!networkCustomPropertiesSupported) { addViolation(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_CUSTOM_PROPERTIES_NOT_SUPPORTED, @@ -485,7 +485,7 @@ } private List<String> translateViolations() { - List<String> violationMessages = new ArrayList<String>(violations.size() * 2); + List<String> violationMessages = new ArrayList<>(violations.size() * 2); for (Map.Entry<VdcBllMessages, List<String>> v : violations.entrySet()) { String violationName = v.getKey().name(); violationMessages.add(violationName); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkBy.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkBy.java deleted file mode 100644 index 064a2d3..0000000 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/NetworkBy.java +++ /dev/null @@ -1,26 +0,0 @@ -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.network.Network; -import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; -import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; - -//TODO MM: or rather inline all this class? It'll be less verbose but still ok. -public class NetworkBy { - private final BusinessEntityMap<Network> map; - - - public NetworkBy(List<Network> networks) { - map = new BusinessEntityMap<>(networks); - } - - public Network attachment(NetworkAttachment attachment) { - return map.get(attachment.getNetworkId()); - } - - public Network iface(VdsNetworkInterface iface) { - return map.get(iface.getNetworkName()); - } -} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java index 6ad23fa..07e3f77 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java @@ -12,6 +12,7 @@ import org.ovirt.engine.core.common.action.NetworkAttachmentParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.BusinessEntityMap; import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; @@ -66,9 +67,11 @@ private boolean validateCrossAttachments() { List<NetworkAttachment> expectedAttachments = getExpectedNetworkAttachments(); + final List<org.ovirt.engine.core.common.businessentities.network.Network> networks = getNetworkDAO().getAllForCluster( + getVdsGroupId()); NetworkAttachmentsValidator crossAttachmentsValidator = new NetworkAttachmentsValidator(expectedAttachments, - new NetworkBy(getNetworkDAO().getAllForCluster(getVdsGroupId()))); + new BusinessEntityMap<>(networks)); return validate(crossAttachmentsValidator.validateNetworkExclusiveOnNics()); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java index 5ea937a..b7543cf 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java @@ -9,7 +9,7 @@ import org.apache.commons.collections.bag.HashBag; import org.ovirt.engine.core.bll.ValidationResult; -import org.ovirt.engine.core.bll.network.host.NetworkBy; +import org.ovirt.engine.core.common.businessentities.BusinessEntityMap; import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; import org.ovirt.engine.core.common.errors.VdcBllMessages; @@ -23,12 +23,12 @@ public class NetworkAttachmentsValidator { private final Collection<NetworkAttachment> attachmentsToConfigure; - private final NetworkBy networkBy; + private final BusinessEntityMap<Network> networkMap; public NetworkAttachmentsValidator(Collection<NetworkAttachment> attachmentsToConfigure, - NetworkBy networkBy) { + BusinessEntityMap<Network> networkMap) { this.attachmentsToConfigure = attachmentsToConfigure; - this.networkBy = networkBy; + this.networkMap = networkMap; } public ValidationResult validateNetworkExclusiveOnNics() { @@ -39,7 +39,7 @@ nicsToNetworks.put(nicName, new ArrayList<NetworkType>()); } - Network networkToConfigure = networkBy.attachment(attachment); + Network networkToConfigure = networkMap.get(attachment.getNetworkId()); nicsToNetworks.get(nicName).add(determineNetworkType(networkToConfigure)); } -- To view, visit http://gerrit.ovirt.org/36144 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1b1cc2856ef3b3048863be6a693d320ca532f89d 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
