Search in sources :

Example 1 with PersistentHostSetupNetworksParameters

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

the class PersistentHostSetupNetworksParametersFactory method create.

/**
 * @param hostId host on which networks to be updated reside
 * @param networks networks to be updated; it is assumed, that all those networks belongs to given host.
 *
 * @return PersistentHostSetupNetworksParameters to refresh all given networks.
 */
public PersistentHostSetupNetworksParameters create(Guid hostId, List<Network> networks) {
    Map<Network, NetworkAttachment> networksToSync = getNetworksToSync(hostId, networks);
    PersistentHostSetupNetworksParameters parameters = new PersistentHostSetupNetworksParameters(hostId);
    parameters.setRollbackOnFailure(true);
    parameters.setShouldBeLogged(false);
    parameters.setNetworkNames(getNetworkNames(networksToSync.keySet()));
    parameters.setNetworkAttachments(new ArrayList<>(networksToSync.values()));
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 2 with PersistentHostSetupNetworksParameters

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

the class RefreshNetworksParametersFactory method create.

/**
 * @param networks networks to be refreshed.
 * @return list of PersistentHostSetupNetworksParameters instances to update all given networks on all hosts where
 * they are used.
 */
public ArrayList<ActionParametersBase> create(List<Network> networks) {
    Map<Guid, List<Network>> vdsIdToNetworksOfAlteredQos = mapNetworksByAttachedHosts(networks);
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    for (Map.Entry<Guid, List<Network>> entry : vdsIdToNetworksOfAlteredQos.entrySet()) {
        Guid hostId = entry.getKey();
        List<Network> networksOfAlteredQos = entry.getValue();
        PersistentHostSetupNetworksParameters setupNetworkParams = persistentHostSetupNetworksParametersFactory.create(hostId, networksOfAlteredQos);
        parameters.add(setupNetworkParams);
    }
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 3 with PersistentHostSetupNetworksParameters

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

the class SyncAllHostNetworksCommand method executeCommand.

@Override
protected void executeCommand() {
    PersistentHostSetupNetworksParameters parameters = generateSyncAllHostNetworksParameters();
    ActionReturnValue retVal = runInternalAction(ActionType.PersistentHostSetupNetworks, parameters, cloneContextAndDetachFromParent());
    if (!retVal.getSucceeded()) {
        propagateFailure(retVal);
    } else {
        setSucceeded(true);
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)

Example 4 with PersistentHostSetupNetworksParameters

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

the class PersistentHostSetupNetworksParametersFactoryTest method testCreate.

@Test
public void testCreate() {
    when(networkAttachmentDao.getAllForHost(hostId)).thenReturn(Arrays.asList(networkAttachmentA, networkAttachmentB));
    PersistentHostSetupNetworksParameters parameters = underTest.create(hostId, Arrays.asList(networkA, networkB));
    assertThat(parameters.getShouldBeLogged(), is(false));
    assertThat(parameters.rollbackOnFailure(), is(true));
    String expectedSubstitutedNetworkNames = networkB.getName();
    assertThat(parameters.getNetworkNames(), is(expectedSubstitutedNetworkNames));
    assertThat(parameters.getNetworkAttachments(), hasSize(1));
    NetworkAttachment soleAttachment = parameters.getNetworkAttachments().iterator().next();
    assertThat(soleAttachment.getId(), is(networkAttachmentB.getId()));
    assertThat(soleAttachment.isOverrideConfiguration(), is(true));
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 5 with PersistentHostSetupNetworksParameters

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

the class ManageNetworksParametersBuilderImpl method buildParameters.

@Override
public PersistentHostSetupNetworksParameters buildParameters(Guid vdsId, List<Network> labeledNetworksToBeAdded, List<Network> labeledNetworksToBeRemoved, Map<String, VdsNetworkInterface> nicsByLabel, List<Network> updatedNetworks) {
    final PersistentHostSetupNetworksParameters addSetupNetworksParameters = addNetworksByLabelParametersBuilder.buildParameters(vdsId, labeledNetworksToBeAdded, nicsByLabel);
    final PersistentHostSetupNetworksParameters removeSetupNetworksParameters = removeNetworksByLabelParametersBuilder.buildParameters(vdsId, labeledNetworksToBeRemoved);
    PersistentHostSetupNetworksParameters updatedNetworksParams = createHostSetupNetworksParameters(vdsId);
    Map<Guid, NetworkAttachment> networkIdToAttachmentMap = getNetworkIdToAttachmentMap(vdsId);
    List<NetworkAttachment> updatedNetworkAttachments = updatedNetworks.stream().map(Network::getId).map(networkIdToAttachmentMap::get).collect(Collectors.toList());
    updatedNetworkAttachments.forEach(networkAttachment -> networkAttachment.setOverrideConfiguration(true));
    updatedNetworksParams.getNetworkAttachments().addAll(updatedNetworkAttachments);
    final PersistentHostSetupNetworksParameters combinedParams = combine(combine(addSetupNetworksParameters, removeSetupNetworksParameters), updatedNetworksParams);
    combinedParams.setNetworkNames(commaSeparateNetworkNames(Arrays.asList(labeledNetworksToBeAdded.stream(), labeledNetworksToBeRemoved.stream(), updatedNetworks.stream())));
    return combinedParams;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Aggregations

PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)15 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)7 Network (org.ovirt.engine.core.common.businessentities.network.Network)6 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)5 ArrayList (java.util.ArrayList)4 EngineException (org.ovirt.engine.core.common.errors.EngineException)4 Guid (org.ovirt.engine.core.compat.Guid)4 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)1