http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/api/src/com/cloud/network/vpc/VpcService.java ----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/api/src/org/apache/cloudstack/api/ApiConstants.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java ---------------------------------------------------------------------- diff --cc engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java index 0000000,2e8ee91..a518ba1 mode 000000,100644..100644 --- a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java +++ b/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java @@@ -1,0 -1,142 +1,142 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF licenses this file + // to you under the Apache License, Version 2.0 (the + // "License"); you may not use this file except in compliance + // with the License. You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, + // software distributed under the License is distributed on an + // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + // KIND, either express or implied. See the License for the + // specific language governing permissions and limitations + // under the License. + package com.cloud.network.dao; + + import java.util.UUID; + + import javax.persistence.Column; + import javax.persistence.Entity; + import javax.persistence.GeneratedValue; + import javax.persistence.GenerationType; + import javax.persistence.Id; + import javax.persistence.Table; + + import com.cloud.network.RemoteAccessVpn; + + @Entity + @Table(name=("remote_access_vpn")) + public class RemoteAccessVpnVO implements RemoteAccessVpn { + @Column(name="account_id") + private long accountId; + + @Column(name="network_id") + private long networkId; + + @Column(name="domain_id") + private long domainId; + + @Column(name="vpn_server_addr_id") + private long serverAddressId; + + @Column(name="local_ip") + private String localIp; + + @Column(name="ip_range") + private String ipRange; + + @Column(name="ipsec_psk") + private String ipsecPresharedKey; + + @Column(name="state") + private State state; - ++ + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + private long id; - ++ + @Column(name="uuid") + private String uuid; + - public RemoteAccessVpnVO() { ++ public RemoteAccessVpnVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public RemoteAccessVpnVO(long accountId, long domainId, long networkId, long publicIpId, String localIp, String ipRange, String presharedKey) { + this.accountId = accountId; + this.serverAddressId = publicIpId; + this.ipRange = ipRange; + this.ipsecPresharedKey = presharedKey; + this.localIp = localIp; + this.domainId = domainId; + this.networkId = networkId; + this.state = State.Added; + this.uuid = UUID.randomUUID().toString(); + } + + @Override + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public long getServerAddressId() { + return serverAddressId; + } + + @Override + public String getIpRange() { + return ipRange; + } + + public void setIpRange(String ipRange) { + this.ipRange = ipRange; + } + + @Override + public String getIpsecPresharedKey() { + return ipsecPresharedKey; + } + + public void setIpsecPresharedKey(String ipsecPresharedKey) { + this.ipsecPresharedKey = ipsecPresharedKey; + } + + @Override + public String getLocalIp() { + return localIp; + } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getNetworkId() { + return networkId; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java ---------------------------------------------------------------------- diff --cc engine/schema/src/com/cloud/upgrade/DatabaseCreator.java index 0000000,9b1be6b..d9f9e7b mode 000000,100755..100755 --- a/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java +++ b/engine/schema/src/com/cloud/upgrade/DatabaseCreator.java @@@ -1,0 -1,233 +1,233 @@@ + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package com.cloud.upgrade; + + import java.io.*; + import java.sql.Connection; + import java.sql.DriverManager; + import java.sql.SQLException; + import java.sql.Statement; + import java.util.ArrayList; + import java.util.List; + import java.util.Properties; + + import org.springframework.context.support.ClassPathXmlApplicationContext; + + import com.cloud.utils.PropertiesUtil; + + import com.cloud.utils.component.ComponentContext; + import com.cloud.utils.component.SystemIntegrityChecker; + import com.cloud.utils.db.ScriptRunner; + import com.cloud.utils.db.Transaction; + + // Creates the CloudStack Database by using the 4.0 schema and apply + // upgrade steps to it. + public class DatabaseCreator { + + protected static void printHelp(String cmd) { + System.out.println( + "\nDatabaseCreator creates the database schema by removing the \n" + + "previous schema, creating the schema, and running \n" + + "through the database updaters."); + System.out.println("Usage: " + cmd + " [options] [db.properties file] [schema.sql files] [database upgrade class]\nOptions:" + + "\n --database=a,b comma separate databases to initialize, use the db name in db.properties defined as db.xyz.host, xyz should be passed" + + "\n --rootpassword=password, by default it will try with an empty password" + + "\n --dry or -d, this would not run any process, just does a dry run" + + "\n --verbose or -v to print running sql commands, by default it won't print them" + + "\n --help or -h for help"); + } + + private static boolean fileExists(String file) { + File f = new File(file); + if (!f.exists()) + System.out.println("========> WARNING: Provided file does not exist: " + file); + return f.exists(); + } + + private static void runScript(Connection conn, Reader reader, String filename, boolean verbosity) { + ScriptRunner runner = new ScriptRunner(conn, false, true, verbosity); + try { + runner.runScript(reader); + } catch (IOException e) { + System.err.println("Unable to read " + filename + ": " + e.getMessage()); + System.exit(1); + } catch (SQLException e) { + System.err.println("Unable to execute " + filename + ": " + e.getMessage()); + System.exit(1); + } + } + + private static void runQuery(String host, String port, String rootPassword, String query, boolean dryRun) { + System.out.println("============> Running query: " + query); + Connection conn = null; + try { + conn = DriverManager.getConnection(String.format("jdbc:mysql://%s:%s/", host, port), + "root", rootPassword); + Statement stmt = conn.createStatement(); + if (!dryRun) + stmt.executeUpdate(query); + conn.close(); + } catch (SQLException e) { + System.out.println("SQL exception in trying initDB: " + e); + System.exit(1); + } + } + + private static void initDB(String dbPropsFile, String rootPassword, String[] databases, boolean dryRun) { + Properties dbProperties = new Properties(); + try { + dbProperties.load(new FileInputStream(new File(dbPropsFile))); + } catch (IOException e) { + System.out.println("IOError: unable to load/read db properties file: " + e); + System.exit(1); + } + + for (String database: databases) { + String host = dbProperties.getProperty(String.format("db.%s.host", database)); + String port = dbProperties.getProperty(String.format("db.%s.port", database)); + String username = dbProperties.getProperty(String.format("db.%s.username", database)); + String password = dbProperties.getProperty(String.format("db.%s.password", database)); + String dbName = dbProperties.getProperty(String.format("db.%s.name", database)); + System.out.println(String.format("========> Initializing database=%s with host=%s port=%s username=%s password=%s", dbName, host, port, username, password)); + + List<String> queries = new ArrayList<String>(); + queries.add(String.format("drop database if exists `%s`", dbName)); + queries.add(String.format("create database `%s`", dbName)); + queries.add(String.format("GRANT ALL ON %s.* to '%s'@`localhost` identified by '%s'", dbName, username, password)); + queries.add(String.format("GRANT ALL ON %s.* to '%s'@`%%` identified by '%s'", dbName, username, password)); + + for (String query: queries) { + runQuery(host, port, rootPassword, query, dryRun); + } + } + } + + public static void main(String[] args) { - - ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( - new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"}); - appContext.getBean(ComponentContext.class); - ++ ++ ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( ++ new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"}); ++ appContext.getBean(ComponentContext.class); ++ + String dbPropsFile = ""; + List<String> sqlFiles = new ArrayList<String>(); + List<String> upgradeClasses = new ArrayList<String>(); + String[] databases = new String[] {}; + String rootPassword = ""; + boolean verbosity = false; + boolean dryRun = false; + + // Process opts + for (String arg: args) { + if (arg.equals("--help") || arg.equals("-h")) { + printHelp("DatabaseCreator"); + System.exit(0); + } else if (arg.equals("--verbose") || arg.equals("-v")) { + verbosity = true; + } else if (arg.equals("--dry") || arg.equals("-d")) { + dryRun = true; + } else if (arg.startsWith("--rootpassword=")) { + rootPassword = arg.substring(arg.lastIndexOf("=") + 1, arg.length()); + } else if (arg.startsWith("--database=")) { + databases = arg.substring(arg.lastIndexOf("=") + 1, arg.length()).split(","); + } else if (arg.endsWith(".sql")) { + sqlFiles.add(arg); + } else if (arg.endsWith(".properties")) { + if (!dbPropsFile.endsWith("properties.override") && fileExists(arg)) + dbPropsFile = arg; + } else if (arg.endsWith("properties.override")) { + if (fileExists(arg)) + dbPropsFile = arg; + } else { + upgradeClasses.add(arg); + } + } + + if ((dbPropsFile.isEmpty()) + || (sqlFiles.size() == 0) && upgradeClasses.size() == 0) { + printHelp("DatabaseCreator"); + System.exit(1); + } + + try { + Transaction.initDataSource(dbPropsFile); + } catch (NullPointerException e) { + } + initDB(dbPropsFile, rootPassword, databases, dryRun); + + // Process sql files + for (String sqlFile: sqlFiles) { + File sqlScript = PropertiesUtil.findConfigFile(sqlFile); + if (sqlScript == null) { + System.err.println("Unable to find " + sqlFile); + printHelp("DatabaseCreator"); + System.exit(1); + } + + System.out.println("========> Processing SQL file at " + sqlScript.getAbsolutePath()); + Connection conn = Transaction.getStandaloneConnection(); + try { + FileReader reader = null; + try { + reader = new FileReader(sqlScript); + } catch (FileNotFoundException e) { + System.err.println("Unable to read " + sqlFile + ": " + e.getMessage()); + System.exit(1); + } + if (!dryRun) + runScript(conn, reader, sqlFile, verbosity); + } finally { + try { + conn.close(); + } catch (SQLException e) { + System.err.println("Unable to close DB connection: " + e.getMessage()); + } + } + } + + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + // Process db upgrade classes + for (String upgradeClass: upgradeClasses) { + System.out.println("========> Processing upgrade: " + upgradeClass); + Class<?> clazz = null; + try { + clazz = Class.forName(upgradeClass); + if (!SystemIntegrityChecker.class.isAssignableFrom(clazz)) { + System.err.println("The class must be of SystemIntegrityChecker: " + clazz.getName()); + System.exit(1); + } + SystemIntegrityChecker checker = (SystemIntegrityChecker)clazz.newInstance(); + checker.check(); + } catch (ClassNotFoundException e) { + System.err.println("Unable to find " + upgradeClass + ": " + e.getMessage()); + System.exit(1); + } catch (InstantiationException e) { + System.err.println("Unable to instantiate " + upgradeClass + ": " + e.getMessage()); + System.exit(1); + } catch (IllegalAccessException e) { + System.err.println("Unable to access " + upgradeClass + ": " + e.getMessage()); + System.exit(1); + } + + } + } finally { + txn.close(); + } + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java ---------------------------------------------------------------------- diff --cc engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index 0000000,05e2b49..d9cff7a mode 000000,100644..100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@@ -1,0 -1,402 +1,402 @@@ + // Licensed to the Apache Software Foundation (ASF) under one + // or more contributor license agreements. See the NOTICE file + // distributed with this work for additional information + // regarding copyright ownership. The ASF licenses this file + // to you under the Apache License, Version 2.0 (the + // "License"); you may not use this file except in compliance + // with the License. You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, + // software distributed under the License is distributed on an + // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + // KIND, either express or implied. See the License for the + // specific language governing permissions and limitations + // under the License. + + package com.cloud.upgrade.dao; + + import com.cloud.utils.exception.CloudRuntimeException; + import com.cloud.utils.script.Script; + import org.apache.log4j.Logger; + + import java.io.File; + import java.sql.Connection; + import java.sql.PreparedStatement; + import java.sql.ResultSet; + import java.sql.SQLException; + import java.util.UUID; + + public class Upgrade410to420 implements DbUpgrade { + final static Logger s_logger = Logger.getLogger(Upgrade410to420.class); + + @Override + public String[] getUpgradableVersionRange() { + return new String[] { "4.1.0", "4.2.0" }; + } + + @Override + public String getUpgradedVersion() { + return "4.2.0"; + } + + @Override + public boolean supportsRollingUpgrade() { + return false; + } + + @Override + public File[] getPrepareScripts() { + String script = Script.findScript("", "db/schema-410to420.sql"); + if (script == null) { + throw new CloudRuntimeException("Unable to find db/schema-410to420.sql"); + } + + return new File[] { new File(script) }; + } + + @Override + public void performDataMigration(Connection conn) { + upgradeVmwareLabels(conn); + createPlaceHolderNics(conn); + updateRemoteAccessVpn(conn); + updateSystemVmTemplates(conn); + updateCluster_details(conn); + updatePrimaryStore(conn); + addEgressFwRulesForSRXGuestNw(conn); + upgradeEIPNetworkOfferings(conn); + } + + private void updateSystemVmTemplates(Connection conn) { + PreparedStatement sql = null; + try { + sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'"); + sql.executeUpdate(); + } catch (SQLException e) { + throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString()); + } finally { + if (sql != null) { + try { + sql.close(); + } catch (SQLException e) { + } + } + } + } + + private void updatePrimaryStore(Connection conn) { + PreparedStatement sql = null; + PreparedStatement sql2 = null; + try { + sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'"); + sql.setString(1, "ancient primary data store provider"); + sql.setString(2, "HOST"); + sql.executeUpdate(); + + sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'"); + sql2.setString(1, "ancient primary data store provider"); + sql2.setString(2, "CLUSTER"); + sql2.executeUpdate(); + } catch (SQLException e) { + throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString()); + } finally { + if (sql != null) { + try { + sql.close(); + } catch (SQLException e) { + } + } + + if (sql2 != null) { + try { + sql2.close(); + } catch (SQLException e) { + } + } + } + } + + //update the cluster_details table with default overcommit ratios. + private void updateCluster_details(Connection conn) { + PreparedStatement pstmt = null; + PreparedStatement pstmt1 = null; + PreparedStatement pstmt2 =null; + ResultSet rs = null; + + try { + pstmt = conn.prepareStatement("select id from `cloud`.`cluster`"); + pstmt1=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value) VALUES(?, 'cpuOvercommitRatio', '1')"); + pstmt2=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value) VALUES(?, 'memoryOvercommitRatio', '1')"); + rs = pstmt.executeQuery(); + while (rs.next()) { + long id = rs.getLong(1); + //update cluster_details table with the default overcommit ratios. + pstmt1.setLong(1,id); + pstmt1.execute(); + pstmt2.setLong(1,id); + pstmt2.execute(); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to update cluster_details with default overcommit ratios.", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + + + @Override + public File[] getCleanupScripts() { + String script = Script.findScript("", "db/schema-410to420-cleanup.sql"); + if (script == null) { + throw new CloudRuntimeException("Unable to find db/schema-410to420-cleanup.sql"); + } + + return new File[] { new File(script) }; + } + + private String getNewLabel(ResultSet rs, String oldParamValue) { + int separatorIndex; + String oldGuestLabel; + String newGuestLabel = oldParamValue; + try { + // No need to iterate because the global param setting applies to all physical networks irrespective of traffic type + if (rs.next()) { + oldGuestLabel = rs.getString("vmware_network_label"); + // guestLabel is in format [[<VSWITCHNAME>],VLANID] + separatorIndex = oldGuestLabel.indexOf(","); + if(separatorIndex > -1) { + newGuestLabel += oldGuestLabel.substring(separatorIndex); + } + } + } catch (SQLException e) { + s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e)); + } finally { + try { + if (rs != null) { + rs.close(); + } + } catch (SQLException e) { + } + } + return newGuestLabel; + } + + private void upgradeVmwareLabels(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rsParams = null; + ResultSet rsLabel = null; + String newLabel; + String trafficType = null; + String trafficTypeVswitchParam; + String trafficTypeVswitchParamValue; + + try { + // update the existing vmware traffic labels + pstmt = conn.prepareStatement("select name,value from `cloud`.`configuration` where category='Hidden' and value is not NULL and name REGEXP 'vmware\\.*\\.vswitch';"); + rsParams = pstmt.executeQuery(); + while (rsParams.next()) { + trafficTypeVswitchParam = rsParams.getString("name"); + trafficTypeVswitchParamValue = rsParams.getString("value"); + // When upgraded from 4.0 to 4.1 update physical network traffic label with trafficTypeVswitchParam + if (trafficTypeVswitchParam.equals("vmware.private.vswitch")) { + trafficType = "Management"; //TODO(sateesh): Ignore storage traffic, as required physical network already implemented, anything else tobe done? + } else if (trafficTypeVswitchParam.equals("vmware.public.vswitch")) { + trafficType = "Public"; + } else if (trafficTypeVswitchParam.equals("vmware.guest.vswitch")) { + trafficType = "Guest"; + } + s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt); + pstmt = conn.prepareStatement("select physical_network_id, traffic_type, vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';"); + rsLabel = pstmt.executeQuery(); + newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue); + pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = " + newLabel + " where traffic_type = '" + trafficType + "' and vmware_network_label is not NULL;"); + pstmt.executeUpdate(); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to set vmware traffic labels ", e); + } finally { + try { + if (rsParams != null) { + rsParams.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } - ++ + private void createPlaceHolderNics(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = conn.prepareStatement("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null"); + rs = pstmt.executeQuery(); + while (rs.next()) { + Long networkId = rs.getLong(1); + String gateway = rs.getString(2); + String ip = rs.getString(3); + String uuid = UUID.randomUUID().toString(); + //Insert placeholder nic for each Domain router nic in Shared network + pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')"); + pstmt.setString(1, uuid); + pstmt.setString(2, ip); + pstmt.setString(3, gateway); + pstmt.setLong(4, networkId); + pstmt.executeUpdate(); + s_logger.debug("Created placeholder nic for the ipAddress " + ip); - ++ + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to create placeholder nics", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } - - ++ ++ + private void updateRemoteAccessVpn(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = conn.prepareStatement("SELECT vpn_server_addr_id FROM `cloud`.`remote_access_vpn`"); + rs = pstmt.executeQuery(); + long id=1; + while (rs.next()) { + String uuid = UUID.randomUUID().toString(); + Long ipId = rs.getLong(1); + pstmt = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?"); + pstmt.setString(1, uuid); + pstmt.setLong(2, id); + pstmt.setLong(3, ipId); + pstmt.executeUpdate(); + id++; + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to update id/uuid of remote_access_vpn table", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + private void addEgressFwRulesForSRXGuestNw(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rs = null; + ResultSet rsId = null; + ResultSet rsNw = null; + try { + pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='JuniperSRX' "); + rs = pstmt.executeQuery(); + while (rs.next()) { + long netId = rs.getLong(1); + //checking for Isolated OR Virtual + pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? "); + pstmt.setLong(1, netId); + s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt); + rsNw = pstmt.executeQuery(); + + if(rsNw.next()) { + long accountId = rsNw.getLong(1); + long domainId = rsNw.getLong(2); + + //Add new rule for the existing networks + s_logger.debug("Adding default egress firewall rule for network " + netId); + pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')"); + pstmt.setString(1, UUID.randomUUID().toString()); + pstmt.setLong(2, accountId); + pstmt.setLong(3, domainId); + pstmt.setLong(4, netId); + pstmt.setString(5, UUID.randomUUID().toString()); + s_logger.debug("Inserting default egress firewall rule " + pstmt); + pstmt.executeUpdate(); + + pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?"); + pstmt.setLong(1, netId); + rsId = pstmt.executeQuery(); + + long firewallRuleId; + if(rsId.next()) { + firewallRuleId = rsId.getLong(1); + pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')"); + pstmt.setLong(1, firewallRuleId); + s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); + pstmt.executeUpdate(); + } + } + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to set egress firewall rules ", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + + private void upgradeEIPNetworkOfferings(Connection conn) { + + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'"); + rs = pstmt.executeQuery(); + while (rs.next()) { + long id = rs.getLong(1); + // check if elastic IP service is enabled for network offering + if (rs.getLong(2) != 0) { + //update network offering with eip_associate_public_ip set to true + pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?"); + pstmt.setBoolean(1, true); + pstmt.setLong(2, id); + pstmt.executeUpdate(); + } + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to set elastic_ip_service for network offerings with EIP service enabled.", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/pom.xml ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/server/src/com/cloud/network/NetworkServiceImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/server/src/com/cloud/network/vpc/VpcManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/server/test/com/cloud/vpc/MockVpcManagerImpl.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/test/integration/smoke/test_scale_vm.py ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf67e584/tools/marvin/marvin/cloudstackConnection.py ----------------------------------------------------------------------
