CLOUDSTACK-4259 Dedicated Resources: createAffinityGroup API should not allow admin to create the group of this type through API

Changes:
- Block API from creating this type of group
This commit is contained in:
Prachi Damle 2013-08-12 11:46:29 -07:00
parent 25cc9eb869
commit 96ca70e2da
4 changed files with 33 additions and 2 deletions

View File

@ -79,4 +79,7 @@ public interface AffinityGroupService {
boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId);
AffinityGroup createAffinityGroupInternal(String account, Long domainId, String affinityGroupName,
String affinityGroupType, String description);
}

View File

@ -609,7 +609,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
}
group = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
group = _affinityGroupService.createAffinityGroupInternal(accountName, domainId, affinityGroupName,
"ExplicitDedication", "dedicated resources group");
return group;

View File

@ -1852,7 +1852,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
group = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
group = _affinityGroupService.createAffinityGroupInternal(accountName, domainId, affinityGroupName,
"ExplicitDedication", "dedicated resources group");
return group;

View File

@ -134,6 +134,34 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
if (processor.isAdminControlledGroup()) {
throw new PermissionDeniedException("Cannot create the affinity group");
}
return createAffinityGroupInternal(account, domainId, affinityGroupName, affinityGroupType, description);
}
@DB
@Override
public AffinityGroup createAffinityGroupInternal(String account, Long domainId, String affinityGroupName,
String affinityGroupType, String description) {
Account caller = UserContext.current().getCaller();
// validate the affinityGroupType
Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
if (!typeProcessorMap.containsKey(affinityGroupType)) {
throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type"
+ affinityGroupType);
}
} else {
throw new InvalidParameterValueException(
"Unable to create affinity group, no Affinity Group Types configured");
}
AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
if (processor.isAdminControlledGroup() && !_accountMgr.isRootAdmin(caller.getType())) {
throw new PermissionDeniedException("Cannot create the affinity group");
}