Yair Zaslavsky has uploaded a new change for review.

Change subject: Revert "Revert "engine : VdsUpdateRuntimeInfo updates the data 
of a specific VDS.""
......................................................................

Revert "Revert "engine : VdsUpdateRuntimeInfo updates the data of a specific 
VDS.""

Change-Id: Icb9f9a51d597797508e53e94f50c02fdad30b982
Signed-off-by: Yair Zaslavsky <[email protected]>
---
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
17 files changed, 233 insertions(+), 67 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/19172/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java
index ea7deaa..0a71eb6 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java
@@ -5,6 +5,7 @@
 
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
@@ -63,4 +64,24 @@
     protected RowMapper<DiskImageDynamic> createEntityRowMapper() {
         return DiskImageDynamicRowMapper.instance;
     }
+
+    @Override
+    public MapSqlParameterMapper<DiskImageDynamic> getBatchMapper() {
+        return new MapSqlParameterMapper<DiskImageDynamic>() {
+
+            @Override
+            public MapSqlParameterSource map(DiskImageDynamic entity) {
+                MapSqlParameterSource paramValue = new MapSqlParameterSource()
+                        .addValue("image_id", entity.getId())
+                        .addValue("read_rate", entity.getread_rate())
+                        .addValue("write_rate", entity.getwrite_rate())
+                        .addValue("actual_size", entity.getactual_size())
+                        .addValue("read_latency_seconds", 
entity.getReadLatency())
+                        .addValue("write_latency_seconds", 
entity.getWriteLatency())
+                        .addValue("flush_latency_seconds", 
entity.getFlushLatency());
+
+                return paramValue;
+            }
+        };
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
index 9d8ac3b..c71f67f 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
@@ -4,7 +4,6 @@
 import java.util.Collection;
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
-import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 
 /**
  * Data Access Object which supports mass operations for the given entity type.
@@ -44,17 +43,15 @@
     void removeAll(Collection<ID> ids);
 
     /**
-     * Calls an update stored procedure multiple timse in a batch
-     *
+     * Calls an update stored procedure multiple times in a batch
      * @param procedureName
      * @param entities
      */
-    void updateAllInBatch(String procedureName, Collection<T> paramValues, 
MapSqlParameterMapper<T> mapper);
+    void updateAllInBatch(Collection<T> entities);
 
     /**
      * Saves the given entities using a more efficient method to save all of 
them at once, rather than each at a time.
      * The procedure name to be used is "InsertEntityName" where EntityName 
stands for the name of the entity
-     *
      * @param entities
      *            The entities to insert
      */
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
index 12bb977..53726d4 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
@@ -40,13 +40,12 @@
         }
     }
 
-    @Override
     /**
      * Enables to send update procedure name as a parameter that overrides the 
default
      * one.
      * In case this parameter is null the default procedure is used.
      */
-    public void updateAllInBatch(String procedureName,
+    protected void updateAllInBatch(String procedureName,
             Collection<T> paramValues,
             MapSqlParameterMapper<T> mapper) {
         getCallsHandler().executeStoredProcAsBatch(procedureName == null ? 
getProcedureNameForUpdate() : procedureName,
@@ -66,4 +65,11 @@
             save(entity);
         }
     }
+
+    @Override
+    public void updateAllInBatch(Collection<T> entities) {
+        updateAllInBatch(getProcedureNameForUpdate(), entities, 
getBatchMapper());
+    }
+
+    public abstract MapSqlParameterMapper<T> getBatchMapper();
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
index 8a68ec0..9ce5d2f 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
@@ -11,6 +11,7 @@
 import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.utils.SerializationFactory;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -196,4 +197,19 @@
 
     }
 
+    @Override
+    public MapSqlParameterMapper<VmDevice> getBatchMapper() {
+        return new MapSqlParameterMapper<VmDevice>() {
+            @Override
+            public MapSqlParameterSource map(VmDevice entity) {
+                MapSqlParameterSource paramValue = new MapSqlParameterSource()
+                        .addValue("device_id", entity.getDeviceId())
+                        .addValue("vm_id", entity.getVmId())
+                        .addValue("address", entity.getAddress())
+                        .addValue("alias", entity.getAlias());
+
+                return paramValue;
+            }
+        };
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
index b120789..0b8c494 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
@@ -64,4 +64,5 @@
      *   otherwise
      */
     boolean updateConsoleUserWithOptimisticLocking(VmDynamic vm);
+
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java
index ee37de2..9c7d125 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java
@@ -15,6 +15,7 @@
 import org.ovirt.engine.core.common.businessentities.VmPauseStatus;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
@@ -26,7 +27,6 @@
         setProcedureNameForGet("GetVmDynamicByVmGuid");
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public List<VmDynamic> getAllRunningForVds(Guid id) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
@@ -174,4 +174,49 @@
             }
         };
     }
