Moti Asayag has uploaded a new change for review. Change subject: engine: Re-construct SetupNetworks steps ......................................................................
engine: Re-construct SetupNetworks steps The deprecated SetupNetworks command is being updated to use HostSetupNetworks introduced sequence of actions: 1. DRY - reuse the HostSetupNetworkPoller for polling connectivity to the host while executing the setupnetworks on vdsm. 2. Replaced 'all-in-one' vdsbroker CollectVdsNetworkDate with few steps that separates the concern of persisting the network changes from the network data collected process. SetupNetworks requires specific behavior to preserves nics additional attributes (i.e. labels), hence specifying that logic explicitly as part of this command clarify the action. Change-Id: I79fe45714f0f9ed4348f7c68c2b38cf1ace57fa6 Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java 1 file changed, 28 insertions(+), 37 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/76/35376/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java index 2e75d5d..9cf2160 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksCommand.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -17,6 +18,7 @@ import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.businessentities.network.NetworkAttachment; import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; @@ -24,14 +26,15 @@ import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.interfaces.FutureVDSCall; -import org.ovirt.engine.core.common.vdscommands.CollectHostNetworkDataVdsCommandParameters; import org.ovirt.engine.core.common.vdscommands.FutureVDSCommandType; import org.ovirt.engine.core.common.vdscommands.SetupNetworksVdsCommandParameters; +import org.ovirt.engine.core.common.vdscommands.UserConfiguredNetworkData; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; -import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase; +import org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; +import org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkTopologyPersisterImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,8 +49,6 @@ NO_CHANGES_DETECTED; }; - /** Time between polling attempts, to prevent flooding the host/network. */ - private static final long POLLING_BREAK = 500; private static final List<VDSStatus> SUPPORTED_HOST_STATUSES = Arrays.asList(VDSStatus.Maintenance, VDSStatus.Up, VDSStatus.NonOperational); private static final Logger log = LoggerFactory.getLogger(SetupNetworksCommand.class); @@ -115,6 +116,7 @@ return; } + T bckndCmdParams = getParameters(); final SetupNetworksVdsCommandParameters vdsCmdParams = new SetupNetworksVdsCommandParameters( getVds(), @@ -147,7 +149,12 @@ VdsHandler.handleVdsResult(retVal); if (retVal.getSucceeded()) { - setSucceeded(TransactionSupport.executeInNewTransaction(updateVdsNetworksInTx())); + VDSReturnValue returnValue = + runVdsCommand(VDSCommandType.GetCapabilities, + new VdsIdAndVdsVDSCommandParametersBase(getVds())); + VDS updatedHost = (VDS) returnValue.getReturnValue(); + persistNetworkChanges(updatedHost); + setSucceeded(true); } } } catch (TimeoutException e) { @@ -204,50 +211,35 @@ * @param timeout */ private void pollInterruptively(final FutureVDSCall<VDSReturnValue> setupNetworksTask) { + HostSetupNetworkPoller poller = new HostSetupNetworkPoller(); while (!setupNetworksTask.isDone()) { - pollVds(); + poller.poll(getVdsId()); } } - /** - * update the new VDSM networks to DB in new transaction. - * - * @return - */ - private TransactionMethod<Boolean> updateVdsNetworksInTx() { - return new TransactionMethod<Boolean>() { - + private void persistNetworkChanges(final VDS updatedHost) { + TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override - public Boolean runInTransaction() { - // save the new network topology to DB + public Void runInTransaction() { + getVdsDynamicDao().updateNetConfigDirty(getVds().getId(), getVds().getNetConfigDirty()); + List<VdsNetworkInterface> ifaces = new ArrayList<>(getInterfaces()); ifaces.addAll(getRemovedBonds().values()); - runVdsCommand(VDSCommandType.CollectVdsNetworkData, - new CollectHostNetworkDataVdsCommandParameters(getVds(), ifaces)); + UserConfiguredNetworkData userConfiguredNetworkData = + new UserConfiguredNetworkData(Collections.<NetworkAttachment> emptyList(), ifaces); - // Update cluster networks (i.e. check if need to activate each new network) + // save the new network topology to DB + HostNetworkTopologyPersisterImpl.getInstance().persistAndEnforceNetworkCompliance(updatedHost, + false, + userConfiguredNetworkData); + for (Network net : getNetworks()) { NetworkClusterHelper.setStatus(getVdsGroupId(), net); } - return Boolean.TRUE; - } - }; - } - private void pollVds() { - long timeBeforePoll = System.currentTimeMillis(); - FutureVDSCall<VDSReturnValue> task = - Backend.getInstance().getResourceManager().runFutureVdsCommand(FutureVDSCommandType.Poll, - new VdsIdVDSCommandParametersBase(getVds().getId())); - try { - task.get(Config.<Integer> getValue(ConfigValues.SetupNetworksPollingTimeout), TimeUnit.SECONDS); - - if (System.currentTimeMillis() - timeBeforePoll < POLLING_BREAK) { - Thread.sleep(POLLING_BREAK); + return null; } - } catch (Exception e) { - // ignore failure. network can go down due to VDSM changing the network - } + }); } private FutureVDSCall<VDSReturnValue> createFutureTask(final SetupNetworksVdsCommandParameters vdsCmdParams) { @@ -255,5 +247,4 @@ .getResourceManager() .runFutureVdsCommand(FutureVDSCommandType.SetupNetworks, vdsCmdParams); } - } -- To view, visit http://gerrit.ovirt.org/35376 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I79fe45714f0f9ed4348f7c68c2b38cf1ace57fa6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
