mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-9814 : Unable to edit a Sub domain, which has the same name in different domains
This commit is contained in:
parent
61ce75e901
commit
254771c01c
|
|
@ -22,7 +22,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
|
||||
import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
|
||||
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsMappingCmd;
|
||||
import org.apache.cloudstack.api.command.admin.guest.ListGuestOsMappingCmd;
|
||||
|
|
@ -63,7 +62,6 @@ import com.cloud.alert.Alert;
|
|||
import com.cloud.capacity.Capacity;
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.ManagementServerException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
|
|
@ -227,15 +225,6 @@ public interface ManagementService {
|
|||
|
||||
VirtualMachine upgradeSystemVM(UpgradeSystemVMCmd cmd);
|
||||
|
||||
/**
|
||||
* update an existing domain
|
||||
*
|
||||
* @param cmd
|
||||
* - the command containing domainId and new domainName
|
||||
* @return Domain object if the command succeeded
|
||||
*/
|
||||
Domain updateDomain(UpdateDomainCmd cmd);
|
||||
|
||||
/**
|
||||
* Searches for alerts
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2270,79 +2270,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
return new Pair<String, Integer>(null, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public DomainVO updateDomain(final UpdateDomainCmd cmd) {
|
||||
final Long domainId = cmd.getId();
|
||||
final String domainName = cmd.getDomainName();
|
||||
final String networkDomain = cmd.getNetworkDomain();
|
||||
|
||||
// check if domain exists in the system
|
||||
final DomainVO domain = _domainDao.findById(domainId);
|
||||
if (domain == null) {
|
||||
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain with specified domain id");
|
||||
ex.addProxyObject(domainId.toString(), "domainId");
|
||||
throw ex;
|
||||
} else if (domain.getParent() == null && domainName != null) {
|
||||
// check if domain is ROOT domain - and deny to edit it with the new
|
||||
// name
|
||||
throw new InvalidParameterValueException("ROOT domain can not be edited with a new name");
|
||||
}
|
||||
|
||||
final Account caller = getCaller();
|
||||
_accountMgr.checkAccess(caller, domain);
|
||||
|
||||
// domain name is unique under the parent domain
|
||||
if (domainName != null) {
|
||||
final SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
||||
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
||||
sc.addAnd("parent", SearchCriteria.Op.EQ, domain.getParent());
|
||||
final List<DomainVO> domains = _domainDao.search(sc, null);
|
||||
|
||||
final boolean sameDomain = domains.size() == 1 && domains.get(0).getId() == domainId;
|
||||
|
||||
if (!domains.isEmpty() && !sameDomain) {
|
||||
final InvalidParameterValueException ex = new InvalidParameterValueException("Failed to update specified domain id with name '" + domainName
|
||||
+ "' since it already exists in the system");
|
||||
ex.addProxyObject(domain.getUuid(), "domainId");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
// validate network domain
|
||||
if (networkDomain != null && !networkDomain.isEmpty()) {
|
||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
throw new InvalidParameterValueException(
|
||||
"Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
|
||||
+ "and the hyphen ('-'); can't start or end with \"-\"");
|
||||
}
|
||||
}
|
||||
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
@Override
|
||||
public void doInTransactionWithoutResult(final TransactionStatus status) {
|
||||
if (domainName != null) {
|
||||
final String updatedDomainPath = getUpdatedDomainPath(domain.getPath(), domainName);
|
||||
updateDomainChildren(domain, updatedDomainPath);
|
||||
domain.setName(domainName);
|
||||
domain.setPath(updatedDomainPath);
|
||||
}
|
||||
|
||||
if (networkDomain != null) {
|
||||
if (networkDomain.isEmpty()) {
|
||||
domain.setNetworkDomain(null);
|
||||
} else {
|
||||
domain.setNetworkDomain(networkDomain);
|
||||
}
|
||||
}
|
||||
_domainDao.update(domainId, domain);
|
||||
}
|
||||
});
|
||||
|
||||
return _domainDao.findById(domainId);
|
||||
|
||||
}
|
||||
|
||||
private String getUpdatedDomainPath(final String oldPath, final String newName) {
|
||||
final String[] tokenizedPath = oldPath.split("/");
|
||||
tokenizedPath[tokenizedPath.length - 1] = newName;
|
||||
|
|
|
|||
|
|
@ -619,6 +619,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||
if (domainName != null) {
|
||||
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
|
||||
sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
|
||||
sc.addAnd("parent", SearchCriteria.Op.EQ, domain.getParent());
|
||||
List<DomainVO> domains = _domainDao.search(sc, null);
|
||||
|
||||
boolean sameDomain = (domains.size() == 1 && domains.get(0).getId() == domainId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue