Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8C7D6D2D7 for ; Thu, 10 Jan 2013 23:29:23 +0000 (UTC) Received: (qmail 5752 invoked by uid 500); 10 Jan 2013 23:29:23 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 5672 invoked by uid 500); 10 Jan 2013 23:29:23 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 5644 invoked by uid 99); 10 Jan 2013 23:29:23 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jan 2013 23:29:23 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id E14D817CE8; Thu, 10 Jan 2013 23:29:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ahuang@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [3/7] more files changed Message-Id: <20130110232922.E14D817CE8@tyr.zones.apache.org> Date: Thu, 10 Jan 2013 23:29:22 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/src/com/cloud/test/DatabaseConfig.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java index 03cf083..f0e9d82 100755 --- a/server/src/com/cloud/test/DatabaseConfig.java +++ b/server/src/com/cloud/test/DatabaseConfig.java @@ -54,7 +54,7 @@ import com.cloud.service.dao.ServiceOfferingDaoImpl; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.dao.DiskOfferingDaoImpl; import com.cloud.utils.PropertiesUtil; -import com.cloud.utils.component.LegacyComponentLocator; +import com.cloud.utils.component.ComponentContext; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; import com.cloud.utils.net.NfsUtils; @@ -74,86 +74,86 @@ public class DatabaseConfig { // Change to HashSet private static HashSet objectNames = new HashSet(); private static HashSet fieldNames = new HashSet(); - + // Maintain an IPRangeConfig object to handle IP related logic - private final IPRangeConfig iprc = LegacyComponentLocator.inject(IPRangeConfig.class); - + private final IPRangeConfig iprc = ComponentContext.inject(IPRangeConfig.class); + // Maintain a PodZoneConfig object to handle Pod/Zone related logic - private final PodZoneConfig pzc = LegacyComponentLocator.inject(PodZoneConfig.class); - + private final PodZoneConfig pzc = ComponentContext.inject(PodZoneConfig.class); + // Global variables to store network.throttling.rate and multicast.throttling.rate from the configuration table // Will be changed from null to a non-null value if the value existed in the configuration table private String _networkThrottlingRate = null; private String _multicastThrottlingRate = null; - + static { - // initialize the objectNames ArrayList - objectNames.add("zone"); + // initialize the objectNames ArrayList + objectNames.add("zone"); objectNames.add("physicalNetwork"); - objectNames.add("vlan"); - objectNames.add("pod"); + objectNames.add("vlan"); + objectNames.add("pod"); objectNames.add("cluster"); - objectNames.add("storagePool"); - objectNames.add("secondaryStorage"); - objectNames.add("serviceOffering"); + objectNames.add("storagePool"); + objectNames.add("secondaryStorage"); + objectNames.add("serviceOffering"); objectNames.add("diskOffering"); - objectNames.add("user"); - objectNames.add("pricing"); - objectNames.add("configuration"); - objectNames.add("privateIpAddresses"); - objectNames.add("publicIpAddresses"); + objectNames.add("user"); + objectNames.add("pricing"); + objectNames.add("configuration"); + objectNames.add("privateIpAddresses"); + objectNames.add("publicIpAddresses"); objectNames.add("physicalNetworkServiceProvider"); objectNames.add("virtualRouterProvider"); - - // initialize the fieldNames ArrayList - fieldNames.add("id"); - fieldNames.add("name"); - fieldNames.add("dns1"); - fieldNames.add("dns2"); - fieldNames.add("internalDns1"); - fieldNames.add("internalDns2"); - fieldNames.add("guestNetworkCidr"); - fieldNames.add("gateway"); - fieldNames.add("netmask"); - fieldNames.add("vncConsoleIp"); - fieldNames.add("zoneId"); - fieldNames.add("vlanId"); - fieldNames.add("cpu"); - fieldNames.add("ramSize"); - fieldNames.add("speed"); - fieldNames.add("useLocalStorage"); - fieldNames.add("hypervisorType"); - fieldNames.add("diskSpace"); - fieldNames.add("nwRate"); - fieldNames.add("mcRate"); - fieldNames.add("price"); - fieldNames.add("username"); - fieldNames.add("password"); - fieldNames.add("firstname"); - fieldNames.add("lastname"); - fieldNames.add("email"); - fieldNames.add("priceUnit"); - fieldNames.add("type"); - fieldNames.add("value"); - fieldNames.add("podId"); - fieldNames.add("podName"); - fieldNames.add("ipAddressRange"); - fieldNames.add("vlanType"); - fieldNames.add("vlanName"); - fieldNames.add("cidr"); - fieldNames.add("vnet"); - fieldNames.add("mirrored"); - fieldNames.add("enableHA"); - fieldNames.add("displayText"); - fieldNames.add("domainId"); - fieldNames.add("hostAddress"); - fieldNames.add("hostPath"); - fieldNames.add("guestIpType"); - fieldNames.add("url"); - fieldNames.add("storageType"); - fieldNames.add("category"); - fieldNames.add("tags"); - fieldNames.add("networktype"); + + // initialize the fieldNames ArrayList + fieldNames.add("id"); + fieldNames.add("name"); + fieldNames.add("dns1"); + fieldNames.add("dns2"); + fieldNames.add("internalDns1"); + fieldNames.add("internalDns2"); + fieldNames.add("guestNetworkCidr"); + fieldNames.add("gateway"); + fieldNames.add("netmask"); + fieldNames.add("vncConsoleIp"); + fieldNames.add("zoneId"); + fieldNames.add("vlanId"); + fieldNames.add("cpu"); + fieldNames.add("ramSize"); + fieldNames.add("speed"); + fieldNames.add("useLocalStorage"); + fieldNames.add("hypervisorType"); + fieldNames.add("diskSpace"); + fieldNames.add("nwRate"); + fieldNames.add("mcRate"); + fieldNames.add("price"); + fieldNames.add("username"); + fieldNames.add("password"); + fieldNames.add("firstname"); + fieldNames.add("lastname"); + fieldNames.add("email"); + fieldNames.add("priceUnit"); + fieldNames.add("type"); + fieldNames.add("value"); + fieldNames.add("podId"); + fieldNames.add("podName"); + fieldNames.add("ipAddressRange"); + fieldNames.add("vlanType"); + fieldNames.add("vlanName"); + fieldNames.add("cidr"); + fieldNames.add("vnet"); + fieldNames.add("mirrored"); + fieldNames.add("enableHA"); + fieldNames.add("displayText"); + fieldNames.add("domainId"); + fieldNames.add("hostAddress"); + fieldNames.add("hostPath"); + fieldNames.add("guestIpType"); + fieldNames.add("url"); + fieldNames.add("storageType"); + fieldNames.add("category"); + fieldNames.add("tags"); + fieldNames.add("networktype"); fieldNames.add("clusterId"); fieldNames.add("physicalNetworkId"); fieldNames.add("destPhysicalNetworkId"); @@ -169,7 +169,7 @@ public class DatabaseConfig { fieldNames.add("userData"); fieldNames.add("securityGroup"); fieldNames.add("nspId"); - + s_configurationDescriptions.put("host.stats.interval", "the interval in milliseconds when host stats are retrieved from agents"); s_configurationDescriptions.put("storage.stats.interval", "the interval in milliseconds when storage stats (per host) are retrieved from agents"); s_configurationDescriptions.put("volume.stats.interval", "the interval in milliseconds when volume stats are retrieved from agents"); @@ -220,17 +220,17 @@ public class DatabaseConfig { s_configurationDescriptions.put("snapshot.test.weeks.per.month", "Set it to a smaller value to take more recurring snapshots"); s_configurationDescriptions.put("snapshot.test.months.per.year", "Set it to a smaller value to take more recurring snapshots"); s_configurationDescriptions.put("hypervisor.type", "The type of hypervisor that this deployment will use."); - - + + s_configurationComponents.put("host.stats.interval", "management-server"); s_configurationComponents.put("storage.stats.interval", "management-server"); s_configurationComponents.put("volume.stats.interval", "management-server"); s_configurationComponents.put("integration.api.port", "management-server"); s_configurationComponents.put("usage.stats.job.exec.time", "management-server"); s_configurationComponents.put("usage.stats.job.aggregation.range", "management-server"); - s_configurationComponents.put("consoleproxy.domP.enable", "management-server"); - s_configurationComponents.put("consoleproxy.port", "management-server"); - s_configurationComponents.put("consoleproxy.url.port", "management-server"); + s_configurationComponents.put("consoleproxy.domP.enable", "management-server"); + s_configurationComponents.put("consoleproxy.port", "management-server"); + s_configurationComponents.put("consoleproxy.url.port", "management-server"); s_configurationComponents.put("alert.email.addresses", "management-server"); s_configurationComponents.put("alert.smtp.host", "management-server"); s_configurationComponents.put("alert.smtp.port", "management-server"); @@ -256,22 +256,22 @@ public class DatabaseConfig { s_configurationComponents.put("instance.name", "AgentManager"); s_configurationComponents.put("storage.overprovisioning.factor", "StorageAllocator"); s_configurationComponents.put("retries.per.host", "AgentManager"); - s_configurationComponents.put("start.retry", "AgentManager"); - s_configurationComponents.put("wait", "AgentManager"); - s_configurationComponents.put("ping.timeout", "AgentManager"); - s_configurationComponents.put("ping.interval", "AgentManager"); - s_configurationComponents.put("alert.wait", "AgentManager"); - s_configurationComponents.put("update.wait", "AgentManager"); - s_configurationComponents.put("guest.domain.suffix", "AgentManager"); - s_configurationComponents.put("consoleproxy.ram.size", "AgentManager"); - s_configurationComponents.put("consoleproxy.cmd.port", "AgentManager"); - s_configurationComponents.put("consoleproxy.loadscan.interval", "AgentManager"); - s_configurationComponents.put("consoleproxy.capacityscan.interval", "AgentManager"); - s_configurationComponents.put("consoleproxy.capacity.standby", "AgentManager"); - s_configurationComponents.put("consoleproxy.session.max", "AgentManager"); - s_configurationComponents.put("consoleproxy.session.timeout", "AgentManager"); - s_configurationComponents.put("expunge.workers", "UserVmManager"); - s_configurationComponents.put("extract.url.cleanup.interval", "management-server"); + s_configurationComponents.put("start.retry", "AgentManager"); + s_configurationComponents.put("wait", "AgentManager"); + s_configurationComponents.put("ping.timeout", "AgentManager"); + s_configurationComponents.put("ping.interval", "AgentManager"); + s_configurationComponents.put("alert.wait", "AgentManager"); + s_configurationComponents.put("update.wait", "AgentManager"); + s_configurationComponents.put("guest.domain.suffix", "AgentManager"); + s_configurationComponents.put("consoleproxy.ram.size", "AgentManager"); + s_configurationComponents.put("consoleproxy.cmd.port", "AgentManager"); + s_configurationComponents.put("consoleproxy.loadscan.interval", "AgentManager"); + s_configurationComponents.put("consoleproxy.capacityscan.interval", "AgentManager"); + s_configurationComponents.put("consoleproxy.capacity.standby", "AgentManager"); + s_configurationComponents.put("consoleproxy.session.max", "AgentManager"); + s_configurationComponents.put("consoleproxy.session.timeout", "AgentManager"); + s_configurationComponents.put("expunge.workers", "UserVmManager"); + s_configurationComponents.put("extract.url.cleanup.interval", "management-server"); s_configurationComponents.put("stop.retry.interval", "HighAvailabilityManager"); s_configurationComponents.put("restart.retry.interval", "HighAvailabilityManager"); s_configurationComponents.put("investigate.retry.interval", "HighAvailabilityManager"); @@ -294,7 +294,7 @@ public class DatabaseConfig { s_configurationComponents.put("snapshot.test.months.per.year", "SnapshotManager"); s_configurationComponents.put("hypervisor.type", "ManagementServer"); - + s_defaultConfigurationValues.put("host.stats.interval", "60000"); s_defaultConfigurationValues.put("storage.stats.interval", "60000"); //s_defaultConfigurationValues.put("volume.stats.interval", "-1"); @@ -336,7 +336,7 @@ public class DatabaseConfig { s_defaultConfigurationValues.put("cpu.overprovisioning.factor", "1"); s_defaultConfigurationValues.put("mem.overprovisioning.factor", "1"); } - + protected DatabaseConfig() { } @@ -346,20 +346,20 @@ public class DatabaseConfig { public static void main(String[] args) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"); - + File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); if(file != null) { - System.out.println("Log4j configuration from : " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); - } else { - System.out.println("Configure log4j with default properties"); - } - + System.out.println("Log4j configuration from : " + file.getAbsolutePath()); + DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); + } else { + System.out.println("Configure log4j with default properties"); + } + if (args.length < 1) { s_logger.error("error starting database config, missing initial data file"); } else { try { - DatabaseConfig config = LegacyComponentLocator.inject(DatabaseConfig.class, args[0]); + DatabaseConfig config = ComponentContext.inject(DatabaseConfig.class, args[0]); config.doVersionCheck(); config.doConfig(); System.exit(0); @@ -374,65 +374,65 @@ public class DatabaseConfig { public DatabaseConfig(String configFileName) { _configFileName = configFileName; } - + private void doVersionCheck() { - try { - String warningMsg = "\nYou are using an outdated format for server-setup.xml. Please switch to the new format.\n"; - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder dbuilder = dbf.newDocumentBuilder(); - File configFile = new File(_configFileName); - Document d = dbuilder.parse(configFile); - NodeList nodeList = d.getElementsByTagName("version"); - - if (nodeList.getLength() == 0) { - System.out.println(warningMsg); - return; - } - - Node firstNode = nodeList.item(0); - String version = firstNode.getTextContent(); - - if (!version.equals("2.0")) { - System.out.println(warningMsg); - } - - } catch (ParserConfigurationException parserException) { - parserException.printStackTrace(); - } catch (IOException ioException) { - ioException.printStackTrace(); - } catch (SAXException saxException) { - saxException.printStackTrace(); - } + try { + String warningMsg = "\nYou are using an outdated format for server-setup.xml. Please switch to the new format.\n"; + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder dbuilder = dbf.newDocumentBuilder(); + File configFile = new File(_configFileName); + Document d = dbuilder.parse(configFile); + NodeList nodeList = d.getElementsByTagName("version"); + + if (nodeList.getLength() == 0) { + System.out.println(warningMsg); + return; + } + + Node firstNode = nodeList.item(0); + String version = firstNode.getTextContent(); + + if (!version.equals("2.0")) { + System.out.println(warningMsg); + } + + } catch (ParserConfigurationException parserException) { + parserException.printStackTrace(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } catch (SAXException saxException) { + saxException.printStackTrace(); + } } @DB protected void doConfig() { Transaction txn = Transaction.currentTxn(); try { - + File configFile = new File(_configFileName); - + SAXParserFactory spfactory = SAXParserFactory.newInstance(); SAXParser saxParser = spfactory.newSAXParser(); DbConfigXMLHandler handler = new DbConfigXMLHandler(); handler.setParent(this); - + txn.start(); // Save user configured values for all fields saxParser.parse(configFile, handler); - + // Save default values for configuration fields saveVMTemplate(); saveRootDomain(); saveDefaultConfiguations(); - + txn.commit(); // Check pod CIDRs against each other, and against the guest ip network/netmask pzc.checkAllPodCidrSubnets(); - + } catch (Exception ex) { - System.out.print("ERROR IS"+ex); + System.out.print("ERROR IS"+ex); s_logger.error("error", ex); txn.rollback(); } @@ -448,7 +448,7 @@ public class DatabaseConfig { } else if ("physicalNetwork".equals(_currentObjectName)) { savePhysicalNetwork(); } else if ("vlan".equals(_currentObjectName)) { - saveVlan(); + saveVlan(); } else if ("pod".equals(_currentObjectName)) { savePod(); } else if ("serviceOffering".equals(_currentObjectName)) { @@ -460,9 +460,9 @@ public class DatabaseConfig { } else if ("configuration".equals(_currentObjectName)) { saveConfiguration(); } else if ("storagePool".equals(_currentObjectName)) { - saveStoragePool(); + saveStoragePool(); } else if ("secondaryStorage".equals(_currentObjectName)) { - saveSecondaryStorage(); + saveSecondaryStorage(); } else if ("cluster".equals(_currentObjectName)) { saveCluster(); } else if ("physicalNetworkServiceProvider".equals(_currentObjectName)) { @@ -472,88 +472,88 @@ public class DatabaseConfig { } _currentObjectParams = null; } - + @DB public void saveSecondaryStorage() { - long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId")); - String url = _currentObjectParams.get("url"); - String mountPoint; - try { - mountPoint = NfsUtils.url2Mount(url); - } catch (URISyntaxException e1) { - return; - } - String insertSql1 = "INSERT INTO `host` (`id`, `name`, `status` , `type` , `private_ip_address`, `private_netmask` ,`private_mac_address` , `storage_ip_address` ,`storage_netmask`, `storage_mac_address`, `data_center_id`, `version`, `dom0_memory`, `last_ping`, `resource`, `guid`, `hypervisor_type`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - String insertSqlHostDetails = "INSERT INTO `host_details` (`id`, `host_id`, `name`, `value`) VALUES(?,?,?,?)"; + long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId")); + String url = _currentObjectParams.get("url"); + String mountPoint; + try { + mountPoint = NfsUtils.url2Mount(url); + } catch (URISyntaxException e1) { + return; + } + String insertSql1 = "INSERT INTO `host` (`id`, `name`, `status` , `type` , `private_ip_address`, `private_netmask` ,`private_mac_address` , `storage_ip_address` ,`storage_netmask`, `storage_mac_address`, `data_center_id`, `version`, `dom0_memory`, `last_ping`, `resource`, `guid`, `hypervisor_type`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String insertSqlHostDetails = "INSERT INTO `host_details` (`id`, `host_id`, `name`, `value`) VALUES(?,?,?,?)"; String insertSql2 = "INSERT INTO `op_host` (`id`, `sequence`) VALUES(?, ?)"; - Transaction txn = Transaction.currentTxn(); - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1); - stmt.setLong(1, 0); - stmt.setString(2, url); - stmt.setString(3, "UP"); - stmt.setString(4, "SecondaryStorage"); - stmt.setString(5, "192.168.122.1"); - stmt.setString(6, "255.255.255.0"); - stmt.setString(7, "92:ff:f5:ad:23:e1"); - stmt.setString(8, "192.168.122.1"); - stmt.setString(9, "255.255.255.0"); - stmt.setString(10, "92:ff:f5:ad:23:e1"); - stmt.setLong(11, dataCenterId); - stmt.setString(12, "2.2.4"); - stmt.setLong(13, 0); - stmt.setLong(14, 1238425896); - - boolean nfs = false; - if (url.startsWith("nfs")) { - nfs = true; - } - if (nfs) { - stmt.setString(15, "com.cloud.storage.resource.NfsSecondaryStorageResource"); - } else { - stmt.setString(15, "com.cloud.storage.secondary.LocalSecondaryStorageResource"); - } - stmt.setString(16, url); - stmt.setString(17, "None"); - stmt.executeUpdate(); - - stmt = txn.prepareAutoCloseStatement(insertSqlHostDetails); - stmt.setLong(1, 1); - stmt.setLong(2, 1); - stmt.setString(3, "mount.parent"); - if (nfs) { - stmt.setString(4, "/mnt"); - } else { + Transaction txn = Transaction.currentTxn(); + try { + PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1); + stmt.setLong(1, 0); + stmt.setString(2, url); + stmt.setString(3, "UP"); + stmt.setString(4, "SecondaryStorage"); + stmt.setString(5, "192.168.122.1"); + stmt.setString(6, "255.255.255.0"); + stmt.setString(7, "92:ff:f5:ad:23:e1"); + stmt.setString(8, "192.168.122.1"); + stmt.setString(9, "255.255.255.0"); + stmt.setString(10, "92:ff:f5:ad:23:e1"); + stmt.setLong(11, dataCenterId); + stmt.setString(12, "2.2.4"); + stmt.setLong(13, 0); + stmt.setLong(14, 1238425896); + + boolean nfs = false; + if (url.startsWith("nfs")) { + nfs = true; + } + if (nfs) { + stmt.setString(15, "com.cloud.storage.resource.NfsSecondaryStorageResource"); + } else { + stmt.setString(15, "com.cloud.storage.secondary.LocalSecondaryStorageResource"); + } + stmt.setString(16, url); + stmt.setString(17, "None"); + stmt.executeUpdate(); + + stmt = txn.prepareAutoCloseStatement(insertSqlHostDetails); + stmt.setLong(1, 1); + stmt.setLong(2, 1); + stmt.setString(3, "mount.parent"); + if (nfs) { + stmt.setString(4, "/mnt"); + } else { stmt.setString(4, "/"); } - stmt.executeUpdate(); - - stmt.setLong(1, 2); - stmt.setLong(2, 1); - stmt.setString(3, "mount.path"); - if (nfs) { - stmt.setString(4, mountPoint); - } else { + stmt.executeUpdate(); + + stmt.setLong(1, 2); + stmt.setLong(2, 1); + stmt.setString(3, "mount.path"); + if (nfs) { + stmt.setString(4, mountPoint); + } else { stmt.setString(4, url.replaceFirst("file:/", "")); } - stmt.executeUpdate(); - - stmt.setLong(1, 3); - stmt.setLong(2, 1); - stmt.setString(3, "orig.url"); - stmt.setString(4, url); - stmt.executeUpdate(); - + stmt.executeUpdate(); + + stmt.setLong(1, 3); + stmt.setLong(2, 1); + stmt.setString(3, "orig.url"); + stmt.setString(4, url); + stmt.executeUpdate(); + stmt = txn.prepareAutoCloseStatement(insertSql2); stmt.setLong(1, 1); stmt.setLong(2, 1); stmt.executeUpdate(); - } catch (SQLException ex) { - System.out.println("Error creating secondary storage: " + ex.getMessage()); - return; - } + } catch (SQLException ex) { + System.out.println("Error creating secondary storage: " + ex.getMessage()); + return; + } } - + @DB public void saveCluster() { String name = _currentObjectParams.get("name"); @@ -562,7 +562,7 @@ public class DatabaseConfig { long podId = Long.parseLong(_currentObjectParams.get("podId")); String hypervisor = _currentObjectParams.get("hypervisorType"); String insertSql1 = "INSERT INTO `cluster` (`id`, `name`, `data_center_id` , `pod_id`, `hypervisor_type` , `cluster_type`, `allocation_state`) VALUES (?,?,?,?,?,?,?)"; - + Transaction txn = Transaction.currentTxn(); try { PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1); @@ -583,54 +583,54 @@ public class DatabaseConfig { } - + @DB public void saveStoragePool() { - String name = _currentObjectParams.get("name"); - long id = Long.parseLong(_currentObjectParams.get("id")); - long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId")); - long podId = Long.parseLong(_currentObjectParams.get("podId")); - long clusterId = Long.parseLong(_currentObjectParams.get("clusterId")); - String hostAddress = _currentObjectParams.get("hostAddress"); - String hostPath = _currentObjectParams.get("hostPath"); - String storageType = _currentObjectParams.get("storageType"); - String uuid = UUID.nameUUIDFromBytes(new String(hostAddress+hostPath).getBytes()).toString(); - - String insertSql1 = "INSERT INTO `storage_pool` (`id`, `name`, `uuid` , `pool_type` , `port`, `data_center_id` ,`available_bytes` , `capacity_bytes` ,`host_address`, `path`, `created`, `pod_id`,`status` , `cluster_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - // String insertSql2 = "INSERT INTO `netfs_storage_pool` VALUES (?,?,?)"; - - Transaction txn = Transaction.currentTxn(); - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1); - stmt.setLong(1, id); - stmt.setString(2, name); - stmt.setString(3, uuid); - if (storageType == null) { + String name = _currentObjectParams.get("name"); + long id = Long.parseLong(_currentObjectParams.get("id")); + long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId")); + long podId = Long.parseLong(_currentObjectParams.get("podId")); + long clusterId = Long.parseLong(_currentObjectParams.get("clusterId")); + String hostAddress = _currentObjectParams.get("hostAddress"); + String hostPath = _currentObjectParams.get("hostPath"); + String storageType = _currentObjectParams.get("storageType"); + String uuid = UUID.nameUUIDFromBytes(new String(hostAddress+hostPath).getBytes()).toString(); + + String insertSql1 = "INSERT INTO `storage_pool` (`id`, `name`, `uuid` , `pool_type` , `port`, `data_center_id` ,`available_bytes` , `capacity_bytes` ,`host_address`, `path`, `created`, `pod_id`,`status` , `cluster_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + // String insertSql2 = "INSERT INTO `netfs_storage_pool` VALUES (?,?,?)"; + + Transaction txn = Transaction.currentTxn(); + try { + PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1); + stmt.setLong(1, id); + stmt.setString(2, name); + stmt.setString(3, uuid); + if (storageType == null) { stmt.setString(4, "NetworkFileSystem"); } else { stmt.setString(4, storageType); } - stmt.setLong(5, 111); - stmt.setLong(6, dataCenterId); - stmt.setLong(7,0); - stmt.setLong(8,0); - stmt.setString(9, hostAddress); - stmt.setString(10, hostPath); - stmt.setDate(11, new Date(new java.util.Date().getTime())); - stmt.setLong(12, podId); - stmt.setString(13, Status.Up.toString()); - stmt.setLong(14, clusterId); - stmt.executeUpdate(); - - } catch (SQLException ex) { - System.out.println("Error creating storage pool: " + ex.getMessage()); - s_logger.error("error creating storage pool ", ex); - return; - } - - } - - private void saveZone() { + stmt.setLong(5, 111); + stmt.setLong(6, dataCenterId); + stmt.setLong(7,0); + stmt.setLong(8,0); + stmt.setString(9, hostAddress); + stmt.setString(10, hostPath); + stmt.setDate(11, new Date(new java.util.Date().getTime())); + stmt.setLong(12, podId); + stmt.setString(13, Status.Up.toString()); + stmt.setLong(14, clusterId); + stmt.executeUpdate(); + + } catch (SQLException ex) { + System.out.println("Error creating storage pool: " + ex.getMessage()); + s_logger.error("error creating storage pool ", ex); + return; + } + + } + + private void saveZone() { long id = Long.parseLong(_currentObjectParams.get("id")); String name = _currentObjectParams.get("name"); //String description = _currentObjectParams.get("description"); @@ -641,7 +641,7 @@ public class DatabaseConfig { //String vnetRange = _currentObjectParams.get("vnet"); String guestNetworkCidr = _currentObjectParams.get("guestNetworkCidr"); String networkType = _currentObjectParams.get("networktype"); - + // Check that all IPs are valid String ipError = "Please enter a valid IP address for the field: "; if (!IPRangeConfig.validOrBlankIP(dns1)) { @@ -659,15 +659,15 @@ public class DatabaseConfig { if (!IPRangeConfig.validCIDR(guestNetworkCidr)) { printError("Please enter a valid value for guestNetworkCidr"); } - - pzc.saveZone(false, id, name, dns1, dns2, internalDns1, internalDns2, guestNetworkCidr, networkType); + + pzc.saveZone(false, id, name, dns1, dns2, internalDns1, internalDns2, guestNetworkCidr, networkType); } - + private void savePhysicalNetwork() { long id = Long.parseLong(_currentObjectParams.get("id")); String zoneId = _currentObjectParams.get("zoneId"); String vnetRange = _currentObjectParams.get("vnet"); - + int vnetStart = -1; int vnetEnd = -1; if (vnetRange != null) { @@ -677,16 +677,16 @@ public class DatabaseConfig { } long zoneDbId = Long.parseLong(zoneId); pzc.savePhysicalNetwork(false, id, zoneDbId, vnetStart, vnetEnd); - + } - + private void savePhysicalNetworkServiceProvider() { long id = Long.parseLong(_currentObjectParams.get("id")); long physicalNetworkId = Long.parseLong(_currentObjectParams.get("physicalNetworkId")); String providerName = _currentObjectParams.get("providerName"); long destPhysicalNetworkId = Long.parseLong(_currentObjectParams.get("destPhysicalNetworkId")); String uuid = UUID.randomUUID().toString(); - + int vpn = Integer.parseInt(_currentObjectParams.get("vpn")); int dhcp = Integer.parseInt(_currentObjectParams.get("dhcp")); int dns = Integer.parseInt(_currentObjectParams.get("dns")); @@ -698,12 +698,12 @@ public class DatabaseConfig { int pf =Integer.parseInt(_currentObjectParams.get("portForwarding")); int userData =Integer.parseInt(_currentObjectParams.get("userData")); int securityGroup =Integer.parseInt(_currentObjectParams.get("securityGroup")); - + String insertSql1 = "INSERT INTO `physical_network_service_providers` (`id`, `uuid`, `physical_network_id` , `provider_name`, `state` ," + - "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," + - "`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," + - "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," + + "`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," + + "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + Transaction txn = Transaction.currentTxn(); try { PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1); @@ -732,7 +732,7 @@ public class DatabaseConfig { } } - + private void saveVirtualRouterProvider() { long id = Long.parseLong(_currentObjectParams.get("id")); long nspId = Long.parseLong(_currentObjectParams.get("nspId")); @@ -740,7 +740,7 @@ public class DatabaseConfig { String type = _currentObjectParams.get("type"); String insertSql1 = "INSERT INTO `virtual_router_providers` (`id`, `nsp_id`, `uuid` , `type` , `enabled`) " + - "VALUES (?,?,?,?,?)"; + "VALUES (?,?,?,?,?)"; Transaction txn = Transaction.currentTxn(); try { @@ -758,18 +758,18 @@ public class DatabaseConfig { } } - + private void saveVlan() { - String zoneId = _currentObjectParams.get("zoneId"); - String physicalNetworkIdStr = _currentObjectParams.get("physicalNetworkId"); - String vlanId = _currentObjectParams.get("vlanId"); - String gateway = _currentObjectParams.get("gateway"); + String zoneId = _currentObjectParams.get("zoneId"); + String physicalNetworkIdStr = _currentObjectParams.get("physicalNetworkId"); + String vlanId = _currentObjectParams.get("vlanId"); + String gateway = _currentObjectParams.get("gateway"); String netmask = _currentObjectParams.get("netmask"); String publicIpRange = _currentObjectParams.get("ipAddressRange"); String vlanType = _currentObjectParams.get("vlanType"); String vlanPodName = _currentObjectParams.get("podName"); - - + + String ipError = "Please enter a valid IP address for the field: "; if (!IPRangeConfig.validOrBlankIP(gateway)) { printError(ipError + "gateway"); @@ -777,51 +777,51 @@ public class DatabaseConfig { if (!IPRangeConfig.validOrBlankIP(netmask)) { printError(ipError + "netmask"); } - + // Check that the given IP address range was valid - if (!checkIpAddressRange(publicIpRange)) { + if (!checkIpAddressRange(publicIpRange)) { printError("Please enter a valid public IP range."); } - - // Split the IP address range - String[] ipAddressRangeArray = publicIpRange.split("\\-"); - String startIP = ipAddressRangeArray[0]; - String endIP = null; - if (ipAddressRangeArray.length > 1) { + + // Split the IP address range + String[] ipAddressRangeArray = publicIpRange.split("\\-"); + String startIP = ipAddressRangeArray[0]; + String endIP = null; + if (ipAddressRangeArray.length > 1) { endIP = ipAddressRangeArray[1]; } - - // If a netmask was provided, check that the startIP, endIP, and gateway all belong to the same subnet - if (netmask != null && netmask != "") { - if (endIP != null) { - if (!IPRangeConfig.sameSubnet(startIP, endIP, netmask)) { + + // If a netmask was provided, check that the startIP, endIP, and gateway all belong to the same subnet + if (netmask != null && netmask != "") { + if (endIP != null) { + if (!IPRangeConfig.sameSubnet(startIP, endIP, netmask)) { printError("Start and end IPs for the public IP range must be in the same subnet, as per the provided netmask."); } - } - - if (gateway != null && gateway != "") { - if (!IPRangeConfig.sameSubnet(startIP, gateway, netmask)) { + } + + if (gateway != null && gateway != "") { + if (!IPRangeConfig.sameSubnet(startIP, gateway, netmask)) { printError("The start IP for the public IP range must be in the same subnet as the gateway, as per the provided netmask."); } - if (endIP != null) { - if (!IPRangeConfig.sameSubnet(endIP, gateway, netmask)) { + if (endIP != null) { + if (!IPRangeConfig.sameSubnet(endIP, gateway, netmask)) { printError("The end IP for the public IP range must be in the same subnet as the gateway, as per the provided netmask."); } - } - } - } - - long zoneDbId = Long.parseLong(zoneId); - String zoneName = PodZoneConfig.getZoneName(zoneDbId); - - long physicalNetworkId = Long.parseLong(physicalNetworkIdStr); - - //Set networkId to be 0, the value will be updated after management server starts up - pzc.modifyVlan(zoneName, true, vlanId, gateway, netmask, vlanPodName, vlanType, publicIpRange, 0, physicalNetworkId); - - long vlanDbId = pzc.getVlanDbId(zoneName, vlanId); - iprc.saveIPRange("public", -1, zoneDbId, vlanDbId, startIP, endIP, null, physicalNetworkId); - + } + } + } + + long zoneDbId = Long.parseLong(zoneId); + String zoneName = PodZoneConfig.getZoneName(zoneDbId); + + long physicalNetworkId = Long.parseLong(physicalNetworkIdStr); + + //Set networkId to be 0, the value will be updated after management server starts up + pzc.modifyVlan(zoneName, true, vlanId, gateway, netmask, vlanPodName, vlanType, publicIpRange, 0, physicalNetworkId); + + long vlanDbId = pzc.getVlanDbId(zoneName, vlanId); + iprc.saveIPRange("public", -1, zoneDbId, vlanDbId, startIP, endIP, null, physicalNetworkId); + } private void savePod() { @@ -835,7 +835,7 @@ public class DatabaseConfig { String startIP = null; String endIP = null; String vlanRange = _currentObjectParams.get("vnet"); - + int vlanStart = -1; int vlanEnd = -1; if (vlanRange != null) { @@ -843,51 +843,51 @@ public class DatabaseConfig { vlanStart = Integer.parseInt(tokens[0]); vlanEnd = Integer.parseInt(tokens[1]); } - + // Get the individual cidrAddress and cidrSize values - String[] cidrPair = cidr.split("\\/"); - String cidrAddress = cidrPair[0]; - String cidrSize = cidrPair[1]; + String[] cidrPair = cidr.split("\\/"); + String cidrAddress = cidrPair[0]; + String cidrSize = cidrPair[1]; long cidrSizeNum = Long.parseLong(cidrSize); - + // Check that the gateway is in the same subnet as the CIDR - if (!IPRangeConfig.sameSubnetCIDR(gateway, cidrAddress, cidrSizeNum)) { - printError("For pod " + name + " in zone " + zoneName + " , please ensure that your gateway is in the same subnet as the pod's CIDR address."); - } - + if (!IPRangeConfig.sameSubnetCIDR(gateway, cidrAddress, cidrSizeNum)) { + printError("For pod " + name + " in zone " + zoneName + " , please ensure that your gateway is in the same subnet as the pod's CIDR address."); + } + pzc.savePod(false, id, name, dataCenterId, gateway, cidr, vlanStart, vlanEnd); - - if (privateIpRange != null) { - // Check that the given IP address range was valid - if (!checkIpAddressRange(privateIpRange)) { + + if (privateIpRange != null) { + // Check that the given IP address range was valid + if (!checkIpAddressRange(privateIpRange)) { printError("Please enter a valid private IP range."); } - - String[] ipAddressRangeArray = privateIpRange.split("\\-"); - startIP = ipAddressRangeArray[0]; - endIP = null; - if (ipAddressRangeArray.length > 1) { + + String[] ipAddressRangeArray = privateIpRange.split("\\-"); + startIP = ipAddressRangeArray[0]; + endIP = null; + if (ipAddressRangeArray.length > 1) { endIP = ipAddressRangeArray[1]; } - } - - // Check that the start IP and end IP match up with the CIDR - if (!IPRangeConfig.sameSubnetCIDR(startIP, endIP, cidrSizeNum)) { - printError("For pod " + name + " in zone " + zoneName + ", please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size."); - } - - if (!IPRangeConfig.sameSubnetCIDR(startIP, cidrAddress, cidrSizeNum)) { - printError("For pod " + name + " in zone " + zoneName + ", please ensure that your start IP is in the same subnet as the pod's CIDR address."); - } - - if (!IPRangeConfig.sameSubnetCIDR(endIP, cidrAddress, cidrSizeNum)) { - printError("For pod " + name + " in zone " + zoneName + ", please ensure that your end IP is in the same subnet as the pod's CIDR address."); - } - - if (privateIpRange != null) { - // Save the IP address range - iprc.saveIPRange("private", id, dataCenterId, -1, startIP, endIP, null, -1); - } + } + + // Check that the start IP and end IP match up with the CIDR + if (!IPRangeConfig.sameSubnetCIDR(startIP, endIP, cidrSizeNum)) { + printError("For pod " + name + " in zone " + zoneName + ", please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size."); + } + + if (!IPRangeConfig.sameSubnetCIDR(startIP, cidrAddress, cidrSizeNum)) { + printError("For pod " + name + " in zone " + zoneName + ", please ensure that your start IP is in the same subnet as the pod's CIDR address."); + } + + if (!IPRangeConfig.sameSubnetCIDR(endIP, cidrAddress, cidrSizeNum)) { + printError("For pod " + name + " in zone " + zoneName + ", please ensure that your end IP is in the same subnet as the pod's CIDR address."); + } + + if (privateIpRange != null) { + // Save the IP address range + iprc.saveIPRange("private", id, dataCenterId, -1, startIP, endIP, null, -1); + } } @@ -900,30 +900,30 @@ public class DatabaseConfig { int ramSize = Integer.parseInt(_currentObjectParams.get("ramSize")); int speed = Integer.parseInt(_currentObjectParams.get("speed")); String useLocalStorageValue = _currentObjectParams.get("useLocalStorage"); - + // int nwRate = Integer.parseInt(_currentObjectParams.get("nwRate")); // int mcRate = Integer.parseInt(_currentObjectParams.get("mcRate")); boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA")); boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored")); - + boolean useLocalStorage; if (useLocalStorageValue != null) { - if (Boolean.parseBoolean(useLocalStorageValue)) { - useLocalStorage = true; - } else { - useLocalStorage = false; - } + if (Boolean.parseBoolean(useLocalStorageValue)) { + useLocalStorage = true; + } else { + useLocalStorage = false; + } } else { - useLocalStorage = false; + useLocalStorage = false; } - + ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, useLocalStorage, false, null, false, null, false); - ServiceOfferingDaoImpl dao = LegacyComponentLocator.inject(ServiceOfferingDaoImpl.class); + ServiceOfferingDaoImpl dao = ComponentContext.inject(ServiceOfferingDaoImpl.class); try { dao.persist(serviceOffering); } catch (Exception e) { s_logger.error("error creating service offering", e); - + } /* String insertSql = "INSERT INTO `cloud`.`service_offering` (id, name, cpu, ram_size, speed, nw_rate, mc_rate, created, ha_enabled, mirrored, display_text, guest_ip_type, use_local_storage) " + @@ -937,9 +937,9 @@ public class DatabaseConfig { s_logger.error("error creating service offering", ex); return; } - */ + */ } - + @DB protected void saveDiskOffering() { long id = Long.parseLong(_currentObjectParams.get("id")); @@ -953,9 +953,9 @@ public class DatabaseConfig { String useLocal = _currentObjectParams.get("useLocal"); boolean local = false; if (useLocal != null) { - local = Boolean.parseBoolean(useLocal); + local = Boolean.parseBoolean(useLocal); } - + if (tags != null && tags.length() > 0) { String[] tokens = tags.split(","); StringBuilder newTags = new StringBuilder(); @@ -967,12 +967,12 @@ public class DatabaseConfig { } DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace , tags, false); diskOffering.setUseLocalStorage(local); - DiskOfferingDaoImpl offering = LegacyComponentLocator.inject(DiskOfferingDaoImpl.class); + DiskOfferingDaoImpl offering = ComponentContext.inject(DiskOfferingDaoImpl.class); try { offering.persist(diskOffering); } catch (Exception e) { s_logger.error("error creating disk offering", e); - + } /* String insertSql = "INSERT INTO `cloud`.`disk_offering` (id, domain_id, name, display_text, disk_size, mirrored, tags) " + @@ -987,37 +987,37 @@ public class DatabaseConfig { s_logger.error("error creating disk offering", ex); return; } - */ + */ } - + @DB protected void saveThrottlingRates() { - boolean saveNetworkThrottlingRate = (_networkThrottlingRate != null); - boolean saveMulticastThrottlingRate = (_multicastThrottlingRate != null); - - if (!saveNetworkThrottlingRate && !saveMulticastThrottlingRate) { + boolean saveNetworkThrottlingRate = (_networkThrottlingRate != null); + boolean saveMulticastThrottlingRate = (_multicastThrottlingRate != null); + + if (!saveNetworkThrottlingRate && !saveMulticastThrottlingRate) { return; } - - String insertNWRateSql = "UPDATE `cloud`.`service_offering` SET `nw_rate` = ?"; - String insertMCRateSql = "UPDATE `cloud`.`service_offering` SET `mc_rate` = ?"; - + + String insertNWRateSql = "UPDATE `cloud`.`service_offering` SET `nw_rate` = ?"; + String insertMCRateSql = "UPDATE `cloud`.`service_offering` SET `mc_rate` = ?"; + Transaction txn = Transaction.currentTxn(); - try { + try { PreparedStatement stmt; - + if (saveNetworkThrottlingRate) { - stmt = txn.prepareAutoCloseStatement(insertNWRateSql); - stmt.setString(1, _networkThrottlingRate); - stmt.executeUpdate(); + stmt = txn.prepareAutoCloseStatement(insertNWRateSql); + stmt.setString(1, _networkThrottlingRate); + stmt.executeUpdate(); } - + if (saveMulticastThrottlingRate) { - stmt = txn.prepareAutoCloseStatement(insertMCRateSql); - stmt.setString(1, _multicastThrottlingRate); - stmt.executeUpdate(); + stmt = txn.prepareAutoCloseStatement(insertMCRateSql); + stmt.setString(1, _multicastThrottlingRate); + stmt.executeUpdate(); } - + } catch (SQLException ex) { s_logger.error("error saving network and multicast throttling rates to all service offerings", ex); return; @@ -1026,7 +1026,7 @@ public class DatabaseConfig { // no configurable values for VM Template, hard-code the defaults for now private void saveVMTemplate() { - /* + /* long id = 1; String uniqueName = "routing"; String name = "DomR Template"; @@ -1051,8 +1051,8 @@ public class DatabaseConfig { } finally { txn.close(); } - */ -/* + */ + /* // do it again for console proxy template id = 2; uniqueName = "consoleproxy"; @@ -1060,7 +1060,7 @@ public class DatabaseConfig { isPublic = 0; path = "template/private/u000000/os/consoleproxy"; type = "ext3"; - + insertSql = "INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, path, created, type, hvm, bits, created_by, ready) " + "VALUES (" + id + ",'" + uniqueName + "','" + name + "'," + isPublic + ",'" + path + "',now(),'" + type + "'," + requiresHvm + "," + bits + "," + createdByUserId + "," + isReady + ")"; @@ -1074,7 +1074,7 @@ public class DatabaseConfig { } finally { txn.close(); } -*/ + */ } @DB @@ -1091,27 +1091,27 @@ public class DatabaseConfig { // insert system user insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created)" + - " VALUES (1, 'system', RAND(), 1, 'system', 'cloud', now())"; - txn = Transaction.currentTxn(); - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); - stmt.executeUpdate(); - } catch (SQLException ex) { - s_logger.error("error creating system user", ex); - } - - // insert admin user + " VALUES (1, 'system', RAND(), 1, 'system', 'cloud', now())"; + txn = Transaction.currentTxn(); + try { + PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); + stmt.executeUpdate(); + } catch (SQLException ex) { + s_logger.error("error creating system user", ex); + } + + // insert admin user long id = Long.parseLong(_currentObjectParams.get("id")); String username = _currentObjectParams.get("username"); String firstname = _currentObjectParams.get("firstname"); String lastname = _currentObjectParams.get("lastname"); String password = _currentObjectParams.get("password"); String email = _currentObjectParams.get("email"); - + if (email == null || email.equals("")) { printError("An email address for each user is required."); } - + MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); @@ -1158,45 +1158,45 @@ public class DatabaseConfig { saveConfiguration(name, value, null); } } - + private void saveConfiguration() { String name = _currentObjectParams.get("name"); String value = _currentObjectParams.get("value"); String category = _currentObjectParams.get("category"); saveConfiguration(name, value, category); } - + @DB protected void saveConfiguration(String name, String value, String category) { String instance = "DEFAULT"; String description = s_configurationDescriptions.get(name); String component = s_configurationComponents.get(name); if (category == null) { - category = "Advanced"; + category = "Advanced"; } - + String instanceNameError = "Please enter a non-blank value for the field: "; if (name.equals("instance.name")) { - if (value == null || value.isEmpty() || !value.matches("^[A-Za-z0-9]{1,8}$")) { + if (value == null || value.isEmpty() || !value.matches("^[A-Za-z0-9]{1,8}$")) { printError(instanceNameError + "configuration: instance.name can not be empty and can only contain numbers and alphabets up to 8 characters long"); } } - + if (name.equals("network.throttling.rate")) { - if (value != null && !value.isEmpty()) { + if (value != null && !value.isEmpty()) { _networkThrottlingRate = value; } } - + if (name.equals("multicast.throttling.rate")) { - if (value != null && !value.isEmpty()) { + if (value != null && !value.isEmpty()) { _multicastThrottlingRate = value; } } String insertSql = "INSERT INTO `cloud`.`configuration` (instance, component, name, value, description, category) " + - "VALUES ('" + instance + "','" + component + "','" + name + "','" + value + "','" + description + "','" + category + "')"; - + "VALUES ('" + instance + "','" + component + "','" + name + "','" + value + "','" + description + "','" + category + "')"; + String selectSql = "SELECT name FROM cloud.configuration WHERE name = '" + name + "'"; Transaction txn = Transaction.currentTxn(); @@ -1205,38 +1205,38 @@ public class DatabaseConfig { ResultSet result = stmt.executeQuery(); Boolean hasRow = result.next(); if (!hasRow) { - stmt = txn.prepareAutoCloseStatement(insertSql); - stmt.executeUpdate(); + stmt = txn.prepareAutoCloseStatement(insertSql); + stmt.executeUpdate(); } } catch (SQLException ex) { s_logger.error("error creating configuration", ex); } } - + private boolean checkIpAddressRange(String ipAddressRange) { - String[] ipAddressRangeArray = ipAddressRange.split("\\-"); - String startIP = ipAddressRangeArray[0]; - String endIP = null; - if (ipAddressRangeArray.length > 1) { + String[] ipAddressRangeArray = ipAddressRange.split("\\-"); + String startIP = ipAddressRangeArray[0]; + String endIP = null; + if (ipAddressRangeArray.length > 1) { endIP = ipAddressRangeArray[1]; } - - if (!IPRangeConfig.validIP(startIP)) { - s_logger.error("The private IP address: " + startIP + " is invalid."); - return false; - } - - if (!IPRangeConfig.validOrBlankIP(endIP)) { - s_logger.error("The private IP address: " + endIP + " is invalid."); - return false; - } - - if (!IPRangeConfig.validIPRange(startIP, endIP)) { - s_logger.error("The IP range " + startIP + " -> " + endIP + " is invalid."); - return false; - } - - return true; + + if (!IPRangeConfig.validIP(startIP)) { + s_logger.error("The private IP address: " + startIP + " is invalid."); + return false; + } + + if (!IPRangeConfig.validOrBlankIP(endIP)) { + s_logger.error("The private IP address: " + endIP + " is invalid."); + return false; + } + + if (!IPRangeConfig.validIPRange(startIP, endIP)) { + s_logger.error("The IP range " + startIP + " -> " + endIP + " is invalid."); + return false; + } + + return true; } @DB @@ -1249,7 +1249,7 @@ public class DatabaseConfig { } catch (SQLException ex) { s_logger.error("error creating ROOT domain", ex); } - + /* String updateSql = "update account set domain_id = 1 where id = 2"; Transaction txn = Transaction.currentTxn(); @@ -1272,7 +1272,7 @@ public class DatabaseConfig { } finally { txn.close(); } - */ + */ } class DbConfigXMLHandler extends DefaultHandler { @@ -1295,14 +1295,14 @@ public class DatabaseConfig { @Override public void startElement(String s, String s1, String s2, Attributes attributes) throws SAXException { - if ("object".equals(s2)) { - _parent.setCurrentObjectName(convertName(attributes.getValue("name"))); - } else if ("field".equals(s2)) { - if (_currentObjectParams == null) { - _currentObjectParams = new HashMap(); - } - _currentFieldName = convertName(attributes.getValue("name")); - } else if (DatabaseConfig.objectNames.contains(s2)) { + if ("object".equals(s2)) { + _parent.setCurrentObjectName(convertName(attributes.getValue("name"))); + } else if ("field".equals(s2)) { + if (_currentObjectParams == null) { + _currentObjectParams = new HashMap(); + } + _currentFieldName = convertName(attributes.getValue("name")); + } else if (DatabaseConfig.objectNames.contains(s2)) { _parent.setCurrentObjectName(s2); } else if (DatabaseConfig.fieldNames.contains(s2)) { if (_currentObjectParams == null) { @@ -1313,95 +1313,95 @@ public class DatabaseConfig { } @Override - public void characters(char[] ch, int start, int length) throws SAXException { + public void characters(char[] ch, int start, int length) throws SAXException { if ((_currentObjectParams != null) && (_currentFieldName != null)) { String currentFieldVal = new String(ch, start, length); _currentObjectParams.put(_currentFieldName, currentFieldVal); } } - + private String convertName(String name) { - if (name.contains(".")){ - String[] nameArray = name.split("\\."); - for (int i = 1; i < nameArray.length; i++) { - String word = nameArray[i]; - nameArray[i] = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); - } - name = ""; - for (int i = 0; i < nameArray.length; i++) { - name = name.concat(nameArray[i]); - } - } - return name; - } + if (name.contains(".")){ + String[] nameArray = name.split("\\."); + for (int i = 1; i < nameArray.length; i++) { + String word = nameArray[i]; + nameArray[i] = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); + } + name = ""; + for (int i = 0; i < nameArray.length; i++) { + name = name.concat(nameArray[i]); + } + } + return name; + } } - + public static List genReturnList(String success, String message) { - List returnList = new ArrayList(2); - returnList.add(0, success); - returnList.add(1, message); - return returnList; - } - + List returnList = new ArrayList(2); + returnList.add(0, success); + returnList.add(1, message); + return returnList; + } + public static void printError(String message) { - System.out.println(message); - System.exit(1); + System.out.println(message); + System.exit(1); } public static String getDatabaseValueString(String selectSql, String name, String errorMsg) { - Transaction txn = Transaction.open("getDatabaseValueString"); - PreparedStatement stmt = null; - - try { - stmt = txn.prepareAutoCloseStatement(selectSql); - ResultSet rs = stmt.executeQuery(); - if (rs.next()) { - String value = rs.getString(name); - return value; - } else { + Transaction txn = Transaction.open("getDatabaseValueString"); + PreparedStatement stmt = null; + + try { + stmt = txn.prepareAutoCloseStatement(selectSql); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { + String value = rs.getString(name); + return value; + } else { return null; } - } catch (SQLException e) { - System.out.println("Exception: " + e.getMessage()); - printError(errorMsg); - } finally { - txn.close(); - } - return null; - } - + } catch (SQLException e) { + System.out.println("Exception: " + e.getMessage()); + printError(errorMsg); + } finally { + txn.close(); + } + return null; + } + public static long getDatabaseValueLong(String selectSql, String name, String errorMsg) { - Transaction txn = Transaction.open("getDatabaseValueLong"); - PreparedStatement stmt = null; - - try { - stmt = txn.prepareAutoCloseStatement(selectSql); - ResultSet rs = stmt.executeQuery(); - if (rs.next()) { + Transaction txn = Transaction.open("getDatabaseValueLong"); + PreparedStatement stmt = null; + + try { + stmt = txn.prepareAutoCloseStatement(selectSql); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { return rs.getLong(name); } else { return -1; } - } catch (SQLException e) { - System.out.println("Exception: " + e.getMessage()); - printError(errorMsg); - } finally { - txn.close(); - } - return -1; - } - + } catch (SQLException e) { + System.out.println("Exception: " + e.getMessage()); + printError(errorMsg); + } finally { + txn.close(); + } + return -1; + } + public static void saveSQL(String sql, String errorMsg) { Transaction txn = Transaction.open("saveSQL"); - try { + try { PreparedStatement stmt = txn.prepareAutoCloseStatement(sql); stmt.executeUpdate(); } catch (SQLException ex) { - System.out.println("SQL Exception: " + ex.getMessage()); + System.out.println("SQL Exception: " + ex.getMessage()); printError(errorMsg); } finally { txn.close(); } - } - + } + }