bug 7505: updateDomain with a new name - update the path for child domains

status 7505: resolved fixed
This commit is contained in:
alena 2011-02-10 17:24:26 -08:00
parent 81afd13f24
commit 1ff3aefd1a
3 changed files with 56 additions and 13 deletions

View File

@ -18,6 +18,8 @@
package com.cloud.domain.dao;
import java.util.List;
import com.cloud.domain.DomainVO;
import com.cloud.utils.db.GenericDao;
@ -25,5 +27,6 @@ public interface DomainDao extends GenericDao<DomainVO, Long> {
public void update(Long id, String domainName);
public DomainVO create(DomainVO domain);
public DomainVO findDomainByPath(String domainPath);
public boolean isChildDomain(Long parentId, Long childId);
public boolean isChildDomain(Long parentId, Long childId);
List<DomainVO> listDomainChildren(long parentDomainId);
}

View File

@ -40,7 +40,8 @@ public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements Dom
protected SearchBuilder<DomainVO> DomainNameLikeSearch;
protected SearchBuilder<DomainVO> ParentDomainNameLikeSearch;
protected SearchBuilder<DomainVO> DomainPairSearch;
protected SearchBuilder<DomainVO> DomainPairSearch;
protected SearchBuilder<DomainVO> ChildDomainsSearch;
public DomainDaoImpl () {
DomainNameLikeSearch = createSearchBuilder();
@ -54,7 +55,12 @@ public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements Dom
DomainPairSearch = createSearchBuilder();
DomainPairSearch.and("id", DomainPairSearch.entity().getId(), SearchCriteria.Op.IN);
DomainPairSearch.done();
DomainPairSearch.done();
ChildDomainsSearch = createSearchBuilder();
ChildDomainsSearch.and("path", ChildDomainsSearch.entity().getPath(), SearchCriteria.Op.LIKE);
ChildDomainsSearch.and("id", ChildDomainsSearch.entity().getId(), SearchCriteria.Op.NEQ);
ChildDomainsSearch.done();
}
public void update(Long id, String domainName) {
@ -218,5 +224,15 @@ public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements Dom
}
}
return result;
}
@Override
public List<DomainVO> listDomainChildren(long parentDomainId) {
DomainVO parentDomain = findById(parentDomainId);
SearchCriteria sc = ChildDomainsSearch.create();
sc.setParameters("path", parentDomain.getPath() + "%");
//don't include parent domain
sc.setParameters("id", parentDomainId);
return listBy(sc);
}
}

View File

@ -3820,18 +3820,18 @@ public class ManagementServerImpl implements ManagementServer {
//if account doesn't have direct ip addresses and there are no direct Zone wide vlans, return virtual service offerings only
List<VlanVO> accountDirectVlans = new ArrayList<VlanVO>();
List<VlanVO> zoneDirectVlans = new ArrayList<VlanVO>();
if (accountId != null || zoneId != null) {
if (accountId != null && zoneId != null) {
accountDirectVlans = _vlanDao.listVlansForAccountByType(null, ((Long)accountId).longValue(), VlanType.DirectAttached);
zoneDirectVlans = listZoneWideVlansByType(VlanType.DirectAttached, (Long)zoneId);
} else if (zoneId != null) {
zoneDirectVlans = listZoneWideVlansByType(VlanType.DirectAttached, (Long)zoneId);
}
if (accountId != null && zoneId != null) {
accountDirectVlans = _vlanDao.listVlansForAccountByType(null, ((Long)accountId).longValue(), VlanType.DirectAttached);
zoneDirectVlans = listZoneWideVlansByType(VlanType.DirectAttached, (Long)zoneId);
if (accountDirectVlans.isEmpty() && zoneDirectVlans.isEmpty()) {
sc.addAnd("guestIpType", SearchCriteria.Op.EQ, GuestIpType.Virtualized);
}
}
} else if (zoneId != null) {
zoneDirectVlans = listZoneWideVlansByType(VlanType.DirectAttached, (Long)zoneId);
if (zoneDirectVlans.isEmpty()) {
sc.addAnd("guestIpType", SearchCriteria.Op.EQ, GuestIpType.Virtualized);
}
}
return _offeringsDao.search(sc, searchFilter);
@ -6243,14 +6243,38 @@ public class ManagementServerImpl implements ManagementServer {
return success && deleteDomainSuccess;
}
@DB
public void updateDomain(Long domainId, String domainName) {
SearchCriteria sc = _domainDao.createSearchCriteria();
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
List<DomainVO> domains = _domainDao.search(sc, null);
Transaction txn = Transaction.currentTxn();
if ((domains == null) || domains.isEmpty()) {
_domainDao.update(domainId, domainName);
txn.start();
DomainVO domain = _domainDao.findById(domainId);
String newName = domainName;
String oldName = domain.getName();
domain.setName(newName);
_domainDao.update(domainId, domain);
//update path for parent domain and all domain children
List<DomainVO> domainChildren = _domainDao.listDomainChildren(domainId);
domainChildren.add(domain);
String parentPath = domain.getPath().substring(0, domain.getPath().length() - oldName.length()-1);
for (DomainVO domainChild : domainChildren) {
String originalPath = domainChild.getPath();
String resultPath = parentPath + newName + originalPath.substring(parentPath.length() + oldName.length());
domainChild.setPath(resultPath);
_domainDao.update(domainChild.getId(), domainChild);
}
saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_UPDATE, "Domain, " + domainName + " was updated");
txn.commit();
} else {
DomainVO domain = _domainDao.findById(domainId);
saveEvent(new Long(1), domain.getOwner(), EventVO.LEVEL_ERROR, EventTypes.EVENT_DOMAIN_UPDATE, "Failed to update domain " + domain.getName() + " with name " + domainName + ", name in use.");