Martin Beták has uploaded a new change for review.

Change subject: engine: Ability to assign multiple VMs from a pool to single 
user
......................................................................

engine: Ability to assign multiple VMs from a pool to single user

Added a new field VmPool.maxAssignedVmsPerUser representing maximumum
number of VMs a single user can attach to from the same pool. Default value of
1 is equivalent to current behavior.

This patch also includes necessary minimal frontend changes in userportal
due to the logic of showing/hiding VmPools in userportal.

Change-Id: I3a1cc836db48d7094c2e7a03ee3a60b0b34a52a9
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=827248
Signed-off-by: Martin Betak <mbe...@redhat.com>
---
M backend/manager/dbscripts/create_views.sql
A backend/manager/dbscripts/upgrade/03_03_0040_add_max_assigned_vms_per_user.sql
M backend/manager/dbscripts/vm_pools_sp.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/DetachUserFromVmFromPoolCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolHandler.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolSimpleUserCommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolSimpleUserParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolUserParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmPoolDAODbFacadeImpl.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalBasicListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
17 files changed, 141 insertions(+), 65 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/14005/1

diff --git a/backend/manager/dbscripts/create_views.sql 
b/backend/manager/dbscripts/create_views.sql
index 0bdf467d..12725c7 100644
--- a/backend/manager/dbscripts/create_views.sql
+++ b/backend/manager/dbscripts/create_views.sql
@@ -763,7 +763,8 @@
 CREATE OR REPLACE VIEW vm_pools_view
 AS
 SELECT     vm_pools.vm_pool_id as vm_pool_id, vm_pools.vm_pool_name as 
vm_pool_name, vm_pools.vm_pool_description as vm_pool_description, 
vm_pools.vm_pool_type as vm_pool_type,
-                      vm_pools.parameters as parameters, 
vm_pools.prestarted_vms as prestarted_vms, vm_pools.vds_group_id as 
vds_group_id, vds_groups.name as vds_group_name
+                      vm_pools.parameters as parameters, 
vm_pools.prestarted_vms as prestarted_vms, vm_pools.vds_group_id as 
vds_group_id, vds_groups.name as vds_group_name,
+                      vm_pools.max_assigned_vms_per_user as 
max_assigned_vms_per_user
 FROM         vm_pools INNER JOIN
 vds_groups ON vm_pools.vds_group_id = vds_groups.vds_group_id;
 
@@ -772,7 +773,7 @@
 CREATE OR REPLACE VIEW vm_pools_full_view
 AS
 
-SELECT     vm_pool_id as vm_pool_id, vm_pool_name as vm_pool_name, 
vm_pool_description as vm_pool_description, vm_pool_type as vm_pool_type, 
parameters as parameters, prestarted_vms as prestarted_vms, vds_group_id as 
vds_group_id, vds_group_name as vds_group_name,
+SELECT     vm_pool_id as vm_pool_id, vm_pool_name as vm_pool_name, 
vm_pool_description as vm_pool_description, vm_pool_type as vm_pool_type, 
parameters as parameters, prestarted_vms as prestarted_vms, vds_group_id as 
vds_group_id, vds_group_name as vds_group_name, max_assigned_vms_per_user as 
max_assigned_vms_per_user,
               (SELECT     COUNT(vm_pool_map.vm_pool_id) as Expr1
    FROM        vm_pools_view AS v1 LEFT OUTER JOIN
    vm_pool_map ON v1.vm_pool_id = vm_pool_map.vm_pool_id AND v1.vm_pool_id = 
vmp.vm_pool_id) as assigned_vm_count,
diff --git 
a/backend/manager/dbscripts/upgrade/03_03_0040_add_max_assigned_vms_per_user.sql
 
b/backend/manager/dbscripts/upgrade/03_03_0040_add_max_assigned_vms_per_user.sql
new file mode 100644
index 0000000..52c8130
--- /dev/null
+++ 
b/backend/manager/dbscripts/upgrade/03_03_0040_add_max_assigned_vms_per_user.sql
@@ -0,0 +1 @@
+select fn_db_add_column('vm_pools', 'max_assigned_vms_per_user', 'smallint 
default 1');
diff --git a/backend/manager/dbscripts/vm_pools_sp.sql 
b/backend/manager/dbscripts/vm_pools_sp.sql
index b91f9ab..c1d71b7 100644
--- a/backend/manager/dbscripts/vm_pools_sp.sql
+++ b/backend/manager/dbscripts/vm_pools_sp.sql
@@ -9,12 +9,13 @@
  v_vm_pool_type INTEGER,
  v_parameters VARCHAR(200),
  v_prestarted_vms INTEGER,
- v_vds_group_id UUID)
+ v_vds_group_id UUID,
+ v_max_assigned_vms_per_user SMALLINT)
 RETURNS VOID
    AS $procedure$
 BEGIN
-      INSERT INTO vm_pools(vm_pool_id,vm_pool_description, vm_pool_name, 
vm_pool_type,parameters, prestarted_vms, vds_group_id)
-      VALUES(v_vm_pool_id,v_vm_pool_description, 
v_vm_pool_name,v_vm_pool_type,v_parameters, v_prestarted_vms, v_vds_group_id);
+      INSERT INTO vm_pools(vm_pool_id,vm_pool_description, vm_pool_name, 
vm_pool_type,parameters, prestarted_vms, vds_group_id, 
max_assigned_vms_per_user)
+      VALUES(v_vm_pool_id,v_vm_pool_description, 
v_vm_pool_name,v_vm_pool_type,v_parameters, v_prestarted_vms, v_vds_group_id, 
v_max_assigned_vms_per_user);
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -28,7 +29,8 @@
  v_vm_pool_type INTEGER,
  v_parameters VARCHAR(200),
  v_prestarted_vms INTEGER,
- v_vds_group_id UUID)
+ v_vds_group_id UUID,
+ v_max_assigned_vms_per_user SMALLINT)
 RETURNS VOID
 
        --The [vm_pools] table doesn't have a timestamp column. Optimistic 
concurrency logic cannot be generated
@@ -36,7 +38,8 @@
 BEGIN
       UPDATE vm_pools
       SET vm_pool_description = v_vm_pool_description,vm_pool_name = 
v_vm_pool_name,
-      vm_pool_type = v_vm_pool_type,parameters = v_parameters, prestarted_vms 
= v_prestarted_vms, vds_group_id = v_vds_group_id
+      vm_pool_type = v_vm_pool_type,parameters = v_parameters, prestarted_vms 
= v_prestarted_vms, vds_group_id = v_vds_group_id,
+      max_assigned_vms_per_user = v_max_assigned_vms_per_user
       WHERE vm_pool_id = v_vm_pool_id;
 END; $procedure$
 LANGUAGE plpgsql;
@@ -66,7 +69,7 @@
 
 
 DROP TYPE IF EXISTS GetAllFromVm_pools_rs CASCADE;
-Create type GetAllFromVm_pools_rs AS (vm_pool_id UUID, assigned_vm_count 
INTEGER, vm_running_count INTEGER, vm_pool_description VARCHAR(4000), 
vm_pool_name VARCHAR(255), vm_pool_type INTEGER, parameters VARCHAR(200), 
prestarted_vms INTEGER, vds_group_id UUID, vds_group_name VARCHAR(40));
+Create type GetAllFromVm_pools_rs AS (vm_pool_id UUID, assigned_vm_count 
INTEGER, vm_running_count INTEGER, vm_pool_description VARCHAR(4000), 
vm_pool_name VARCHAR(255), vm_pool_type INTEGER, parameters VARCHAR(200), 
prestarted_vms INTEGER, vds_group_id UUID, vds_group_name VARCHAR(40), 
max_assigned_vms_per_user SMALLINT);
 Create or replace FUNCTION GetAllFromVm_pools() RETURNS SETOF 
GetAllFromVm_pools_rs
    AS $procedure$
 BEGIN
@@ -136,7 +139,8 @@
             parameters VARCHAR(200),
             prestarted_vms INTEGER,
             vds_group_id UUID,
-            vds_group_name VARCHAR(40)
+            vds_group_name VARCHAR(40),
+            max_assigned_vms_per_user SMALLINT
          ) WITH OIDS;
          exception when others then
             truncate table tt_VM_POOL_RESULT;
@@ -150,10 +154,11 @@
             parameters,
             prestarted_vms,
             vds_group_id,
-            vds_group_name)
+            vds_group_name,
+            max_assigned_vms_per_user)
       select ppr.vm_pool_id, ppr.assigned_vm_count, ppr.vm_running_count,
                                 p.vm_pool_description, p.vm_pool_name, 
p.vm_pool_type, p.parameters, p.prestarted_vms,
-                                        p.vds_group_id, p.vds_group_name
+                                        p.vds_group_id, p.vds_group_name, 
p.max_assigned_vms_per_user
       from tt_VM_POOL_PRERESULT ppr
       inner join vm_pools_view p on ppr.vm_pool_id = p.vm_pool_id;
       RETURN QUERY select *
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolCommand.java
index 8d9722b..982cb03 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolCommand.java
@@ -4,6 +4,7 @@
 import org.ovirt.engine.core.common.action.VmPoolOperationParameters;
 import org.ovirt.engine.core.common.businessentities.VmPool;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.VdcBllMessages;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 
 public class AddVmPoolCommand<T extends VmPoolOperationParameters> extends 
VmPoolCommandBase<T> {
@@ -23,6 +24,19 @@
     }
 
     @Override
+    protected boolean canDoAction() {
+        boolean returnValue = super.canDoAction();
+        if (returnValue) {
+            VmPool pool = getParameters().getVmPool();
+            if (pool.getMaxAssignedVmsPerUser() < 1 || 
pool.getMaxAssignedVmsPerUser() > pool.getAssignedVmsCount()) {
+                
addCanDoActionMessage(VdcBllMessages.VM_POOL_NUMBER_OF_ASSIGNED_VMS_OUT_OF_RANGE);
+                returnValue = false;
+            }
+        }
+        return returnValue;
+    }
+
+    @Override
     protected void executeCommand() {
         VmPool vmPool = getVmPool();
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
index 9c86cd5..16f180c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
@@ -63,16 +63,22 @@
             }
         }
 
-        // check user isn't already attached to vm from this pool
+        // check user isn't already attached to maximum number of vms from 
this pool
         if (returnValue) {
             List<VM> vmsForUser = 
DbFacade.getInstance().getVmDao().getAllForUser(getAdUserId());
 
+            int vmCount = 0;
             for (VM vm : vmsForUser) {
                 if (vm.getVmPoolId() != null && 
getVmPoolId().equals(vm.getVmPoolId())) {
-                    
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_USER_ATTACHED_TO_POOL);
-                    returnValue = false;
+                    vmCount++;
                 }
             }
+
+            int limit = 
DbFacade.getInstance().getVmPoolDao().get(getVmPoolId()).getMaxAssignedVmsPerUser();
+            if (vmCount >= limit) {
+                
addCanDoActionMessage(VdcBllMessages.VM_POOL_CANNOT_ATTACH_TO_MORE_VMS_FROM_POOL);
+                returnValue = false;
+            }
         }
         if (!returnValue) {
             
addCanDoActionMessage(VdcBllMessages.VAR__ACTION__ALLOCATE_AND_RUN);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
index 6ad1bd8..0b0409f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
@@ -177,6 +177,10 @@
 
     @Override
     protected boolean canDoAction() {
+        if (!super.canDoAction()) {
+            return false;
+        }
+
         VDSGroup grp = 
getVdsGroupDAO().get(getParameters().getVmPool().getVdsGroupId());
         if (grp == null) {
             addCanDoActionMessage(VdcBllMessages.VDS_CLUSTER_IS_NOT_VALID);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/DetachUserFromVmFromPoolCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/DetachUserFromVmFromPoolCommand.java
index 522b915..68d3c5d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/DetachUserFromVmFromPoolCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/DetachUserFromVmFromPoolCommand.java
@@ -1,7 +1,5 @@
 package org.ovirt.engine.core.bll;
 
-import java.util.List;
-
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VmOperationParameterBase;
@@ -31,23 +29,40 @@
 
     }
 
-    protected void DetachAllVmsFromUser() {
-        List<VM> vms = 
DbFacade.getInstance().getVmDao().getAllForUser(getAdUserId());
-        for (VM vm : vms) {
-            if (getVmPoolId().equals(vm.getVmPoolId())) {
-                permissions perm = DbFacade
-                        .getInstance()
-                        .getPermissionDao()
-                        .getForRoleAndAdElementAndObject(
-                                PredefinedRoles.ENGINE_USER.getId(),
-                                getAdUserId(), vm.getId());
-                if (perm != null) {
-                    
DbFacade.getInstance().getPermissionDao().remove(perm.getId());
-                    RestoreVmFromBaseSnapshot(vm);
-                }
+//    protected void DetachAllVmsFromUser() {
+//        List<VM> vms = 
DbFacade.getInstance().getVmDao().getAllForUser(getAdUserId());
+//        for (VM vm : vms) {
+//            if (getVmPoolId().equals(vm.getVmPoolId())) {
+//                permissions perm = DbFacade
+//                        .getInstance()
+//                        .getPermissionDao()
+//                        .getForRoleAndAdElementAndObject(
+//                                PredefinedRoles.ENGINE_USER.getId(),
+//                                getAdUserId(), vm.getId());
+//                if (perm != null) {
+//                    
DbFacade.getInstance().getPermissionDao().remove(perm.getId());
+//                    RestoreVmFromBaseSnapshot(vm);
+//                }
+//            }
+//        }
+//
+//    }
+
+    protected void DetachVmFromUser() {
+        VM vm = DbFacade.getInstance().getVmDao().get(getVmId());
+
+        if (getVmPoolId().equals(vm.getVmPoolId())) {
+            permissions perm = DbFacade
+                    .getInstance()
+                    .getPermissionDao()
+                    .getForRoleAndAdElementAndObject(
+                            PredefinedRoles.ENGINE_USER.getId(),
+                            getAdUserId(), vm.getId());
+            if (perm != null) {
+                DbFacade.getInstance().getPermissionDao().remove(perm.getId());
+                RestoreVmFromBaseSnapshot(vm);
             }
         }
-
     }
 
     private void RestoreVmFromBaseSnapshot(VM vm) {
@@ -66,7 +81,7 @@
     @Override
     protected void executeCommand() {
         if (getVmPoolId() != null) {
-            DetachAllVmsFromUser();
+            DetachVmFromUser();
         }
         setSucceeded(true);
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolHandler.java
index 5d2c0ef..584a7a8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolHandler.java
@@ -9,9 +9,9 @@
 import org.ovirt.engine.core.common.action.VmPoolSimpleUserParameters;
 import org.ovirt.engine.core.common.businessentities.DbUser;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
-import org.ovirt.engine.core.common.businessentities.VmPoolType;
-import org.ovirt.engine.core.common.businessentities.VmPoolMap;
 import org.ovirt.engine.core.common.businessentities.VmPool;
+import org.ovirt.engine.core.common.businessentities.VmPoolMap;
+import org.ovirt.engine.core.common.businessentities.VmPoolType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.log.Log;
@@ -39,8 +39,7 @@
                 // should be only one user in the collection
                 for (DbUser dbUser : users) {
                     
Backend.getInstance().runInternalAction(VdcActionType.DetachUserFromVmFromPool,
-                            new 
VmPoolSimpleUserParameters(map.getvm_pool_id(), dbUser.getuser_id()),
-                            context);
+                            new 
VmPoolSimpleUserParameters(map.getvm_pool_id(), dbUser.getuser_id(), vmId), 
context);
                 }
             }
         } else {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolSimpleUserCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolSimpleUserCommandBase.java
index 7ddd76b..a5c4b48 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolSimpleUserCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolSimpleUserCommandBase.java
@@ -64,4 +64,15 @@
     public void setAdUserName(String value) {
         mAdUserName = value;
     }
+
+
+    @Override
+    public Guid getVmId() {
+        return getParameters().getVmId();
+    }
+
+    @Override
+    public void setVmId(Guid value) {
+        getParameters().setVmId(value);
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolSimpleUserParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolSimpleUserParameters.java
index 6d1ea93..ebada90 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolSimpleUserParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolSimpleUserParameters.java
@@ -9,15 +9,30 @@
     private static final long serialVersionUID = -956095100193433604L;
 
     @NotNull
-    private Guid _userId = Guid.Empty;
+    private Guid userId = Guid.Empty;
 
     public VmPoolSimpleUserParameters(NGuid vmPoolId, Guid userId) {
         super(vmPoolId);
-        _userId = userId;
+        this.userId = userId;
+    }
+
+    public VmPoolSimpleUserParameters(NGuid vmPoolId, Guid userId, Guid vmId) {
+        this(vmPoolId, userId);
+        this.vmId = vmId;
     }
 
     public Guid getUserId() {
-        return _userId;
+        return userId;
+    }
+
+    private Guid vmId = Guid.Empty;
+
+    public Guid getVmId() {
+        return vmId;
+    }
+
+    public void setVmId(Guid value) {
+        vmId = value;
     }
 
     public VmPoolSimpleUserParameters() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolUserParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolUserParameters.java
index b43364d..f139599 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolUserParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmPoolUserParameters.java
@@ -1,8 +1,7 @@
 package org.ovirt.engine.core.common.action;
 
-import org.ovirt.engine.core.compat.*;
-
-import org.ovirt.engine.core.common.users.*;
+import org.ovirt.engine.core.common.users.VdcUser;
+import org.ovirt.engine.core.compat.Guid;
 
 public class VmPoolUserParameters extends VmPoolSimpleUserParameters 
implements java.io.Serializable {
     private static final long serialVersionUID = -5672324868972973061L;
@@ -31,16 +30,6 @@
 
     private void setIsInternal(boolean value) {
         privateIsInternal = value;
-    }
-
-    private Guid privateVmId = new Guid();
-
-    public Guid getVmId() {
-        return privateVmId;
-    }
-
-    public void setVmId(Guid value) {
-        privateVmId = value;
     }
 
     public VmPoolUserParameters() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java
index c2db042..de08fc3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java
@@ -50,6 +50,8 @@
 
     private int vmPoolRunningCount = 1;
 
+    private int maxAssignedVmsPerUser = 1;
+
     public static final char MASK_CHARACTER = '?';
 
     public VmPool() {
@@ -71,6 +73,7 @@
         result = prime * result + ((name == null) ? 0 : name.hashCode());
         result = prime * result + vmPoolRunningCount;
         result = prime * result + ((type == null) ? 0 : type.hashCode());
+        result = prime * result + maxAssignedVmsPerUser;
         return result;
     }
 
@@ -94,7 +97,8 @@
                 && ObjectUtils.objectsEqual(vdsGroupId, other.vdsGroupId)
                 && ObjectUtils.objectsEqual(description, other.description)
                 && ObjectUtils.objectsEqual(name, other.name)
-                && ObjectUtils.objectsEqual(type, other.type));
+                && ObjectUtils.objectsEqual(type, other.type)
+                && maxAssignedVmsPerUser == other.maxAssignedVmsPerUser);
     }
 
     private void initializeTimeLeasedDefaultData(String parameter) {
@@ -208,6 +212,14 @@
         vmPoolAssignedCount = value;
     }
 
+    public int getMaxAssignedVmsPerUser() {
+        return maxAssignedVmsPerUser;
+    }
+
+    public void setMaxAssignedVmsPerUser(int maxAssignedVmsPerUser) {
+        this.maxAssignedVmsPerUser = maxAssignedVmsPerUser;
+    }
+
     public int getRunningVmsCount() {
         return vmPoolRunningCount;
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index 3a7ef19..8588bb4 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -328,7 +328,8 @@
     VM_POOL_CANNOT_REMOVE_VM_POOL_WITH_VMS,
     VM_POOL_CANNOT_REMOVE_RUNNING_VM_FROM_POOL,
     VM_POOL_CANNOT_ADD_RUNNING_VM_TO_POOL,
-    ACTION_TYPE_FAILED_USER_ATTACHED_TO_POOL,
+    VM_POOL_NUMBER_OF_ASSIGNED_VMS_OUT_OF_RANGE,
+    VM_POOL_CANNOT_ATTACH_TO_MORE_VMS_FROM_POOL,
     VM_POOL_CANNOT_ADD_VM_WITH_USERS_ATTACHED_TO_POOL,
     VM_POOL_CANNOT_ADD_VM_ATTACHED_TO_POOL,
     VM_POOL_CANNOT_DETACH_VM_NOT_ATTACHED_TO_POOL,
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmPoolDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmPoolDAODbFacadeImpl.java
index 27fc683..ac4dbb7 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmPoolDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmPoolDAODbFacadeImpl.java
@@ -83,7 +83,8 @@
                 .addValue("vm_pool_type", pool.getVmPoolType())
                 .addValue("parameters", pool.getParameters())
                 .addValue("prestarted_vms", pool.getPrestartedVms())
-                .addValue("vds_group_id", pool.getVdsGroupId());
+                .addValue("vds_group_id", pool.getVdsGroupId())
+                .addValue("max_assigned_vms_per_user", 
pool.getMaxAssignedVmsPerUser());
 
         getCallsHandler().executeModification("InsertVm_pools", 
parameterSource);
     }
@@ -97,7 +98,8 @@
                 .addValue("vm_pool_type", pool.getVmPoolType())
                 .addValue("parameters", pool.getParameters())
                 .addValue("prestarted_vms", pool.getPrestartedVms())
-                .addValue("vds_group_id", pool.getVdsGroupId());
+                .addValue("vds_group_id", pool.getVdsGroupId())
+                .addValue("max_assigned_vms_per_user", 
pool.getMaxAssignedVmsPerUser());
 
         getCallsHandler().executeModification("UpdateVm_pools", 
parameterSource);
     }
@@ -192,6 +194,7 @@
             entity.setVdsGroupName(rs.getString("vds_group_name"));
             entity.setAssignedVmsCount(rs.getInt("assigned_vm_count"));
             entity.setRunningVmsCount(rs.getInt("vm_running_count"));
+            
entity.setMaxAssignedVmsPerUser(rs.getInt("max_assigned_vms_per_user"));
             return entity;
         }
     }
@@ -214,6 +217,7 @@
             entity.setVdsGroupId(Guid.createGuidFromString(rs
                     .getString("vds_group_id")));
             entity.setVdsGroupName(rs.getString("vds_group_name"));
+            
entity.setMaxAssignedVmsPerUser(rs.getInt("max_assigned_vms_per_user"));
             return entity;
         }
     }
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 4874abb..6528b47 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -106,7 +106,7 @@
 VDS_GROUP_CANNOT_REMOVE_HAS_VM_POOLS=Cannot ${action} ${type}.One or more 
