Gilad Chaplik has uploaded a new change for review.

Change subject: core: validate profile is not attched before removing it
......................................................................

core: validate profile is not attched before removing it

When deleting a profile, we will check that there are no
vms/templates attached to the profile.

For disk profile we'll check also for unattched disks (left disks).

Change-Id: Ic927e020118354751943b9890daef52373e3896f
Bug-Url: https://bugzilla.redhat.com/1142935
Signed-off-by: Gilad Chaplik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileValidator.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/ProfileValidator.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/RemoveProfileCommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DiskImageDAOTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M packaging/dbscripts/disk_images_sp.sql
M packaging/dbscripts/vm_templates_sp.sql
M packaging/dbscripts/vms_sp.sql
21 files changed, 303 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/33903/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileValidator.java
index f72dfa0..aaee68b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileValidator.java
@@ -5,6 +5,8 @@
 import org.apache.commons.lang.ObjectUtils;
 import org.ovirt.engine.core.bll.ValidationResult;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.profiles.CpuProfile;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.compat.Guid;
@@ -84,4 +86,14 @@
     protected List<CpuProfile> getProfilesByParentEntity() {
         return 
getDbFacade().getCpuProfileDao().getAllForCluster(getCluster().getId());
     }
+
+    @Override
+    public List<VmTemplate> getTemplatesUsingProfile() {
+        return 
getDbFacade().getVmTemplateDao().getAllForCpuProfile(getProfile().getId());
+    }
+
+    @Override
+    public List<VM> getVmsUsingProfile() {
+        return 
getDbFacade().getVmDao().getAllForCpuProfile(getProfile().getId());
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java
index 1fc02ef..1f1a737 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java
@@ -1,15 +1,21 @@
 package org.ovirt.engine.core.bll.profiles;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.commons.lang.ObjectUtils;
 import org.ovirt.engine.core.bll.ValidationResult;
 import org.ovirt.engine.core.bll.validator.StorageDomainValidator;
+import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.profiles.DiskProfile;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.profiles.DiskProfileDao;
+import org.ovirt.engine.core.utils.ReplacementUtils;
 
 
 public class DiskProfileValidator extends ProfileValidator<DiskProfile> {
@@ -73,6 +79,30 @@
     }
 
     @Override
+    public ValidationResult profileNotUsed() {
+        ValidationResult validationResult = super.profileNotUsed();
+        if (!validationResult.isValid()) {
+            return validationResult;
+        }
+        return validateUnattachedDisks();
+    }
+
+    private ValidationResult validateUnattachedDisks() {
+        List<DiskImage> entities = 
getDbFacade().getDiskImageDao().getAllForDiskProfile(getProfile().getId());
+        if (entities.isEmpty()) {
+            return ValidationResult.VALID;
+        }
+
+        List<Object> nameList = new ArrayList<>();
+        for (DiskImage diskImage : entities) {
+            nameList.add(diskImage.getDiskAlias());
+        }
+        Collection<String> replacements = 
ReplacementUtils.replaceWith("ENTITIES_USING_PROFILE", nameList);
+        replacements.add(VdcBllMessages.VAR__ENTITIES__DISKS.name());
+        return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_PROFILE_IN_USE, 
replacements);
+    }
+
+    @Override
     protected DiskProfileDao getProfileDao() {
         return getDbFacade().getDiskProfileDao();
     }
@@ -81,4 +111,14 @@
     protected List<DiskProfile> getProfilesByParentEntity() {
         return 
getDbFacade().getDiskProfileDao().getAllForStorageDomain(getStorageDomain().getId());
     }
+
+    @Override
+    protected List<VmTemplate> getTemplatesUsingProfile() {
+        return 
getDbFacade().getVmTemplateDao().getAllForDiskProfile(getProfile().getId());
+    }
+
+    @Override
+    protected List<VM> getVmsUsingProfile() {
+        return 
getDbFacade().getVmDao().getAllForDiskProfile(getProfile().getId());
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/ProfileValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/ProfileValidator.java
index 508d897..fa0306c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/ProfileValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/ProfileValidator.java
@@ -5,6 +5,8 @@
 
 import org.ovirt.engine.core.bll.ValidationResult;
 import org.ovirt.engine.core.common.businessentities.Nameable;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.profiles.ProfileBase;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.compat.Guid;
@@ -61,6 +63,17 @@
         return ValidationResult.VALID;
     }
 
+    public ValidationResult profileNotUsed() {
+        ValidationResult vmsErrorMsg =
+                profileNotUsed(getVmsUsingProfile(),
+                        VdcBllMessages.VAR__ENTITIES__VMS);
+        if (!vmsErrorMsg.isValid()) {
+            return vmsErrorMsg;
+        }
+        return profileNotUsed(getTemplatesUsingProfile(),
+                VdcBllMessages.VAR__ENTITIES__VM_TEMPLATES);
+    }
+
     protected ValidationResult profileNotUsed(List<? extends Nameable> 
entities, VdcBllMessages entitiesReplacement) {
         if (entities.isEmpty()) {
             return ValidationResult.VALID;
@@ -97,4 +110,8 @@
     protected abstract List<T> getProfilesByParentEntity();
 
     protected abstract ProfilesDao<T> getProfileDao();
+
+    protected abstract List<VmTemplate> getTemplatesUsingProfile();
+
+    protected abstract List<VM> getVmsUsingProfile();
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/RemoveProfileCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/RemoveProfileCommandBase.java
index cda3b6e..3a68f7c3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/RemoveProfileCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/RemoveProfileCommandBase.java
@@ -15,7 +15,8 @@
         Q validator = getProfileValidator();
         return validate(validator.profileIsSet())
                 && validate(validator.profileExists())
-                && validate(validator.isLastProfileInParentEntity());
+                && validate(validator.isLastProfileInParentEntity())
+                && validate(validator.profileNotUsed());
     }
 
     @Override
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 750c860..9cc5e73 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -11,6 +11,7 @@
     VAR__TYPE__VM__CLUSTER,
     VAR__TYPE__VM_TEMPLATE,
     VAR__ENTITIES__VM_TEMPLATES,
+    VAR__ENTITIES__DISKS,
     VAR__TYPE__SNAPSHOT,
     VAR__TYPE__DESKTOP_POOL,
     VAR__TYPE__VM_FROM_VM_POOL,
@@ -1036,7 +1037,7 @@
     ACTION_TYPE_FAILED_PROFILE_NOT_EXISTS(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_PROFILE_NAME_IN_USE(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE(ErrorType.BAD_PARAMETERS),
-    ACTION_TYPE_FAILED_PROFILE_IN_USE(ErrorType.BAD_PARAMETERS),
+    ACTION_TYPE_FAILED_PROFILE_IN_USE(ErrorType.CONFLICT),
     ACTION_TYPE_DISK_PROFILE_EMPTY(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND(ErrorType.BAD_PARAMETERS),
     
ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED(ErrorType.BAD_PARAMETERS),
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAO.java
index f0a4787..2a75d77 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAO.java
@@ -117,4 +117,13 @@
      * @return List of DiskImages related to the Storage Domain.
      */
     List<DiskImage> getAllForStorageDomain(Guid storageDomainId);
+
+    /**
+     * Return all images that attached to disk profile.
+     *
+     * @param diskProfileId
+     *            The Disk Profile Id attached to disks.
+     * @return List of DiskImages
+     */
+    List<DiskImage> getAllForDiskProfile(Guid diskProfileId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
index 107a027..8ad18ec 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDAODbFacadeImpl.java
@@ -142,6 +142,16 @@
                 parameterSource);
     }
 
+    @Override
+    public List<DiskImage> getAllForDiskProfile(Guid diskProfileId) {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
+                .addValue("disk_profile_id", diskProfileId);
+
+        return getCallsHandler().executeReadList("GetAllForDiskProfile",
+                DiskImageRowMapper.instance,
+                parameterSource);
+    }
+
     protected static class DiskImageRowMapper extends 
AbstractDiskRowMapper<DiskImage> {
 
         public static final DiskImageRowMapper instance = new 
DiskImageRowMapper();
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
index 1caca5ff..ee70e81 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
@@ -319,4 +319,22 @@
      * @return the list of ids of these vms
      */
     List<Guid> getVmIdsForVersionUpdate(Guid baseTemplateId);
+
+    /**
+     * Retrieves all VMS that are attached to provided profile
+     *
+     * @param cpuProfileId
+     *            CPU profile id
+     * @return the list of VMs
+     */
+    List<VM> getAllForCpuProfile(Guid cpuProfileId);
+
+    /**
+     * Retrieves all VMS that have disks attached to provided profile
+     *
+     * @param diskProfileId
+     *            disk profile id
+     * @return the list of VMs
+     */
+    List<VM> getAllForDiskProfile(Guid diskProfileId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
index d9e4cfa..17a3843 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
@@ -90,6 +90,7 @@
                         .addValue("instance_type_id", id));
     }
 
+    @Override
     public List<Pair<VM, VmDevice>> getVmsWithPlugInfo(Guid id) {
         return getCallsHandler().executeReadList
                 ("GetVmsByDiskId",
@@ -287,6 +288,20 @@
                     .addValue("base_template_id", baseTemplateId));
     }
 
+    @Override
+    public List<VM> getAllForCpuProfile(Guid cpuProfileId) {
+        return getCallsHandler().executeReadList("GetVmsByCpuProfileId",
+                VMRowMapper.instance, getCustomMapSqlParameterSource()
+                        .addValue("cpu_profile_id", cpuProfileId));
+    }
+
+    @Override
+    public List<VM> getAllForDiskProfile(Guid diskProfileId) {
+        return 
getCallsHandler().executeReadList("GetAllVmsRelatedToDiskProfile",
+                VMRowMapper.instance, getCustomMapSqlParameterSource()
+                        .addValue("disk_profile_id", diskProfileId));
+    }
+
     static final class VMRowMapper implements RowMapper<VM> {
         public static final VMRowMapper instance = new VMRowMapper();
 
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
index 5f9dd80..e79544d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
@@ -195,4 +195,22 @@
      */
     List<VmTemplate> getAllTemplatesWithDisksOnOtherStorageDomain(Guid 
storageDomainGuid);
 
+    /**
+     * Retrieves all templates that are attached to provided profile
+     *
+     * @param cpuProfileId
+     *            CPU profile id
+     * @return the list of Templates
+     */
+    List<VmTemplate> getAllForCpuProfile(Guid cpuProfileId);
+
+    /**
+     * Retrieves all templates that have disks attached to provided profile
+     *
+     * @param diskProfileId
+     *            disk profile id
+     * @return the list of Templates
+     */
+    List<VmTemplate> getAllForDiskProfile(Guid diskProfileId);
+
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
index 3f5c041..f1d76ef 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
@@ -227,6 +227,21 @@
                         .addValue("template_id", id));
     }
 
+    @Override
+    public List<VmTemplate> getAllForCpuProfile(Guid cpuProfileId) {
+        return 
getCallsHandler().executeReadList("GetVmTemplatesByCpuProfileId",
+                VMTemplateRowMapper.instance,
+                getCustomMapSqlParameterSource()
+                        .addValue("cpu_profile_id", cpuProfileId));
+    }
+
+    @Override
+    public List<VmTemplate> getAllForDiskProfile(Guid diskProfileId) {
+        return 
getCallsHandler().executeReadList("GetAllVmTemplatesRelatedToDiskProfile",
+                VMTemplateRowMapper.instance, getCustomMapSqlParameterSource()
+                        .addValue("disk_profile_id", diskProfileId));
+    }
+
     private final static class VMTemplateRowMapper extends 
AbstractVmRowMapper<VmTemplate> {
         public static final VMTemplateRowMapper instance = new 
VMTemplateRowMapper();
 
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 3b63397..ddd3585 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -285,6 +285,7 @@
 VAR__TYPE__COMPUTER_ACCOUNT=$type Computer Account
 VAR__TYPE__VM_TEMPLATE=$type Template
 VAR__ENTITIES__VM_TEMPLATES=$entities templates
+VAR__ENTITIES__DISKS=$entities Disks
 VAR__TYPE__SNAPSHOT=$type Snapshot
 VAR__TYPE__DESKTOP_POOL=$type VM-Pool
 VAR__TYPE__VM_FROM_VM_POOL=$type VM from VM-Pool
@@ -1158,7 +1159,7 @@
 ACTION_TYPE_FAILED_PROFILE_NOT_EXISTS=Cannot ${action} ${type}. Profile not 
exists.
 ACTION_TYPE_FAILED_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. Profile name 
is in use.
 ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE=Cannot ${action} ${type}. Cannot 
change profile.
-ACTION_TYPE_FAILED_PROFILE_IN_USE=Cannot ${action} ${type}. Profile is in use.
+ACTION_TYPE_FAILED_PROFILE_IN_USE=Cannot ${action} ${type}. Several 
${entities} (${ENTITIES_USING_PROFILE_COUNTER}) are using this 
Profile:\n${ENTITIES_USING_PROFILE}\n - Please remove it from all ${entities} 
that are using it and try again.
 ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND=Cannot ${action} ${type}. Disk 
Profile wasn't found.
 ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED=Cannot ${action} ${type}. 
Storage Domain wasn't provided.
 ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN=Cannot ${action} ${type}. 
Disk Profile doesn't match provided Storage Domain.
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DiskImageDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DiskImageDAOTest.java
index 1cdeef9..245ca05 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DiskImageDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DiskImageDAOTest.java
@@ -170,4 +170,20 @@
 
         assertTrue(images.isEmpty());
     }
+
+    @Test
+    public void testEmptyGetAllDisksByDiskProfile() {
+        List<DiskImage> diskImages = dao.getAllForDiskProfile(Guid.newGuid());
+
+        assertNotNull(diskImages);
+        assertTrue(diskImages.isEmpty());
+    }
+
+    @Test
+    public void testGetAllDisksByDiskProfile() {
+        List<DiskImage> diskImages = 
dao.getAllForDiskProfile(FixturesTool.DISK_PROFILE_1);
+
+        assertNotNull(diskImages);
+        assertEquals(4, diskImages.size());
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
index f5f08dc..c62d7ef 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
@@ -533,4 +533,35 @@
         assertTrue(result.isEmpty());
     }
 
+    @Test
+    public void testEmptyGetAllForCpuProfile() {
+        List<VM> result = dao.getAllForCpuProfile(Guid.newGuid());
+
+        assertNotNull(result);
+        assertTrue(result.isEmpty());
+    }
+
+    @Test
+    public void testGetAllForCpuProfile() {
+        List<VM> result = dao.getAllForCpuProfile(FixturesTool.CPU_PROFILE_1);
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+    }
+
+    @Test
+    public void testEmptyGetAllForDiskProfile() {
+        List<VM> result = dao.getAllForDiskProfile(Guid.newGuid());
+
+        assertNotNull(result);
+        assertTrue(result.isEmpty());
+    }
+
+    @Test
+    public void testGetAllForDiskProfile() {
+        List<VM> result = 
dao.getAllForDiskProfile(FixturesTool.DISK_PROFILE_1);
+
+        assertNotNull(result);
+        assertEquals(2, result.size());
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
index af6bf50..fcf6068 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
@@ -14,9 +14,9 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.Transformer;
 import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.ArchitectureType;
 import org.ovirt.engine.core.common.businessentities.ImageType;
 import org.ovirt.engine.core.common.businessentities.InstanceType;
-import org.ovirt.engine.core.common.businessentities.ArchitectureType;
 import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
@@ -412,4 +412,36 @@
     public void testGetTemplateWithLatestVersionInChain() {
         assertEquals(FixturesTool.VM_TEMPLATE_RHEL5_V2, 
dao.getTemplateWithLatestVersionInChain(FixturesTool.VM_TEMPLATE_RHEL5).getId());
     }
+
+    @Test
+    public void testEmptyGetAllForCpuProfile() {
+        List<VmTemplate> result = dao.getAllForCpuProfile(Guid.newGuid());
+
+        assertNotNull(result);
+        assertTrue(result.isEmpty());
+    }
+
+    @Test
+    public void testGetAllForCpuProfile() {
+        List<VmTemplate> result = 
dao.getAllForCpuProfile(FixturesTool.CPU_PROFILE_1);
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+    }
+
+    @Test
+    public void testEmptyGetAllForDiskProfile() {
+        List<VmTemplate> result = dao.getAllForDiskProfile(Guid.newGuid());
+
+        assertNotNull(result);
+        assertTrue(result.isEmpty());
+    }
+
+    @Test
+    public void testGetAllForDiskProfile() {
+        List<VmTemplate> result = 
dao.getAllForDiskProfile(FixturesTool.DISK_PROFILE_1);
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+    }
 }
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index f579459..401da1c 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -772,6 +772,9 @@
     @DefaultStringValue("$entities templates")
     String VAR__ENTITIES__VM_TEMPLATES();
 
+    @DefaultStringValue("$entities Disks")
+    String VAR__ENTITIES__DISKS();
+
     @DefaultStringValue("$type Snapshot")
     String VAR__TYPE__SNAPSHOT();
 
@@ -3125,7 +3128,7 @@
     @DefaultStringValue("Cannot ${action} ${type}. Cannot change profile.")
     String ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE();
 
-    @DefaultStringValue("Cannot ${action} ${type}. Profile is in use.")
+    @DefaultStringValue("Cannot ${action} ${type}. Several ${entities} 
(${ENTITIES_USING_PROFILE_COUNTER}) are using this 
Profile:\n${ENTITIES_USING_PROFILE}\n - Please remove it from all ${entities} 
that are using it and try again.")
     String ACTION_TYPE_FAILED_PROFILE_IN_USE();
 
     @DefaultStringValue("Cannot ${action} ${type}. Disk Profile wasn't found.")
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 02c11fc..0a1f27e 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -271,6 +271,7 @@
 VAR__TYPE__COMPUTER_ACCOUNT=$type Computer Account
 VAR__TYPE__VM_TEMPLATE=$type Template
 VAR__ENTITIES__VM_TEMPLATES=$entities templates
+VAR__ENTITIES__VM_DISK=$entities Virtual Machine Disk
 VAR__TYPE__SNAPSHOT=$type Snapshot
 VAR__TYPE__DESKTOP_POOL=$type VM-Pool
 VAR__TYPE__VM_FROM_VM_POOL=$type VM from VM-Pool
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 5c15576..e7d4cbc 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -283,6 +283,7 @@
 VAR__TYPE__COMPUTER_ACCOUNT=$type Computer Account
 VAR__TYPE__VM_TEMPLATE=$type Template
 VAR__ENTITIES__VM_TEMPLATE=$entities templates
+VAR__ENTITIES__DISKS=$entities Disks
 VAR__TYPE__SNAPSHOT=$type Snapshot
 VAR__TYPE__DESKTOP_POOL=$type VM-Pool
 VAR__TYPE__VM_FROM_VM_POOL=$type VM from VM-Pool
@@ -1127,7 +1128,7 @@
 ACTION_TYPE_FAILED_PROFILE_NOT_EXISTS=Cannot ${action} ${type}. Profile not 
exists.
 ACTION_TYPE_FAILED_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. Profile name 
is in use.
 ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE=Cannot ${action} ${type}. Cannot 
change profile.
-ACTION_TYPE_FAILED_PROFILE_IN_USE=Cannot ${action} ${type}. Profile is in use.
+ACTION_TYPE_FAILED_PROFILE_IN_USE=Cannot ${action} ${type}. Several 
${entities} (${ENTITIES_USING_PROFILE_COUNTER}) are using this 
Profile:\n${ENTITIES_USING_PROFILE}\n - Please remove it from all ${entities} 
that are using it and try again.
 ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND=Cannot ${action} ${type}. Disk 
Profile wasn't found.
 ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED=Cannot ${action} ${type}. 
Storage Domain wasn't provided.
 ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN=Cannot ${action} ${type}. 
Disk Profile doesn't match provided Storage Domain.
diff --git a/packaging/dbscripts/disk_images_sp.sql 
b/packaging/dbscripts/disk_images_sp.sql
index d2d7904..ac37ac4 100644
--- a/packaging/dbscripts/disk_images_sp.sql
+++ b/packaging/dbscripts/disk_images_sp.sql
@@ -203,4 +203,15 @@
 LANGUAGE plpgsql;
 
 
+Create or replace FUNCTION GetAllForDiskProfile(v_disk_profile_id UUID)
+RETURNS SETOF images_storage_domain_view STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT images_storage_domain_view.*
+      FROM  images_storage_domain_view
+      WHERE active AND images_storage_domain_view.disk_profile_id = 
v_disk_profile_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
 
diff --git a/packaging/dbscripts/vm_templates_sp.sql 
b/packaging/dbscripts/vm_templates_sp.sql
index ff34b18..ef4cfde 100644
--- a/packaging/dbscripts/vm_templates_sp.sql
+++ b/packaging/dbscripts/vm_templates_sp.sql
@@ -560,3 +560,25 @@
       WHERE image_storage_domain_map.storage_domain_id != v_storage_domain_id;
 END; $procedure$
 LANGUAGE plpgsql;
+
+Create or replace FUNCTION GetVmTemplatesByCpuProfileId(v_cpu_profile_id UUID) 
RETURNS SETOF vm_templates_view STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT vm_templates.*
+      FROM vm_templates_view
+      WHERE cpu_profile_id = v_cpu_profile_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION 
GetAllVmTemplatesRelatedToDiskProfile(v_disk_profile_id UUID) RETURNS SETOF 
vm_templates_view STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT vm_templates.*
+      FROM vm_templates_view vm_templates
+      INNER JOIN vm_device vd ON vd.vm_id = vm_templates.vmt_guid
+      INNER JOIN images ON images.image_group_id = vd.device_id AND 
images.active = TRUE
+      INNER JOIN image_storage_domain_map ON image_storage_domain_map.image_id 
= images.image_guid
+      WHERE image_storage_domain_map.disk_profile_id = v_disk_profile_id;
+END; $procedure$
+LANGUAGE plpgsql;
diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql
index 9892e54..3195f83 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -1399,3 +1399,26 @@
    WHERE vds_group_id = v_cluster_id;
 END; $procedure$
 LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetVmsByCpuProfileId(v_cpu_profile_id UUID) RETURNS 
SETOF vms STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT vms.*
+      FROM vms
+      WHERE cpu_profile_id = v_cpu_profile_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetAllVmsRelatedToDiskProfile(v_disk_profile_id 
UUID) RETURNS SETOF vms STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT vms.*
+      FROM vms
+      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
+      INNER JOIN images ON images.image_group_id = vd.device_id AND 
images.active = TRUE
+      INNER JOIN image_storage_domain_map ON image_storage_domain_map.image_id 
= images.image_guid
+      WHERE image_storage_domain_map.disk_profile_id = v_disk_profile_id;
+END; $procedure$
+LANGUAGE plpgsql;


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

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

Reply via email to