+
+    @Override
+    public MapSqlParameterMapper<VmDynamic> getBatchMapper() {
+        return new MapSqlParameterMapper<VmDynamic>() {
+            @Override
+            public MapSqlParameterSource map(VmDynamic entity) {
+                MapSqlParameterSource paramValue = new MapSqlParameterSource()
+                        .addValue("guest_cur_user_name", 
entity.getGuestCurrentUserName())
+                        .addValue("console_cur_user_name", 
entity.getConsoleCurrentUserName())
+                        .addValue("guest_last_login_time", 
entity.getGuestLastLoginTime())
+                        .addValue("guest_last_logout_time", 
entity.getGuestLastLogoutTime())
+                        .addValue("console_user_id", entity.getConsoleUserId())
+                        .addValue("guest_os", entity.getGuestOs())
+                        .addValue("migrating_to_vds", 
entity.getMigratingToVds())
+                        .addValue("run_on_vds", entity.getRunOnVds())
+                        .addValue("status", entity.getStatus())
+                        .addValue("vm_guid", entity.getId())
+                        .addValue("vm_host", entity.getVmHost())
+                        .addValue("vm_ip", entity.getVmIp())
+                        .addValue("last_start_time", entity.getLastStartTime())
+                        .addValue("vm_pid", entity.getVmPid())
+                        .addValue("display", entity.getDisplay())
+                        .addValue("acpi_enable", entity.getAcpiEnable())
+                        .addValue("session", entity.getSession())
+                        .addValue("display_ip", entity.getDisplayIp())
+                        .addValue("display_type", entity.getDisplayType())
+                        .addValue("kvm_enable", entity.getKvmEnable())
+                        .addValue("boot_sequence", entity.getBootSequence())
+                        .addValue("display_secure_port", 
entity.getDisplaySecurePort())
+                        .addValue("utc_diff", entity.getUtcDiff())
+                        .addValue("last_vds_run_on", entity.getLastVdsRunOn())
+                        .addValue("client_ip", entity.getClientIp())
+                        .addValue("guest_requested_memory", 
entity.getGuestRequestedMemory())
+                        .addValue("hibernation_vol_handle", 
entity.getHibernationVolHandle())
+                        .addValue("exit_status", entity.getExitStatus())
+                        .addValue("pause_status", entity.getPauseStatus())
+                        .addValue("exit_message", entity.getExitMessage())
+                        .addValue("hash", entity.getHash())
+                        .addValue("guest_agent_nics_hash", 
entity.getGuestAgentNicsHash())
+                        .addValue("last_watchdog_event", 
entity.getLastWatchdogEvent())
+                        .addValue("last_watchdog_action", 
entity.getLastWatchdogAction());
+
+                return paramValue;
+            }};
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java
index e89b626..1c6b31d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java
@@ -7,6 +7,7 @@
 import org.apache.commons.lang.NotImplementedException;
 import org.ovirt.engine.core.common.businessentities.VmStatistics;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
@@ -68,4 +69,23 @@
         };
     }
 
