Account caller = UserContext.current().getCaller();
Long groupId = cmd.getId();
String groupName = cmd.getGroupName();
// Verify input parameters
InstanceGroupVO group = _vmGroupDao.findById(groupId.longValue());
if (group == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a vm group with specified groupId");
ex.addProxyObject(group, groupId, "groupId");
throw ex;
}
_accountMgr.checkAccess(caller, null, true, group);
// Check if name is already in use by this account (exclude this group)
boolean isNameInUse = _vmGroupDao.isNameInUse(group.getAccountId(), groupName);
if (isNameInUse && !group.getName().equals(groupName)) {
throw new InvalidParameterValueException("Unable to update vm group, a group with name " + groupName + " already exists for account");
}
if (groupName != null) {
_vmGroupDao.updateVmGroup(groupId, groupName);