Martin Peřina has uploaded a new change for review.

Change subject: core: Adds entity DwhHistoryTimekeeping and variable heartBeat
......................................................................

core: Adds entity DwhHistoryTimekeeping and variable heartBeat

Adds store procedures to access dwh_history_timekeeping table.
Adds business entity DwhShistoryTimekeeping and its DAO.
Adds new variable 'heartBeat' to dwh_history_timekeeping table

Change-Id: Ib4f41ed69d77f006ce406f09d20b259ed3335ff9
Bug-Url: https://bugzilla.redhat.com/962177
Signed-off-by: Martin Perina <mper...@redhat.com>
---
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeeping.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeepingVariable.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/dwh/DwhHistoryTimekeepingDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDaoDbFacadeImpl.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/dwh/DwhHistoryTimekeepingDaoTest.java
A packaging/dbscripts/dwh_history_timekeeping_sp.sql
A packaging/dbscripts/upgrade/03_03_0930_add_dwh_heartbeat.sql
9 files changed, 296 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/19827/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeeping.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeeping.java
new file mode 100644
index 0000000..c5e4848
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeeping.java
@@ -0,0 +1,76 @@
+package org.ovirt.engine.core.common.businessentities;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * Represents variable in {@code dwh_history_timekeeping} table
+ */
+public class DwhHistoryTimekeeping implements Serializable {
+    private static final long serialVersionUID = -6971859290406886614L;
+
+    /**
+     * Variable
+     */
+    private DwhHistoryTimekeepingVariable variable;
+
+    /**
+     * Variable value
+     */
+    private String value;
+
+    /**
+     * Variable timestamp
+     */
+    private Date dateTime;
+
+    public DwhHistoryTimekeeping() {
+        variable = DwhHistoryTimekeepingVariable.UNDEFINED;
+        value = null;
+        dateTime = null;
+    }
+
+    public DwhHistoryTimekeepingVariable getVariable() {
+        return variable;
+    }
+
+    public void setVariable(DwhHistoryTimekeepingVariable variable) {
+        if (variable == null) {
+            this.variable = DwhHistoryTimekeepingVariable.UNDEFINED;
+        } else {
+            this.variable = variable;
+        }
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public Date getDateTime() {
+        return dateTime;
+    }
+
+    public void setDateTime(Date datetTime) {
+        this.dateTime = datetTime;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof DwhHistoryTimekeeping)) {
+            return false;
+        }
+        return variable == ((DwhHistoryTimekeeping)obj).getVariable();
+    }
+
+    @Override
+    public int hashCode() {
+        return variable.hashCode();
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeepingVariable.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeepingVariable.java
new file mode 100644
index 0000000..15a3857
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DwhHistoryTimekeepingVariable.java
@@ -0,0 +1,56 @@
+package org.ovirt.engine.core.common.businessentities;
+
+/**
+ * Variables, that exists in {@code dwh_history_timekeeping} table
+ */
+public enum DwhHistoryTimekeepingVariable {
+    LAST_SYNC("lastSync"),
+
+    LAST_FULL_HOST_CHECK("lastFullHostCheck"),
+
+    LAST_OS_INFO_UPDATE("lastOsinfoUpdate"),
+
+    /**
+     * This variable is used to tell DWH that engine is alive
+     */
+    HEART_BEAT("heartBeat"),
+
+    /**
+     * Nonexistent variable, used to fix {@code null} problems
+     */
+    UNDEFINED(null);
+
+    /**
+     * Name of the variable in {@code dwh_history_timekeeping} table
+     */
+    private String varName;
+
+    private DwhHistoryTimekeepingVariable(String varName) {
+        this.varName = varName;
+    }
+
+    public String getVarName() {
+        return varName;
+    }
+
+    /**
+     * Creates an enum instance for specified variable name
+     *
+     * @param varName
+     *            specified variable name
+     * @return enum instance of {@code null} if specified variable is invalid
+     */
+    public static DwhHistoryTimekeepingVariable forVarName(String varName) {
+        DwhHistoryTimekeepingVariable result = UNDEFINED;
+
+        if (varName != null) {
+            for (DwhHistoryTimekeepingVariable var : 
DwhHistoryTimekeepingVariable.values()) {
+                if (var.getVarName().equals(varName)) {
+                    result = var;
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+}
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 f5a5e28..eb9c599 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
@@ -13,6 +13,7 @@
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
+import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping;
 import org.ovirt.engine.core.common.businessentities.Image;
 import org.ovirt.engine.core.common.businessentities.Provider;
 import org.ovirt.engine.core.common.businessentities.Role;
@@ -97,6 +98,7 @@
 import org.ovirt.engine.core.dao.VmStaticDAO;
 import org.ovirt.engine.core.dao.VmStatisticsDAO;
 import org.ovirt.engine.core.dao.VmTemplateDAO;
+import org.ovirt.engine.core.dao.dwh.DwhHistoryTimekeepingDao;
 import org.ovirt.engine.core.dao.gluster.GlusterBrickDao;
 import org.ovirt.engine.core.dao.gluster.GlusterClusterServiceDao;
 import org.ovirt.engine.core.dao.gluster.GlusterHooksDao;
@@ -166,6 +168,7 @@
             put(Step.class, StepDao.class);
             put(VnicProfile.class, VnicProfileDao.class);
             put(VnicProfileView.class, VnicProfileDao.class);
+            put(DwhHistoryTimekeeping.class, DwhHistoryTimekeepingDao.class);
         }
     };
 
@@ -959,6 +962,16 @@
         return getDao(VmNicDao.class);
     }
 
+
+    /**
+     * Returns the singleton instance of {@link DwhHistoryTimekeepingDAO}.
+     *
+     * @return the dao instance
+     */
+    public DwhHistoryTimekeepingDao getDwhHistoryTimekeepingDao() {
+        return getDao(DwhHistoryTimekeepingDao.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/dwh/DwhHistoryTimekeepingDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDao.java
new file mode 100644
index 0000000..c6e07a1
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDao.java
@@ -0,0 +1,24 @@
+package org.ovirt.engine.core.dao.dwh;
+
+import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping;
+import 
org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeepingVariable;
+import org.ovirt.engine.core.dao.DAO;
+
+public interface DwhHistoryTimekeepingDao extends DAO {
+    /**
+     * Retrieves content of the specified variable
+     *
+     * @param variable
+     *            specified variable
+     * @return content of the specified variable
+     */
+    DwhHistoryTimekeeping get(DwhHistoryTimekeepingVariable variable);
+
+    /**
+     * Saves content of the specified variable
+     *
+     * @param variable
+     *            specified variable
+     */
+    void save(DwhHistoryTimekeeping variable);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDaoDbFacadeImpl.java
new file mode 100644
index 0000000..27c6bc3
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDaoDbFacadeImpl.java
@@ -0,0 +1,41 @@
+package org.ovirt.engine.core.dao.dwh;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping;
+import 
org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeepingVariable;
+import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils;
+import org.ovirt.engine.core.dao.BaseDAODbFacade;
+import org.springframework.jdbc.core.RowMapper;
+
+public class DwhHistoryTimekeepingDaoDbFacadeImpl extends BaseDAODbFacade 
implements DwhHistoryTimekeepingDao {
+    private static class DwhHistoryTimekeepingMapper implements 
RowMapper<DwhHistoryTimekeeping> {
+        private static final DwhHistoryTimekeepingMapper instance = new 
DwhHistoryTimekeepingMapper();
+
+        @Override
+        public DwhHistoryTimekeeping mapRow(ResultSet rs, int rowNum) throws 
SQLException {
+            DwhHistoryTimekeeping entity = new DwhHistoryTimekeeping();
+            
entity.setVariable(DwhHistoryTimekeepingVariable.forVarName(rs.getString("var_name")));
+            entity.setValue(rs.getString("var_value"));
+            
entity.setDateTime(DbFacadeUtils.fromDate(rs.getTimestamp("var_datetime")));
+            return entity;
+        }
+    }
+
+    @Override
+    public DwhHistoryTimekeeping get(DwhHistoryTimekeepingVariable variable) {
+        return 
getCallsHandler().executeRead("GetDwhHistoryTimekeepingByVarName",
+                DwhHistoryTimekeepingMapper.instance,
+                getCustomMapSqlParameterSource()
+                        .addValue("var_name", variable.getVarName()));
+    }
+
+    @Override
+    public void save(DwhHistoryTimekeeping variable) {
+        getCallsHandler().executeModification("UpdateDwhHistoryTimekeeping", 
getCustomMapSqlParameterSource()
+                .addValue("var_name", variable.getVariable().getVarName())
+                .addValue("var_value", variable.getValue())
+                .addValue("var_datetime", variable.getDateTime()));
+    }
+}
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 351b430..128e8ee 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
@@ -69,3 +69,4 @@
 NetworkQoSDao=org.ovirt.engine.core.dao.network.NetworkQoSDaoFacadeImpl
 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/dwh/DwhHistoryTimekeepingDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDaoTest.java
new file mode 100644
index 0000000..e47bb47
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/dwh/DwhHistoryTimekeepingDaoTest.java
@@ -0,0 +1,59 @@
+package org.ovirt.engine.core.dao.dwh;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.Date;
+
+import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping;
+import 
org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeepingVariable;
+import org.ovirt.engine.core.dao.BaseDAOTestCase;
+
+/**
+ * {@link DwhHistoryTimekeepingDao} tests
+ */
+public class DwhHistoryTimekeepingDaoTest extends BaseDAOTestCase {
+    /**
+     * Tests reading existing variables
+     */
+    @Test
+    public void getAllExistingVariables() {
+        for (DwhHistoryTimekeepingVariable var: 
DwhHistoryTimekeepingVariable.values()) {
+            if (var != DwhHistoryTimekeepingVariable.UNDEFINED) {
+                assertNotNull(dbFacade.getDwhHistoryTimekeepingDao().get(var));
+            }
+        }
+    }
+
+    /**
+     * Tests reading nonexistent variable
+     */
+    @Test
+    public void getNonexistentVariable() {
+        
assertNull(dbFacade.getDwhHistoryTimekeepingDao().get(DwhHistoryTimekeepingVariable.UNDEFINED));
+    }
+
+    /**
+     * Tests saving variable
+     */
+    @Test
+    public void testSave() {
+        DwhHistoryTimekeeping var = new DwhHistoryTimekeeping();
+        var.setVariable(DwhHistoryTimekeepingVariable.HEART_BEAT);
+        var.setValue(null);
+        var.setDateTime(new Date());
+
+        DwhHistoryTimekeepingDao dao = dbFacade.getDwhHistoryTimekeepingDao();
+
+        dao.save(var);
+
+        DwhHistoryTimekeeping found = dao.get(var.getVariable());
+
+        assertNotNull(found);
+        assertEquals(var.getVariable(), found.getVariable());
+        assertEquals(var.getValue(), found.getValue());
+        assertEquals(var.getDateTime(), found.getDateTime());
+    }
+}
diff --git a/packaging/dbscripts/dwh_history_timekeeping_sp.sql 
b/packaging/dbscripts/dwh_history_timekeeping_sp.sql
new file mode 100644
index 0000000..00eb9ef
--- /dev/null
+++ b/packaging/dbscripts/dwh_history_timekeeping_sp.sql
@@ -0,0 +1,25 @@
+----------------------------------------------------------------
+-- [dwh_history_timekeeping] Table
+----------------------------------------------------------------
+Create or replace FUNCTION UpdateDwhHistoryTimekeeping(v_var_name VARCHAR(50),
+    v_var_value VARCHAR(255),
+    v_var_datetime TIMESTAMP WITH TIME ZONE)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+      UPDATE dwh_history_timekeeping
+      SET var_value = v_var_value,
+          var_datetime = v_var_datetime
+      WHERE var_name = v_var_name;
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION GetDwhHistoryTimekeepingByVarName(v_var_name 
VARCHAR(50))
+RETURNS SETOF dwh_history_timekeeping STABLE
+   AS $procedure$
+BEGIN
+   RETURN QUERY SELECT *
+   FROM dwh_history_timekeeping
+   WHERE var_name = v_var_name;
+END; $procedure$
+LANGUAGE plpgsql;
diff --git a/packaging/dbscripts/upgrade/03_03_0930_add_dwh_heartbeat.sql 
b/packaging/dbscripts/upgrade/03_03_0930_add_dwh_heartbeat.sql
new file mode 100644
index 0000000..6ae8c10
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_03_0930_add_dwh_heartbeat.sql
@@ -0,0 +1 @@
+INSERT INTO dwh_history_timekeeping VALUES('heartBeat', NULL, 
to_timestamp('01/01/2000', 'DD/MM/YYYY'));


-- 
To view, visit http://gerrit.ovirt.org/19827
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4f41ed69d77f006ce406f09d20b259ed3335ff9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Martin Peřina <mper...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to