incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aprat...@apache.org
Subject git commit: CLOUDSTACK-596 : DeployVM command takes a lot of time to return job id Issue happens while deploying VM in advanced zone and 'networkids' parameter is not passed to deployVM command. In this case CS tries to identify a default guest network t
Date Mon, 10 Dec 2012 09:43:39 GMT
Updated Branches:
  refs/heads/master e49b3b27d -> 238c55fb6


CLOUDSTACK-596 : DeployVM command takes a lot of time to return job id Issue happens while
deploying VM in advanced zone and 'networkids' parameter is not passed to deployVM command.
In this case CS tries to identify a default guest network to be used for deploying VM. This
logic is not optimized and latency increases with increase in user accounts and guest networks.
Optimized logic for getting default network.

Signed-off-by: Koushik Das <koushik.das@citrix.com>
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/238c55fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/238c55fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/238c55fb

Branch: refs/heads/master
Commit: 238c55fb6e40220cbbf60b241a902cdc7ccf8d37
Parents: e49b3b2
Author: Koushik Das <koushik.das@citrix.com>
Authored: Mon Dec 10 13:56:51 2012 +0530
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Mon Dec 10 15:02:53 2012 +0530

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManagerImpl.java  |   13 +------
 server/src/com/cloud/network/dao/NetworkDao.java   |    2 +
 .../src/com/cloud/network/dao/NetworkDaoImpl.java  |   27 +++++++++++++-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |    7 +---
 .../test/com/cloud/vpc/dao/MockNetworkDaoImpl.java |    9 +++++
 5 files changed, 39 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/238c55fb/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 b3fdf32..3f8b085 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -4540,18 +4540,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
 
     @Override
     public List<NetworkVO> listNetworksForAccount(long accountId, long zoneId, Network.GuestType
type) {
-        List<NetworkVO> accountNetworks = new ArrayList<NetworkVO>();
-        List<NetworkVO> zoneNetworks = _networksDao.listByZone(zoneId);
-
-        for (NetworkVO network : zoneNetworks) {
-            if (!isNetworkSystem(network)) {
-                if (network.getGuestType() == Network.GuestType.Shared || !_networksDao.listBy(accountId,
network.getId()).isEmpty()) {
-                    if (type == null || type == network.getGuestType()) {
-                        accountNetworks.add(network);
-                    }
-                }
-            }
-        }
+        List<NetworkVO> accountNetworks = _networksDao.listNetworksByAccount(accountId,
zoneId, type, false);
         return accountNetworks;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/238c55fb/server/src/com/cloud/network/dao/NetworkDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/NetworkDao.java b/server/src/com/cloud/network/dao/NetworkDao.java
index a2e37b7..4079955 100644
--- a/server/src/com/cloud/network/dao/NetworkDao.java
+++ b/server/src/com/cloud/network/dao/NetworkDao.java
@@ -108,4 +108,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long>
{
     
     long countVpcNetworks(long vpcId);
 
+    List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Network.GuestType
type, boolean isSystem);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/238c55fb/server/src/com/cloud/network/dao/NetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java
index cbfec89..8228393 100644
--- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java
+++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java
@@ -72,8 +72,8 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>
implements N
     final SearchBuilder<NetworkVO> SourceNATSearch;
     final GenericSearchBuilder<NetworkVO, Long>  CountByZoneAndURI;
     final GenericSearchBuilder<NetworkVO, Long> VpcNetworksCount;
-    
-    
+    final SearchBuilder<NetworkVO> OfferingAccountNetworkSearch;
+
     ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
     NetworkAccountDaoImpl _accountsDao = ComponentLocator.inject(NetworkAccountDaoImpl.class);
     NetworkDomainDaoImpl _domainsDao = ComponentLocator.inject(NetworkDomainDaoImpl.class);
@@ -202,6 +202,17 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>
implements N
         VpcNetworksCount.select(null, Func.COUNT, VpcNetworksCount.entity().getId());
         VpcNetworksCount.done();
 
+        OfferingAccountNetworkSearch = createSearchBuilder();
+        OfferingAccountNetworkSearch.select(null, Func.DISTINCT, OfferingAccountNetworkSearch.entity().getId());
+        SearchBuilder<NetworkOfferingVO> ntwkOfferingJoin = _ntwkOffDao.createSearchBuilder();
+        ntwkOfferingJoin.and("isSystem", ntwkOfferingJoin.entity().isSystemOnly(), Op.EQ);
+        OfferingAccountNetworkSearch.join("ntwkOfferingSearch", ntwkOfferingJoin, OfferingAccountNetworkSearch.entity().getNetworkOfferingId(),
ntwkOfferingJoin.entity().getId(), JoinBuilder.JoinType.LEFT);
+        SearchBuilder<NetworkAccountVO> ntwkAccountJoin = _accountsDao.createSearchBuilder();
+        ntwkAccountJoin.and("accountId", ntwkAccountJoin.entity().getAccountId(), Op.EQ);
+        OfferingAccountNetworkSearch.join("ntwkAccountSearch", ntwkAccountJoin, OfferingAccountNetworkSearch.entity().getId(),
ntwkAccountJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        OfferingAccountNetworkSearch.and("zoneId", OfferingAccountNetworkSearch.entity().getDataCenterId(),
Op.EQ);
+        OfferingAccountNetworkSearch.and("type", OfferingAccountNetworkSearch.entity().getGuestType(),
Op.EQ);
+        OfferingAccountNetworkSearch.done();
     }
 
     @Override
@@ -551,4 +562,16 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>
implements N
         sc.setParameters("vpcId", vpcId);
         return customSearch(sc, null).get(0);
     }
+
+    @Override
+    public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Network.GuestType
type, boolean isSystem) {
+        SearchCriteria<NetworkVO> sc = OfferingAccountNetworkSearch.create();
+        sc.setJoinParameters("ntwkOfferingSearch", "isSystem", isSystem);
+        sc.setJoinParameters("ntwkAccountSearch", "accountId", accountId);
+        sc.setParameters("zoneId", zoneId);
+        sc.setParameters("type", type);
+
+        List<NetworkVO> networks = search(sc, null);
+        return networks;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/238c55fb/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 837e3f7..eeb1c78 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2262,7 +2262,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
             if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
                 // get Virtual networks
                 List<NetworkVO> virtualNetworks = _networkMgr.listNetworksForAccount(owner.getId(),
zone.getId(), Network.GuestType.Isolated);
-
                 if (virtualNetworks.isEmpty()) {
                     long physicalNetworkId = _networkMgr.findPhysicalNetworkId(zone.getId(),
requiredOfferings.get(0).getTags(), requiredOfferings.get(0).getTrafficType());
                     // Validate physical network
@@ -2278,7 +2277,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                 } else if (virtualNetworks.size() > 1) {
                     throw new InvalidParameterValueException("More than 1 default Isolated
networks are found for account " + owner + "; please specify networkIds");
                 } else {
-                    defaultNetwork = virtualNetworks.get(0);
+                    defaultNetwork = _networkDao.findById(virtualNetworks.get(0).getId());
                 }
             } else {
                 throw new InvalidParameterValueException("Required network offering id="
+ requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); 
@@ -3701,7 +3700,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                     if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled)
{
                         // get Virtual networks
                         List<NetworkVO> virtualNetworks = _networkMgr.listNetworksForAccount(newAccount.getId(),
zone.getId(), Network.GuestType.Isolated);
-
                         if (virtualNetworks.isEmpty()) {
                             long physicalNetworkId = _networkMgr.findPhysicalNetworkId(zone.getId(),
requiredOfferings.get(0).getTags(), requiredOfferings.get(0).getTrafficType());
                             // Validate physical network
@@ -3709,7 +3707,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                             if (physicalNetwork == null) {
                                 throw new InvalidParameterValueException("Unable to find
physical network with id: "+physicalNetworkId   + " and tag: " +requiredOfferings.get(0).getTags());
                             }
-                            
                             s_logger.debug("Creating network for account " + newAccount +
" from the network offering id=" + 
                         requiredOfferings.get(0).getId() + " as a part of deployVM process");
                             Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(),

@@ -3720,7 +3717,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService,
Manager
                             throw new InvalidParameterValueException("More than 1 default
Isolated networks are found " +
                                     "for account " + newAccount + "; please specify networkIds");
                         } else {
-                            defaultNetwork = virtualNetworks.get(0);
+                            defaultNetwork = _networkDao.findById(virtualNetworks.get(0).getId());
                         }
                     } else {
                         throw new InvalidParameterValueException("Required network offering
id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled);


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/238c55fb/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
index 2a675b3..509d9c7 100644
--- a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
+++ b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
@@ -342,4 +342,13 @@ public class MockNetworkDaoImpl extends GenericDaoBase<NetworkVO,
Long> implemen
         return 0;
     }
 
+    /* (non-Javadoc)
+     * @see com.cloud.network.dao.NetworkDao#listNetworksByAccount(long, long, com.cloud.network.Network.GuestType,
boolean)
+     */
+    @Override
+    public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, GuestType
type, boolean isSystem) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }


Mime
View raw message