From 4d0d47f6fcba0b1b720e31be62d75ebcddb413f3 Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 21 Jan 2011 10:54:59 -0800 Subject: [PATCH] listVlanIpRanges api: for Account specific Virtual ip range return account information taken from account_vlan_map table instead of taking it from corresponding network --- .../configuration/ConfigurationService.java | 3 +++ server/src/com/cloud/api/ApiDBUtils.java | 4 ++++ .../src/com/cloud/api/ApiResponseHelper.java | 20 +++++----------- .../ConfigurationManagerImpl.java | 24 +++++++++++++++++++ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java index e2ad06e1b28..0bb032b22ae 100644 --- a/api/src/com/cloud/configuration/ConfigurationService.java +++ b/api/src/com/cloud/configuration/ConfigurationService.java @@ -31,6 +31,7 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; +import com.cloud.user.Account; public interface ConfigurationService { @@ -188,5 +189,7 @@ public interface ConfigurationService { NetworkOffering getNetworkOffering(long id); Integer getNetworkRate(long networkOfferingId); + + Account getVlanAccount(long vlanId); } diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 67f5b7b4c6a..37bc5da460a 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -528,4 +528,8 @@ public class ApiDBUtils { return _configMgr.getNetworkRate(networkOfferingId); } + public static Account getVlanAccount(long vlanId) { + return _configMgr.getVlanAccount(vlanId); + } + } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index eecdb703898..bd274c51ad7 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -568,20 +568,12 @@ public class ApiResponseHelper implements ResponseGenerator { vlanResponse.setStartIp(range[0]); vlanResponse.setEndIp(range[1]); - Long networkId = vlan.getNetworkId(); - if (networkId != null) { - vlanResponse.setNetworkId(vlan.getNetworkId()); - Network network = ApiDBUtils.findNetworkById(networkId); - if (network != null) { - Long accountId = network.getAccountId(); - //Set account information - if (accountId != null) { - Account account = ApiDBUtils.findAccountById(accountId); - vlanResponse.setAccountName(account.getAccountName()); - vlanResponse.setDomainId(account.getDomainId()); - vlanResponse.setDomainName(ApiDBUtils.findDomainById(account.getDomainId()).getName()); - } - } + vlanResponse.setNetworkId(vlan.getNetworkId()); + Account owner = ApiDBUtils.getVlanAccount(vlan.getId()); + if (owner != null) { + vlanResponse.setAccountName(owner.getAccountName()); + vlanResponse.setDomainId(owner.getDomainId()); + vlanResponse.setDomainName(ApiDBUtils.findDomainById(owner.getDomainId()).getName()); } vlanResponse.setObjectName("vlan"); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index ff4532d4480..ab218a28325 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2782,4 +2782,28 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return networkRate; } + + @Override + public Account getVlanAccount(long vlanId) { + Vlan vlan = _vlanDao.findById(vlanId); + Long accountId = null; + + //if vlan is Virtual Account specific, get vlan information from the accountVlanMap; otherwise get account information from the network + if (vlan.getVlanType() == VlanType.VirtualNetwork) { + List maps = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanId); + if (maps != null && !maps.isEmpty()) { + return _accountMgr.getAccount(maps.get(0).getAccountId()); + } + } + + Long networkId = vlan.getNetworkId(); + if (networkId != null) { + Network network = _networkMgr.getNetwork(networkId); + if (network != null) { + accountId = network.getAccountId(); + } + } + + return _accountMgr.getAccount(accountId); + } }