mirror of https://github.com/apache/cloudstack.git
bug 6163: implementing the search function for zone wide searches for vlans
This commit is contained in:
parent
10ad2aa468
commit
743187a951
|
|
@ -50,4 +50,6 @@ public interface VlanDao extends GenericDao<VlanVO, Long> {
|
|||
|
||||
List<VlanVO> listZoneWideVlans(long zoneId, VlanType vlanType, String vlanId);
|
||||
|
||||
List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType,String vlanId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package com.cloud.dc.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -35,13 +38,18 @@ import com.cloud.dc.Vlan.VlanType;
|
|||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Local(value={VlanDao.class})
|
||||
public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao {
|
||||
|
||||
private final String FindZoneWideVlans = "SELECT * FROM vlan WHERE data_center_id=? and vlan_type=? and vlan_id!=? and id not in (select vlan_db_id from account_vlan_map)";
|
||||
|
||||
protected SearchBuilder<VlanVO> ZoneVlanIdSearch;
|
||||
protected SearchBuilder<VlanVO> ZoneSearch;
|
||||
protected SearchBuilder<VlanVO> ZoneTypeSearch;
|
||||
|
|
@ -83,10 +91,6 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
ZoneTypeSearch.and("vlanType", ZoneTypeSearch.entity().getVlanType(), SearchCriteria.Op.EQ);
|
||||
ZoneTypeSearch.done();
|
||||
|
||||
ZoneVlanSearch = createSearchBuilder();
|
||||
ZoneVlanSearch.and("vlanType", ZoneVlanSearch.entity().getVlanType(), SearchCriteria.Op.EQ);
|
||||
ZoneVlanSearch.and("vlanId", ZoneVlanSearch.entity().getVlanId(), SearchCriteria.Op.NEQ);
|
||||
ZoneVlanSearch.and("zoneId", ZoneTypeSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -270,5 +274,33 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
return new Pair<String, VlanVO>(ipAddress, vlan);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId){
|
||||
|
||||
StringBuilder sql = new StringBuilder(FindZoneWideVlans);
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(sql.toString());
|
||||
pstmt.setLong(1, dcId);
|
||||
pstmt.setString(2, vlanType);
|
||||
pstmt.setString(3, vlanId);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
|
||||
|
||||
while (rs.next()) {
|
||||
zoneWideVlans.add(toEntityBean(rs, false));
|
||||
}
|
||||
|
||||
return zoneWideVlans;
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2201,4 +2201,5 @@ public interface ManagementServer {
|
|||
VolumeVO getRootVolume(Long instanceId);
|
||||
long getPsMaintenanceCount(long podId);
|
||||
boolean isPoolUp(long instanceId);
|
||||
List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType,String vlanId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8807,5 +8807,10 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId){
|
||||
return _vlanDao.searchForZoneWideVlans(dcId, vlanType, vlanId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,10 +80,12 @@ import com.cloud.capacity.dao.CapacityDao;
|
|||
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.configuration.dao.ResourceLimitDao;
|
||||
import com.cloud.dc.AccountVlanMapVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.dao.AccountVlanMapDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.dc.dao.VlanDao;
|
||||
|
|
@ -169,6 +171,8 @@ import com.cloud.utils.component.Inject;
|
|||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.exception.ExecutionException;
|
||||
|
|
@ -221,12 +225,13 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
@Inject AsyncJobManager _asyncMgr;
|
||||
@Inject protected StoragePoolHostDao _storagePoolHostDao;
|
||||
@Inject VlanDao _vlanDao;
|
||||
@Inject AccountVlanMapDao _accountVlanMapDao;
|
||||
@Inject StoragePoolDao _storagePoolDao;
|
||||
@Inject VMTemplateHostDao _vmTemplateHostDao;
|
||||
@Inject NetworkGroupManager _networkGroupManager;
|
||||
@Inject ServiceOfferingDao _serviceOfferingDao;
|
||||
@Inject EventDao _eventDao = null;
|
||||
|
||||
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
ScheduledExecutorService _executor = null;
|
||||
int _expungeInterval;
|
||||
|
|
@ -1868,6 +1873,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
Enumeration<IpAddrAllocator> it = ipAllocators.enumeration();
|
||||
_IpAllocator = it.nextElement();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2647,15 +2653,30 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
List<VlanVO> vlansForAccount = _vlanDao.listVlansForAccountByType(dc.getId(), account.getId(), VlanType.DirectAttached);
|
||||
|
||||
boolean forAccount = false;
|
||||
boolean forZone = false;
|
||||
if (vlansForAccount.size() > 0) {
|
||||
forAccount = true;
|
||||
guestVlan = vlansForAccount.get(0);//FIXME: iterate over all vlans
|
||||
}
|
||||
else
|
||||
{
|
||||
//list zone wide vlans that are direct attached and tagged
|
||||
//if exists pick random one
|
||||
//set forZone = true
|
||||
|
||||
//note the dao method below does a NEQ on vlan id, hence passing untagged
|
||||
List<VlanVO> zoneWideVlans = _vlanDao.listZoneWideVlans(dc.getId(),VlanType.DirectAttached,"untagged");
|
||||
|
||||
if(zoneWideVlans!=null && zoneWideVlans.size()>0){
|
||||
forZone = true;
|
||||
guestVlan = zoneWideVlans.get(0);//FIXME: iterate over all vlans
|
||||
}
|
||||
}
|
||||
while ((pod = _agentMgr.findPod(template, offering, dc, account.getId(), avoids)) != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Attempting to create direct attached vm in pod " + pod.first().getName());
|
||||
}
|
||||
if (!forAccount) {
|
||||
if (!forAccount && !forZone) {
|
||||
List<VlanVO> vlansForPod = _vlanDao.listVlansForPodByType(pod.first().getId(), VlanType.DirectAttached);
|
||||
if (vlansForPod.size() < 1) {
|
||||
avoids.add(pod.first().getId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue