Skip to content

Commit 91d054c

Browse files
sedukullDaanHoogland
authored andcommitted
CLOUDSTACK-6793: Fixed an invalid Domain Id Issue
Signed-off-by: sedukull <santhosh.edukulla@gmail.com>
1 parent 96bfa8a commit 91d054c

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎engine/schema/src/com/cloud/user/dao/AccountDao.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@ public interface AccountDao extends GenericDao<AccountVO, Long> {
6363
Account findActiveNonProjectAccount(String accountName, Long domainId);
6464

6565
List<Long> getAccountIdsForDomains(List<Long> ids);
66+
67+
/*
68+
@Desc: Retrieves the DomainId for a given Account Id
69+
@Input: id : Id of the Account
70+
@Output: DomainId matching for the given Account Id. Returns -1
71+
in case of no match;
72+
*/
73+
long getDomainIdForGivenAccountId(long id);
74+
6675
}

‎engine/schema/src/com/cloud/user/dao/AccountDaoImpl.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,20 @@ public List<Long> getAccountIdsForDomains(List<Long> domainIds) {
278278
return customSearch(sc, null);
279279
}
280280

281+
@Override
282+
public long getDomainIdForGivenAccountId(long id) {
283+
long domain_id = -1;
284+
try {
285+
AccountVO account_vo = findById(id);
286+
domain_id = account_vo.getDomainId();
287+
}
288+
catch (Exception e) {
289+
s_logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage());
290+
}
291+
finally {
292+
return domain_id;
293+
}
294+
}
295+
296+
281297
}

‎server/src/com/cloud/tags/TaggedResourceManagerImpl.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28+
import com.cloud.user.dao.AccountDao;
29+
import com.cloud.utils.exception.CloudRuntimeException;
2830
import org.apache.cloudstack.api.Identity;
2931
import org.apache.cloudstack.api.InternalIdentity;
3032
import org.apache.cloudstack.context.CallContext;
@@ -33,7 +35,6 @@
3335

3436
import com.cloud.api.query.dao.ResourceTagJoinDao;
3537
import com.cloud.dc.DataCenterVO;
36-
import com.cloud.domain.Domain;
3738
import com.cloud.domain.PartOf;
3839
import com.cloud.event.ActionEvent;
3940
import com.cloud.event.EventTypes;
@@ -136,6 +137,8 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
136137
ResourceTagJoinDao _resourceTagJoinDao;
137138
@Inject
138139
DomainManager _domainMgr;
140+
@Inject
141+
AccountDao _accountDao;
139142

140143

141144
@Override
@@ -185,10 +188,10 @@ private Pair<Long, Long> getAccountDomain(long resourceId, ResourceObjectType re
185188
accountId = Account.ACCOUNT_ID_SYSTEM;
186189
}
187190

188-
if (domainId == null) {
189-
domainId = Domain.ROOT_DOMAIN;
191+
if ( ((accountId != null) && (domainId == -1)) || (domainId == null) )
192+
{
193+
domainId = _accountDao.getDomainIdForGivenAccountId(accountId);
190194
}
191-
192195
return new Pair<Long, Long>(accountId, domainId);
193196
}
194197

@@ -226,6 +229,11 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
226229
Pair<Long, Long> accountDomainPair = getAccountDomain(id, resourceType);
227230
Long domainId = accountDomainPair.second();
228231
Long accountId = accountDomainPair.first();
232+
233+
if ((domainId != null) && (domainId == -1))
234+
{
235+
throw new CloudRuntimeException("Invalid DomainId : -1");
236+
}
229237
if (accountId != null) {
230238
_accountMgr.checkAccess(caller, null, false, _accountMgr.getAccount(accountId));
231239
} else if (domainId != null && !_accountMgr.isNormalUser(caller.getId())) {

0 commit comments

Comments
 (0)