Search in sources :

Example 6 with ManageNetworkClustersParameters

use of org.ovirt.engine.core.common.action.ManageNetworkClustersParameters in project ovirt-engine by oVirt.

the class AddNetworkCommand method attachToClusters.

private void attachToClusters(List<NetworkCluster> networkAttachments, Guid networkId) {
    networkAttachments.forEach(networkCluster -> networkCluster.setNetworkId(networkId));
    runInternalAction(ActionType.ManageNetworkClusters, new ManageNetworkClustersParameters(networkAttachments), getContext().clone().withoutLock());
}
Also used : ManageNetworkClustersParameters(org.ovirt.engine.core.common.action.ManageNetworkClustersParameters)

Example 7 with ManageNetworkClustersParameters

use of org.ovirt.engine.core.common.action.ManageNetworkClustersParameters in project ovirt-engine by oVirt.

the class ClusterNetworkManageModel method onManage.

private void onManage() {
    Iterable<ClusterNetworkModel> manageList = getItems();
    final List<NetworkCluster> toAttach = new ArrayList<>();
    final List<NetworkCluster> toDetach = new ArrayList<>();
    final List<NetworkCluster> toUpdate = new ArrayList<>();
    for (ClusterNetworkModel manageModel : manageList) {
        NetworkCluster networkCluster = manageModel.getOriginalNetworkCluster();
        boolean wasAttached = networkCluster != null;
        boolean needsAttach = manageModel.isAttached() && !wasAttached;
        boolean needsDetach = !manageModel.isAttached() && wasAttached;
        boolean needsUpdate = false;
        // Attachment wasn't changed- check if needs update
        if (wasAttached && !needsDetach) {
            if ((manageModel.isRequired() != networkCluster.isRequired()) || manageModel.isDisplayNetwork() != networkCluster.isDisplay() || manageModel.isMigrationNetwork() != networkCluster.isMigration() || manageModel.isManagement() != networkCluster.isManagement() || manageModel.isDefaultRouteNetwork() != networkCluster.isDefaultRoute() || manageModel.isGlusterNetwork() != networkCluster.isGluster()) {
                needsUpdate = true;
                copyRoles(manageModel, networkCluster);
            }
        }
        if (needsAttach) {
            toAttach.add(createNetworkCluster(manageModel));
        }
        if (needsDetach) {
            toDetach.add(networkCluster);
        }
        if (needsUpdate) {
            toUpdate.add(networkCluster);
        }
    }
    startProgress();
    needsAnyChange = !(toAttach.isEmpty() && toDetach.isEmpty() && toUpdate.isEmpty());
    if (needsAnyChange) {
        Frontend.getInstance().runAction(ActionType.ManageNetworkClusters, new ManageNetworkClustersParameters(toAttach, toDetach, toUpdate), result -> {
            needsAnyChange = false;
            doFinish();
        });
    }
    doFinish();
}
Also used : ManageNetworkClustersParameters(org.ovirt.engine.core.common.action.ManageNetworkClustersParameters) ArrayList(java.util.ArrayList) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster)

Example 8 with ManageNetworkClustersParameters

use of org.ovirt.engine.core.common.action.ManageNetworkClustersParameters in project ovirt-engine by oVirt.

the class NetworkHelper method attachNetworkToClusters.

public ActionReturnValue attachNetworkToClusters(Guid networkId, Collection<Guid> clusterIds) {
    List<NetworkCluster> networkAttachments = createNetworkClusters(clusterIds);
    networkAttachments.forEach(networkAttachment -> networkAttachment.setNetworkId(networkId));
    return backend.runInternalAction(ActionType.ManageNetworkClusters, new ManageNetworkClustersParameters(networkAttachments));
}
Also used : ManageNetworkClustersParameters(org.ovirt.engine.core.common.action.ManageNetworkClustersParameters) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster)

Example 9 with ManageNetworkClustersParameters

use of org.ovirt.engine.core.common.action.ManageNetworkClustersParameters in project ovirt-engine by oVirt.

the class PropagateNetworksToClusterHostsCommand method mapParametersByClusterId.

private Map<Guid, ManageNetworkClustersParameters> mapParametersByClusterId() {
    ManageNetworkClustersParameters parameters = getParameters();
    Map<Guid, List<NetworkCluster>> attachmentByClusterId = groupByClusterId(parameters.getAttachments());
    Map<Guid, List<NetworkCluster>> detachmentByClusterId = groupByClusterId(parameters.getDetachments());
    Map<Guid, List<NetworkCluster>> updatesByClusterId = groupByClusterId(parameters.getUpdates());
    Set<Guid> clusterIds = Stream.of(attachmentByClusterId, detachmentByClusterId, updatesByClusterId).flatMap(e -> e.keySet().stream()).collect(Collectors.toSet());
    return clusterIds.stream().collect(Collectors.toMap(Function.identity(), clusterId -> new ManageNetworkClustersParameters(nullToEmptyList(attachmentByClusterId.get(clusterId)), nullToEmptyList(detachmentByClusterId.get(clusterId)), nullToEmptyList(updatesByClusterId.get(clusterId)))));
}
Also used : NonTransactiveCommandAttribute(org.ovirt.engine.core.bll.NonTransactiveCommandAttribute) CollectionUtils.nullToEmptyList(org.ovirt.engine.core.utils.CollectionUtils.nullToEmptyList) InternalCommandAttribute(org.ovirt.engine.core.bll.InternalCommandAttribute) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) Set(java.util.Set) CommandBase(org.ovirt.engine.core.bll.CommandBase) HostSetupNetworksParametersBuilder(org.ovirt.engine.core.bll.network.HostSetupNetworksParametersBuilder) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) NetworkClustersToSetupNetworksParametersTransformerFactory(org.ovirt.engine.core.bll.network.cluster.transformer.NetworkClustersToSetupNetworksParametersTransformerFactory) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ManageNetworkClustersParameters(org.ovirt.engine.core.common.action.ManageNetworkClustersParameters) ActionType(org.ovirt.engine.core.common.action.ActionType) List(java.util.List) Stream(java.util.stream.Stream) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) Map(java.util.Map) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) Collections(java.util.Collections) NetworkClustersToSetupNetworksParametersTransformer(org.ovirt.engine.core.bll.network.cluster.transformer.NetworkClustersToSetupNetworksParametersTransformer) ManageNetworkClustersParameters(org.ovirt.engine.core.common.action.ManageNetworkClustersParameters) CollectionUtils.nullToEmptyList(org.ovirt.engine.core.utils.CollectionUtils.nullToEmptyList) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

ManageNetworkClustersParameters (org.ovirt.engine.core.common.action.ManageNetworkClustersParameters)9 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)2 AttachNetworkToClusterParameter (org.ovirt.engine.core.common.action.AttachNetworkToClusterParameter)2 Guid (org.ovirt.engine.core.compat.Guid)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 CommandBase (org.ovirt.engine.core.bll.CommandBase)1 InternalCommandAttribute (org.ovirt.engine.core.bll.InternalCommandAttribute)1 NonTransactiveCommandAttribute (org.ovirt.engine.core.bll.NonTransactiveCommandAttribute)1 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)1 HostSetupNetworksParametersBuilder (org.ovirt.engine.core.bll.network.HostSetupNetworksParametersBuilder)1