Search in sources :

Example 1 with BusinessEntityMap

use of org.ovirt.engine.core.common.businessentities.BusinessEntityMap in project ovirt-engine by oVirt.

the class NetworkAttachmentsValidatorTest method testVerifyUserAttachmentsDoesNotReferenceSameNetworkDuplicatelyWhenNoDuplicates.

@Test
public void testVerifyUserAttachmentsDoesNotReferenceSameNetworkDuplicatelyWhenNoDuplicates() {
    Network networkA = createNetworkWithIdAndName("networkA");
    NetworkAttachment networkAttachmentA = createNetworkAttachment(networkA);
    Network networkB = createNetworkWithIdAndName("networkB");
    NetworkAttachment networkAttachmentB = createNetworkAttachment(networkB);
    List<NetworkAttachment> attachments = Arrays.asList(networkAttachmentA, networkAttachmentB);
    BusinessEntityMap<Network> networksMap = new BusinessEntityMap<>(Arrays.asList(networkA, networkB));
    NetworkAttachmentsValidator validator = new NetworkAttachmentsValidator(attachments, networksMap, networkExclusivenessValidator);
    assertThat(validator.verifyUserAttachmentsDoesNotReferenceSameNetworkDuplicately(), isValid());
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 2 with BusinessEntityMap

use of org.ovirt.engine.core.common.businessentities.BusinessEntityMap in project ovirt-engine by oVirt.

the class GetNetworkAttachmentsByHostIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Guid hostId = getParameters().getId();
    List<NetworkAttachment> networkAttachments = networkAttachmentDao.getAllForHost(hostId);
    List<VdsNetworkInterface> allInterfacesForHost = interfaceDao.getAllInterfacesForVds(hostId);
    VDS vds = hostDao.get(hostId);
    Guid clusterId = vds.getClusterId();
    BusinessEntityMap<Network> networkMap = new BusinessEntityMap<>(networkDao.getAllForCluster(clusterId));
    reportedConfigurationsFiller.fillReportedConfigurations(allInterfacesForHost, networkMap, networkAttachments, vds.getDynamicData().getReportedDnsResolverConfiguration(), clusterId);
    completeNicNames(networkAttachments, allInterfacesForHost);
    completeNetworkNames(networkAttachments, networkMap);
    getQueryReturnValue().setReturnValue(networkAttachments);
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 3 with BusinessEntityMap

use of org.ovirt.engine.core.common.businessentities.BusinessEntityMap in project ovirt-engine by oVirt.

the class UnmanagedNetworkValidatorTest method testValidateRemovedUnmanagedNetworks.

@Test
public void testValidateRemovedUnmanagedNetworks() {
    String networkName = "networkName";
    Nic nic = createNicWithNetworkImplementationDetails("eth0", false);
    nic.setNetworkName(networkName);
    Network network = new Network();
    network.setName(networkName);
    ValidationResult result = validator.validateRemovedUnmanagedNetworks(Collections.singletonList(networkName), Collections.singletonList(nic), new BusinessEntityMap<>(Collections.emptySet()));
    assertTrue(result.isValid());
    result = validator.validateRemovedUnmanagedNetworks(Collections.singletonList(networkName), Collections.singletonList(nic), new BusinessEntityMap<>(Collections.singletonList(network)));
    assertThat(result, failsWith(EngineMessage.REMOVED_UNMANAGED_NETWORK_IS_A_CLUSTER_NETWORK, ReplacementUtils.createSetVariableString(NETWORK, networkName)));
    String unmanagedNetworkNotPresentOnAnyNic = "unmanagedNetworkNotPresentOnAnyNic";
    result = validator.validateRemovedUnmanagedNetworks(Arrays.asList(networkName, unmanagedNetworkNotPresentOnAnyNic), Collections.singletonList(nic), new BusinessEntityMap<>(Collections.emptySet()));
    assertThat(result, failsWith(EngineMessage.REMOVED_UNMANAGED_NETWORK_DOES_NOT_EXISIT_ON_HOST, ReplacementUtils.createSetVariableString(NETWORK, unmanagedNetworkNotPresentOnAnyNic)));
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 4 with BusinessEntityMap

use of org.ovirt.engine.core.common.businessentities.BusinessEntityMap in project ovirt-engine by oVirt.

the class UnmanagedNetworksHelper method getUnmanagedNetworks.

public List<UnmanagedNetwork> getUnmanagedNetworks(Guid hostId) {
    List<UnmanagedNetwork> unmanagedNetworks = new ArrayList<>();
    VDS host = vdsDao.get(hostId);
    if (host != null) {
        List<VdsNetworkInterface> hostNetworkInterfaces = interfaceDao.getAllInterfacesForVds(hostId);
        BusinessEntityMap<Network> clusterNetworkMap = new BusinessEntityMap<>(getClusterNetworks(host));
        for (VdsNetworkInterface vdsNetworkInterface : hostNetworkInterfaces) {
            String networkName = vdsNetworkInterface.getNetworkName();
            if (networkName != null && !clusterNetworkMap.containsKey(networkName)) {
                unmanagedNetworks.add(createUnmanagedNetworkEntity(vdsNetworkInterface, networkName));
            }
        }
    }
    return unmanagedNetworks;
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) VDS(org.ovirt.engine.core.common.businessentities.VDS) UnmanagedNetwork(org.ovirt.engine.core.common.businessentities.UnmanagedNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) UnmanagedNetwork(org.ovirt.engine.core.common.businessentities.UnmanagedNetwork)

Example 5 with BusinessEntityMap

use of org.ovirt.engine.core.common.businessentities.BusinessEntityMap in project ovirt-engine by oVirt.

the class NetworkMtuValidatorTest method testGetNetworksOnNics.

@Test
public void testGetNetworksOnNics() throws Exception {
    Network networkA = createNetwork(1, true, "netA");
    Network networkB = createNetwork(2, true, "netB");
    Network networkC = createNetwork(2, true, "netC");
    List<Network> networks = Arrays.asList(networkA, networkB, networkC);
    NetworkMtuValidator networkMtuValidatorSpy = spy(new NetworkMtuValidator(new BusinessEntityMap<>(networks)));
    String nicAName = "NicA";
    String nicCName = "NicC";
    NetworkAttachment networkAttachmentA = createNetworkAttachment(networkA, nicAName);
    NetworkAttachment networkAttachmentB = createNetworkAttachment(networkB, nicAName);
    NetworkAttachment networkAttachmentC = createNetworkAttachment(networkC, nicCName);
    List<NetworkAttachment> networkAttachments = Arrays.asList(networkAttachmentA, networkAttachmentB, networkAttachmentC);
    Map<String, List<Network>> networksOnNics = networkMtuValidatorSpy.getNetworksOnNics(networkAttachments);
    assertThat(networksOnNics.keySet().size(), is(2));
    assertThat(networksOnNics.containsKey(nicAName), is(true));
    assertThat(networksOnNics.containsKey(nicCName), is(true));
    assertThat(networksOnNics.get(nicAName).size(), is(2));
    assertThat(networksOnNics.get(nicAName), CoreMatchers.hasItems(networkA, networkB));
    assertThat(networksOnNics.get(nicCName).size(), is(1));
    assertThat(networksOnNics.get(nicCName), CoreMatchers.hasItems(networkC));
}
Also used : BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) List(java.util.List) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Aggregations

BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)7 Network (org.ovirt.engine.core.common.businessentities.network.Network)7 Test (org.junit.Test)4 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)4 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)3 ArrayList (java.util.ArrayList)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 Guid (org.ovirt.engine.core.compat.Guid)2 List (java.util.List)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 UnmanagedNetwork (org.ovirt.engine.core.common.businessentities.UnmanagedNetwork)1 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)1 NetworkInSyncWithVdsNetworkInterface (org.ovirt.engine.core.utils.NetworkInSyncWithVdsNetworkInterface)1