Tal Nisan has uploaded a new change for review.

Change subject: core: Added a query to fetch the number of images in a storage 
domain
......................................................................

core: Added a query to fetch the number of images in a storage domain

Change-Id: Id771444bc7d8916faa5e98fd54afb3d43157da15
Signed-off-by: Tal Nisan <[email protected]>
---
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/StorageDomainDAOTest.java
M packaging/dbscripts/storages_sp.sql
4 files changed, 49 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/28958/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAO.java
index c5dc7bc..7d87ee7 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAO.java
@@ -194,4 +194,13 @@
      * Retrieves all ids of vms and templates that has image disks on the 
given domain
      */
     List<Guid> getVmAndTemplatesIdsByStorageDomainId(Guid storageDomainId, 
boolean includeShareableDisks, boolean includeSnapshotDisks);
+
+    /**
+     * Retrieves the number of images in the specified storage domain.
+     *
+     * @param storageId
+     *            The storage domain ID
+     * @return the number of images in the specified storage domain
+     */
+    long getNumberOfImagesInStorageDomain(Guid storageDomainId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAODbFacadeImpl.java
index c53825b..8a97d0a 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/StorageDomainDAODbFacadeImpl.java
@@ -13,6 +13,7 @@
 import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.compat.Guid;
 import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
 /**
  * <code>StorageDomainDAODbFacadeImpl</code> provides an implementation of 
{@link StorageDomainDAO} based on code from
@@ -204,6 +205,12 @@
                         .addValue("active_only", !includeSnapshotDisks));
     }
 
+    @Override
+    public long getNumberOfImagesInStorageDomain(Guid storageDomainId) {
+        MapSqlParameterSource params = 
getCustomMapSqlParameterSource().addValue("storage_domain_id", storageDomainId);
+        return 
getCallsHandler().executeRead("GetNumberOfImagesInStorageDomain", 
getLongMapper(), params);
+    }
+
     /**
      * Gets the storage domain id of the given type for the given storage pool
      *
@@ -219,4 +226,6 @@
         }
         return returnValue;
     }
+
+
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/StorageDomainDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/StorageDomainDAOTest.java
index 1644191..e4ece1f 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/StorageDomainDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/StorageDomainDAOTest.java
@@ -26,6 +26,7 @@
     private static final Guid EXISTING_STORAGE_POOL_ID = new 
Guid("72b9e200-f48b-4687-83f2-62828f249a47");
     private static final String EXISTING_CONNECTION = 
"10.35.64.25:/export/share";
     private static final Guid EXISTING_USER_ID = new 
Guid("9bf7c640-b620-456f-a550-0348f366544b");
+    private static final long NUMBER_OF_IMAGES_ON_EXISTING_DOMAIN = 5;
 
     private StorageDomainDAO dao;
     private StorageDomain existingDomain;
@@ -425,6 +426,18 @@
         assertNull(getDbFacade().getBaseDiskDao().get(FixturesTool.DISK_ID));
     }
 
+    @Test
+    public void testGetNumberOfImagesInExistingDomain() {
+        long numOfImages = 
dao.getNumberOfImagesInStorageDomain(EXISTING_DOMAIN_ID);
+        assertEquals("Number of images on storage domain different than 
expected", NUMBER_OF_IMAGES_ON_EXISTING_DOMAIN, numOfImages);
+    }
+
+    @Test
+    public void testGetNumberOfImagesInNonExistingDomain() {
+        long numOfImages = 
dao.getNumberOfImagesInStorageDomain(Guid.newGuid());
+        assertEquals("Number of images on a non existing domain should be 0", 
0, numOfImages);
+    }
+
     /**
      * Asserts that the existing Storage Domain exists and has VMs and VM 
Templates, the after remove asserts
      * that the existing domain is removed along with the VM and VM Templates
diff --git a/packaging/dbscripts/storages_sp.sql 
b/packaging/dbscripts/storages_sp.sql
index b9de62d..74ceda3 100644
--- a/packaging/dbscripts/storages_sp.sql
+++ b/packaging/dbscripts/storages_sp.sql
@@ -881,4 +881,21 @@
    WHERE  storage_pool_id = v_storage_pool_id
    AND    storage_domain_type IN (0,1);  -- 0 = MASTER, 1 = DATA
 END; $procedure$
-LANGUAGE plpgsql;
\ No newline at end of file
+LANGUAGE plpgsql;
+
+
+
+
+-- This SP returns the number of images in the specified storage domain
+Create or replace FUNCTION 
GetNumberOfImagesInStorageDomain(v_storage_domain_id UUID)
+  RETURNS SETOF BIGINT STABLE
+AS $procedure$
+BEGIN
+   RETURN QUERY
+   SELECT COUNT(*)
+   FROM images i
+   JOIN image_storage_domain_map isdm
+   ON i.image_guid = isdm.image_id
+   WHERE isdm.storage_domain_id = v_storage_domain_id;
+END; $procedure$
+LANGUAGE plpgsql;


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

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

Reply via email to