-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CLOUDSTACK-9432: cluster/host dedicated to a domain is owned by the root domain #2124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,7 @@ public AffinityGroup createAffinityGroup(CreateAffinityGroupCmd createAffinityGr | |
| @DB | ||
| @Override | ||
| public AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType, | ||
| final String description) { | ||
| final String description) { | ||
|
|
||
| // validate the affinityGroupType | ||
| Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap(); | ||
|
|
@@ -158,7 +158,7 @@ public AffinityGroup createAffinityGroup(final String accountName, final Long pr | |
| verifyAffinityGroupNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName); | ||
| verifyDomainLevelAffinityGroupName(domainLevel, owner.getDomainId(), affinityGroupName); | ||
|
|
||
| AffinityGroupVO group = createAffinityGroup(processor, owner, aclType, affinityGroupName, affinityGroupType, description); | ||
| AffinityGroupVO group = createAffinityGroup(processor, owner, aclType, affinityGroupName, affinityGroupType, description, domainLevel, domainId); | ||
|
|
||
| if (s_logger.isDebugEnabled()) { | ||
| s_logger.debug("Created affinity group =" + affinityGroupName); | ||
|
|
@@ -176,25 +176,27 @@ private void verifyAccessToDomainWideProcessor(Account caller, AffinityGroupProc | |
| } | ||
| } | ||
|
|
||
| private AffinityGroupVO createAffinityGroup(final AffinityGroupProcessor processor, final Account owner, final ACLType aclType, final String affinityGroupName, final String affinityGroupType, final String description) { | ||
| 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) { | ||
|
|
||
| final Long affinityGroupDomainId = getDomainIdBasedOnDomainLevel(owner, domainLevel, domainId); | ||
|
|
||
| return Transaction.execute(new TransactionCallback<AffinityGroupVO>() { | ||
| @Override | ||
| public AffinityGroupVO doInTransaction(TransactionStatus status) { | ||
| AffinityGroupVO group = | ||
| new AffinityGroupVO(affinityGroupName, affinityGroupType, description, owner.getDomainId(), owner.getId(), aclType); | ||
| AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, affinityGroupDomainId, owner.getId(), aclType); | ||
| _affinityGroupDao.persist(group); | ||
|
|
||
| if (aclType == ACLType.Domain) { | ||
| boolean subDomainAccess = false; | ||
| subDomainAccess = processor.subDomainAccess(); | ||
| AffinityGroupDomainMapVO domainMap = new AffinityGroupDomainMapVO(group.getId(), owner.getDomainId(), | ||
| AffinityGroupDomainMapVO domainMap = new AffinityGroupDomainMapVO(group.getId(), affinityGroupDomainId, | ||
| subDomainAccess); | ||
| _affinityGroupDomainMapDao.persist(domainMap); | ||
| //send event for storing the domain wide resource access | ||
| Map<String, Object> params = new HashMap<String, Object>(); | ||
| params.put(ApiConstants.ENTITY_TYPE, AffinityGroup.class); | ||
| params.put(ApiConstants.ENTITY_ID, group.getId()); | ||
| params.put(ApiConstants.DOMAIN_ID, owner.getDomainId()); | ||
| params.put(ApiConstants.DOMAIN_ID, affinityGroupDomainId); | ||
| params.put(ApiConstants.SUBDOMAIN_ACCESS, subDomainAccess); | ||
| _messageBus.publish(_name, EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, PublishScope.LOCAL, | ||
| params); | ||
|
|
@@ -205,6 +207,20 @@ public AffinityGroupVO doInTransaction(TransactionStatus status) { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * If the account is null (domainLevel is true), then returns the domain id passed as a | ||
| * parameter; otherwise (domainLevel is false) it returns the domain id from the owner account. | ||
| * | ||
| * @note: this method fixes a critical bug. More details in JIRA ticket CLOUDSTACK-9432. | ||
| */ | ||
| protected Long getDomainIdBasedOnDomainLevel(final Account owner, boolean domainLevel, Long domainId) { | ||
| Long domainIdBasedOnDomainLevel = owner.getDomainId(); | ||
| if (domainLevel) { | ||
| domainIdBasedOnDomainLevel = domainId; | ||
| } | ||
| return domainIdBasedOnDomainLevel; | ||
| } | ||
|
|
||
| private DomainVO getDomain(Long domainId) { | ||
| DomainVO domain = _domainDao.findById(domainId); | ||
| if (domain == null) { | ||
|
|
@@ -225,6 +241,7 @@ private void verifyDomainLevelAffinityGroupName(boolean domainLevel, long domain | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| @DB | ||
| @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") | ||
| public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long projectId, Long domainId, String affinityGroupName) { | ||
|
|
@@ -258,7 +275,7 @@ private AffinityGroupVO getAffinityGroup(Long affinityGroupId, String account, L | |
| throw new InvalidParameterValueException("Either the affinity group Id or group name must be specified to delete the group"); | ||
| } | ||
| if (group == null) { | ||
| throw new InvalidParameterValueException("Unable to find affinity group " + (affinityGroupId == null ? affinityGroupName : affinityGroupId)); | ||
| throw new InvalidParameterValueException("Unable to find affinity group " + (affinityGroupId == null ? affinityGroupName : affinityGroupId)); | ||
| } | ||
| return group; | ||
| } | ||
|
|
@@ -292,10 +309,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { | |
| List<AffinityGroupVMMapVO> affinityGroupVmMap = _affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId); | ||
| if (!affinityGroupVmMap.isEmpty()) { | ||
| SearchBuilder<AffinityGroupVMMapVO> listByAffinityGroup = _affinityGroupVMMapDao.createSearchBuilder(); | ||
| listByAffinityGroup.and("affinityGroupId", listByAffinityGroup.entity().getAffinityGroupId(), SearchCriteria.Op.EQ); | ||
| listByAffinityGroup.and("affinityGroupId", listByAffinityGroup.entity().getAffinityGroupId(), SearchCriteria.Op.EQ); | ||
| listByAffinityGroup.done(); | ||
| SearchCriteria<AffinityGroupVMMapVO> sc = listByAffinityGroup.create(); | ||
| sc.setParameters("affinityGroupId", affinityGroupId); | ||
| sc.setParameters("affinityGroupId", affinityGroupId); | ||
|
|
||
| _affinityGroupVMMapDao.lockRows(sc, null, true); | ||
| _affinityGroupVMMapDao.remove(sc); | ||
|
|
@@ -323,12 +340,12 @@ public List<String> listAffinityGroupTypes() { | |
| List<String> types = new ArrayList<String>(); | ||
|
|
||
| for (AffinityGroupProcessor processor : _affinityProcessors) { | ||
| if (processor.isAdminControlledGroup()) { | ||
| continue; // we dont list the type if this group can be | ||
| // created only as an admin/system operation. | ||
| } | ||
| types.add(processor.getType()); | ||
| if (processor.isAdminControlledGroup()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these formatting changes needed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first I tried to submit without those changes in lines which I did not touch; however, it failed to pass in check style validation. When my environment formatted the code (with the CloudStack style), all checks have passed. I can review those changes and see if I can minimize them. But some will be necessary.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, ok. |
||
| continue; // we dont list the type if this group can be | ||
| // created only as an admin/system operation. | ||
| } | ||
| types.add(processor.getType()); | ||
| } | ||
|
|
||
| return types; | ||
| } | ||
|
|
@@ -394,20 +411,20 @@ public boolean preStateTransitionEvent(State oldState, Event event, State newSta | |
|
|
||
| @Override | ||
| public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) { | ||
| if (!status) { | ||
| return false; | ||
| } | ||
| State newState = transition.getToState(); | ||
| if ((newState == State.Expunging) || (newState == State.Error)) { | ||
| // cleanup all affinity groups associations of the Expunged VM | ||
| SearchCriteria<AffinityGroupVMMapVO> sc = _affinityGroupVMMapDao.createSearchCriteria(); | ||
| sc.addAnd("instanceId", SearchCriteria.Op.EQ, vo.getId()); | ||
| _affinityGroupVMMapDao.expunge(sc); | ||
| } | ||
| return true; | ||
| if (!status) { | ||
| return false; | ||
| } | ||
| State newState = transition.getToState(); | ||
| if ((newState == State.Expunging) || (newState == State.Error)) { | ||
| // cleanup all affinity groups associations of the Expunged VM | ||
| SearchCriteria<AffinityGroupVMMapVO> sc = _affinityGroupVMMapDao.createSearchCriteria(); | ||
| sc.addAnd("instanceId", SearchCriteria.Op.EQ, vo.getId()); | ||
| _affinityGroupVMMapDao.expunge(sc); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| @Override | ||
| public UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds) { | ||
| // Verify input parameters | ||
| UserVmVO vmInstance = _userVmDao.findById(vmId); | ||
|
|
@@ -419,7 +436,7 @@ public UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds) { | |
| if (!vmInstance.getState().equals(State.Stopped)) { | ||
| s_logger.warn("Unable to update affinity groups of the virtual machine " + vmInstance.toString() + " in state " + 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."); | ||
| vmInstance.getState() + "; make sure the virtual machine is stopped and not in an error state before updating."); | ||
| } | ||
|
|
||
| Account caller = CallContext.current().getCallingAccount(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelweingartner thanks for the review. The code now is in a method with tests and documentation.