Search in sources :

Example 31 with NetworkCluster

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

the class AttachNetworkToClusterInternalCommand method attachNetwork.

private void attachNetwork(Guid clusterId, NetworkCluster networkClusterFromUserRequest, Network network) {
    networkClusterDao.save(new NetworkCluster(clusterId, network.getId(), NetworkStatus.OPERATIONAL, false, networkClusterFromUserRequest.isRequired(), false, false, false, false));
    List<VDS> hosts = vdsDao.getAllForCluster(clusterId);
    List<Network> networksOfCluster = networkDao.getAllForCluster(clusterId);
    for (VDS host : hosts) {
        HostNetworkAttachmentsPersister persister = new HostNetworkAttachmentsPersister(this.networkAttachmentDao, host.getId(), interfaceDao.getAllInterfacesForVds(host.getId()), Collections.emptyList(), networksOfCluster);
        persister.persistNetworkAttachments();
    }
    if (network.getCluster().isDisplay()) {
        final DisplayNetworkClusterHelper displayNetworkClusterHelper = new DisplayNetworkClusterHelper(networkClusterDao, vmDao, clusterDao, networkClusterFromUserRequest, network.getName(), auditLogDirector);
        if (displayNetworkClusterHelper.isDisplayToBeUpdated()) {
            displayNetworkClusterHelper.warnOnActiveVm();
        }
        networkClusterDao.setNetworkExclusivelyAsDisplay(clusterId, network.getId());
    }
    if (network.getCluster().isMigration()) {
        networkClusterDao.setNetworkExclusivelyAsMigration(clusterId, network.getId());
    }
    if (network.getCluster().isGluster()) {
        networkClusterDao.setNetworkExclusivelyAsGluster(clusterId, network.getId());
    }
    if (network.getCluster().isDefaultRoute()) {
        networkClusterDao.setNetworkExclusivelyAsDefaultRoute(clusterId, network.getId());
    }
    networkClusterHelper.setStatus(clusterId, network);
}
Also used : DisplayNetworkClusterHelper(org.ovirt.engine.core.bll.network.cluster.helper.DisplayNetworkClusterHelper) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) HostNetworkAttachmentsPersister(org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister)

Example 32 with NetworkCluster

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

the class GetClustersAndNetworksByNetworkIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    List<PairQueryable<Cluster, NetworkCluster>> networkClusterPairs = new ArrayList<>();
    Network network = networkDao.get(getParameters().getId());
    if (network != null && network.getDataCenterId() != null) {
        List<Cluster> clusters = clusterDao.getAllForStoragePool(network.getDataCenterId());
        List<NetworkCluster> networkClusters = networkClusterDao.getAllForNetwork(getParameters().getId());
        final Map<NetworkClusterId, NetworkCluster> networkClustersById = Entities.businessEntitiesById(networkClusters);
        for (Cluster cluster : clusters) {
            networkClusterPairs.add(new PairQueryable<>(cluster, networkClustersById.get(new NetworkClusterId(cluster.getId(), getParameters().getId()))));
        }
    }
    getQueryReturnValue().setReturnValue(networkClusterPairs);
}
Also used : PairQueryable(org.ovirt.engine.core.common.utils.PairQueryable) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) NetworkClusterId(org.ovirt.engine.core.common.businessentities.network.NetworkClusterId)

Example 33 with NetworkCluster

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

the class NetworkClustersToSetupNetworksParametersTransformerImpl method transform.

@Override
public List<PersistentHostSetupNetworksParameters> transform(Collection<NetworkCluster> attachments, Collection<NetworkCluster> detachments, Collection<NetworkCluster> updates) {
    final Map<Guid, List<Network>> attachNetworksByHost = new HashMap<>();
    final Map<Guid, Map<String, VdsNetworkInterface>> labelsToNicsByHost = new HashMap<>();
    for (NetworkCluster networkCluster : attachments) {
        final Network network = networkDao.get(networkCluster.getNetworkId());
        final List<VdsNetworkInterface> nics = interfaceDao.getAllInterfacesByLabelForCluster(networkCluster.getClusterId(), network.getLabel());
        for (VdsNetworkInterface nic : nics) {
            if (!attachNetworksByHost.containsKey(nic.getVdsId())) {
                attachNetworksByHost.put(nic.getVdsId(), new ArrayList<>());
                labelsToNicsByHost.put(nic.getVdsId(), new HashMap<>());
            }
            labelsToNicsByHost.get(nic.getVdsId()).put(network.getLabel(), nic);
            attachNetworksByHost.get(nic.getVdsId()).add(network);
        }
    }
    Map<Guid, List<Network>> detachNetworksByHost = new HashMap<>();
    for (NetworkCluster networkCluster : detachments) {
        final Network network = networkDao.get(networkCluster.getNetworkId());
        final List<VdsNetworkInterface> nics = interfaceDao.getAllInterfacesByLabelForCluster(networkCluster.getClusterId(), network.getLabel());
        for (VdsNetworkInterface nic : nics) {
            if (!detachNetworksByHost.containsKey(nic.getVdsId())) {
                detachNetworksByHost.put(nic.getVdsId(), new ArrayList<>());
            }
            detachNetworksByHost.get(nic.getVdsId()).add(network);
        }
    }
    return createSetupNetworksParameters(attachNetworksByHost, labelsToNicsByHost, detachNetworksByHost, getUpdatedNetworksByHost(updates));
}
Also used : HashMap(java.util.HashMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) CollectionUtils.nullToEmptyList(org.ovirt.engine.core.utils.CollectionUtils.nullToEmptyList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with NetworkCluster

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

the class AddBricksToGlusterVolumeCommandTest method getNetworks.

private List<Network> getNetworks() {
    List<Network> networks = new ArrayList<>();
    Network nw = new Network();
    nw.setName(GLUSTER_NW);
    NetworkCluster nc = new NetworkCluster();
    nc.setGluster(true);
    nw.setCluster(nc);
    networks.add(nw);
    return networks;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster)

Example 35 with NetworkCluster

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

the class VmInfoBuildUtils method getDisplayNetwork.

public Network getDisplayNetwork(VM vm) {
    List<NetworkCluster> all = networkClusterDao.getAllForCluster(vm.getClusterId());
    NetworkCluster networkCluster = null;
    for (NetworkCluster tempNetworkCluster : all) {
        if (tempNetworkCluster.isDisplay()) {
            networkCluster = tempNetworkCluster;
            break;
        }
    }
    if (networkCluster != null) {
        List<Network> allNetworks = networkDao.getAll();
        for (Network tempNetwork : allNetworks) {
            if (tempNetwork.getId().equals(networkCluster.getNetworkId())) {
                return tempNetwork;
            }
        }
    }
    return null;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster)

Aggregations

NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)62 Test (org.junit.Test)19 Network (org.ovirt.engine.core.common.businessentities.network.Network)17 ArrayList (java.util.ArrayList)15 NetworkClusterId (org.ovirt.engine.core.common.businessentities.network.NetworkClusterId)7 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)6 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)6 ManageNetworkClustersParameters (org.ovirt.engine.core.common.action.ManageNetworkClustersParameters)5 List (java.util.List)4 Map (java.util.Map)4 PairQueryable (org.ovirt.engine.core.common.utils.PairQueryable)4 Guid (org.ovirt.engine.core.compat.Guid)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)3 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)3 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2