From 4cb6fcc17ae0c72d136582de8c42682c610eded8 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 16 Dec 2011 11:54:05 -0800 Subject: [PATCH] bug 12591: fixed updateDomain status 12591: resolved fixed --- .../cloud/api/commands/UpdateAccountCmd.java | 2 +- .../com/cloud/api/commands/UpdateDomainCmd.java | 2 +- .../com/cloud/api/commands/UpdateZoneCmd.java | 2 +- .../configuration/ConfigurationManagerImpl.java | 13 +++++++++---- .../com/cloud/server/ManagementServerImpl.java | 12 +++++++++--- .../src/com/cloud/user/AccountManagerImpl.java | 17 +++++++++++++---- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/api/src/com/cloud/api/commands/UpdateAccountCmd.java b/api/src/com/cloud/api/commands/UpdateAccountCmd.java index 596194b48e4..7c5feddbfac 100755 --- a/api/src/com/cloud/api/commands/UpdateAccountCmd.java +++ b/api/src/com/cloud/api/commands/UpdateAccountCmd.java @@ -54,7 +54,7 @@ public class UpdateAccountCmd extends BaseCmd{ @Parameter(name=ApiConstants.NEW_NAME, type=CommandType.STRING, required=true, description="new name for the account") private String newName; - @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the account's networks") + @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the account's networks; empty string will update domainName with NULL value") private String networkDomain; @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters") diff --git a/api/src/com/cloud/api/commands/UpdateDomainCmd.java b/api/src/com/cloud/api/commands/UpdateDomainCmd.java index 3570a7c7df9..53dc59aae40 100644 --- a/api/src/com/cloud/api/commands/UpdateDomainCmd.java +++ b/api/src/com/cloud/api/commands/UpdateDomainCmd.java @@ -46,7 +46,7 @@ public class UpdateDomainCmd extends BaseCmd { @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="updates domain with this name") private String domainName; - @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the domain's networks") + @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the domain's networks; empty string will update domainName with NULL value") private String networkDomain; ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/UpdateZoneCmd.java b/api/src/com/cloud/api/commands/UpdateZoneCmd.java index 3d511797395..1f6cba8949a 100755 --- a/api/src/com/cloud/api/commands/UpdateZoneCmd.java +++ b/api/src/com/cloud/api/commands/UpdateZoneCmd.java @@ -75,7 +75,7 @@ public class UpdateZoneCmd extends BaseCmd { @Parameter(name=ApiConstants.DHCP_PROVIDER, type=CommandType.STRING, description="the dhcp Provider for the Zone") private String dhcpProvider; - @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Network domain name for the networks in the zone") + @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Network domain name for the networks in the zone; empty string will update domain with NULL value") private String domain; @Parameter(name=ApiConstants.DNS_SEARCH_ORDER, type=CommandType.LIST, collectionType = CommandType.STRING, description="the dns search order list") diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index f6906fcf3f2..b506bf7f9c4 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1353,14 +1353,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } // validate network domain - if (networkDomain != null) { + 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 \"-\""); } - } else { - networkDomain = zone.getDomain(); } boolean checkForDuplicates = !zoneName.equals(oldZoneName); @@ -1380,7 +1378,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura zone.setDns2(dns2); zone.setInternalDns1(internalDns1); zone.setInternalDns2(internalDns2); - zone.setDomain(networkDomain); + + if (networkDomain != null) { + if (networkDomain.isEmpty()) { + zone.setDomain(null); + } else { + zone.setDomain(networkDomain); + } + } // update a private zone to public; not vice versa if (isPublic != null && isPublic) { diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index bc01b0585d4..1aaa36df542 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -2155,13 +2155,15 @@ public class ManagementServerImpl implements ManagementServer { sc.addAnd("name", SearchCriteria.Op.EQ, domainName); List domains = _domainDao.search(sc, null); - if (!domains.isEmpty()) { + boolean sameDomain = (domains.size() == 1 && domains.get(0).getId() == domainId); + + if (!domains.isEmpty() && !sameDomain) { throw new InvalidParameterValueException("Failed to update domain id=" + domainId + "; domain with name " + domainName + " already exists in the system"); } } //validate network domain - if (networkDomain != null){ + 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', " @@ -2181,7 +2183,11 @@ public class ManagementServerImpl implements ManagementServer { } if (networkDomain != null) { - domain.setNetworkDomain(networkDomain); + if (networkDomain.isEmpty()) { + domain.setNetworkDomain(null); + } else { + domain.setNetworkDomain(networkDomain); + } } _domainDao.update(domainId, domain); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 1782c76e39d..295b96eff19 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -1052,7 +1052,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag } } - @Override + @Override @DB public AccountVO updateAccount(UpdateAccountCmd cmd) { Long accountId = cmd.getId(); Long domainId = cmd.getDomainId(); @@ -1095,7 +1095,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag + duplicateAcccount.getId()); } - if (networkDomain != null) { + 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', " @@ -1107,15 +1107,24 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag acctForUpdate.setAccountName(newAccountName); if (networkDomain != null) { - acctForUpdate.setNetworkDomain(networkDomain); + if (networkDomain.isEmpty()) { + acctForUpdate.setNetworkDomain(null); + } else { + acctForUpdate.setNetworkDomain(networkDomain); + } } + Transaction txn = Transaction.currentTxn(); + txn.start(); + success = _accountDao.update(account.getId(), acctForUpdate); - if (details != null) { + if (details != null && success) { _accountDetailsDao.update(account.getId(), details); } + txn.commit(); + if (success) { return _accountDao.findById(account.getId()); } else {