Search in sources :

Example 66 with Network

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

the class NetworkAttachmentsValidator method createNicNameToNetworkTypesMap.

private Map<String, List<NetworkType>> createNicNameToNetworkTypesMap() {
    Map<String, List<NetworkType>> nicNameToNetworkTypes = new HashMap<>();
    for (NetworkAttachment attachment : attachmentsToConfigure) {
        String nicName = attachment.getNicName();
        // have to check since if null, multiple results would be merged producing invalid results.
        if (nicName == null) {
            throw new IllegalArgumentException("nic name cannot be null");
        }
        Network networkToConfigure = networkBusinessEntityMap.get(attachment.getNetworkId());
        NetworkType networkTypeToAdd = determineNetworkType(networkToConfigure);
        nicNameToNetworkTypes.computeIfAbsent(nicName, k -> new ArrayList<>()).add(networkTypeToAdd);
    }
    return nicNameToNetworkTypes;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkExclusivenessValidator(org.ovirt.engine.core.bll.validator.network.NetworkExclusivenessValidator) NetworkType(org.ovirt.engine.core.bll.validator.network.NetworkType) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) HashMap(java.util.HashMap) BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) Collectors(java.util.stream.Collectors) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Map(java.util.Map) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Entry(java.util.Map.Entry) Network(org.ovirt.engine.core.common.businessentities.network.Network) HashMap(java.util.HashMap) NetworkType(org.ovirt.engine.core.bll.validator.network.NetworkType) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 67 with Network

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

the class IscsiBondValidator method getNetworksMissingInDataCenter.

private List<Guid> getNetworksMissingInDataCenter(Collection<Guid> networks, Guid dataCenterId) {
    Set<Guid> existingNetworkIds = new HashSet<>();
    List<Guid> res = new LinkedList<>();
    List<Network> dcLogicalNetworks = getDBFacade().getNetworkDao().getAllForDataCenter(dataCenterId);
    for (Network network : dcLogicalNetworks) {
        existingNetworkIds.add(network.getId());
    }
    for (Guid id : networks) {
        if (!existingNetworkIds.contains(id)) {
            res.add(id);
        }
    }
    return res;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) Guid(org.ovirt.engine.core.compat.Guid) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 68 with Network

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

the class RemoveProviderValidatorTest method networksUsedTest.

private void networksUsedTest(boolean vmsNotUsingNetwork, boolean templatesNotUsingNetwork, Matcher<ValidationResult> matcher) {
    NetworkValidator networkValidator = mock(NetworkValidator.class);
    for (Network network : networks) {
        when(validator.getValidator(network)).thenReturn(networkValidator);
    }
    when(networkValidator.networkNotUsedByVms()).thenReturn(createValidationResult(vmsNotUsingNetwork));
    when(networkValidator.networkNotUsedByTemplates()).thenReturn(createValidationResult(templatesNotUsingNetwork));
    assertThat(validator.providerNetworksNotUsed(), matcher);
}
Also used : NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 69 with Network

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

the class RemoveProviderValidatorTest method networksUsedByAVmMultipleNetworks.

@Test
public void networksUsedByAVmMultipleNetworks() throws Exception {
    Network net = mockNetwork();
    Network net2 = mockNetwork();
    networksUsedTest(false, true, both(failsWith(EngineMessage.ACTION_TYPE_FAILED_PROVIDER_NETWORKS_USED_MULTIPLE_TIMES)).and(replacements(hasItem(containsString(net.getName())))).and(replacements(hasItem(containsString(net2.getName())))));
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) Test(org.junit.Test)

Example 70 with Network

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

the class GetAllExternalNetworksOnProviderQueryTest method testExecuteQueryCommand.

@Test
@SuppressWarnings("unchecked")
public void testExecuteQueryCommand() {
    when(params.getId()).thenReturn(mock(Guid.class));
    when((Provider<AdditionalProperties>) providerDao.get(any())).thenReturn(networkProvider);
    when(providerProxyFactory.create(networkProvider)).thenReturn(client);
    Network network = mock(Network.class);
    ProviderNetwork providerNetwork = mock(ProviderNetwork.class);
    when(client.getAll()).thenReturn(Collections.singletonList(network));
    when(network.getProvidedBy()).thenReturn(providerNetwork);
    when(providerNetwork.getExternalId()).thenReturn("");
    Guid id = mock(Guid.class);
    when(dcDao.getDcIdByExternalNetworkId(any())).thenReturn(Collections.singletonList(id));
    Map<Network, Set<Guid>> expected = new HashMap<>();
    expected.put(network, Collections.singleton(id));
    query = getQuery();
    query.executeQueryCommand();
    assertEquals("Wrong result returned", expected, getQuery().getQueryReturnValue().getReturnValue());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork) Guid(org.ovirt.engine.core.compat.Guid) Provider(org.ovirt.engine.core.common.businessentities.Provider) Test(org.junit.Test) AbstractQueryTest(org.ovirt.engine.core.bll.AbstractQueryTest)

Aggregations

Network (org.ovirt.engine.core.common.businessentities.network.Network)292 Test (org.junit.Test)105 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)63 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)47 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)46 ArrayList (java.util.ArrayList)44 Guid (org.ovirt.engine.core.compat.Guid)44 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)39 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)23 List (java.util.List)21 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)21 HashMap (java.util.HashMap)19 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)19 Map (java.util.Map)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)13 HashSet (java.util.HashSet)9 Set (java.util.Set)9 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9