mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
e49b3b27de
commit
238c55fb6e
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue