Skip to content

Commit cd72e2a

Browse files
committed
fix a bug in listServiceOffering with vmId
1 parent db890bc commit cd72e2a

1 file changed

Lines changed: 35 additions & 24 deletions

File tree

server/src/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,27 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
24232423
}
24242424
}
24252425

2426+
if (vmId != null) {
2427+
UserVmVO vmInstance = _userVmDao.findById(vmId);
2428+
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
2429+
InvalidParameterValueException ex = new InvalidParameterValueException(
2430+
"unable to find a virtual machine with specified id");
2431+
ex.addProxyObject(vmId.toString(), "vmId");
2432+
throw ex;
2433+
}
2434+
2435+
_accountMgr.checkAccess(caller, null, true, vmInstance);
2436+
2437+
ServiceOfferingVO offering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
2438+
sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId());
2439+
2440+
// Only return offerings with the same Guest IP type and storage
2441+
// pool preference
2442+
// sc.addAnd("guestIpType", SearchCriteria.Op.EQ,
2443+
// offering.getGuestIpType());
2444+
sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
2445+
}
2446+
24262447
// boolean includePublicOfferings = false;
24272448
if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
24282449
|| caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
@@ -2432,11 +2453,20 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
24322453
}
24332454
// find all domain Id up to root domain for this account
24342455
List<Long> domainIds = new ArrayList<Long>();
2435-
DomainVO domainRecord = _domainDao.findById(caller.getDomainId());
2436-
if (domainRecord == null) {
2437-
s_logger.error("Could not find the domainId for account:" + caller.getAccountName());
2438-
throw new CloudAuthenticationException("Could not find the domainId for account:"
2439-
+ caller.getAccountName());
2456+
DomainVO domainRecord;
2457+
if (vmId != null) {
2458+
UserVmVO vmInstance = _userVmDao.findById(vmId);
2459+
domainRecord = _domainDao.findById(vmInstance.getDomainId());
2460+
if ( domainRecord == null ){
2461+
s_logger.error("Could not find the domainId for vmId:" + vmId);
2462+
throw new CloudAuthenticationException("Could not find the domainId for vmId:" + vmId);
2463+
}
2464+
} else {
2465+
domainRecord = _domainDao.findById(caller.getDomainId());
2466+
if ( domainRecord == null ){
2467+
s_logger.error("Could not find the domainId for account:" + caller.getAccountName());
2468+
throw new CloudAuthenticationException("Could not find the domainId for account:" + caller.getAccountName());
2469+
}
24402470
}
24412471
domainIds.add(domainRecord.getId());
24422472
while (domainRecord.getParent() != null) {
@@ -2466,25 +2496,6 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
24662496
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
24672497

24682498
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
2469-
} else if (vmId != null) {
2470-
UserVmVO vmInstance = _userVmDao.findById(vmId);
2471-
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
2472-
InvalidParameterValueException ex = new InvalidParameterValueException(
2473-
"unable to find a virtual machine with specified id");
2474-
ex.addProxyObject(vmId.toString(), "vmId");
2475-
throw ex;
2476-
}
2477-
2478-
_accountMgr.checkAccess(caller, null, true, vmInstance);
2479-
2480-
ServiceOfferingVO offering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
2481-
sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId());
2482-
2483-
// Only return offerings with the same Guest IP type and storage
2484-
// pool preference
2485-
// sc.addAnd("guestIpType", SearchCriteria.Op.EQ,
2486-
// offering.getGuestIpType());
2487-
sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
24882499
}
24892500

24902501
if (id != null) {

0 commit comments

Comments
 (0)