diff --git a/core/src/com/cloud/dc/DataCenterVO.java b/core/src/com/cloud/dc/DataCenterVO.java index 7f48dbf19ba..d0d122b252f 100644 --- a/core/src/com/cloud/dc/DataCenterVO.java +++ b/core/src/com/cloud/dc/DataCenterVO.java @@ -58,23 +58,26 @@ public class DataCenterVO implements DataCenter { @Column(name="vnet") private String vnet = null; - - @Column(name="guest_network_cidr") + + @Column(name="guest_network_cidr") private String guestNetworkCidr = null; + @Column(name="domain_id") + private Long domainId = null; + @Column(name="domain") private String domain = null; - + @Column(name="mac_address", updatable = false, nullable=false) @TableGenerator(name="mac_address_sq", table="data_center", pkColumnName="id", valueColumnName="mac_address", allocationSize=1) private long macAddress = 1; - public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain) { - this(name, description, dns1, dns2, dns3, dns4, vnet, guestCidr, domain); + public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId) { + this(name, description, dns1, dns2, dns3, dns4, vnet, guestCidr, domain, domainId); this.id = id; } - public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain) { + public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId) { this.name = name; this.description = description; this.dns1 = dns1; @@ -84,7 +87,16 @@ public class DataCenterVO implements DataCenter { this.vnet = vnet; this.guestNetworkCidr = guestCidr; this.domain = domain; - } + this.domainId = domainId; + } + + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } public String getDescription() { return description; diff --git a/server/src/com/cloud/api/commands/CreateZoneCmd.java b/server/src/com/cloud/api/commands/CreateZoneCmd.java index ce192231cd7..beda30082af 100644 --- a/server/src/com/cloud/api/commands/CreateZoneCmd.java +++ b/server/src/com/cloud/api/commands/CreateZoneCmd.java @@ -21,6 +21,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; @@ -36,7 +37,6 @@ public class CreateZoneCmd extends BaseCmd { ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name="dns1", type=CommandType.STRING, required=true, description="the first DNS for the Zone") private String dns1; @@ -62,7 +62,8 @@ public class CreateZoneCmd extends BaseCmd { @Parameter(name="domain", type=CommandType.STRING, description="Domain name for the Vms in the zone") private String domain; - + @Parameter(name="domainid", type=CommandType.LONG, description="the ID of the containing domain, null for public zones") + private Long domainId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -99,6 +100,10 @@ public class CreateZoneCmd extends BaseCmd { return domain; } + public Long getDomainId(){ + return domainId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -123,6 +128,7 @@ public class CreateZoneCmd extends BaseCmd { response.setGuestCidrAddress(zone.getGuestNetworkCidr()); response.setDomain(zone.getDomain()); response.setResponseName(getName()); + response.setDomainId(zone.getDomainId()); return response; } } diff --git a/server/src/com/cloud/api/commands/UpdateZoneCmd.java b/server/src/com/cloud/api/commands/UpdateZoneCmd.java index 09d80553721..543eeca94ec 100644 --- a/server/src/com/cloud/api/commands/UpdateZoneCmd.java +++ b/server/src/com/cloud/api/commands/UpdateZoneCmd.java @@ -21,6 +21,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; +import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; @@ -28,7 +29,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.ZoneResponse; import com.cloud.dc.DataCenterVO; -@Implementation(method="updateZone", manager=Manager.ConfigManager, description="Updates a Zone.") +@Implementation(method="editZone", manager=Manager.ConfigManager, description="Updates a Zone.") public class UpdateZoneCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(UpdateZoneCmd.class.getName()); @@ -65,6 +66,8 @@ public class UpdateZoneCmd extends BaseCmd { @Parameter(name="domain", type=CommandType.STRING, description="Domain name for the Vms in the zone") private String domain; + @Parameter(name="domainid", type=CommandType.LONG, description="the ID of the containing domain, null for public zones") + private Long domainId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -105,6 +108,13 @@ public class UpdateZoneCmd extends BaseCmd { return domain; } + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/api/response/ZoneResponse.java b/server/src/com/cloud/api/response/ZoneResponse.java index ec3a797838f..9bf3054a518 100644 --- a/server/src/com/cloud/api/response/ZoneResponse.java +++ b/server/src/com/cloud/api/response/ZoneResponse.java @@ -59,6 +59,9 @@ public class ZoneResponse extends BaseResponse { @SerializedName("domain") @Param(description="Domain name for the Vms in the zone") private String domain; + @SerializedName("domainid") @Param(description="the ID of the containing domain, null for public zones") + private Long domainId; + public Long getId() { return id; } @@ -154,4 +157,13 @@ public class ZoneResponse extends BaseResponse { public void setDomain(String domain) { this.domain = domain; } + + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + } diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 8d6a2a9faee..7d5bfd2035f 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -219,7 +219,7 @@ public interface ConfigurationManager extends Manager { * @throws InvalidParameterValueException * @throws InternalErrorException */ - DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain) throws InvalidParameterValueException, InternalErrorException; + DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId) throws InvalidParameterValueException, InternalErrorException; /** * Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone. diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 11953ea0e31..3aac91cac2c 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -64,6 +64,7 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; @@ -116,6 +117,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { @Inject PodVlanMapDao _podVlanMapDao; @Inject DataCenterDao _zoneDao; @Inject DomainRouterDao _domrDao; + @Inject DomainDao _domainDao; @Inject ServiceOfferingDao _serviceOfferingDao; @Inject DiskOfferingDao _diskOfferingDao; @Inject VlanDao _vlanDao; @@ -722,7 +724,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } - private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates) throws InvalidParameterValueException { + private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId) throws InvalidParameterValueException { if (checkForDuplicates) { // Check if a zone with the specified name already exists if (validZone(zoneName)) { @@ -730,6 +732,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } } + //check if valid domain + if(domainId != null){ + DomainVO domain = _domainDao.findById(domainId); + + if(domain == null) + throw new InvalidParameterValueException("Please specify a valid domain id"); + } + // Check IP validity for DNS addresses if (dns1 != null && !NetUtils.isValidIp(dns1)) { @@ -813,7 +823,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager { String guestCidr = cmd.getGuestCidrAddress(); String domain = cmd.getDomain(); Long userId = UserContext.current().getUserId(); - + Long domainId = cmd.getDomainId(); + if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); } @@ -867,7 +878,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { domain = zone.getDomain(); boolean checkForDuplicates = !zoneName.equals(oldZoneName); - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates); + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, domainId); zone.setName(zoneName); zone.setDns1(dns1); @@ -942,7 +953,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } @Override @DB - public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain) throws InvalidParameterValueException, InternalErrorException { + public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId) throws InvalidParameterValueException, InternalErrorException { int vnetStart, vnetEnd; if (vnetRange != null) { String[] tokens = vnetRange.split("-"); @@ -973,10 +984,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager { throw new InvalidParameterValueException("Please enter a valid guest cidr"); } - checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true); + checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId); // Create the new zone in the database - DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain); + DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId); zone = _zoneDao.persist(zone); // Add vnet entries for the new zone @@ -999,12 +1010,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager { String vnetRange = cmd.getVlan(); String guestCidr = cmd.getGuestCidrAddress(); String domain = cmd.getDomain(); - + Long domainId = cmd.getDomainId(); + if (userId == null) { userId = User.UID_SYSTEM; } - return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain); + return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId); } @Override diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 846616b1cec..0713beef3c3 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -48,6 +48,7 @@ import com.cloud.dc.HostPodVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.offering.NetworkOffering; @@ -75,6 +76,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { private final HostPodDao _podDao; private final DiskOfferingDao _diskOfferingDao; private final ServiceOfferingDao _serviceOfferingDao; + private final DomainDao _domainDao; public ConfigurationServerImpl() { ComponentLocator locator = ComponentLocator.getLocator(Name); @@ -84,6 +86,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { _podDao = locator.getDao(HostPodDao.class); _diskOfferingDao = locator.getDao(DiskOfferingDao.class); _serviceOfferingDao = locator.getDao(ServiceOfferingDao.class); + _domainDao = locator.getDao(DomainDao.class); } public void persistDefaultValues() throws InvalidParameterValueException, InternalErrorException { @@ -190,7 +193,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { if (dns == null) { dns = "4.2.2.2"; } - DataCenterVO zone = createZone(User.UID_SYSTEM, "Default", dns, null, dns, null, "1000-2000","10.1.1.0/24", null); + DataCenterVO zone = createZone(User.UID_SYSTEM, "Default", dns, null, dns, null, "1000-2000","10.1.1.0/24", null, null); // Create a default pod String networkType = _configDao.getValue("network.type"); @@ -527,7 +530,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { } } - private DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain) throws InvalidParameterValueException, InternalErrorException { + private DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId) throws InvalidParameterValueException, InternalErrorException { int vnetStart, vnetEnd; if (vnetRange != null) { String[] tokens = vnetRange.split("-"); @@ -558,8 +561,14 @@ public class ConfigurationServerImpl implements ConfigurationServer { throw new InvalidParameterValueException("Please enter a valid guest cidr"); } + if(domainId!=null){ + DomainVO domainVo = _domainDao.findById(domainId); + + if(domainVo == null) + throw new InvalidParameterValueException("Please specify a valid domain id"); + } // Create the new zone in the database - DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain); + DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId); zone = _zoneDao.persist(zone); // Add vnet entries for the new zone diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 8d8e0961772..2e292ce6133 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -351,6 +351,7 @@ CREATE TABLE `cloud`.`data_center` ( `mac_address` bigint unsigned NOT NULL DEFAULT '1' COMMENT 'Next available mac address for the ethernet card interacting with public internet', `guest_network_cidr` varchar(18), `domain` varchar(100) COMMENT 'Network domain name of the Vms of the zone', + `domain_id` bigint unsigned COMMENT 'domain id for the parent domain to this zone (null signifies public zone)', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/ui/new/scripts/cloud.core2.domain.js b/ui/new/scripts/cloud.core2.domain.js index aa51c4bdb3f..d2224aaab42 100644 --- a/ui/new/scripts/cloud.core2.domain.js +++ b/ui/new/scripts/cloud.core2.domain.js @@ -58,7 +58,7 @@ function afterLoadDomainJSP() { if (domains != null && domains.length > 0) { for (var i = 0; i < domains.length; i++) { drawNode(domains[i], level, container); - if(domains[i].haschild == true) + if(domains[i].haschild == true || domains[i].haschild == "true") //After API refactor, returned boolean value is true/false instead of "true"/"false". For testing convenience (Some people might not have backend update-to-date), check both true and "true". drawTree(domains[i].id, (level+1), $("#domain_children_container_"+domains[i].id)); } } diff --git a/ui/new/scripts/cloud.core2.init.js b/ui/new/scripts/cloud.core2.init.js index 1ebec059d3d..bbe39e35c41 100644 --- a/ui/new/scripts/cloud.core2.init.js +++ b/ui/new/scripts/cloud.core2.init.js @@ -57,19 +57,7 @@ $(document).ready(function() { selectLeftMenu($(this)); listMidMenuItems("listAccounts", "listaccountsresponse", "account", "jsp/account.jsp", afterLoadAccountJSP, accountToMidmenu, accountToRigntPanel, getMidmenuId); return false; - }); - $("#leftmenu_domain").bind("click", function(event) { - selectLeftMenu($(this), true); - hideMiddleMenu(); - disableMultipleSelectionInMidMenu(); - clearMiddleMenu(); - - $("#right_panel").load("jsp/domain.jsp", function(){ - afterLoadDomainJSP(); - }); - - return false; - }); + }); $("#leftmenu_events").bind("click", function(event) { selectLeftMenu($(this), true); return false; @@ -99,6 +87,19 @@ $(document).ready(function() { bindAndListMidMenuItems("leftmenu_service_offering", "listServiceOfferings", "listserviceofferingsresponse", "serviceoffering", "jsp/serviceoffering.jsp", afterLoadServiceOfferingJSP, serviceOfferingToMidmenu, serviceOfferingToRigntPanel, getMidmenuId); bindAndListMidMenuItems("leftmenu_disk_offering", "listDiskOfferings", "listdiskofferingsresponse", "diskoffering", "jsp/diskoffering.jsp", afterLoadDiskOfferingJSP, diskOfferingToMidmenu, diskOfferingToRigntPanel, getMidmenuId); bindAndListMidMenuItems("leftmenu_global_setting", "listConfigurations", "listconfigurationsresponse", "configuration", "jsp/globalsetting.jsp", afterLoadGlobalSettingJSP, globalSettingToMidmenu, globalSettingToRigntPanel, globalSettingGetMidmenuId, getMidmenuId); + + $("#leftmenu_domain").bind("click", function(event) { + selectLeftMenu($(this), true); + hideMiddleMenu(); + disableMultipleSelectionInMidMenu(); + clearMiddleMenu(); + + $("#right_panel").load("jsp/domain.jsp", function(){ + afterLoadDomainJSP(); + }); + + return false; + }); $("#leftmenu_resource").bind("click", function(event) { showMiddleMenu();