+    @Override
+    public MapSqlParameterMapper<VmStatistics> getBatchMapper() {
+        return new MapSqlParameterMapper<VmStatistics>() {
+            @Override
+            public MapSqlParameterSource map(VmStatistics entity) {
+                MapSqlParameterSource paramValue = new MapSqlParameterSource()
+                        .addValue("cpu_sys", entity.getcpu_sys())
+                        .addValue("cpu_user", entity.getcpu_user())
+                        .addValue("elapsed_time", entity.getelapsed_time())
+                        .addValue("usage_cpu_percent", 
entity.getusage_cpu_percent())
+                        .addValue("usage_mem_percent", 
entity.getusage_mem_percent())
+                        .addValue("usage_network_percent", 
entity.getusage_network_percent())
+                        .addValue("disks_usage", entity.getDisksUsage())
+                        .addValue("vm_guid", entity.getId());
+
+                return paramValue;
+            }
+        };
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
index d859808..4f076b9 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
@@ -10,6 +10,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import org.ovirt.engine.core.common.utils.EnumUtils;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -158,4 +159,10 @@
     protected RowMapper<GlusterBrickEntity> createEntityRowMapper() {
         return brickRowMapper;
     }
+
+    @Override
+    public MapSqlParameterMapper<GlusterBrickEntity> getBatchMapper() {
+        // TODO: Implement this
+        throw new RuntimeException("Unsupported operation");
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
index 60b7027..6479590 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java
@@ -12,6 +12,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook;
 import org.ovirt.engine.core.common.utils.EnumUtils;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -299,4 +300,10 @@
         return getCustomMapSqlParameterSource().addValue("id", id);
     }
 
+    @Override
+    public MapSqlParameterMapper<GlusterHookEntity> getBatchMapper() {
+        // TODO: Implement this
+        throw new RuntimeException("Unsupported operation");
+    }
+
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
index 6399952..c418afd 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
@@ -8,6 +8,7 @@
 import org.apache.commons.lang.StringUtils;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -92,4 +93,10 @@
     protected RowMapper<GlusterVolumeOptionEntity> createEntityRowMapper() {
         return optionRowMapper;
     }
+
+    @Override
+    public MapSqlParameterMapper<GlusterVolumeOptionEntity> getBatchMapper() {
+        // TODO: Implement this
+        throw new RuntimeException("Unsupported operation");
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java
index c17aa3c..d3b3525 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java
@@ -9,6 +9,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.ServiceType;
 import org.ovirt.engine.core.common.utils.EnumUtils;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
@@ -113,4 +114,10 @@
             return entity;
         }
     }
+
+    @Override
+    public MapSqlParameterMapper<GlusterServerService> getBatchMapper() {
+        // TODO: Implement this
+        throw new RuntimeException("Unsupported operation");
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
index 9af0993..9434541 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
@@ -20,6 +20,7 @@
 import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.common.utils.EnumUtils;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -426,4 +427,10 @@
             removeTransportType(volumeId, transportType);
         }
     }
+
+    @Override
+    public MapSqlParameterMapper<GlusterVolumeEntity> getBatchMapper() {
+        // TODO: Implement this
+        throw new RuntimeException("Unsupported operation");
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java
index 6804b92..1f0d6d4 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java
@@ -8,6 +8,7 @@
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.DAO;
 
+//TODO: Split to 2 interfaces - one for statistics and one for interfaces. 
Both should extend MassOperation
 public interface InterfaceDao extends DAO {
     /**
      * Saves the specified statistics
@@ -50,9 +51,17 @@
      */
     void updateInterfaceForVds(VdsNetworkInterface iface);
 
+
+    /**
+     * Updates the given collection of vds network interface using a more 
efficient method to update all of them at
+     * once, rather than each at a time.
+     * @param statistics
+     *            The collection of statistics to update.
+     */
+    void massUpdateInterfacesForVds(List<VdsNetworkInterface> dbIfacesToBatch);
+
     /**
      * Retrieves all interfaces for the given VDS id.
-     *
      * @param id
      *            the VDS id
      * @return the list of interfaces
@@ -127,4 +136,5 @@
      * @return
      */
     List<VdsNetworkInterface> getAllInterfacesWithIpAddress(Guid clusterId, 
String ipAddress);
+
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java
index 25ff0b8..4bb05f6 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java
@@ -14,6 +14,7 @@
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkStatistics;
 import org.ovirt.engine.core.common.businessentities.network.Vlan;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.BaseDAODbFacade;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -80,6 +81,41 @@
                 executions);
     }
 
