Kobi Ianko has uploaded a new change for review. Change subject: db: Adding Cpu Qos DB config ......................................................................
db: Adding Cpu Qos DB config Adding the Cpu Qos db config, the Cpu Qos consists of one parameter:cpu_limit. The parameter will be added to the qos table. support for this feature is for all 3.x versions. Change-Id: I533bcc601ac44289c51f5d56a6da0dd2455116d6 Bug-Url: https://bugzilla.redhat.com/1084930 Signed-off-by: Kobi Ianko <[email protected]> --- M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/qos/CpuQos.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDao.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDaoFacadeImpl.java M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties A backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/qos/CpuQosDaoTest.java M backend/manager/modules/dal/src/test/resources/fixtures.xml M packaging/dbscripts/qos_sp.sql A packaging/dbscripts/upgrade/03_05_0430_add_cpu_limit_to_qos.sql M packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql 13 files changed, 248 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/27686/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java index 6c8f0c8..bfb23cb 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java @@ -199,6 +199,15 @@ return supportedInConfig(ConfigValues.StorageQosSupported, version); } + /** + * @param version + * Compatibility version to check for. + * @return <code>true</code> if Cpu QoS is supported for the cluster version. + */ + public static boolean cpuQoS(Version version) { + return supportedInConfig(ConfigValues.CpuQosSupported, version); + } + public static boolean hostNetworkQos(Version version) { return supportedInConfig(ConfigValues.HostNetworkQosSupported, version); } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/qos/CpuQos.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/qos/CpuQos.java index 1949857..76ba11d 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/qos/CpuQos.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/qos/CpuQos.java @@ -17,6 +17,14 @@ message = "ACTION_TYPE_FAILED_QOS_OUT_OF_RANGE_VALUES") private Integer cpuLimit; + public Integer getCpuLimit() { + return cpuLimit; + } + + public void setCpuLimit(Integer cpuLimit) { + this.cpuLimit = cpuLimit; + } + @Override public int valuesHashCode() { final int prime = 31; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java index a509885..665d4a0 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java @@ -1559,6 +1559,10 @@ @TypeConverterAttribute(Boolean.class) @DefaultValueAttribute("true") + CpuQosSupported, + + @TypeConverterAttribute(Boolean.class) + @DefaultValueAttribute("true") HostNetworkQosSupported, @TypeConverterAttribute(Boolean.class) diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java index 320fb37..96b965a 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java @@ -98,6 +98,7 @@ VirtIoScsiEnabled(ConfigAuthType.User), HostNetworkQosSupported, StorageQosSupported, + CpuQosSupported, SshSoftFencingCommand, MemorySnapshotSupported(ConfigAuthType.User), MaxAverageNetworkQoSValue, diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java index 94ec3f6..68f7c07 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java @@ -123,6 +123,7 @@ import org.ovirt.engine.core.dao.network.VnicProfileDao; import org.ovirt.engine.core.dao.network.VnicProfileViewDao; import org.ovirt.engine.core.dao.provider.ProviderDao; +import org.ovirt.engine.core.dao.qos.CpuQosDao; import org.ovirt.engine.core.dao.qos.StorageQosDao; import org.ovirt.engine.core.dao.scheduling.AffinityGroupDao; import org.ovirt.engine.core.dao.scheduling.ClusterPolicyDao; @@ -920,6 +921,10 @@ return getDao(StorageQosDao.class); } + public CpuQosDao getCpuQosDao() { + return getDao(CpuQosDao.class); + } + /** * Returns the singleton instance of {@link PolicyUnitDao}. * diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDao.java new file mode 100644 index 0000000..63c9a1c --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDao.java @@ -0,0 +1,6 @@ +package org.ovirt.engine.core.dao.qos; + +import org.ovirt.engine.core.common.businessentities.qos.CpuQos; + +public interface CpuQosDao extends QosDao<CpuQos> { +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDaoFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDaoFacadeImpl.java new file mode 100644 index 0000000..d7fbcd8 --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/CpuQosDaoFacadeImpl.java @@ -0,0 +1,28 @@ +package org.ovirt.engine.core.dao.qos; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.ovirt.engine.core.common.businessentities.qos.CpuQos; +import org.ovirt.engine.core.common.businessentities.qos.QosType; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; + +public class CpuQosDaoFacadeImpl extends BaseQosDaoFacadeImpl<CpuQos> implements CpuQosDao { + + public CpuQosDaoFacadeImpl() { + super(QosType.CPU); + } + + @Override + protected CpuQos createPartialQosEntity(ResultSet rs) throws SQLException { + CpuQos entity = new CpuQos(); + entity.setCpuLimit(getIntegerOrNull(rs, "cpu_limit")); + return entity; + } + + @Override + protected void updatePartialParametersMapper(MapSqlParameterSource map, CpuQos obj) { + map.addValue("cpu_limit", obj.getCpuLimit()); + } + +} diff --git a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties index 9e32ef3..4700a6d 100644 --- a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties +++ b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties @@ -68,6 +68,7 @@ GlusterServerDao=org.ovirt.engine.core.dao.gluster.GlusterServerDaoDbFacadeImpl NetworkQoSDao=org.ovirt.engine.core.dao.network.NetworkQoSDaoFacadeImpl StorageQosDao=org.ovirt.engine.core.dao.qos.StorageQosDaoFacadeImpl +CpuQosDao=org.ovirt.engine.core.dao.qos.CpuQosDaoFacadeImpl PolicyUnitDao=org.ovirt.engine.core.dao.scheduling.PolicyUnitDaoImpl ClusterPolicyDao=org.ovirt.engine.core.dao.scheduling.ClusterPolicyDaoImpl DwhHistoryTimekeepingDao=org.ovirt.engine.core.dao.dwh.DwhHistoryTimekeepingDaoDbFacadeImpl diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/qos/CpuQosDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/qos/CpuQosDaoTest.java new file mode 100644 index 0000000..42d49cb --- /dev/null +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/qos/CpuQosDaoTest.java @@ -0,0 +1,113 @@ +package org.ovirt.engine.core.dao.qos; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.List; + +import org.junit.Test; +import org.ovirt.engine.core.common.businessentities.qos.CpuQos; +import org.ovirt.engine.core.common.businessentities.qos.QosType; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.BaseDAOTestCase; +import org.ovirt.engine.core.dao.FixturesTool; +import org.ovirt.engine.core.utils.linq.LinqUtils; +import org.ovirt.engine.core.utils.linq.Predicate; + +public class CpuQosDaoTest extends BaseDAOTestCase { + + private final CpuQosDao dao = getDbFacade().getCpuQosDao(); + + private static final Guid qosAId = + Guid.createGuidFromString("be956031-6be2-43d6-bb90-5191c8253314"); + private static final Guid qosBId = + Guid.createGuidFromString("be956031-6be2-43d6-bb90-5191c8253315"); + private static final Guid qosCId = + Guid.createGuidFromString("be956031-6be2-43d6-bb90-5191c8253316"); + private static final Guid qosDId = + Guid.createGuidFromString("be956031-6be2-43d6-bb90-5191c8253317"); + + + /** + * Ensures that retrieving with an invalid ID returns null. + */ + @Test + public void testGetWithInvalidId() { + assertNull(dao.get(Guid.newGuid())); + } + + /** + * Ensures that retrieving VDS by ID works as expected. + */ + @Test + public void testGetCpuQos() { + CpuQos cpuQos = new CpuQos(); + cpuQos.setId(qosAId); + cpuQos.setName("qos_a"); + cpuQos.setDescription("You don't understand. There's relationship George, and then there's the George you know. Baudy George, Funny George"); + cpuQos.setStoragePoolId(FixturesTool.STORAGE_POOL_NFS_2); + cpuQos.setCpuLimit(50); + + assertEquals(cpuQos, dao.get(qosAId)); + } + + /** + * test update + */ + @Test + public void testUpdateStorageQos() { + CpuQos cpuQos = new CpuQos(); + cpuQos.setId(qosBId); + cpuQos.setName("newB"); + cpuQos.setDescription("If I owned a company, my employees would love me. They’d have huge pictures of me up the walls and in their home, like Lenin."); + cpuQos.setStoragePoolId(FixturesTool.STORAGE_POOL_NFS_2); + cpuQos.setCpuLimit(50); + + dao.update(cpuQos); + + assertEquals(cpuQos, dao.get(qosBId)); + } + + /** + * test remove + */ + @Test + public void testRemoveCpuQos() { + dao.remove(qosCId); + assertNull(dao.get(qosCId)); + } + + /** + * test save + */ + @Test + public void testSaveCpuQos() { + CpuQos cpuQos = new CpuQos(); + cpuQos.setId(qosDId); + cpuQos.setName("qos_d"); + cpuQos.setDescription("bla bla"); + cpuQos.setStoragePoolId(FixturesTool.STORAGE_POOL_NFS_2); + cpuQos.setCpuLimit(50); + + dao.save(cpuQos); + assertEquals(cpuQos, dao.get(qosDId)); + } + + /** + * Test getAllForStoragePool + */ + @Test + public void testGetAllCpuQosForStoragePool() { + List<CpuQos> qoss = dao.getAllForStoragePoolId(FixturesTool.STORAGE_POOL_NFS_2); + LinqUtils.filter(qoss, new Predicate<CpuQos>() { + + @Override + public boolean eval(CpuQos t) { + return t.getQoSType().equals(QosType.CPU); + } + + }); + assertEquals(2, qoss.size()); + } + +} diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml b/backend/manager/modules/dal/src/test/resources/fixtures.xml index 2039d83..0dbf1dd 100644 --- a/backend/manager/modules/dal/src/test/resources/fixtures.xml +++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml @@ -1067,6 +1067,7 @@ <column>max_iops</column> <column>max_read_iops</column> <column>max_write_iops</column> + <column>cpu_limit</column> <row> <value>ae956031-6be2-43d6-bb90-5191c9253314</value> <value>1</value> @@ -1079,6 +1080,7 @@ <value>1000</value> <value>2000</value> <value>500</value> + <null /> </row> <row> <value>ae956031-6be2-43d6-bb90-5191c9253315</value> @@ -1092,6 +1094,7 @@ <value>1200</value> <value>2400</value> <value>500</value> + <null /> </row> <row> <value>ae956031-6be2-43d6-bb90-5191c9253316</value> @@ -1105,6 +1108,7 @@ <value>700</value> <value>1400</value> <value>500</value> + <null /> </row> <row> <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9db</value> @@ -1118,6 +1122,63 @@ <value>700</value> <value>1400</value> <value>500</value> + <null /> + </row> + <row> + <value>be956031-6be2-43d6-bb90-5191c8253314</value> + <value>2</value> + <value>qos_cpu_a</value> + <value>desc</value> + <value>386bffd1-e7ed-4b08-bce9-d7df10f8c9a0</value> + <null /> + <null /> + <null /> + <null /> + <null /> + <null /> + <value>50</value> + </row> + <row> + <value>be956031-6be2-43d6-bb90-5191c8253315</value> + <value>2</value> + <value>qos_cpu_b</value> + <value>desc</value> + <value>386bffd1-e7ed-4b08-bce9-d7df10f8c9a0</value> + <null /> + <null /> + <null /> + <null /> + <null /> + <null /> + <value>50</value> + </row> + <row> + <value>be956031-6be2-43d6-bb90-5191c8253316</value> + <value>2</value> + <value>qos_cpu_c</value> + <value>desc</value> + <value>72b9e200-f48b-4687-83f2-62828f249a47</value> + <null /> + <null /> + <null /> + <null /> + <null /> + <null /> + <value>50</value> + </row> + <row> + <value>aa31682e-6ae7-4f9d-8c6f-04c93acca9db</value> + <value>2</value> + <value>qos_cpu_d</value> + <value>desc</value> + <null /> + <null /> + <null /> + <null /> + <null /> + <null /> + <null /> + <value>50</value> </row> </table> diff --git a/packaging/dbscripts/qos_sp.sql b/packaging/dbscripts/qos_sp.sql index 77385b0..37b972d 100644 --- a/packaging/dbscripts/qos_sp.sql +++ b/packaging/dbscripts/qos_sp.sql @@ -12,12 +12,13 @@ v_max_write_throughput INTEGER, v_max_iops INTEGER, v_max_read_iops INTEGER, - v_max_write_iops INTEGER) + v_max_write_iops INTEGER), + v_cpu_limit INTEGER) RETURNS VOID AS $procedure$ BEGIN -INSERT INTO qos(id, qos_type, name, description, storage_pool_id, max_throughput, max_read_throughput, max_write_throughput, max_iops, max_read_iops, max_write_iops) - VALUES(v_id, v_qos_type, v_name, v_description, v_storage_pool_id, v_max_throughput, v_max_read_throughput, v_max_write_throughput, v_max_iops, v_max_read_iops, v_max_write_iops); +INSERT INTO qos(id, qos_type, name, description, storage_pool_id, max_throughput, max_read_throughput, max_write_throughput, max_iops, max_read_iops, max_write_iops, cpu_limit) + VALUES(v_id, v_qos_type, v_name, v_description, v_storage_pool_id, v_max_throughput, v_max_read_throughput, v_max_write_throughput, v_max_iops, v_max_read_iops, v_max_write_iops, v_cpu_limit); END; $procedure$ LANGUAGE plpgsql; @@ -31,13 +32,14 @@ v_max_write_throughput INTEGER, v_max_iops INTEGER, v_max_read_iops INTEGER, - v_max_write_iops INTEGER) + v_max_write_iops INTEGER), + v_cpu_limit INTEGER) RETURNS VOID AS $procedure$ BEGIN UPDATE qos SET qos_type = v_qos_type, name = v_name, description = v_description, storage_pool_id = v_storage_pool_id, max_throughput = v_max_throughput, max_read_throughput = v_max_read_throughput, - max_write_throughput = v_max_write_throughput, max_iops = v_max_iops, max_read_iops = v_max_read_iops, max_write_iops = v_max_write_iops, + max_write_throughput = v_max_write_throughput, max_iops = v_max_iops, max_read_iops = v_max_read_iops, max_write_iops = v_max_write_iops, cpu_limit = v_cpu_limit, _update_date = LOCALTIMESTAMP WHERE id = v_id; END; $procedure$ diff --git a/packaging/dbscripts/upgrade/03_05_0430_add_cpu_limit_to_qos.sql b/packaging/dbscripts/upgrade/03_05_0430_add_cpu_limit_to_qos.sql new file mode 100644 index 0000000..f876e28 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_0430_add_cpu_limit_to_qos.sql @@ -0,0 +1 @@ +select fn_db_add_column('qos', 'cpu_limit', 'smallint default null'); diff --git a/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql b/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql index a1e2410..93286d1 100644 --- a/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql +++ b/packaging/dbscripts/upgrade/pre_upgrade/0000_config.sql @@ -212,6 +212,10 @@ select fn_db_add_config_value('StorageQosSupported','false','3.1'); select fn_db_add_config_value('StorageQosSupported','false','3.3'); select fn_db_add_config_value('StorageQosSupported','false','3.4'); +select fn_db_add_config_value('CpuQosSupported','false','3.0'); +select fn_db_add_config_value('CpuQosSupported','false','3.1'); +select fn_db_add_config_value('CpuQosSupported','false','3.3'); +select fn_db_add_config_value('CpuQosSupported','false','3.4'); select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.0'); select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.1'); select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.2'); -- To view, visit http://gerrit.ovirt.org/27686 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I533bcc601ac44289c51f5d56a6da0dd2455116d6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Kobi Ianko <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