VM-Pools are still associated with it
 VM_IMAGE_LOCKED=Cannot run VM. The disk image is being copied. Please wait for 
the copy operation to complete.
 VM_POOL_CANNOT_ADD_VM_WITH_USERS_ATTACHED_TO_POOL=Cannot attach VM to VM-Pool. 
VM-Pool is already attached to a User.
-ACTION_TYPE_FAILED_USER_ATTACHED_TO_POOL=User is already attached to this 
VM-Pool.
+VM_POOL_CANNOT_ATTACH_TO_MORE_VMS_FROM_POOL=User is already attached to 
maximum number of VMs from this VM-Pool.
 VM_POOL_CANNOT_ADD_VM_ATTACHED_TO_POOL=Cannot attach VM to pool. VM is already 
attached to another VM-Pool.
 VM_POOL_CANNOT_DETACH_VM_NOT_ATTACHED_TO_POOL=Cannot detach VM from pool. VM 
is not attached to the VM-Pool.
 VM_POOL_CANNOT_ADD_VM_DIFFERENT_CLUSTER=Cannot attach VM to VM-Pool. VM 
resides on different Host Cluster than VM-Pool.
@@ -115,6 +115,7 @@
 VM_POOL_CANNOT_REMOVE_VM_POOL_WITH_VMS=Cannot remove VM-Pool. Detach VMs from 
VM-Pool first.
 VM_POOL_CANNOT_REMOVE_RUNNING_VM_FROM_POOL=Cannot detach VM from VM-Pool. VM 
is running.
 VM_POOL_CANNOT_ADD_RUNNING_VM_TO_POOL=Cannot attach VM to VM-Pool. VM is 
running.
+VM_POOL_NUMBER_OF_ASSIGNED_VMS_OUT_OF_RANGE=Number of max assigned VMs per 
user must be between 1 and the current size of the pool.
 VM_INVALID_SERVER_CLUSTER_ID=Invalid Host Cluster id.
 VMT_CANNOT_CREATE_TEMPLATE_FROM_DOWN_VM=Cannot ${action} ${type}. VM still 
running, stop the VM and try again.
 VMT_CANNOT_REMOVE_BLANK_TEMPLATE=Cannot ${action} ${type}. Removing Blank 
Template is not allowed.
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalBasicListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalBasicListModel.java
index 659b1d2..acec2f6 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalBasicListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalBasicListModel.java
@@ -293,17 +293,16 @@
                 // Add pool to map.
                 poolMap.put(pool.getVmPoolId(), pool);
 
-                boolean found = false;
+                int attachedVmsCount = 0;
                 for (VM vm : getvms())
                 {
                     if (vm.getVmPoolId() != null && 
vm.getVmPoolId().equals(pool.getVmPoolId()))
                     {
-                        found = true;
-                        break;
+                        attachedVmsCount++;
                     }
                 }
 
-                if (!found)
+                if (attachedVmsCount < pool.getMaxAssignedVmsPerUser())
                 {
                     filteredPools.add(pool);
                 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
index df4513a..9f8af2e 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
@@ -1720,17 +1720,16 @@
                 // Add pool to map.
                 poolMap.put(pool.getVmPoolId(), pool);
 
-                boolean found = false;
+                int attachedVmsCount = 0;
                 for (VM vm : getvms())
                 {
                     if (vm.getVmPoolId() != null && 
vm.getVmPoolId().equals(pool.getVmPoolId()))
                     {
-                        found = true;
-                        break;
+                        attachedVmsCount++;
                     }
                 }
 
-                if (!found)
+                if (attachedVmsCount < pool.getMaxAssignedVmsPerUser())
                 {
                     filteredPools.add(pool);
                 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a1cc836db48d7094c2e7a03ee3a60b0b34a52a9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Beták <mbe...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to