+    @Override
+    public void massUpdateInterfacesForVds(List<VdsNetworkInterface> 
dbIfacesToBatch) {
+        updateAllInBatch("Updatevds_interface", dbIfacesToBatch, new 
MapSqlParameterMapper<VdsNetworkInterface>() {
+            @Override
+            public MapSqlParameterSource map(VdsNetworkInterface entity) {
+                MapSqlParameterSource paramValue = new 
MapSqlParameterSource().addValue("addr", entity.getAddress())
+                        .addValue("bond_name", entity.getBondName())
+                        .addValue("bond_type", entity.getBondType())
+                        .addValue("gateway", entity.getGateway())
+                        .addValue("id", entity.getId())
+                        .addValue("is_bond", entity.getBonded())
+                        .addValue("bond_opts", entity.getBondOptions())
+                        .addValue("mac_addr", entity.getMacAddress())
+                        .addValue("name", entity.getName())
+                        .addValue("network_name", entity.getNetworkName())
+                        .addValue("speed", entity.getSpeed())
+                        .addValue("subnet", entity.getSubnet())
+                        .addValue("boot_protocol", entity.getBootProtocol())
+                        .addValue("type", entity.getType())
+                        .addValue("vds_id", entity.getVdsId())
+                        .addValue("vlan_id", entity.getVlanId())
+                        .addValue("mtu", entity.getMtu())
+                        .addValue("bridged", entity.isBridged());
+                return paramValue;
+            }
+        });
+    }
+
+    public void updateAllInBatch(String procedureName,
+            Collection<VdsNetworkInterface> paramValues,
+            MapSqlParameterMapper<VdsNetworkInterface> mapper) {
+        getCallsHandler().executeStoredProcAsBatch(procedureName,
+                paramValues, mapper);
+    }
+
     /**
      * Update the {@link VdsNetworkStatistics} in the DB using the given 
{@link SimpleJdbcCall}.
      *
@@ -140,7 +176,6 @@
                 vdsNetworkInterfaceRowMapper, parameterSource);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public List<VdsNetworkInterface> getAllInterfacesForVds(Guid id, Guid 
userID, boolean isFiltered) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
@@ -259,4 +294,5 @@
                     return iface;
                 }
             };
+
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java
index 5b21cdb..bc81b1e 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java
@@ -8,6 +8,7 @@
 import org.ovirt.engine.core.common.businessentities.network.InterfaceStatus;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -58,4 +59,24 @@
             }
         };
     }
+
+    @Override
+    public MapSqlParameterMapper<VmNetworkStatistics> getBatchMapper() {
+        return new MapSqlParameterMapper<VmNetworkStatistics>() {
+
+            @Override
+            public MapSqlParameterSource map(VmNetworkStatistics entity) {
+                MapSqlParameterSource paramValue = new MapSqlParameterSource()
+                        .addValue("id", entity.getId())
+                        .addValue("rx_drop", entity.getReceiveDropRate())
+                        .addValue("rx_rate", entity.getReceiveRate())
+                        .addValue("tx_drop", entity.getTransmitDropRate())
+                        .addValue("tx_rate", entity.getTransmitRate())
+                        .addValue("iface_status", entity.getStatus())
+                        .addValue("vm_id", entity.getVmId());
+
+                return paramValue;
+            }
+        };
+    }
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index c6e14e4..39a4caf 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -1,8 +1,6 @@
 package org.ovirt.engine.core.vdsbroker;
 
-import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -18,7 +16,6 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.ovirt.engine.core.common.AuditLogType;
-import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
@@ -65,7 +62,6 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
-import org.ovirt.engine.core.dao.MassOperationsDao;
 import org.ovirt.engine.core.utils.NetworkUtils;
 import org.ovirt.engine.core.utils.ObjectIdentityChecker;
 import org.ovirt.engine.core.utils.log.Log;
@@ -159,8 +155,8 @@
             }
         }
 
-        updateAllInTransaction(_vmDynamicToSave.values(), 
getDbFacade().getVmDynamicDao());
-        updateAllInTransaction(_vmStatisticsToSave.values(), 
getDbFacade().getVmStatisticsDao());
+        
getDbFacade().getVmDynamicDao().updateAllInBatch(_vmDynamicToSave.values());
+        
getDbFacade().getVmStatisticsDao().updateAllInBatch(_vmStatisticsToSave.values());
 
         final List<VmNetworkStatistics> allVmInterfaceStatistics = new 
LinkedList<VmNetworkStatistics>();
         for (List<VmNetworkInterface> list : 
_vmInterfaceStatisticsToSave.values()) {
@@ -169,8 +165,9 @@
             }
         }
 
-        updateAllInTransaction(allVmInterfaceStatistics, 
getDbFacade().getVmNetworkStatisticsDao());
-        updateAllInTransaction(_vmDiskImageDynamicToSave.values(), 
getDbFacade().getDiskImageDynamicDao());
+        
getDbFacade().getVmNetworkStatisticsDao().updateAllInBatch(allVmInterfaceStatistics);
+
+        
getDbFacade().getDiskImageDynamicDao().updateAllInBatch(_vmDiskImageDynamicToSave.values());
         saveVmDevicesToDb();
         saveVmGuestAgentNetworkDevices();
         
ResourceManager.getInstance().getEventListener().addExternallyManagedVms(_externalVmsToAdd);
@@ -200,7 +197,7 @@
     }
 
     private void saveVmDevicesToDb() {
-        updateAllInTransaction("UpdateVmDeviceRuntimeInfo", 
vmDeviceToSave.values(), getDbFacade().getVmDeviceDao());
+        
getDbFacade().getVmDeviceDao().updateAllInBatch(vmDeviceToSave.values());
 
         if (!removedDeviceIds.isEmpty()) {
             TransactionSupport.executeInScope(TransactionScopeOption.Required,
@@ -220,53 +217,6 @@
                         @Override
                         public Void runInTransaction() {
                             
getDbFacade().getVmDeviceDao().saveAll(newVmDevices);
-                            return null;
-                        }
-                    });
-        }
-    }
-
-    /**
-     * Update all the given entities in a transaction, so that a new 
connection/transaction won't be opened for each
-     * entity update.
-     *
-     * @param <T>
-     *            The type of entity.
-     * @param entities
-     *            The entities to update.
-     * @param dao
-     *            The DAO used for updating.
-     */
-    private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends 
Serializable & Comparable<? super ID>> void updateAllInTransaction(final 
Collection<T> entities,
-            final MassOperationsDao<T, ID> dao) {
-        updateAllInTransaction(null, entities, dao);
-    }
-
-    /**
-     * Update all the given entities in a transaction, so that a new 
connection/transaction won't be opened for each
-     * entity update.
-     *
-     * @param <T>
-     *            The type of entity.
-     * @param procedureName
-     *            The name of stored procedure to use for update
-     * @param entities
-     *            The entities to update.
-     * @param dao
-     *            The DAO used for updating.
-     */
-
-    private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends 
Serializable & Comparable<? super ID>> void updateAllInTransaction
-            (final String procedureName, final Collection<T> entities, final 
MassOperationsDao<T, ID> dao) {
-        final List<T> sortedList = new ArrayList<T>(entities);
-        Collections.sort(sortedList);
-        if (!entities.isEmpty()) {
-            TransactionSupport.executeInScope(TransactionScopeOption.Required,
-                    new TransactionMethod<Void>() {
-
-                        @Override
-                        public Void runInTransaction() {
-                            dao.updateAll(procedureName, sortedList);
                             return null;
                         }
                     });
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
index 44cce51..6143bf8 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java
@@ -162,16 +162,20 @@
         List<VdsNetworkInterface> dbIfaces = 
interfaceDAO.getAllInterfacesForVds(vds.getId());
         List<String> updatedIfaces = new ArrayList<String>();
 
+        List<VdsNetworkInterface> dbIfacesToBatch = new ArrayList<>();
+
         // First we check what interfaces need to update/delete
         for (VdsNetworkInterface dbIface : dbIfaces) {
             boolean found = false;
+
 
             for (VdsNetworkInterface vdsIface : vds.getInterfaces()) {
                 if (dbIface.getName().equals(vdsIface.getName())) {
                     // we preserve only the ID from the Database
                     // everything else is what we got from getVdsCapabilities
                     vdsIface.setId(dbIface.getId());
-                    interfaceDAO.updateInterfaceForVds(vdsIface);
+                    // interfaceDAO.updateInterfaceForVds(vdsIface);
+                    dbIfacesToBatch.add(vdsIface);
                     updatedIfaces.add(vdsIface.getName());
                     found = true;
                     break;
@@ -183,6 +187,10 @@
             }
         }
 
+        if (!dbIfacesToBatch.isEmpty()) {
+            interfaceDAO.massUpdateInterfacesForVds(dbIfacesToBatch);
+        }
+
         // now all that left is add the interfaces that not exists in the 
Database
         for (VdsNetworkInterface vdsIface : vds.getInterfaces()) {
             if (!updatedIfaces.contains(vdsIface.getName())) {


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

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

Reply via email to