test_class.declarator: DOMAIN_ID = 5L
test_class.modifier: private static final
test_class.original_string: private static final long DOMAIN_ID = 5L;
test_class.type: long
test_class.var_name: DOMAIN_ID
test_class.declarator: PROJECT_ID = 10L
test_class.modifier: private static final
test_class.original_string: private static final long PROJECT_ID = 10L;
test_class.type: long
test_class.var_name: PROJECT_ID
test_class.declarator: ACCOUNT_NAME = "user"
test_class.modifier: private static final
test_class.original_string: private static final String ACCOUNT_NAME = "user";
test_class.type: String
test_class.var_name: ACCOUNT_NAME
test_class.declarator: AFFINITY_GROUP_NAME = "group1"
test_class.modifier: private static final
test_class.original_string: private static final String AFFINITY_GROUP_NAME = "group1";
test_class.type: String
test_class.var_name: AFFINITY_GROUP_NAME
test_class.declarator: _affinityService
test_class.modifier: @Inject
test_class.original_string: @Inject
      AffinityGroupServiceImpl _affinityService;
test_class.type: AffinityGroupServiceImpl
test_class.var_name: _affinityService
test_class.declarator: _acctMgr
test_class.modifier: @Inject
test_class.original_string: @Inject
      AccountManager _acctMgr;
test_class.type: AccountManager
test_class.var_name: _acctMgr
test_class.declarator: _processor
test_class.modifier: @Inject
test_class.original_string: @Inject
      AffinityGroupProcessor _processor;
test_class.type: AffinityGroupProcessor
test_class.var_name: _processor
test_class.declarator: _groupDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      AffinityGroupDao _groupDao;
test_class.type: AffinityGroupDao
test_class.var_name: _groupDao
test_class.declarator: _vmDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      UserVmDao _vmDao;
test_class.type: UserVmDao
test_class.var_name: _vmDao
test_class.declarator: _affinityGroupVMMapDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      AffinityGroupVMMapDao _affinityGroupVMMapDao;
test_class.type: AffinityGroupVMMapDao
test_class.var_name: _affinityGroupVMMapDao
test_class.declarator: _affinityGroupDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      AffinityGroupDao _affinityGroupDao;
test_class.type: AffinityGroupDao
test_class.var_name: _affinityGroupDao
test_class.declarator: _eventUtils
test_class.modifier: @Inject
test_class.original_string: @Inject
      ActionEventUtils _eventUtils;
test_class.type: ActionEventUtils
test_class.var_name: _eventUtils
test_class.declarator: _accountDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      AccountDao _accountDao;
test_class.type: AccountDao
test_class.var_name: _accountDao
test_class.declarator: _projectDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      ProjectDao _projectDao;
test_class.type: ProjectDao
test_class.var_name: _projectDao
test_class.declarator: _eventDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      EventDao _eventDao;
test_class.type: EventDao
test_class.var_name: _eventDao
test_class.declarator: _dedicatedDao
test_class.modifier: @Inject
test_class.original_string: @Inject
      DedicatedResourceDao _dedicatedDao;
test_class.type: DedicatedResourceDao
test_class.var_name: _dedicatedDao
test_class.declarator: acct
test_class.modifier: private
test_class.original_string: private AccountVO acct;
test_class.type: AccountVO
test_class.var_name: acct
test_class.file: cosmic-core/server/src/test/java/com/cloud/affinity/AffinityGroupServiceImplTest.java
test_class.identifier: AffinityGroupServiceImplTest
test_case.body: @Test(expected = InvalidParameterValueException.class)
      public void updateAffinityGroupVMRunning() throws ResourceInUseException {
          when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
          final UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false,
                  DOMAIN_ID, 200L, 1, 5L, "", "test", 1L, "Manufacturer", OptimiseFor.Generic,
                  false, "", MaintenancePolicy.LiveMigrate, 0L, "cdrom,hd,network");
          vm.setState(VirtualMachine.State.Running);
          when(_vmDao.findById(10L)).thenReturn(vm);
  
          final List<Long> affinityGroupIds = new ArrayList<>();
          affinityGroupIds.add(20L);
  
          _affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
      }
test_case.class_method_signature: AffinityGroupServiceImplTest.updateAffinityGroupVMRunning()
test_case.full_signature: @Test(expected = InvalidParameterValueException.class) public void updateAffinityGroupVMRunning()
test_case.identifier: updateAffinityGroupVMRunning
test_case.invocations: thenReturn when finalizeOwner anyObject anyString anyLong anyLong setState thenReturn when findById add updateVMAffinityGroups
test_case.modifiers: @Test(expected = InvalidParameterValueException.class) public
test_case.parameters: ()
test_case.return: void
test_case.signature: void updateAffinityGroupVMRunning()
focal_class.declarator: s_logger = LoggerFactory.getLogger(AffinityGroupServiceImpl.class)
focal_class.modifier: public static final
focal_class.original_string: public static final Logger s_logger = LoggerFactory.getLogger(AffinityGroupServiceImpl.class);
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.declarator: _affinityProcessors
focal_class.modifier: protected
focal_class.original_string: protected List<AffinityGroupProcessor> _affinityProcessors;
focal_class.type: List<AffinityGroupProcessor>
focal_class.var_name: _affinityProcessors
focal_class.declarator: _accountMgr
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AccountManager _accountMgr;
focal_class.type: AccountManager
focal_class.var_name: _accountMgr
focal_class.declarator: _affinityGroupDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AffinityGroupDao _affinityGroupDao;
focal_class.type: AffinityGroupDao
focal_class.var_name: _affinityGroupDao
focal_class.declarator: _affinityGroupVMMapDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AffinityGroupVMMapDao _affinityGroupVMMapDao;
focal_class.type: AffinityGroupVMMapDao
focal_class.var_name: _affinityGroupVMMapDao
focal_class.declarator: _affinityGroupDomainMapDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AffinityGroupDomainMapDao _affinityGroupDomainMapDao;
focal_class.type: AffinityGroupDomainMapDao
focal_class.var_name: _affinityGroupDomainMapDao
focal_class.declarator: _domainDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      DomainDao _domainDao;
focal_class.type: DomainDao
focal_class.var_name: _domainDao
focal_class.declarator: _domainMgr
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      DomainManager _domainMgr;
focal_class.type: DomainManager
focal_class.var_name: _domainMgr
focal_class.declarator: _messageBus
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      MessageBus _messageBus;
focal_class.type: MessageBus
focal_class.var_name: _messageBus
focal_class.declarator: _name
focal_class.modifier: private
focal_class.original_string: private String _name;
focal_class.type: String
focal_class.var_name: _name
focal_class.declarator: _userVmDao
focal_class.modifier: @Inject
      private
focal_class.original_string: @Inject
      private UserVmDao _userVmDao;
focal_class.type: UserVmDao
focal_class.var_name: _userVmDao
focal_class.declarator: _dedicatedDao
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      DedicatedResourceDao _dedicatedDao;
focal_class.type: DedicatedResourceDao
focal_class.var_name: _dedicatedDao
focal_class.declarator: _affinityGroupService
focal_class.modifier: @Inject
focal_class.original_string: @Inject
      AffinityGroupService _affinityGroupService;
focal_class.type: AffinityGroupService
focal_class.var_name: _affinityGroupService
focal_class.file: cosmic-core/server/src/main/java/com/cloud/affinity/AffinityGroupServiceImpl.java
focal_class.identifier: AffinityGroupServiceImpl
focal_class.interfaces: implements AffinityGroupService, Manager, StateListener<State, VirtualMachine.Event, VirtualMachine>
focal_class.class_method_signature: AffinityGroupServiceImpl.getAffinityGroupProcessors()
focal_class.full_signature: public List<AffinityGroupProcessor> getAffinityGroupProcessors()
focal_class.identifier: getAffinityGroupProcessors
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<AffinityGroupProcessor>
focal_class.signature: List<AffinityGroupProcessor> getAffinityGroupProcessors()
focal_class.class_method_signature: AffinityGroupServiceImpl.setAffinityGroupProcessors(final List<AffinityGroupProcessor> affinityProcessors)
focal_class.full_signature: public void setAffinityGroupProcessors(final List<AffinityGroupProcessor> affinityProcessors)
focal_class.identifier: setAffinityGroupProcessors
focal_class.modifiers: public
focal_class.parameters: (final List<AffinityGroupProcessor> affinityProcessors)
focal_class.return: void
focal_class.signature: void setAffinityGroupProcessors(final List<AffinityGroupProcessor> affinityProcessors)
focal_class.class_method_signature: AffinityGroupServiceImpl.getName()
focal_class.full_signature: @Override public String getName()
focal_class.identifier: getName
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getName()
focal_class.class_method_signature: AffinityGroupServiceImpl.configure(final String name, final Map<String, Object> params)
focal_class.full_signature: @Override public boolean configure(final String name, final Map<String, Object> params)
focal_class.identifier: configure
focal_class.modifiers: @Override public
focal_class.parameters: (final String name, final Map<String, Object> params)
focal_class.return: boolean
focal_class.signature: boolean configure(final String name, final Map<String, Object> params)
focal_class.class_method_signature: AffinityGroupServiceImpl.createAffinityGroup(final CreateAffinityGroupCmd createAffinityGroupCmd)
focal_class.full_signature: @DB @Override @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_CREATE, eventDescription = "Creating Affinity Group", create = true) public AffinityGroup createAffinityGroup(final CreateAffinityGroupCmd createAffinityGroupCmd)
focal_class.identifier: createAffinityGroup
focal_class.modifiers: @DB @Override @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_CREATE, eventDescription = "Creating Affinity Group", create = true) public
focal_class.parameters: (final CreateAffinityGroupCmd createAffinityGroupCmd)
focal_class.return: AffinityGroup
focal_class.signature: AffinityGroup createAffinityGroup(final CreateAffinityGroupCmd createAffinityGroupCmd)
focal_class.class_method_signature: AffinityGroupServiceImpl.start()
focal_class.full_signature: @Override public boolean start()
focal_class.identifier: start
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean start()
focal_class.class_method_signature: AffinityGroupServiceImpl.stop()
focal_class.full_signature: @Override public boolean stop()
focal_class.identifier: stop
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean stop()
focal_class.class_method_signature: AffinityGroupServiceImpl.createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType,
                                               final String description)
focal_class.full_signature: @DB @Override public AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType,
                                               final String description)
focal_class.identifier: createAffinityGroup
focal_class.modifiers: @DB @Override public
focal_class.parameters: (final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType,
                                               final String description)
focal_class.return: AffinityGroup
focal_class.signature: AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType,
                                               final String description)
focal_class.class_method_signature: AffinityGroupServiceImpl.preStateTransitionEvent(final State oldState, final Event event, final State newState, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.full_signature: @Override public boolean preStateTransitionEvent(final State oldState, final Event event, final State newState, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.identifier: preStateTransitionEvent
focal_class.modifiers: @Override public
focal_class.parameters: (final State oldState, final Event event, final State newState, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.return: boolean
focal_class.signature: boolean preStateTransitionEvent(final State oldState, final Event event, final State newState, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.class_method_signature: AffinityGroupServiceImpl.postStateTransitionEvent(final Transition<State, Event> transition, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.full_signature: @Override public boolean postStateTransitionEvent(final Transition<State, Event> transition, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.identifier: postStateTransitionEvent
focal_class.modifiers: @Override public
focal_class.parameters: (final Transition<State, Event> transition, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.return: boolean
focal_class.signature: boolean postStateTransitionEvent(final Transition<State, Event> transition, final VirtualMachine vo, final boolean status, final Object opaque)
focal_class.class_method_signature: AffinityGroupServiceImpl.verifyAccessToDomainWideProcessor(final Account caller, final AffinityGroupProcessor processor)
focal_class.full_signature: private void verifyAccessToDomainWideProcessor(final Account caller, final AffinityGroupProcessor processor)
focal_class.identifier: verifyAccessToDomainWideProcessor
focal_class.modifiers: private
focal_class.parameters: (final Account caller, final AffinityGroupProcessor processor)
focal_class.return: void
focal_class.signature: void verifyAccessToDomainWideProcessor(final Account caller, final AffinityGroupProcessor processor)
focal_class.class_method_signature: AffinityGroupServiceImpl.createAffinityGroup(final AffinityGroupProcessor processor, final Account owner, final ACLType aclType, final String affinityGroupName, final String
              affinityGroupType, final String description, boolean domainLevel, Long domainId)
focal_class.full_signature: private AffinityGroupVO createAffinityGroup(final AffinityGroupProcessor processor, final Account owner, final ACLType aclType, final String affinityGroupName, final String
              affinityGroupType, final String description, boolean domainLevel, Long domainId)
focal_class.identifier: createAffinityGroup
focal_class.modifiers: private
focal_class.parameters: (final AffinityGroupProcessor processor, final Account owner, final ACLType aclType, final String affinityGroupName, final String
              affinityGroupType, final String description, boolean domainLevel, Long domainId)
focal_class.return: AffinityGroupVO
focal_class.signature: AffinityGroupVO createAffinityGroup(final AffinityGroupProcessor processor, final Account owner, final ACLType aclType, final String affinityGroupName, final String
              affinityGroupType, final String description, boolean domainLevel, Long domainId)
focal_class.class_method_signature: AffinityGroupServiceImpl.getDomain(final Long domainId)
focal_class.full_signature: private DomainVO getDomain(final Long domainId)
focal_class.identifier: getDomain
focal_class.modifiers: private
focal_class.parameters: (final Long domainId)
focal_class.return: DomainVO
focal_class.signature: DomainVO getDomain(final Long domainId)
focal_class.class_method_signature: AffinityGroupServiceImpl.verifyAffinityGroupNameInUse(final long accountId, final long domainId, final String affinityGroupName)
focal_class.full_signature: private void verifyAffinityGroupNameInUse(final long accountId, final long domainId, final String affinityGroupName)
focal_class.identifier: verifyAffinityGroupNameInUse
focal_class.modifiers: private
focal_class.parameters: (final long accountId, final long domainId, final String affinityGroupName)
focal_class.return: void
focal_class.signature: void verifyAffinityGroupNameInUse(final long accountId, final long domainId, final String affinityGroupName)
focal_class.class_method_signature: AffinityGroupServiceImpl.verifyDomainLevelAffinityGroupName(final boolean domainLevel, final long domainId, final String affinityGroupName)
focal_class.full_signature: private void verifyDomainLevelAffinityGroupName(final boolean domainLevel, final long domainId, final String affinityGroupName)
focal_class.identifier: verifyDomainLevelAffinityGroupName
focal_class.modifiers: private
focal_class.parameters: (final boolean domainLevel, final long domainId, final String affinityGroupName)
focal_class.return: void
focal_class.signature: void verifyDomainLevelAffinityGroupName(final boolean domainLevel, final long domainId, final String affinityGroupName)
focal_class.class_method_signature: AffinityGroupServiceImpl.deleteAffinityGroup(final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.full_signature: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") public boolean deleteAffinityGroup(final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.identifier: deleteAffinityGroup
focal_class.modifiers: @Override @DB @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") public
focal_class.parameters: (final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.return: boolean
focal_class.signature: boolean deleteAffinityGroup(final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.class_method_signature: AffinityGroupServiceImpl.getAffinityGroup(final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.full_signature: private AffinityGroupVO getAffinityGroup(final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.identifier: getAffinityGroup
focal_class.modifiers: private
focal_class.parameters: (final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.return: AffinityGroupVO
focal_class.signature: AffinityGroupVO getAffinityGroup(final Long affinityGroupId, final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.class_method_signature: AffinityGroupServiceImpl.getAffinityGroupByName(final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.full_signature: private AffinityGroupVO getAffinityGroupByName(final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.identifier: getAffinityGroupByName
focal_class.modifiers: private
focal_class.parameters: (final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.return: AffinityGroupVO
focal_class.signature: AffinityGroupVO getAffinityGroupByName(final String account, final Long projectId, final Long domainId, final String affinityGroupName)
focal_class.class_method_signature: AffinityGroupServiceImpl.deleteAffinityGroup(final Long affinityGroupId)
focal_class.full_signature: private void deleteAffinityGroup(final Long affinityGroupId)
focal_class.identifier: deleteAffinityGroup
focal_class.modifiers: private
focal_class.parameters: (final Long affinityGroupId)
focal_class.return: void
focal_class.signature: void deleteAffinityGroup(final Long affinityGroupId)
focal_class.class_method_signature: AffinityGroupServiceImpl.listAffinityGroupTypes()
focal_class.full_signature: @Override public List<String> listAffinityGroupTypes()
focal_class.identifier: listAffinityGroupTypes
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: List<String>
focal_class.signature: List<String> listAffinityGroupTypes()
focal_class.class_method_signature: AffinityGroupServiceImpl.getAffinityTypeToProcessorMap()
focal_class.full_signature: protected Map<String, AffinityGroupProcessor> getAffinityTypeToProcessorMap()
focal_class.identifier: getAffinityTypeToProcessorMap
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: Map<String, AffinityGroupProcessor>
focal_class.signature: Map<String, AffinityGroupProcessor> getAffinityTypeToProcessorMap()
focal_class.class_method_signature: AffinityGroupServiceImpl.isAdminControlledGroup(final AffinityGroup group)
focal_class.full_signature: @Override public boolean isAdminControlledGroup(final AffinityGroup group)
focal_class.identifier: isAdminControlledGroup
focal_class.modifiers: @Override public
focal_class.parameters: (final AffinityGroup group)
focal_class.return: boolean
focal_class.signature: boolean isAdminControlledGroup(final AffinityGroup group)
focal_class.class_method_signature: AffinityGroupServiceImpl.getAffinityGroup(final Long groupId)
focal_class.full_signature: @Override public AffinityGroup getAffinityGroup(final Long groupId)
focal_class.identifier: getAffinityGroup
focal_class.modifiers: @Override public
focal_class.parameters: (final Long groupId)
focal_class.return: AffinityGroup
focal_class.signature: AffinityGroup getAffinityGroup(final Long groupId)
focal_class.class_method_signature: AffinityGroupServiceImpl.updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds)
focal_class.full_signature: @Override public UserVm updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds)
focal_class.identifier: updateVMAffinityGroups
focal_class.modifiers: @Override public
focal_class.parameters: (final Long vmId, final List<Long> affinityGroupIds)
focal_class.return: UserVm
focal_class.signature: UserVm updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds)
focal_class.class_method_signature: AffinityGroupServiceImpl.isAffinityGroupProcessorAvailable(final String affinityGroupType)
focal_class.full_signature: @Override public boolean isAffinityGroupProcessorAvailable(final String affinityGroupType)
focal_class.identifier: isAffinityGroupProcessorAvailable
focal_class.modifiers: @Override public
focal_class.parameters: (final String affinityGroupType)
focal_class.return: boolean
focal_class.signature: boolean isAffinityGroupProcessorAvailable(final String affinityGroupType)
focal_class.class_method_signature: AffinityGroupServiceImpl.getAffinityGroupProcessorForType(final String affinityGroupType)
focal_class.full_signature: private AffinityGroupProcessor getAffinityGroupProcessorForType(final String affinityGroupType)
focal_class.identifier: getAffinityGroupProcessorForType
focal_class.modifiers: private
focal_class.parameters: (final String affinityGroupType)
focal_class.return: AffinityGroupProcessor
focal_class.signature: AffinityGroupProcessor getAffinityGroupProcessorForType(final String affinityGroupType)
focal_class.class_method_signature: AffinityGroupServiceImpl.isAffinityGroupAvailableInDomain(final long affinityGroupId, final long domainId)
focal_class.full_signature: @Override public boolean isAffinityGroupAvailableInDomain(final long affinityGroupId, final long domainId)
focal_class.identifier: isAffinityGroupAvailableInDomain
focal_class.modifiers: @Override public
focal_class.parameters: (final long affinityGroupId, final long domainId)
focal_class.return: boolean
focal_class.signature: boolean isAffinityGroupAvailableInDomain(final long affinityGroupId, final long domainId)
focal_class.superclass: extends ManagerBase
focal_method.body: @Override
      public UserVm updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds) {
          // Verify input parameters
          final UserVmVO vmInstance = _userVmDao.findById(vmId);
          if (vmInstance == null) {
              throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
          }
  
          final Account caller = CallContext.current().getCallingAccount();
          final Account owner = _accountMgr.getAccount(vmInstance.getAccountId());
  
          // check that the affinity groups exist
          for (final Long affinityGroupId : affinityGroupIds) {
              final AffinityGroupVO AffinityGroupVO = _affinityGroupDao.findById(affinityGroupId);
              if (AffinityGroupVO == null) {
                  throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
              } else {
                  // verify permissions (same as when deploying VM)
                  _accountMgr.checkAccess(caller, null, false, owner, AffinityGroupVO);
  
                  // Only Explicit Dedication can be handled in non-Stopped state
                  if ("ExplicitDedication".equals(AffinityGroupVO.getType())) {
                      // Check if VM is currently running on host Explicitly Dedicated to this domain
                      Boolean VmRunsOnDedicatedHost = false;
  
                      final Pair<List<DedicatedResourceVO>, Integer> result =
                              _dedicatedDao.searchDedicatedHosts(vmInstance.getHostId(), vmInstance.getDomainId(), null, affinityGroupId);
                      final List<DedicatedResourceVO> DedicatedResourceList = result.first();
                      for (final DedicatedResourceVO dedicatedResourceVO : DedicatedResourceList) {
                          if (dedicatedResourceVO.getHostId() != null && dedicatedResourceVO.getHostId().equals(vmInstance.getHostId())) {
                              VmRunsOnDedicatedHost = true;
                          }
                      }
  
                      if (!VmRunsOnDedicatedHost && !State.Stopped.equals(vmInstance.getState())) {
                          throw new InvalidParameterValueException("Unable update Explicit Dedication affinity groups of the virtual machine " + vmInstance.toString() +
                                  " " + "in state " + vmInstance.getState() + "; make sure the virtual machine is either stopped or running on a host that is part of the " +
                                  "Explicit Dedication Affinity Group.");
                      }
                  } else {
                      if (!State.Stopped.equals(vmInstance.getState())) {
                          throw new InvalidParameterValueException("Unable update affinity groups of the virtual machine " + vmInstance.toString() + " " + "in state " +
                                  vmInstance.getState() + "; make sure the virtual machine is stopped and not in an error state before updating.");
                      }
                  }
                  // Root admin has access to both VM and AG by default, but make sure the
                  // owner of these entities is same
                  if (caller.getId() == Account.ACCOUNT_ID_SYSTEM || _accountMgr.isRootAdmin(caller.getId())) {
                      if (!_affinityGroupService.isAffinityGroupAvailableInDomain(AffinityGroupVO.getId(), owner.getDomainId())) {
                          throw new PermissionDeniedException("Affinity Group " + AffinityGroupVO + " does not belong to the VM's domain");
                      }
                  }
              }
          }
          _affinityGroupVMMapDao.updateMap(vmId, affinityGroupIds);
          if (s_logger.isDebugEnabled()) {
              s_logger.debug("Updated VM :" + vmId + " affinity groups to =" + affinityGroupIds);
          }
          // APIResponseHelper will pull out the updated affinitygroups.
          return vmInstance;
      }
focal_method.class_method_signature: AffinityGroupServiceImpl.updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds)
focal_method.full_signature: @Override public UserVm updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds)
focal_method.identifier: updateVMAffinityGroups
focal_method.invocations: findById getCallingAccount current getAccount getAccountId findById checkAccess equals getType searchDedicatedHosts getHostId getDomainId first getHostId equals getHostId getHostId equals getState toString getState equals getState toString getState getId isRootAdmin getId isAffinityGroupAvailableInDomain getId getDomainId updateMap isDebugEnabled debug
focal_method.modifiers: @Override public
focal_method.parameters: (final Long vmId, final List<Long> affinityGroupIds)
focal_method.return: UserVm
focal_method.signature: UserVm updateVMAffinityGroups(final Long vmId, final List<Long> affinityGroupIds)