You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/08/02 04:08:32 UTC
[10/44] git commit: Fixed numerous bugs in listNetworks call related
to filtering by projectId/listAll/domainId/etc. All the rules below are
followed now:
Fixed numerous bugs in listNetworks call related to filtering by projectId/listAll/domainId/etc. All the rules below are followed now:
1) When account/domainId or projectId are passed in:
* list all account specific networks of the account/project
* list all domain level networks from the domainId + subdomains if the targeted network has allowSubdomainAccess = true
In other words, we use all the networks that can be used for vm deployment by account/domainId.
If listAll is not specified in the request, account/domainId are being defaulted to the account/domainId of the caller
listAll is ignored if the call is being done by the regular user.
2) listAll is passed in by the Root admin, we list:
* all Account specific networks in the system
* all domain specific networks in the system
3) listAll is passed by the Domain admin, we list:
* All Account specific networks belonging to domain/subdomains of the domain admin.
* All domain specific networks belonging to domain/subdomains of the domain admin
* All domain specific networks allowing subdomain access belonging to the parent domain.
4) domainId - can be passed either with or without listAll. We list:
* all account specific networks belonging to the domain
* all domain specific networks of the domain
* all domain specific networks of the subdomains if isRecursive = true is passed in
Conflicts:
server/src/com/cloud/network/NetworkManagerImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/11687471
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/11687471
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/11687471
Branch: refs/heads/master
Commit: 1168747128b562029a647496cc750949b80c0f17
Parents: 10cf9c2
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Aug 1 14:46:22 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Aug 1 18:46:36 2012 -0700
----------------------------------------------------------------------
.../src/com/cloud/network/NetworkManagerImpl.java | 104 ++++++++++-----
1 files changed, 70 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/11687471/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 77da24e..f9c2717 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2751,15 +2751,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
- if (!_accountMgr.isAdmin(caller.getType()) || !listAll) {
+ if (!_accountMgr.isAdmin(caller.getType()) || (!listAll && (projectId != null && projectId != -1 && domainId == null))) {
permittedAccounts.add(caller.getId());
domainId = caller.getDomainId();
}
- if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
- domainId = caller.getDomainId();
- }
-
// set project information
boolean skipProjectNetworks = true;
if (projectId != null) {
@@ -2782,8 +2778,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
skipProjectNetworks = false;
}
- path = _domainDao.findById(caller.getDomainId()).getPath();
- if (listAll) {
+ if (domainId != null) {
+ path = _domainDao.findById(domainId).getPath();
+ } else {
+ path = _domainDao.findById(caller.getDomainId()).getPath();
+ }
+
+ if (listAll && domainId == null) {
isRecursive = true;
}
@@ -2821,37 +2822,50 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
- if (skipProjectNetworks) {
- SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
- accountSearch.and("type", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
- sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
- }
+ SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
+ accountSearch.and("typeNEQ", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
+ accountSearch.and("typeEQ", accountSearch.entity().getType(), SearchCriteria.Op.EQ);
+
+
+ sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+
List<NetworkVO> networksToReturn = new ArrayList<NetworkVO>();
- if (isSystem == null || !isSystem) {
- // Get domain level networks
- if (domainId != null) {
- networksToReturn
- .addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId,
- guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired,
- specifyIpRanges, tags), searchFilter,domainId));
- }
-
+ if (isSystem == null || !isSystem) {
if (!permittedAccounts.isEmpty()) {
+ //get account level networks
networksToReturn.addAll(listAccountSpecificNetworks(
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, tags), searchFilter,
permittedAccounts));
- } else if (domainId == null) {
+ //get domain level networks
+ if (domainId != null) {
+ networksToReturn
+ .addAll(listDomainLevelNetworks(
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
+ physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, tags), searchFilter,
+ domainId, false));
+ }
+ } else {
+ //add account specific networks
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, tags), searchFilter, path,
isRecursive));
+ //add domain specific networks of domain + parent domains
networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(
buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
- physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, tags), searchFilter, path,
+ physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, tags), searchFilter, path,
isRecursive));
+ //add networks of subdomains
+ if (domainId == null) {
+ networksToReturn
+ .addAll(listDomainLevelNetworks(
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
+ physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, tags), searchFilter,
+ caller.getDomainId(), true));
+ }
}
} else {
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId,
@@ -2952,9 +2966,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
if (skipProjectNetworks) {
- sc.setJoinParameters("accountSearch", "type", Account.ACCOUNT_TYPE_PROJECT);
+ sc.setJoinParameters("accountSearch", "typeNEQ", Account.ACCOUNT_TYPE_PROJECT);
+ } else {
+ sc.setJoinParameters("accountSearch", "typeEQ", Account.ACCOUNT_TYPE_PROJECT);
}
-
+
if (restartRequired != null) {
sc.addAnd("restartRequired", SearchCriteria.Op.EQ, restartRequired);
}
@@ -2976,12 +2992,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return sc;
}
- private List<NetworkVO> listDomainLevelNetworks(SearchCriteria<NetworkVO> sc, Filter searchFilter, long domainId) {
+ private List<NetworkVO> listDomainLevelNetworks(SearchCriteria<NetworkVO> sc, Filter searchFilter, long domainId, boolean parentDomainsOnly) {
List<Long> networkIds = new ArrayList<Long>();
Set<Long> allowedDomains = _domainMgr.getDomainParentIds(domainId);
List<NetworkDomainVO> maps = _networkDomainDao.listDomainNetworkMapByDomain(allowedDomains.toArray());
for (NetworkDomainVO map : maps) {
+ if (map.getDomainId() == domainId && parentDomainsOnly) {
+ continue;
+ }
boolean subdomainAccess = (map.isSubdomainAccess() != null) ? map.isSubdomainAccess() : getAllowSubdomainAccessGlobal();
if (map.getDomainId() == domainId || subdomainAccess) {
networkIds.add(map.getNetworkId());
@@ -3028,20 +3047,37 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return _networksDao.search(sc, searchFilter);
}
- private List<NetworkVO> listDomainSpecificNetworksByDomainPath(SearchCriteria<NetworkVO> sc, Filter searchFilter, String path, boolean isRecursive) {
- SearchCriteria<NetworkVO> accountSC = _networksDao.createSearchCriteria();
- accountSC.addAnd("aclType", SearchCriteria.Op.EQ, ACLType.Domain.toString());
+ private List<NetworkVO> listDomainSpecificNetworksByDomainPath(SearchCriteria<NetworkVO> sc, Filter searchFilter,
+ String path, boolean isRecursive) {
- if (path != null) {
+ Set<Long> allowedDomains = new HashSet<Long>();
+ if (path != null) {
if (isRecursive) {
- sc.setJoinParameters("domainSearch", "path", path + "%");
+ allowedDomains = _domainMgr.getDomainChildrenIds(path);
} else {
- sc.setJoinParameters("domainSearch", "path", path);
+ Domain domain = _domainDao.findDomainByPath(path);
+ allowedDomains.add(domain.getId());
}
}
+
+ List<Long> networkIds = new ArrayList<Long>();
+
+ List<NetworkDomainVO> maps = _networkDomainDao.listDomainNetworkMapByDomain(allowedDomains.toArray());
- sc.addAnd("id", SearchCriteria.Op.SC, accountSC);
- return _networksDao.search(sc, searchFilter);
+ for (NetworkDomainVO map : maps) {
+ networkIds.add(map.getNetworkId());
+ }
+
+ if (!networkIds.isEmpty()) {
+ SearchCriteria<NetworkVO> domainSC = _networksDao.createSearchCriteria();
+ domainSC.addAnd("id", SearchCriteria.Op.IN, networkIds.toArray());
+ domainSC.addAnd("aclType", SearchCriteria.Op.EQ, ACLType.Domain.toString());
+
+ sc.addAnd("id", SearchCriteria.Op.SC, domainSC);
+ return _networksDao.search(sc, searchFilter);
+ } else {
+ return new ArrayList<NetworkVO>();
+ }
}
@Override