Liran Zelkha has uploaded a new change for review.

Change subject: Seperation of VDS load. Create TimeToLiveManager and remove 
TimeToLiveInCache annotation
......................................................................

Seperation of VDS load. Create TimeToLiveManager and remove TimeToLiveInCache 
annotation

Change-Id: I08d5bee0835d00f525a02ba31e0fa5852303497b
Signed-off-by: Liran Zelkha <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StoragePool.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
M 
backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/Guid.java
D 
backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/cache/TimeToLiveInCache.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheableJdbcTemplate.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
A 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerEntityTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerTest.java
16 files changed, 207 insertions(+), 110 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/14369/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StoragePool.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StoragePool.java
index 9175f35..3343dde 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StoragePool.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StoragePool.java
@@ -11,9 +11,7 @@
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
 import org.ovirt.engine.core.compat.Version;
-
 public class StoragePool extends IVdcQueryable implements BusinessEntity<Guid> 
{
-public class storage_pool extends IVdcQueryable implements 
BusinessEntity<Guid> {
     private static final long serialVersionUID = 6162262095329980112L;
 
     private Guid id = new Guid();
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
index abd6d97..488429f 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
@@ -180,6 +180,7 @@
     }
 
     public VDS(VdsStatic vdsStatic, VdsDynamic vdsDynamic, VdsStatistics 
vdsStatistics) {
+        this();
         this.mVdsStatic = vdsStatic;
         this.mVdsDynamic = vdsDynamic;
         this.mVdsStatistics = vdsStatistics;
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java
index 7e66c19..49a8272 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java
@@ -12,9 +12,7 @@
 import org.ovirt.engine.core.compat.StringFormat;
 import org.ovirt.engine.core.compat.StringHelper;
 import org.ovirt.engine.core.compat.Version;
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
 
-@TimeToLiveInCache(30)
 public class VdsDynamic implements BusinessEntity<Guid> {
     private static final long serialVersionUID = -6010035855157006935L;
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
index bcbb7e8..b8ecffd 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
@@ -19,9 +19,7 @@
 import org.ovirt.engine.core.common.validation.group.PowerManagementCheck;
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
 
-@TimeToLiveInCache(3000)
 public class VdsStatic implements BusinessEntity<Guid> {
 
     private static final long serialVersionUID = -1425566208615075937L;
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java
index 5436d7c..88f1544 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDynamic.java
@@ -7,9 +7,7 @@
 import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
 
-@TimeToLiveInCache(30)
 public class VmDynamic implements BusinessEntity<Guid>, Comparable<VmDynamic> {
     private static final long serialVersionUID = 7789482445091432555L;
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
index 92e6929..095cf5b 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
@@ -10,9 +10,7 @@
 import org.ovirt.engine.core.common.validation.group.ImportClonedEntity;
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
 
-@TimeToLiveInCache(3000)
 public class VmStatic extends VmBase {
     private static final long serialVersionUID = -2753306386502558044L;
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
index 60c562f..54dd08a 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
@@ -6,6 +6,7 @@
 import javax.validation.constraints.Size;
 
 import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
+import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.utils.ValidationUtils;
 import 
org.ovirt.engine.core.common.validation.annotation.ValidNetworkConfiguration;
 import org.ovirt.engine.core.compat.NGuid;
diff --git 
a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/Guid.java
 
b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/Guid.java
index 573c287..432345b 100644
--- 
a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/Guid.java
+++ 
b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/Guid.java
@@ -2,10 +2,7 @@
 
 import java.util.UUID;
 
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
-
 // This is a wrapper for a java.util.UUID
-@TimeToLiveInCache(3000)
 public class Guid extends NGuid {
     public static final Guid SYSTEM = new 
Guid("AAA00000-0000-0000-0000-123456789AAA");
     public static final Guid EVERYONE = new 
Guid("EEE00000-0000-0000-0000-123456789EEE");
diff --git 
a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/cache/TimeToLiveInCache.java
 
b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/cache/TimeToLiveInCache.java
deleted file mode 100644
index 5b271de..0000000
--- 
a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/cache/TimeToLiveInCache.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.ovirt.engine.core.compat.cache;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-
-public @interface TimeToLiveInCache {
-    int value();
-
-}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java
index add4067..aedc745 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java
@@ -6,7 +6,6 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
@@ -14,7 +13,7 @@
 public class CacheManager {
     private static final Log log = LogFactory
             .getLog(CacheableJdbcTemplate.class);
-    private static CacheManager instance = new CacheManager();
+    private final static CacheManager instance = new CacheManager();
 
     private Map<CacheKey, CacheItemWrapper> cache = new WeakHashMap<CacheKey, 
CacheItemWrapper>();
     private Map<Class, List<CacheKey>> typeToKeymapping = new 
WeakHashMap<Class, List<CacheKey>>();
@@ -59,15 +58,14 @@
         }
 
         // Check cache time vs object TimeToLiveInCache definition
-        TimeToLiveInCache ttlic = (TimeToLiveInCache) type
-                .getAnnotation(TimeToLiveInCache.class);
+        int timeToLiveInCache = 
TimeToLiveManager.getInstance().getTimeToLive(type); 
 
         // Calculate how long this object has been in cache
         long currentTime = System.currentTimeMillis();
         long diff = (currentTime - wrapper.getCacheTime()) / 1000;
 
         // Default behavior when no annotation exists is to disable cache
-        if (ttlic == null || ttlic.value() < diff) {
+        if (timeToLiveInCache < diff) {
             if (log.isDebugEnabled())
                 log.debug("Query "
                         + sql
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheableJdbcTemplate.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheableJdbcTemplate.java
index bb5b944..bb011be 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheableJdbcTemplate.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheableJdbcTemplate.java
@@ -45,28 +45,45 @@
         return super.call(csc, declaredParameters);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public <T> T query(String sql, ResultSetExtractor<T> rse)
             throws DataAccessException {
 
-        // TODO Auto-generated method stub
-        return super.query(sql, rse);
+        T result;
+        result = (T) cacheManager.getFromCache(sql, null);
+
+        if (result == null) {
+            result = super.query(sql,rse);
+            cacheManager.putInCache(sql, null, result);
+        }
+        return result;
+
+//        return super.query(sql, rse);
     }
 
     @Override
     public void query(String sql, RowCallbackHandler rch)
             throws DataAccessException {
-        // TODO Auto-generated method stub
         super.query(sql, rch);
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public <T> List<T> query(String sql, RowMapper<T> rowMapper)
             throws DataAccessException {
-        // TODO Auto-generated method stub
-        return super.query(sql, rowMapper);
+        List<T> result;
+        
+        result = (List<T>) cacheManager.getFromCache(sql, null);
+
+        if (result == null) {
+            result = super.query(sql,rowMapper);
+            cacheManager.putInCache(sql, null, result);
+        }
+        return result;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public Map<String, Object> queryForMap(String sql)
             throws DataAccessException {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java
new file mode 100644
index 0000000..626e3c7
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java
@@ -0,0 +1,42 @@
+package org.ovirt.engine.core.dal.cache;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
+import org.ovirt.engine.core.common.businessentities.VdsDynamic;
+import org.ovirt.engine.core.common.businessentities.VdsStatic;
+import org.ovirt.engine.core.common.businessentities.VmDynamic;
+import org.ovirt.engine.core.common.businessentities.VmStatic;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+import org.ovirt.engine.core.compat.Guid;
+
+public class TimeToLiveManager {
+    private static TimeToLiveManager instance = new TimeToLiveManager();
+    private Map<String, Integer> timeToLive = new HashMap<String, Integer>();
+
+    private TimeToLiveManager() {
+        timeToLive.put(VdsDynamic.class.getName(), 30);
+        timeToLive.put(VdsStatic.class.getName(), 3000);
+        timeToLive.put(VDSGroup.class.getName(), 3000);
+        timeToLive.put(VmStatic.class.getName(), 3000);
+        timeToLive.put(VmDynamic.class.getName(), 30);
+        timeToLive.put(VmTemplate.class.getName(), 30);
+        timeToLive.put(VdsNetworkInterface.class.getName(), 3000);
+        timeToLive.put(Guid.class.getName(), 3000);
+
+    }
+
+    public static TimeToLiveManager getInstance() {
+        return instance;
+    }
+
+    public int getTimeToLive(Class<? extends Object> type) {
+        Integer duration = timeToLive.get(type.getName());
+        if (duration == null)
+            return -1;
+
+        return duration;
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
index c57f281..8081768 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
@@ -100,7 +100,6 @@
         return new CallCreator() {
             @Override
             public SimpleJdbcCall createCall() {
-//                return new 
SimpleJdbcCall(template).withProcedureName(procedureName);
                 return new 
CacheableJdbcCall(template).withProcedureName(procedureName);
             }
         };
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
index efd9ced..7bb3394 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
@@ -7,24 +7,34 @@
 
 import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VDSType;
+import org.ovirt.engine.core.common.businessentities.VdsDynamic;
 import org.ovirt.engine.core.common.businessentities.VdsSelectionAlgorithm;
 import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
+import org.ovirt.engine.core.common.businessentities.VdsStatic;
+import org.ovirt.engine.core.common.businessentities.VdsStatistics;
 import 
org.ovirt.engine.core.common.businessentities.VdsTransparentHugePagesState;
+import org.ovirt.engine.core.common.businessentities.storage_pool;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
 import org.ovirt.engine.core.compat.RpmVersion;
 import org.ovirt.engine.core.compat.Version;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils;
+import org.ovirt.engine.core.utils.log.Log;
+import org.ovirt.engine.core.utils.log.LogFactory;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
 /**
- * <code>VdsDAODbFacadeImpl</code> provides an implementation of {@code 
VdsDAO} that uses previously written code from
- * {@code DbFacade}.
+ * <code>VdsDAODbFacadeImpl</code> provides an implementation of {@code VdsDAO}
+ * that uses previously written code from {@code DbFacade}.
  */
 public class VdsDAODbFacadeImpl extends BaseDAODbFacade implements VdsDAO {
+
+    private static final Log log = LogFactory.getLog(VdsDAODbFacadeImpl.class);
 
     @Override
     public VDS get(NGuid id) {
@@ -33,25 +43,54 @@
 
     @Override
     public VDS get(NGuid id, Guid userID, boolean isFiltered) {
-        return getCallsHandler().executeRead("GetVdsByVdsId",
-                VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_id", id)
-                        .addValue("user_id", userID)
-                        .addValue("is_filtered", isFiltered));
+        VdsStaticDAO staticDao = DbFacade.getInstance().getVdsStaticDao();
+        VdsDynamicDAO dynamicDao = DbFacade.getInstance().getVdsDynamicDao();
+        VdsStatisticsDAO statisticsDao = DbFacade.getInstance()
+                .getVdsStatisticsDao();
+        VdsGroupDAO groupsDao = DbFacade.getInstance().getVdsGroupDao();
+        StoragePoolDAO storageDao = DbFacade.getInstance().getStoragePoolDao();
+
+        VdsStatic vdsStatic = staticDao.get(id.getValue());
+        VdsDynamic vdsDynamic = dynamicDao.get(id.getValue());
+        VdsStatistics vdsStatistics = statisticsDao.get(id.getValue());
+        VDSGroup vdsGroups = groupsDao.get(vdsStatic.getVdsGroupId());
+
+        VDS vds = new VDS(vdsStatic, vdsDynamic, vdsStatistics);
+        
+        vds.calculateFreeVirtualMemory();
+        vds.setVersion(vdsDynamic.getVersion());
+        vds.setVdsGroupCompatibilityVersion(vdsGroups
+                .getcompatibility_version());
+        vds.setVdsGroupCpuName(vdsGroups.getcpu_name());
+        vds.setVdsGroupDescription(vdsGroups.getdescription());
+        vds.setVdsGroupName(vdsGroups.getname());
+
+        storage_pool storage = storageDao.getForVds(vds.getId());
+
+        vds.setStoragePoolId(storage.getId());
+        vds.setStoragePoolName(storage.getname());
+
+        return vds;
+
+        // return getCallsHandler().executeRead("GetVdsByVdsId",
+        // VdsRowMapper.instance,
+        // getCustomMapSqlParameterSource()
+        // .addValue("vds_id", id)
+        // .addValue("user_id", userID)
+        // .addValue("is_filtered", isFiltered));
     }
 
     @Override
     public VDS getByName(String name) {
         return getCallsHandler().executeRead("GetVdsByName",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_name", name));
+                getCustomMapSqlParameterSource().addValue("vds_name", name));
     }
 
     @Override
     public List<VDS> getAllForHostname(String hostname) {
-        return getCallsHandler().executeReadList("GetVdsByHostName",
+        return getCallsHandler().executeReadList(
+                "GetVdsByHostName",
                 VdsRowMapper.instance,
                 getCustomMapSqlParameterSource()
                         .addValue("host_name", hostname));
@@ -61,16 +100,14 @@
     public List<VDS> getAllWithIpAddress(String address) {
         return getCallsHandler().executeReadList("GetVdsByIp",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("ip", address));
+                getCustomMapSqlParameterSource().addValue("ip", address));
     }
 
     @Override
     public List<VDS> getAllWithUniqueId(String id) {
         return getCallsHandler().executeReadList("GetVdsByUniqueID",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_unique_id", id));
+                getCustomMapSqlParameterSource().addValue("vds_unique_id", 
id));
     }
 
     @Override
@@ -86,16 +123,14 @@
     public List<VDS> getAllOfType(VDSType type) {
         return getCallsHandler().executeReadList("GetVdsByType",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_type", type));
+                getCustomMapSqlParameterSource().addValue("vds_type", type));
     }
 
     @Override
     public List<VDS> getAllForVdsGroupWithoutMigrating(Guid id) {
-        return 
getCallsHandler().executeReadList("GetVdsWithoutMigratingVmsByVdsGroupId",
-                VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_group_id", id));
+        return getCallsHandler().executeReadList(
+                "GetVdsWithoutMigratingVmsByVdsGroupId", VdsRowMapper.instance,
+                getCustomMapSqlParameterSource().addValue("vds_group_id", id));
     }
 
     @Override
@@ -110,9 +145,11 @@
 
     @Override
     public List<VDS> getAll(Guid userID, boolean isFiltered) {
-        return getCallsHandler().executeReadList("GetAllFromVds",
+        return getCallsHandler().executeReadList(
+                "GetAllFromVds",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource().addValue("user_id", 
userID).addValue("is_filtered", isFiltered));
+                getCustomMapSqlParameterSource().addValue("user_id", userID)
+                        .addValue("is_filtered", isFiltered));
     }
 
     @Override
@@ -121,8 +158,10 @@
     }
 
     @Override
-    public List<VDS> getAllForVdsGroup(Guid vdsGroupID, Guid userID, boolean 
isFiltered) {
-        return getCallsHandler().executeReadList("GetVdsByVdsGroupId",
+    public List<VDS> getAllForVdsGroup(Guid vdsGroupID, Guid userID,
+            boolean isFiltered) {
+        return getCallsHandler().executeReadList(
+                "GetVdsByVdsGroupId",
                 VdsRowMapper.instance,
                 getCustomMapSqlParameterSource()
                         .addValue("vds_group_id", vdsGroupID)
@@ -136,8 +175,10 @@
     }
 
     @Override
-    public List<VDS> getAllForStoragePool(Guid storagePool, Guid userID, 
boolean isFiltered) {
-        return getCallsHandler().executeReadList("GetVdsByStoragePoolId",
+    public List<VDS> getAllForStoragePool(Guid storagePool, Guid userID,
+            boolean isFiltered) {
+        return getCallsHandler().executeReadList(
+                "GetVdsByStoragePoolId",
                 VdsRowMapper.instance,
                 getCustomMapSqlParameterSource()
                         .addValue("storage_pool_id", storagePool)
@@ -146,33 +187,38 @@
     }
 
     @Override
-    public List<VDS> getAllForVdsGroupWithStatus(Guid vdsGroupId, VDSStatus 
status) {
-        return getCallsHandler().executeReadList("getVdsForVdsGroupWithStatus",
+    public List<VDS> getAllForVdsGroupWithStatus(Guid vdsGroupId,
+            VDSStatus status) {
+        return getCallsHandler().executeReadList(
+                "getVdsForVdsGroupWithStatus",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_group_id", vdsGroupId)
-                        .addValue("status", status.getValue()));
+                getCustomMapSqlParameterSource().addValue("vds_group_id",
+                        vdsGroupId).addValue("status", status.getValue()));
     }
 
     @Override
-    public List<VDS> getAllForStoragePoolAndStatus(Guid storagePool, VDSStatus 
status) {
-        return 
getCallsHandler().executeReadList("getVdsByStoragePoolIdWithStatus",
+    public List<VDS> getAllForStoragePoolAndStatus(Guid storagePool,
+            VDSStatus status) {
+        return getCallsHandler().executeReadList(
+                "getVdsByStoragePoolIdWithStatus",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("storage_pool_id", storagePool)
-                        .addValue("status", status.getValue()));
+                getCustomMapSqlParameterSource().addValue("storage_pool_id",
+                        storagePool).addValue("status", status.getValue()));
     }
 
     @Override
     public List<VDS> getListForSpmSelection(Guid storagePoolId) {
-        return getCallsHandler().executeReadList("GetUpAndPrioritizedVds",
+        return getCallsHandler().executeReadList(
+                "GetUpAndPrioritizedVds",
                 VdsRowMapper.instance,
-                getCustomMapSqlParameterSource().addValue("storage_pool_id", 
storagePoolId));
+                getCustomMapSqlParameterSource().addValue("storage_pool_id",
+                        storagePoolId));
     }
 
     @Override
     public List<VDS> listFailedAutorecoverables() {
-        return getCallsHandler().executeReadList("GetFailingVdss", 
VdsRowMapper.instance, null);
+        return getCallsHandler().executeReadList("GetFailingVdss",
+                VdsRowMapper.instance, null);
     }
 
     @Override
@@ -181,8 +227,7 @@
                 .addValue("network_id", networkId);
 
         return getCallsHandler().executeReadList("GetVdsByNetworkId",
-                VdsRowMapper.instance,
-                parameterSource);
+                VdsRowMapper.instance, parameterSource);
     }
 
     @Override
@@ -191,8 +236,7 @@
                 .addValue("network_id", networkId);
 
         return getCallsHandler().executeReadList("GetVdsWithoutNetwork",
-                VdsRowMapper.instance,
-                parameterSource);
+                VdsRowMapper.instance, parameterSource);
     }
 
     static final class VdsRowMapper implements RowMapper<VDS> {
@@ -200,20 +244,18 @@
         public final static VdsRowMapper instance = new VdsRowMapper();
 
         @Override
-        public VDS mapRow(final ResultSet rs, final int rowNum) throws 
SQLException {
+        public VDS mapRow(final ResultSet rs, final int rowNum)
+                throws SQLException {
             final VDS entity = new VDS();
-            entity.setId(Guid.createGuidFromString(rs
-                    .getString("vds_id")));
+            entity.setId(Guid.createGuidFromString(rs.getString("vds_id")));
             entity.setVdsGroupId(Guid.createGuidFromString(rs
                     .getString("vds_group_id")));
             entity.setVdsGroupName(rs.getString("vds_group_name"));
-            entity.setVdsGroupDescription(rs
-                    .getString("vds_group_description"));
+            
entity.setVdsGroupDescription(rs.getString("vds_group_description"));
             entity.setVdsName(rs.getString("vds_name"));
             entity.setManagementIp(rs.getString("ip"));
             entity.setUniqueId(rs.getString("vds_unique_id"));
-            entity.setServerSslEnabled(rs
-                    .getBoolean("server_SSL_enabled"));
+            entity.setServerSslEnabled(rs.getBoolean("server_SSL_enabled"));
             entity.setHostName(rs.getString("host_name"));
             entity.setPort(rs.getInt("port"));
             entity.setStatus(VDSStatus.forValue(rs.getInt("status")));
@@ -224,16 +266,14 @@
             entity.setCpuSpeedMh(rs.getDouble("cpu_speed_mh"));
             entity.setIfTotalSpeed(rs.getString("if_total_speed"));
             entity.setKvmEnabled((Boolean) rs.getObject("kvm_enabled"));
-            entity.setPhysicalMemMb((Integer) rs
-                    .getObject("physical_mem_mb"));
+            entity.setPhysicalMemMb((Integer) rs.getObject("physical_mem_mb"));
             entity.setCpuIdle(rs.getDouble("cpu_idle"));
             entity.setCpuLoad(rs.getDouble("cpu_load"));
             entity.setCpuSys(rs.getDouble("cpu_sys"));
             entity.setMemCommited((Integer) rs.getObject("mem_commited"));
             entity.setVmActive((Integer) rs.getObject("vm_active"));
             entity.setVmCount((Integer) rs.getObject("vm_count"));
-            entity.setVmsCoresCount((Integer) rs
-                    .getObject("vms_cores_count"));
+            entity.setVmsCoresCount((Integer) rs.getObject("vms_cores_count"));
             entity.setVmMigrating((Integer) rs.getObject("vm_migrating"));
             entity.setUsageCpuPercent((Integer) rs
                     .getObject("usage_cpu_percent"));
@@ -242,8 +282,7 @@
             entity.setUsageNetworkPercent((Integer) rs
                     .getObject("usage_network_percent"));
             entity.setReservedMem((Integer) rs.getObject("reserved_mem"));
-            entity.setGuestOverhead((Integer) rs
-                    .getObject("guest_overhead"));
+            entity.setGuestOverhead((Integer) rs.getObject("guest_overhead"));
             entity.setVersion(new RpmVersion(rs.getString("rpm_version")));
             entity.setSoftwareVersion(rs.getString("software_version"));
             entity.setVersionName(rs.getString("version_name"));
@@ -274,11 +313,11 @@
                     .getInt("max_vds_memory_over_commit"));
             entity.setCpuSockets((Integer) rs.getObject("cpu_sockets"));
             entity.setVdsSpmId((Integer) rs.getObject("vds_spm_id"));
-            entity.setNetConfigDirty((Boolean) rs
-                    .getObject("net_config_dirty"));
+            entity.setNetConfigDirty((Boolean) 
rs.getObject("net_config_dirty"));
             entity.setPmType(rs.getString("pm_type"));
             entity.setPmUser(rs.getString("pm_user"));
-            
entity.setPmPassword(DbFacadeUtils.decryptPassword(rs.getString("pm_password")));
+            entity.setPmPassword(DbFacadeUtils.decryptPassword(rs
+                    .getString("pm_password")));
             entity.setPmPort((Integer) rs.getObject("pm_port"));
             entity.setPmOptions(rs.getString("pm_options"));
             entity.setpm_enabled(rs.getBoolean("pm_enabled"));
@@ -286,16 +325,17 @@
             entity.setPmSecondaryIp((rs.getString("pm_secondary_ip")));
             entity.setPmSecondaryType(rs.getString("pm_secondary_type"));
             entity.setPmSecondaryUser(rs.getString("pm_secondary_user"));
-            
entity.setPmSecondaryPassword(DbFacadeUtils.decryptPassword(rs.getString("pm_secondary_password")));
-            entity.setPmSecondaryPort((Integer) 
rs.getObject("pm_secondary_port"));
+            entity.setPmSecondaryPassword(DbFacadeUtils.decryptPassword(rs
+                    .getString("pm_secondary_password")));
+            entity.setPmSecondaryPort((Integer) rs
+                    .getObject("pm_secondary_port"));
             entity.setPmSecondaryOptions(rs.getString("pm_secondary_options"));
-            
entity.setPmSecondaryConcurrent(rs.getBoolean("pm_secondary_concurrent"));
-            entity.setSpmStatus(VdsSpmStatus.forValue(rs
-                    .getInt("spm_status")));
+            entity.setPmSecondaryConcurrent(rs
+                    .getBoolean("pm_secondary_concurrent"));
+            
entity.setSpmStatus(VdsSpmStatus.forValue(rs.getInt("spm_status")));
             entity.setSwapFree(rs.getLong("swap_free"));
             entity.setSwapTotal(rs.getLong("swap_total"));
-            entity.setKsmCpuPercent((Integer) rs
-                    .getObject("ksm_cpu_percent"));
+            entity.setKsmCpuPercent((Integer) rs.getObject("ksm_cpu_percent"));
             entity.setKsmPages(rs.getLong("ksm_pages"));
             entity.setKsmState((Boolean) rs.getObject("ksm_state"));
             entity.setSupportedClusterLevels(rs
@@ -305,11 +345,11 @@
                     .getString("vds_group_compatibility_version")));
             entity.setHostOs(rs.getString("host_os"));
             entity.setKvmVersion(rs.getString("kvm_version"));
-            entity.setLibvirtVersion(new 
RpmVersion(rs.getString("libvirt_version")));
+            entity.setLibvirtVersion(new RpmVersion(rs
+                    .getString("libvirt_version")));
             entity.setSpiceVersion(rs.getString("spice_version"));
             entity.setKernelVersion(rs.getString("kernel_version"));
-            entity.setIScsiInitiatorName(rs
-                    .getString("iscsi_initiator_name"));
+            entity.setIScsiInitiatorName(rs.getString("iscsi_initiator_name"));
             entity.setTransparentHugePagesState(VdsTransparentHugePagesState
                     .forValue(rs.getInt("transparent_hugepages_state")));
             entity.setAnonymousHugePages(rs.getInt("anonymous_hugepages"));
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerEntityTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerEntityTest.java
new file mode 100644
index 0000000..4cb78cf
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerEntityTest.java
@@ -0,0 +1,28 @@
+package org.ovirt.engine.core.dal.cache;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.VM;
+
+public class CacheManagerEntityTest {
+
+    private CacheManager cacheManager = CacheManager.getInstance();
+
+    @Test
+    public void testVmsWithTags() {
+        VM result = new VM();
+        cacheManager
+                .putInCache(
+                        "SELECT * FROM (SELECT * FROM vms WHERE ( vm_guid IN 
(SELECT vms_with_tags.vm_guid FROM  vms_with_tags  ))  ORDER BY vm_name ASC 
,vm_name ASC ) as T1 OFFSET (1 -1) LIMIT 100",
+                        null, result);
+        Object obj = cacheManager
+                .getFromCache(
+                        "SELECT * FROM (SELECT * FROM vms WHERE ( vm_guid IN 
(SELECT vms_with_tags.vm_guid FROM  vms_with_tags  ))  ORDER BY vm_name ASC 
,vm_name ASC ) as T1 OFFSET (1 -1) LIMIT 100",
+                        null);
+
+        assertEquals(obj, null);
+
+    }
+
+}
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerTest.java
index e8e81f7..d8168bb 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/cache/CacheManagerTest.java
@@ -3,7 +3,6 @@
 import junit.framework.Assert;
 
 import org.junit.Test;
-import org.ovirt.engine.core.compat.cache.TimeToLiveInCache;
 
 public class CacheManagerTest {
 
@@ -93,7 +92,6 @@
         Assert.assertEquals(false, resultFromCache == result);
     }
 
-    @TimeToLiveInCache(5)
     private static class TestResult {
         private int id;
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08d5bee0835d00f525a02ba31e0fa5852303497b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Liran Zelkha <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to