Alona Kaplan has uploaded a new change for review. Change subject: engine: create/update host_nic_vfsConfig according to HostDevListByCaps ......................................................................
engine: create/update host_nic_vfsConfig according to HostDevListByCaps Change-Id: I60ab755a75d93d4bafa5be984b267104f4636197 Signed-off-by: Alona Kaplan <alkap...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/RefreshHostDevicesCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostNicVfsConfigHelper.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java 8 files changed, 170 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/37386/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/RefreshHostDevicesCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/RefreshHostDevicesCommand.java index 539a11c..68121ba 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/RefreshHostDevicesCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/RefreshHostDevicesCommand.java @@ -3,12 +3,16 @@ import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute; import org.ovirt.engine.core.bll.RefreshHostInfoCommandBase; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.network.host.HostNicVfsConfigHelper; import org.ovirt.engine.core.common.action.VdsActionParameters; import org.ovirt.engine.core.common.businessentities.HostDevice; +import org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase; +import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -29,6 +33,9 @@ @Inject private DbFacade dbFacade; + @Inject + HostNicVfsConfigHelper hostNicVfsConfigHelper; + public RefreshHostDevicesCommand(T parameters) { super(parameters); } @@ -39,7 +46,9 @@ @Override protected void executeCommand() { - VDSReturnValue vdsReturnValue = resourceManager.runVdsCommand(VDSCommandType.HostDevListByCaps, new VdsIdAndVdsVDSCommandParametersBase(getVds())); + VDSReturnValue vdsReturnValue = + resourceManager.runVdsCommand(VDSCommandType.HostDevListByCaps, + new VdsIdAndVdsVDSCommandParametersBase(getVds())); List<HostDevice> fetchedDevices = (List<HostDevice>) vdsReturnValue.getReturnValue(); List<HostDevice> oldDevices = dbFacade.getHostDeviceDao().getHostDevicesByHostId(getVdsId()); @@ -67,6 +76,15 @@ } } + final List<HostNicVfsConfig> newHostNicVfsConfigs = new ArrayList<>(); + final List<HostNicVfsConfig> changedHostNicVfsConfigs = new ArrayList<>(); + + getHostNicVfsConfigUpdates(oldMap, newDevices, + changedDevices, + removedDevices, + newHostNicVfsConfigs, + changedHostNicVfsConfigs); + TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override public Void runInTransaction() { @@ -74,6 +92,14 @@ dbFacade.getHostDeviceDao().updateAllInBatch(changedDevices); dbFacade.getHostDeviceDao().removeAllInBatch(removedDevices); +// if (!newHostNicVfsConfigs.isEmpty()) { +// dbFacade.getHostNicVfsConfigDao().saveAllInBatch(newHostNicVfsConfigs); +// } +// +// if (!changedHostNicVfsConfigs.isEmpty()) { +// dbFacade.getHostNicVfsConfigDao().updateAllInBatch(changedHostNicVfsConfigs); +// } + return null; } }); @@ -81,6 +107,57 @@ setSucceeded(true); } + private void getHostNicVfsConfigUpdates(Map<String, HostDevice> oldMap, List<HostDevice> newDevices, + List<HostDevice> changedDevices, + List<HostDevice> removedDevices, + List<HostNicVfsConfig> newHostNicVfsConfigs, + List<HostNicVfsConfig> changedHostNicVfsConfigs) { + for (HostDevice device : newDevices) { + if (device.getTotalVirtualFunctions() != null) { + addHostNicVfsConfig(device); + } + } + + for (HostDevice device : changedDevices) { + Integer oldTotalNumOfVfs = oldMap.get(device.getDeviceName()).getTotalVirtualFunctions(); + + // The nic became sr-iov enabled, an entry should be added to host_nic_vfs_config + if (oldTotalNumOfVfs == null && device.getTotalVirtualFunctions() != null) { + addHostNicVfsConfig(device); + } + } + + for (HostDevice device : removedDevices) { + removeHostNicVfsConfig(device); + } + } + + private void addHostNicVfsConfig(HostDevice device) { + VdsNetworkInterface nic = hostNicVfsConfigHelper.getNicByDevice(device); + + if (nic == null) { + return; + } + + HostNicVfsConfig hostNicVfsConfig = new HostNicVfsConfig(); + hostNicVfsConfig.setId(Guid.newGuid()); + hostNicVfsConfig.setNicId(nic.getId()); + hostNicVfsConfig.setAllNetworksAllowed(true); + + // TODO numOfVfs ? + // TODO maxNumOfVfs ? + // TODO numOfFreeVfs ? + } + + private void removeHostNicVfsConfig(HostDevice device) { + VdsNetworkInterface nic = hostNicVfsConfigHelper.getNicByDevice(device); + if (nic == null) { + return; + } + + dbFacade.getHostNicVfsConfigDao().removeByNicId(nic.getId()); + } + @Override protected void setActionMessageParameters() { addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REFRESH); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostNicVfsConfigHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostNicVfsConfigHelper.java new file mode 100644 index 0000000..444b298 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/HostNicVfsConfigHelper.java @@ -0,0 +1,39 @@ +package org.ovirt.engine.core.bll.network.host; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.ovirt.engine.core.common.businessentities.HostDevice; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +@Singleton +public class HostNicVfsConfigHelper { + + @Inject + private DbFacade dbFacade; + + private VdsNetworkInterface getNicByPciDevice(HostDevice pciDevice) { + HostDevice netDevice = getNetDevice(pciDevice); + return getNicByNetDevice(netDevice); + } + + private VdsNetworkInterface getNicByNetDevice(HostDevice device) { + return dbFacade.getInterfaceDao().getByHostIdAndName(device.getHostId(), device.getNetworkInterfaceName()); + } + + private HostDevice getNetDevice(HostDevice pciDevice) { + return dbFacade.getHostDeviceDao().getChildDevices(pciDevice.getId()).get(0); + } + + public VdsNetworkInterface getNicByDevice(HostDevice device) { + if (device.getTotalVirtualFunctions() != null) { + return getNicByPciDevice(device); + } + + if (device.getNetworkInterfaceName() != null) { + return getNicByNetDevice(device); + } + return null; + } +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java index e845c6c..eff316b 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDao.java @@ -1,14 +1,23 @@ package org.ovirt.engine.core.dao; +import java.util.List; + import org.ovirt.engine.core.common.businessentities.HostDevice; import org.ovirt.engine.core.common.businessentities.HostDeviceId; import org.ovirt.engine.core.compat.Guid; - -import java.util.List; public interface HostDeviceDao extends GenericDao<HostDevice, HostDeviceId>, MassOperationsDao<HostDevice, HostDeviceId> { List<HostDevice> getHostDevicesByHostId(Guid hostId); HostDevice getHostDeviceByHostIdAndDeviceName(Guid hostId, String deviceName); + + /** + * Returns the HostDevices that the device with the given id is their parent device. + * + * @param id + * the id of the parent device + * @return list of HostDevices which are children of the device with the given id + */ + List<HostDevice> getChildDevices(HostDeviceId id); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDaoDbFacadeImpl.java index 0c7bea6..36a5f23 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/HostDeviceDaoDbFacadeImpl.java @@ -57,6 +57,12 @@ return get(new HostDeviceId(hostId, deviceName)); } + @Override + public List<HostDevice> getChildDevices(HostDeviceId id) { + // TODO Auto-generated method stub + return null; + } + private static class HostDeviceRowMapper implements RowMapper<HostDevice> { public static final HostDeviceRowMapper instance = new HostDeviceRowMapper(); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java index 969b8bb..2aeb3f4 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java @@ -5,8 +5,9 @@ import org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.GenericDao; +import org.ovirt.engine.core.dao.MassOperationsDao; -public interface HostNicVfsConfigDao extends GenericDao<HostNicVfsConfig, Guid> { +public interface HostNicVfsConfigDao extends GenericDao<HostNicVfsConfig, Guid>, MassOperationsDao<HostNicVfsConfig, Guid> { /** * Retrieves a list of all the vfsConfig on this host. * Notice: just nics which are SR-IOV enabled have vfsConfig. @@ -22,13 +23,22 @@ * Retrieves the vfsConfig of the specified nic. * * @param nicId - * host nic vfs config id + * the id of the nic * @return the vfsConfig of the specified nic * */ HostNicVfsConfig getByNicId(Guid nicId); /** + * Removes the vfsConfig of the specified nic. + * + * @param nicId + * the id of the nic + * + */ + void removeByNicId(Guid nicId); + + /** * Attaches a network to the allowed network list of the specified vfs config * * @param vfsConfigId diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java index ad9ba2d..a955202 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java @@ -10,12 +10,12 @@ import org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade; +import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SingleColumnRowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -public class HostNicVfsConfigDaoDbFacadeImpl extends DefaultGenericDaoDbFacade<HostNicVfsConfig, Guid> implements HostNicVfsConfigDao { +public class HostNicVfsConfigDaoDbFacadeImpl extends MassOperationsGenericDaoDbFacade<HostNicVfsConfig, Guid> implements HostNicVfsConfigDao { public HostNicVfsConfigDaoDbFacadeImpl() { super("hostNicVfsConfig"); @@ -124,6 +124,11 @@ } @Override + public void removeByNicId(Guid nicId) { + // TODO Auto-generated method stub + } + + @Override public void addNetwork(Guid vfsConfigId, Guid networkId) { getCallsHandler().executeModification("InsertvfsConfigNetwork", createNetworkParametersMapper(vfsConfigId, networkId)); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java index 0af7e26..435f482 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java @@ -132,6 +132,17 @@ List<VdsNetworkInterface> getVdsInterfacesByNetworkId(Guid networkId); /** + * Returns the VdsNetworkInterface that the has the given hostId and name. + * + * @param hostId + * the network + * @param name + * the name of the nic + * @return the list of VdsNetworkInterfaces + */ + VdsNetworkInterface getByHostIdAndName(Guid hostId, String name); + + /** * Returns the VdsNetworkInterface with the specified id. * * @param id diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java index 02c1c3e..d72f2bf 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java @@ -231,6 +231,12 @@ } @Override + public VdsNetworkInterface getByHostIdAndName(Guid hostId, String name) { + // TODO Auto-generated method stub + return null; + } + + @Override public VdsNetworkInterface get(Guid id) { return getCallsHandler().executeRead("GetVdsInterfaceById", vdsNetworkInterfaceRowMapper, -- To view, visit http://gerrit.ovirt.org/37386 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I60ab755a75d93d4bafa5be984b267104f4636197 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alona Kaplan <alkap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches