ofri masad has uploaded a new change for review. Change subject: [WIP] core: Add QoS to to DB and entities ......................................................................
[WIP] core: Add QoS to to DB and entities Add the QoS entity to the DB and business entities. see: http://wiki.ovirt.org/Features/Design/Network_QoS Change-Id: I809c4324432d25aa42cc32ce7d2481a9e1008a35 Bug-Url: https://bugzilla.redhat.com/514420 Signed-off-by: Ofri Masad <oma...@redhat.com> --- M backend/manager/dbscripts/create_tables.sql M backend/manager/dbscripts/create_views.sql A backend/manager/dbscripts/network_qos_sp A backend/manager/dbscripts/upgrade/03_03_02010_add_qos_values_to_vm_interface_statistics A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkQoS.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterfaceProfile.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDao.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDaoImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkInterfaceProfileDaoImpl.java A backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkQosDaoTest.java 10 files changed, 320 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/93/15993/1 diff --git a/backend/manager/dbscripts/create_tables.sql b/backend/manager/dbscripts/create_tables.sql index aabe032..0e448c7 100644 --- a/backend/manager/dbscripts/create_tables.sql +++ b/backend/manager/dbscripts/create_tables.sql @@ -1144,6 +1144,23 @@ WITH OIDS; -- ---------------------------------------------------------------------- +-- table network_qos +-- ---------------------------------------------------------------------- + + +CREATE TABLE network_qos +( + id uuid NOT NULL, + inbound_average INTEGER, + inbound_peak INTEGER, + inbound_burst INTEGER, + outbound_average INTEGER, + outbound_peak INTEGER, + outbound_burst INTEGER, + CONSTRAINT PK_id PRIMARY KEY (id), +) WITH OIDS; + +-- ---------------------------------------------------------------------- -- table vnic_profiles -- ---------------------------------------------------------------------- @@ -1154,6 +1171,7 @@ profile_name VARCHAR(50) NOT NULL, network_id UUID NOT NULL, network_name VARCHAR(50) NOT NULL, + qos_id UUID, port_mirroring BOOLEAN NOT NULL, custom_properties TEXT, CONSTRAINT PK_id PRIMARY KEY (id), @@ -1352,6 +1370,8 @@ ALTER TABLE vnic_profiles ADD CONSTRAINT FK_vnic_profiles_network_name FOREIGN KEY(network_name) REFERENCES network(name); +ALTER TABLE vnic_profiles ADD CONSTRAINT FK_vnic_profiles_qos_id FOREIGN KEY(qos_id) +REFERENCES network_qos(id); CREATE INDEX IDX_permissions_ad_element_id ON permissions diff --git a/backend/manager/dbscripts/create_views.sql b/backend/manager/dbscripts/create_views.sql index c64d47b..04c2a00 100644 --- a/backend/manager/dbscripts/create_views.sql +++ b/backend/manager/dbscripts/create_views.sql @@ -1118,9 +1118,18 @@ vnic_profiles.profile_name AS profile_name, vnic_profiles.network_id AS network_id, vnic_profiles.network_name AS network_name, + vnic_profiles.qos_id AS qos_id, vnic_profiles.port_mirroring AS port_mirroring, vnic_profiles.custom_properties AS custom_properties, -FROM vnic_profiles; + network_qos.inbound_average AS inbound_average, + network_qos.inbound_peak AS inbound_peak, + network_qos.inbound_burst AS inbound_burst, + network_qos.outbound_average AS outbound_average, + network_qos.outbound_peak AS outbound_peak, + network_qos.outbound_burst AS outbound_burst, +FROM vnic_profiles +INNER JOIN network_qos ON vnic_profiles.qos_id = network_qos.id; + ---------------------------------------------- -- Query Permissions ---------------------------------------------- diff --git a/backend/manager/dbscripts/network_qos_sp b/backend/manager/dbscripts/network_qos_sp new file mode 100644 index 0000000..0eb1a0c --- /dev/null +++ b/backend/manager/dbscripts/network_qos_sp @@ -0,0 +1,72 @@ + +---------------------------------------------------------------- +-- [network_qos] Table +---------------------------------------------------------------- + +Create or replace FUNCTION Insert_network_qos(v_id uuid NOT NULL, + v_inbound_average INTEGER, + v_inbound_peak INTEGER, + v_inbound_burst INTEGER, + v_outbound_average INTEGER, + v_outbound_peak INTEGER, + v_outbound_burst INTEGER) +RETURNS VOID + AS $procedure$ +BEGIN +INSERT INTO network_qos(id, inbound_average, inbound_peak, inbound_burst, outbound_average, outbound_peak, outbound_burst) + VALUES(v_id, v_inbound_average, v_inbound_peak, v_inbound_burst, v_outbound_average, v_outbound_peak, v_outbound_burst); +END; $procedure$ +LANGUAGE plpgsql; + + + + +Create or replace FUNCTION Update_network_qos(v_id uuid NOT NULL, + v_inbound_average INTEGER, + v_inbound_peak INTEGER, + v_inbound_burst INTEGER, + v_outbound_average INTEGER, + v_outbound_peak INTEGER, + v_outbound_burst INTEGER) +RETURNS VOID + + AS $procedure$ +BEGIN + UPDATE network_qos + SET inbound_average = v_inbound_average, inbound_peak = v_inbound_peak, inbound_burst = v_inbound_burst, + outbound_average = v_outbound_average, outbound_peak = v_outbound_peak, outbound_burst = v_outbound_burst + WHERE id = v_id; +END; $procedure$ +LANGUAGE plpgsql; + + + +Create or replace FUNCTION Delete_network_qos(v_id UUID) RETURNS VOID + AS $procedure$ +BEGIN + DELETE FROM network_qos + WHERE id = v_id; +END; $procedure$ +LANGUAGE plpgsql; + + + +Create or replace FUNCTION Get_all_network_qos(v_user_id uuid) RETURNS SETOF network_qos + AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM network_qos +END; $procedure$ +LANGUAGE plpgsql; + + + +Create or replace FUNCTION Get_network_qos_by_id(v_id UUID) RETURNS SETOF network_qos + AS $procedure$ +BEGIN +RETURN QUERY SELECT * + FROM network_qos + WHERE id = v_id; +END; $procedure$ +LANGUAGE plpgsql; + diff --git a/backend/manager/dbscripts/upgrade/03_03_02010_add_qos_values_to_vm_interface_statistics b/backend/manager/dbscripts/upgrade/03_03_02010_add_qos_values_to_vm_interface_statistics new file mode 100644 index 0000000..0b403c8 --- /dev/null +++ b/backend/manager/dbscripts/upgrade/03_03_02010_add_qos_values_to_vm_interface_statistics @@ -0,0 +1,7 @@ +--Add qos properties into vm_interface_statistics +SELECT fn_db_add_column('vm_interface_statistics', 'inbound_average', 'INTEGER'); +SELECT fn_db_add_column('vm_interface_statistics', 'inbound_peak', 'INTEGER'); +SELECT fn_db_add_column('vm_interface_statistics', 'inbound_burst', 'INTEGER'); +SELECT fn_db_add_column('vm_interface_statistics', 'outbound_average', 'INTEGER'); +SELECT fn_db_add_column('vm_interface_statistics', 'outbound_peak', 'INTEGER'); +SELECT fn_db_add_column('vm_interface_statistics', 'outbound_burst', 'INTEGER'); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkQoS.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkQoS.java new file mode 100644 index 0000000..eb31c03 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/NetworkQoS.java @@ -0,0 +1,89 @@ +package org.ovirt.engine.core.common.businessentities.network; + + +import org.ovirt.engine.core.common.businessentities.BusinessEntity; +import org.ovirt.engine.core.common.businessentities.IVdcQueryable; +import org.ovirt.engine.core.common.utils.ObjectUtils; +import org.ovirt.engine.core.compat.Guid; + +import java.io.Serializable; + +public class NetworkQoS extends IVdcQueryable implements Serializable, BusinessEntity<Guid> { + + private Integer inboundAverage; + private Integer inboundPeak; + private Integer inboundBurst; + private Integer outboundAverage; + private Integer outboundPeak; + private Integer outboundBurst; + + private Guid id; + + + @Override + public Guid getId() { + return id; + } + + @Override + public void setId(Guid id) { + this.id = id; + } + + public Integer getInboundAverage() { + return inboundAverage; + } + + public void setInboundAverage(Integer inboundAverage) { + this.inboundAverage = inboundAverage; + } + + public Integer getInboundPeak() { + return inboundPeak; + } + + public void setInboundPeak(Integer inboundPeak) { + this.inboundPeak = inboundPeak; + } + + public Integer getInboundBurst() { + return inboundBurst; + } + + public void setInboundBurst(Integer inboundBurst) { + this.inboundBurst = inboundBurst; + } + + public Integer getOutboundAverage() { + return outboundAverage; + } + + public void setOutboundAverage(Integer outboundAverage) { + this.outboundAverage = outboundAverage; + } + + public Integer getOutboundPeak() { + return outboundPeak; + } + + public void setOutboundPeak(Integer outboundPeak) { + this.outboundPeak = outboundPeak; + } + + public Integer getOutboundBurst() { + return outboundBurst; + } + + public void setOutboundBurst(Integer outboundBurst) { + this.outboundBurst = outboundBurst; + } + + public boolean equalValues(NetworkQoS other) { + return ObjectUtils.objectsEqual(this.getInboundAverage(), other.getInboundAverage()) + && ObjectUtils.objectsEqual(this.getInboundPeak(), other.getInboundPeak()) + && ObjectUtils.objectsEqual(this.getInboundBurst(), other.getInboundBurst()) + && ObjectUtils.objectsEqual(this.getOutboundAverage(), other.getOutboundAverage()) + && ObjectUtils.objectsEqual(this.getOutboundPeak(), other.getOutboundPeak()) + && ObjectUtils.objectsEqual(this.getOutboundBurst(), other.getOutboundBurst()); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterfaceProfile.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterfaceProfile.java index c9036ba..1ed80f8 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterfaceProfile.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterfaceProfile.java @@ -14,6 +14,8 @@ private Network network; private Guid networkId; private String networkName; + private NetworkQoS networkQoS; + private Guid networkQoSId; private boolean portMirroringEnabled; private String customProperties; @@ -35,6 +37,14 @@ public void setName(String name) { this.name = name; + } + + public NetworkQoS getNetworkQoS() { + return networkQoS; + } + + public void setNetworkQoS(NetworkQoS networkQoS) { + this.networkQoS = networkQoS; } public boolean isPortMirroringEnabled() { @@ -76,4 +86,12 @@ public void setNetworkName(String networkName) { this.networkName = networkName; } + + public Guid getNetworkQoSId() { + return networkQoSId; + } + + public void setNetworkQoSId(Guid networkQoSId) { + this.networkQoSId = networkQoSId; + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDao.java new file mode 100644 index 0000000..bab0e80 --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDao.java @@ -0,0 +1,9 @@ +package org.ovirt.engine.core.dao.network; + +import org.ovirt.engine.core.common.businessentities.network.NetworkQoS; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.GenericDao; + +public interface NetworkQoSDao extends GenericDao<NetworkQoS, Guid> { + +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDaoImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDaoImpl.java new file mode 100644 index 0000000..a331e74 --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkQoSDaoImpl.java @@ -0,0 +1,79 @@ +package org.ovirt.engine.core.dao.network; + +import org.ovirt.engine.core.common.businessentities.network.NetworkQoS; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.BaseDAODbFacade; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class NetworkQoSDaoImpl extends BaseDAODbFacade implements NetworkQoSDao { + + protected static final RowMapper<NetworkQoS> mapper = + new RowMapper<NetworkQoS>() { + @Override + public NetworkQoS mapRow(ResultSet rs, int rowNum) + throws SQLException { + NetworkQoS entity = new NetworkQoS(); + entity.setId(Guid.createGuidFromString(rs.getString("id"))); + entity.setInboundAverage(rs.getInt("inbound_average")); + entity.setInboundPeak(rs.getInt("inbound_peak")); + entity.setInboundBurst(rs.getInt("inbound_burst")); + entity.setOutboundAverage(rs.getInt("outbound_average")); + entity.setOutboundPeak(rs.getInt("outbound_peak")); + entity.setOutboundBurst(rs.getInt("outbound_burst")); + return entity; + } + }; + + + @Override + public NetworkQoS get(Guid id) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("id", id); + return getCallsHandler().executeRead("Get_network_qos_by_id", mapper, parameterSource); + } + + @Override + public void save(NetworkQoS profile) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("id", profile.getId()) + .addValue("inbound_average", profile.getInboundAverage()) + .addValue("inbound_peak", profile.getInboundPeak()) + .addValue("inbound_burst", profile.getInboundBurst()) + .addValue("outbound_average", profile.getOutboundAverage()) + .addValue("outbound_peak", profile.getOutboundPeak()) + .addValue("outbound_burst", profile.getOutboundBurst()); + + getCallsHandler().executeModification("Insert_network_qos", parameterSource); + } + + @Override + public void update(NetworkQoS profile) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("id", profile.getId()) + .addValue("inbound_average", profile.getInboundAverage()) + .addValue("inbound_peak", profile.getInboundPeak()) + .addValue("inbound_burst", profile.getInboundBurst()) + .addValue("outbound_average", profile.getOutboundAverage()) + .addValue("outbound_peak", profile.getOutboundPeak()) + .addValue("outbound_burst", profile.getOutboundBurst()); + + getCallsHandler().executeModification("Update_network_qos", parameterSource); + } + + @Override + public void remove(Guid id) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("id", id); + + getCallsHandler().executeModification("Delete_network_qos", parameterSource); + } + + @Override + public List<NetworkQoS> getAll() { + return getCallsHandler().executeReadList("Get_all_network_qos", mapper, getCustomMapSqlParameterSource()); + } +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkInterfaceProfileDaoImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkInterfaceProfileDaoImpl.java index f4f97b5..c8df1be 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkInterfaceProfileDaoImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkInterfaceProfileDaoImpl.java @@ -24,8 +24,10 @@ entity.setName(rs.getString("profile_name")); entity.setNetworkId(Guid.createGuidFromString(rs.getString("network_id"))); entity.setNetworkName(rs.getString("network_name")); + entity.setNetworkQoSId(Guid.createGuidFromString(rs.getString("qos_id"))); entity.setCustomProperties(rs.getString("custom_properties")); entity.setPortMirroringEnabled(rs.getBoolean("is_plugged")); + entity.setNetworkQoS(NetworkQoSDaoImpl.mapper.mapRow(rs, rowNum)); return entity; } }; @@ -44,11 +46,15 @@ .addValue("name", profile.getName()) .addValue("network_name", profile.getNetworkName()) .addValue("network_id", profile.getNetworkId()) + .addValue("qos_id", profile.getNetworkQoSId()) .addValue("port_mirroring", profile.isPortMirroringEnabled()) .addValue("custom_properties", profile.getCustomProperties()); getCallsHandler().executeModification("Insert_vm_interface_profile", parameterSource); //TODO + if (profile.getNetworkQoS() != null) { + DbFacade.getInstance().getNetworkQoSDao().save(profile.getNetworkQoS()); + } } @Override @@ -58,11 +64,15 @@ .addValue("name", profile.getName()) .addValue("network_name", profile.getNetworkName()) .addValue("network_id", profile.getNetworkId()) + .addValue("qos_id", profile.getNetworkQoSId()) .addValue("port_mirroring", profile.isPortMirroringEnabled()) .addValue("custom_properties", profile.getCustomProperties()); getCallsHandler().executeModification("Update_vm_interface_profile", parameterSource); //TODO + if (profile.getNetworkQoS() != null) { + DbFacade.getInstance().getNetworkQoSDao().update(profile.getNetworkQoS()); + } } @Override diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkQosDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkQosDaoTest.java new file mode 100644 index 0000000..6b4c2ed --- /dev/null +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkQosDaoTest.java @@ -0,0 +1,6 @@ +package org.ovirt.engine.core.dao.network; + +import org.ovirt.engine.core.dao.BaseDAOTestCase; + +public class NetworkQosDaoTest extends BaseDAOTestCase { +} -- To view, visit http://gerrit.ovirt.org/15993 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I809c4324432d25aa42cc32ce7d2481a9e1008a35 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <oma...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches