bug 7434: list direct service offerings for account only when 1) account has Account specific Direct vlan range 2) there are Zone wide Direct vlan ranges

status 7434: resolved fixed
This commit is contained in:
alena 2011-02-10 13:57:11 -08:00
parent 9fa599f224
commit c8949abb7a
3 changed files with 69 additions and 5 deletions

View File

@ -27,8 +27,8 @@ import org.apache.log4j.Logger;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
import com.cloud.server.Criteria;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.ServiceOffering.GuestIpType;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.vm.UserVmVO;
@ -47,6 +47,9 @@ public class ListServiceOfferingsCmd extends BaseCmd {
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
}
public String getName() {
@ -65,6 +68,9 @@ public class ListServiceOfferingsCmd extends BaseCmd {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
Long startIndex = Long.valueOf(0);
int pageSizeNum = 50;
@ -81,6 +87,7 @@ public class ListServiceOfferingsCmd extends BaseCmd {
c.addCriteria(Criteria.KEYWORD, keyword);
c.addCriteria(Criteria.ID, id);
c.addCriteria(Criteria.NAME, name);
c.addCriteria(Criteria.DATACENTERID, zoneId);
//If vmId is present in the list of parameters, verify it
if (vmId != null) {
@ -96,6 +103,33 @@ public class ListServiceOfferingsCmd extends BaseCmd {
if (keyword == null)
c.addCriteria(Criteria.INSTANCEID, vmId);
}
//add account information to the criteria
Long accountId = null;
if ((account == null) || isAdmin(account.getType())) {
if (domainId != null) {
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list service offerings.");
}
if (accountName != null) {
account = getManagementServer().findActiveAccount(accountName, domainId);
if (account == null) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find account " + accountName + " in domain " + domainId);
}
accountId = account.getId();
}
} else if (account != null && isAdmin(account.getType())) {
accountId = account.getId();
}
} else {
accountId = account.getId();
}
if (accountId != null) {
c.addCriteria(Criteria.ACCOUNTID, accountId);
}
List<ServiceOfferingVO> offerings = getManagementServer().searchForServiceOfferings(c);
if (offerings == null) {

View File

@ -31,15 +31,13 @@ import com.cloud.api.ServerApiException;
import com.cloud.async.AsyncJobVO;
import com.cloud.domain.DomainVO;
import com.cloud.host.HostVO;
import com.cloud.network.security.NetworkGroupVMMapVO;
import com.cloud.network.security.NetworkGroupVO;
import com.cloud.server.Criteria;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.vm.VmStats;
import com.cloud.vm.UserVm;
import com.cloud.vm.VmStats;
public class ListVMsCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName());

View File

@ -3786,6 +3786,8 @@ public class ManagementServerImpl implements ManagementServer {
Object vmIdObj = c.getCriteria(Criteria.INSTANCEID);
Object id = c.getCriteria(Criteria.ID);
Object keyword = c.getCriteria(Criteria.KEYWORD);
Object accountId = c.getCriteria(Criteria.ACCOUNTID);
Object zoneId = c.getCriteria(Criteria.DATACENTERID);
if (keyword != null) {
SearchCriteria ssc = _offeringsDao.createSearchCriteria();
@ -3814,10 +3816,40 @@ public class ManagementServerImpl implements ManagementServer {
sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
}
}
//if account doesn't have direct ip addresses and there are no direct Zone wide vlans, return virtual service offerings only
List<VlanVO> accountDirectVlans = new ArrayList<VlanVO>();
List<VlanVO> zoneDirectVlans = new ArrayList<VlanVO>();
if (accountId != null || zoneId != null) {
if (accountId != null && zoneId != null) {
accountDirectVlans = _vlanDao.listVlansForAccountByType(null, ((Long)accountId).longValue(), VlanType.DirectAttached);
zoneDirectVlans = listZoneWideVlansByType(VlanType.DirectAttached, (Long)zoneId);
} else if (zoneId != null) {
zoneDirectVlans = listZoneWideVlansByType(VlanType.DirectAttached, (Long)zoneId);
}
if (accountDirectVlans.isEmpty() && zoneDirectVlans.isEmpty()) {
sc.addAnd("guestIpType", SearchCriteria.Op.EQ, GuestIpType.Virtualized);
}
}
return _offeringsDao.search(sc, searchFilter);
}
//lists zone wide vlans by type
private List<VlanVO> listZoneWideVlansByType(VlanType type, long zoneId) {
List<VlanVO> zoneVlans = _vlanDao.listByZoneAndType(zoneId, type);
List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
for (VlanVO vlan : zoneVlans) {
if (_accountVlanMapDao.listAccountVlanMapsByVlan(vlan.getId()).isEmpty()) {
zoneWideVlans.add(vlan);
}
}
return zoneWideVlans;
}
@Override
public List<ClusterVO> searchForClusters(Criteria c) {
Filter searchFilter = new Filter(ClusterVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());