Shubhendu Tripathi has uploaded a new change for review. Change subject: core: Added the table vds_deloy_config ......................................................................
core: Added the table vds_deloy_config Added the table to store the deploy configuration details which could be used during hots deploy. Change-Id: Ifc58b36dccfd23165dd5b0dfb7c2c86cf261f488 Signed-off-by: Shubhendu Tripathi <[email protected]> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDeployConfig.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/VdsDeployConfigDAO.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAODbFacadeImpl.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/VdsDeployConfigDAOTest.java M backend/manager/modules/dal/src/test/resources/fixtures.xml A packaging/dbscripts/upgrade/03_05_0330_create_vds_deploy_config_table.sql A packaging/dbscripts/vds_deploy_config_sp.sql 9 files changed, 441 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/27028/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDeployConfig.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDeployConfig.java new file mode 100644 index 0000000..c9c9705 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDeployConfig.java @@ -0,0 +1,61 @@ +package org.ovirt.engine.core.common.businessentities; + +import org.ovirt.engine.core.common.utils.ObjectUtils; + +public class VdsDeployConfig extends IVdcQueryable { + private static final long serialVersionUID = 3185087852755356867L; + private int configId; + private String configName; + private String configType; + private String configValue; + + public int getConfigId() { + return this.configId; + } + public void setConfigId(int id) { + this.configId = id; + } + public String getConfigName() { + return configName; + } + public void setConfigName(String configName) { + this.configName = configName; + } + public String getConfigType() { + return configType; + } + public void setConfigType(String configType) { + this.configType = configType; + } + public String getConfigValue() { + return configValue; + } + public void setConfigValue(String configValue) { + this.configValue = configValue; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((configName == null) ? 0 : configName.hashCode()); + result = prime * result + ((configValue == null) ? 0 : configValue.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + VdsDeployConfig other = (VdsDeployConfig) obj; + return (ObjectUtils.objectsEqual(configName, other.configName) + && ObjectUtils.objectsEqual(configValue, other.configValue)); + } +} 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 b8d519e..8688cff 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 @@ -88,6 +88,7 @@ import org.ovirt.engine.core.dao.TagDAO; import org.ovirt.engine.core.dao.VdcOptionDAO; import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.VdsDeployConfigDAO; import org.ovirt.engine.core.dao.VdsDynamicDAO; import org.ovirt.engine.core.dao.VdsGroupDAO; import org.ovirt.engine.core.dao.VdsSpmIdMapDAO; @@ -983,6 +984,15 @@ } /** + * Returns the singleton instance of {@link VdsDeployConfigDAO} + * + * @return the dao instance + */ + public VdsDeployConfigDAO getVdsDeployConfigDao() { + return getDao(VdsDeployConfigDAO.class); + } + + /** * This call will populate a translation table of OS Ids to they're name * The translation table shall be in use by DWH * diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAO.java new file mode 100644 index 0000000..5b6452c --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAO.java @@ -0,0 +1,59 @@ +package org.ovirt.engine.core.dao; + +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.VdsDeployConfig; + +public interface VdsDeployConfigDAO extends DAO { + /** + * Retrieves the configuration with the specified id. + * + * @param id + * the cfg id + * @return the option + */ + VdsDeployConfig get(int id); + + /** + * Retrieves the configuration with the specified name + * and type + * + * @param cfgName + * the configuration name + * @param cfgTYpe + * the type + * @return the configuration + */ + VdsDeployConfig getByNameAndType(String cfgName, String cfgTYpe); + + /** + * Retrieves all configurations + * + * @return the list of configurations + */ + List<VdsDeployConfig> getAll(); + + /** + * Saves the supplied configuration + * + * @param cfg + * the configuration + */ + void save(VdsDeployConfig cfg); + + /** + * Updates the specified configuration + * + * @param cfg + * the configuration + */ + void update(VdsDeployConfig cfg); + + /** + * Removes the configuration with the specified id. + * + * @param id + * the configuration + */ + void remove(int id); +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAODbFacadeImpl.java new file mode 100644 index 0000000..4a61a1d --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDeployConfigDAODbFacadeImpl.java @@ -0,0 +1,80 @@ +package org.ovirt.engine.core.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.VdsDeployConfig; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; + +public class VdsDeployConfigDAODbFacadeImpl extends BaseDAODbFacade implements VdsDeployConfigDAO { + private static final class VdsDeployConfigRowMapper implements RowMapper<VdsDeployConfig> { + public static final VdsDeployConfigRowMapper instance = new VdsDeployConfigRowMapper(); + + @Override + public VdsDeployConfig mapRow(ResultSet rs, int rowNum) + throws SQLException { + VdsDeployConfig entity = new VdsDeployConfig(); + entity.setConfigId(rs.getInt("cfg_id")); + entity.setConfigName(rs.getString("cfg_name")); + entity.setConfigType(rs.getString("cfg_type")); + entity.setConfigValue(rs.getString("cfg_value")); + return entity; + } + } + + @Override + public VdsDeployConfig get(int id) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("cfg_id", id); + + return getCallsHandler().executeRead("GetVdsDeployConfigById", VdsDeployConfigRowMapper.instance, parameterSource); + } + + @Override + public VdsDeployConfig getByNameAndType(String name, String type) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("cfg_name", name).addValue("cfg_type", type); + + return getCallsHandler().executeRead("GetVdsDeployConfigByNameAndType", VdsDeployConfigRowMapper.instance, parameterSource); + } + + @SuppressWarnings("unchecked") + @Override + public List<VdsDeployConfig> getAll() { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource(); + + return getCallsHandler().executeReadList("GetAllFromVdsDeployConfig", VdsDeployConfigRowMapper.instance, parameterSource); + } + + @Override + public void save(VdsDeployConfig cfg) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("cfg_name", cfg.getConfigName()) + .addValue("cfg_type", cfg.getConfigType()) + .addValue("cfg_value", cfg.getConfigValue()) + .addValue("cfg_id", cfg.getConfigId()); + + getCallsHandler().executeModification("InsertVdsDeployConfig", parameterSource); + } + + @Override + public void update(VdsDeployConfig cfg) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("cfg_name", cfg.getConfigName()) + .addValue("cfg_type", cfg.getConfigType()) + .addValue("cfg_value", cfg.getConfigValue()) + .addValue("cfg_id", cfg.getConfigId()); + + getCallsHandler().executeModification("UpdateVdsDeplotConfig", parameterSource); + } + + @Override + public void remove(int id) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("cfg_id", id); + + getCallsHandler().executeModification("DeleteVdsDeployConfig", parameterSource); + } +} 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 19273d7..b743bbc 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 @@ -5,6 +5,7 @@ VdsDynamicDAO=org.ovirt.engine.core.dao.VdsDynamicDAODbFacadeImpl VdsStatisticsDAO=org.ovirt.engine.core.dao.VdsStatisticsDAODbFacadeImpl VdsSpmIdMapDAO=org.ovirt.engine.core.dao.VdsSpmIdMapDAODbFacadeImpl +VdsDeployConfigDAO=org.ovirt.engine.core.dao.VdsDeployConfigDAODbFacadeImpl AuditLogDAO=org.ovirt.engine.core.dao.AuditLogDAODbFacadeImpl InterfaceDao=org.ovirt.engine.core.dao.network.InterfaceDaoDbFacadeImpl VmNetworkInterfaceDao=org.ovirt.engine.core.dao.network.VmNetworkInterfaceDaoDbFacadeImpl diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsDeployConfigDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsDeployConfigDAOTest.java new file mode 100644 index 0000000..7109e3d --- /dev/null +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsDeployConfigDAOTest.java @@ -0,0 +1,115 @@ +package org.ovirt.engine.core.dao; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.List; + +import org.junit.Test; +import org.ovirt.engine.core.common.businessentities.VdsDeployConfig; + +public class VdsDeployConfigDAOTest extends BaseDAOTestCase { + private VdsDeployConfigDAO dao; + private VdsDeployConfig newConfig1; + private VdsDeployConfig oldConfig1; + private VdsDeployConfig newConfig2; + private VdsDeployConfig oldConfig2; + + @Override + public void setUp() throws Exception { + super.setUp(); + + dao = dbFacade.getVdsDeployConfigDao(); + + oldConfig1 = dao.getByNameAndType("monitoring_enabled", "boolean"); + oldConfig2 = dao.getByNameAndType("monitoring_srvr_ip", "string"); + + newConfig1 = new VdsDeployConfig(); + newConfig1.setConfigId(1); + newConfig1.setConfigName("monitoring_enabled"); + newConfig1.setConfigType("boolean"); + newConfig1.setConfigValue("true"); + + newConfig2 = new VdsDeployConfig(); + newConfig2.setConfigId(2); + newConfig2.setConfigName("monitoring_srvr_ip"); + newConfig2.setConfigType("string"); + newConfig2.setConfigValue("127.0.0.1"); + } + + @Test + public void testGetWithInvalidId() { + VdsDeployConfig cfg = dao.get(123); + assertNull(cfg); + } + + @Test + public void testGet() { + VdsDeployConfig cfg = dao.get(1); + assertNotNull(cfg); + assertEquals(cfg, oldConfig1); + } + + @Test + public void testGetWithNameAndTypeWithInvalidName() { + VdsDeployConfig cfg = dao.getByNameAndType("XYZ", "string"); + assertNull(cfg); + } + + @Test + public void testGetWithNameAndTypeWithInvalidType() { + VdsDeployConfig cfg = dao.getByNameAndType("monitoring_enabled", "number"); + assertNull(cfg); + } + + @Test + public void testGetByNameAndType() { + VdsDeployConfig cfg = dao.getByNameAndType("monitoring_srvr_ip", "string"); + assertNotNull(cfg); + assertEquals(cfg, oldConfig2); + } + + @Test + public void testGetAll() { + List<VdsDeployConfig> cfgList = dao.getAll(); + assertNotNull(cfgList); + assertFalse(cfgList.isEmpty()); + assertEquals(2, cfgList.size()); + } + + @Test + public void testSave() { + VdsDeployConfig newCfg = new VdsDeployConfig(); + newCfg.setConfigId(3); + newCfg.setConfigName("config"); + newCfg.setConfigType("string"); + newCfg.setConfigValue("config_value"); + + dao.save(newCfg); + + VdsDeployConfig result = dao.getByNameAndType("config", "string"); + assertNotNull(result); + assertEquals(result, newCfg); + } + + @Test + public void testUpdate() { + oldConfig1.setConfigValue("false"); + + dao.update(oldConfig1); + + VdsDeployConfig result = dao.getByNameAndType("monitoring_enabled", "boolean"); + + assertEquals(oldConfig1, result); + } + + @Test + public void testRemove() { + dao.remove(2); + + VdsDeployConfig cfg = dao.get(2); + assertNull(cfg); + } +} diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml b/backend/manager/modules/dal/src/test/resources/fixtures.xml index 26f53e8..7526df2 100644 --- a/backend/manager/modules/dal/src/test/resources/fixtures.xml +++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml @@ -6086,6 +6086,25 @@ <value>2012-12-31 11:54:27</value> </row> </table> + + <table name="vds_deploy_config"> + <column>cfg_id</column> + <column>cfg_name</column> + <column>cfg_type</column> + <column>cfg_value</column> + <row> + <value>1</value> + <value>monitoring_enabled</value> + <value>boolean</value> + <value>true</value> + </row> + <row> + <value>2</value> + <value>monitoring_srvr_ip</value> + <value>string</value> + <value>127.0.0.1</value> + </row> + </table> <table name="affinity_groups"> <column>id</column> diff --git a/packaging/dbscripts/upgrade/03_05_0330_create_vds_deploy_config_table.sql b/packaging/dbscripts/upgrade/03_05_0330_create_vds_deploy_config_table.sql new file mode 100644 index 0000000..9facd20 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_0330_create_vds_deploy_config_table.sql @@ -0,0 +1,13 @@ +-- create vds_deploy_config table +CREATE SEQUENCE vds_deploy_config_seq INCREMENT BY 1 START WITH 1; +CREATE TABLE vds_deploy_config +( + cfg_id integer DEFAULT nextval('vds_deploy_config_seq'::regclass) NOT NULL, + cfg_name VARCHAR(128) NOT NULL, + cfg_type VARCHAR(32) NOT NULL, + cfg_value VARCHAR(4000) NOT NULL +); + +-- create index for cfg_name +CREATE INDEX IDX_vds_deploy_config_cfg_name ON vds_deploy_config(cfg_name); + diff --git a/packaging/dbscripts/vds_deploy_config_sp.sql b/packaging/dbscripts/vds_deploy_config_sp.sql new file mode 100644 index 0000000..4110f2e --- /dev/null +++ b/packaging/dbscripts/vds_deploy_config_sp.sql @@ -0,0 +1,83 @@ +Create or replace FUNCTION InsertVdsDeployConfig(v_cfg_name VARCHAR(50), + v_cfg_type VARCHAR(30), + v_cfg_value VARCHAR(50), + INOUT v_cfg_id INTEGER) + AS $procedure$ +BEGIN +INSERT INTO vds_deploy_config(cfg_name, cfg_type, cfg_value) + VALUES(v_cfg_name, v_cfg_type, v_cfg_value); + + v_cfg_id := CURRVAL('vds_deploy_config_seq'); +END; $procedure$ +LANGUAGE plpgsql; + + + + + + Create or replace FUNCTION UpdateVdsDeplotConfig(v_cfg_name VARCHAR(50), + v_cfg_type VARCHAR(30), + v_cfg_value VARCHAR(50), + v_cfg_id INTEGER) + RETURNS VOID + AS $procedure$ + BEGIN + UPDATE vds_deploy_config + SET cfg_name = v_cfg_name, cfg_type = v_cfg_type, cfg_value = v_cfg_value + WHERE cfg_id = v_cfg_id; + END; $procedure$ + LANGUAGE plpgsql; + + + + + + Create or replace FUNCTION DeleteVdsDeployConfig(v_cfg_id INTEGER) + RETURNS VOID + AS $procedure$ + BEGIN + DELETE FROM vds_deploy_config + WHERE cfg_id = v_cfg_id; + END; $procedure$ + LANGUAGE plpgsql; + + + + + + Create or replace FUNCTION GetAllFromVdsDeployConfig() RETURNS SETOF vds_deploy_config STABLE + AS $procedure$ + BEGIN + RETURN QUERY SELECT vds_deploy_config.* + FROM vds_deploy_config; + END; $procedure$ + LANGUAGE plpgsql; + + + + + + Create or replace FUNCTION GetVdsDeployConfigById(v_cfg_id INTEGER) RETURNS SETOF vds_deploy_config STABLE + AS $procedure$ + BEGIN + RETURN QUERY SELECT vds_deploy_config.* + FROM vds_deploy_config + WHERE cfg_id = v_cfg_id; + END; $procedure$ + LANGUAGE plpgsql; + + + + + + Create or replace FUNCTION GetVdsDeployConfigByNameAndType(v_cfg_name VARCHAR(50), v_cfg_type VARCHAR(30)) RETURNS SETOF vds_deploy_config STABLE + AS $procedure$ + BEGIN + RETURN QUERY SELECT vds_deploy_config.* + FROM vds_deploy_config + WHERE cfg_name = v_cfg_name and cfg_type = v_cfg_type; + END; $procedure$ + LANGUAGE plpgsql; + + + -- To view, visit http://gerrit.ovirt.org/27028 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifc58b36dccfd23165dd5b0dfb7c2c86cf261f488 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shubhendu Tripathi <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
