bug 9621: dbUpgrade - set reservation strategy to be Create for Guest Nics in Basic zone

status 9621: resolved fixed

Conflicts:

	server/src/com/cloud/upgrade/dao/Upgrade218to22.java
	setup/db/db/schema-222to224.sql
This commit is contained in:
alena 2011-04-27 22:51:56 -07:00
parent 012d2f1a5d
commit 485f7a10cc
5 changed files with 276 additions and 6 deletions

View File

@ -1212,6 +1212,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate);
guru.reserve(profile, network, vmProfile, dest, context);
nic.setIp4Address(profile.getIp4Address());
nic.setAddressFormat(profile.getFormat());
nic.setIp6Address(profile.getIp6Address());
nic.setMacAddress(profile.getMacAddress());
nic.setIsolationUri(profile.getIsolationUri());
@ -1220,7 +1221,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
nic.setState(Nic.State.Reserved);
nic.setNetmask(profile.getNetmask());
nic.setGateway(profile.getGateway());
nic.setAddressFormat(profile.getFormat());
if (profile.getStrategy() != null) {
nic.setReservationStrategy(profile.getStrategy());
}

View File

@ -122,7 +122,6 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
nic.setBroadcastUri(URI.create("vlan://" + Vlan.UNTAGGED));
nic.setBroadcastType(BroadcastDomainType.Native);
}
nic.setFormat(AddressFormat.Ip4);
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
}

View File

@ -29,16 +29,21 @@ import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
import java.util.UUID;
import org.apache.log4j.Logger;
import com.cloud.consoleproxy.ConsoleProxyManager;
import com.cloud.event.EventTypes;
import com.cloud.event.EventVO;
import com.cloud.event.UsageEventVO;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
@ -258,7 +263,7 @@ public class Upgrade218to22 implements DbUpgrade {
pstmt.close();
}
insertNic(conn, guestNetworkId, domrId, running, guestMac, guestIp, guestNetmask, "Start", gateway, vnet, "DirectPodBasedNetworkGuru", true, 0, "Dhcp", null);
insertNic(conn, guestNetworkId, domrId, running, guestMac, guestIp, guestNetmask, "Create", gateway, vnet, "DirectPodBasedNetworkGuru", true, 0, "Dhcp", null);
} else {
insertNic(conn, publicNetworkId, domrId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "PublicNetworkGuru", true, 2, "Static", null);
long controlNicId = insertNic(conn, controlNetworkId, domrId, running, privateMac, privateIp, privateNetmask, "Start", "169.254.0.1", null, "ControlNetworkGuru", false, 1, "Static",
@ -332,7 +337,7 @@ public class Upgrade218to22 implements DbUpgrade {
pstmt.close();
if (zoneType.equalsIgnoreCase("Basic")) {
insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Start", gateway, publicVlan, "DirectPodBasedNetworkGuru", true, 2, "Dhcp", null);
insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "DirectPodBasedNetworkGuru", true, 2, "Dhcp", null);
} else {
insertNic(conn, publicNetworkId, ssvmId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "PublicNetworkGuru", true, 2, "Static", null);
@ -413,7 +418,7 @@ public class Upgrade218to22 implements DbUpgrade {
pstmt.close();
if (zoneType.equalsIgnoreCase("Basic")) {
insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Start", gateway, publicVlan, "DirectPodBasedNetworkGuru", true, 2, "Dhcp", null);
insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "DirectPodBasedNetworkGuru", true, 2, "Dhcp", null);
} else {
insertNic(conn, publicNetworkId, cpId, running, publicMac, publicIp, publicNetmask, "Create", gateway, publicVlan, "PublicNetworkGuru", true, 2, "Static", null);
}
@ -530,7 +535,7 @@ public class Upgrade218to22 implements DbUpgrade {
count++;
}
}
insertNic(conn, networkId, (Long) vm[0], running, (String) vm[1], (String) vm[2], (String) vm[3], "Start", gateway, vnet, "DirectPodBasedNetworkGuru", true, 0, "Dhcp", null);
insertNic(conn, networkId, (Long) vm[0], running, (String) vm[1], (String) vm[2], (String) vm[3], "Create", gateway, vnet, "DirectPodBasedNetworkGuru", true, 0, "Dhcp", null);
}
pstmt = conn.prepareStatement("SELECT state FROM vm_instance WHERE id=?");
@ -1377,6 +1382,172 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
private void upgradeHostMemoryCapacityInfo(Connection conn) {
try {
// count user_vm memory info (M Bytes)
PreparedStatement pstmt = conn
.prepareStatement("select h.id, sum(s.ram_size) from host h, vm_instance v, service_offering s where h.type='Routing' and v.state='Running' and v.`type`='User' and v.host_id=h.id and v.service_offering_id = s.id group by h.id");
ResultSet rs = pstmt.executeQuery();
Map<Long, Long> hostUsedMemoryInfo = new HashMap<Long, Long>();
while (rs.next()) {
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2));
}
rs.close();
pstmt.close();
int proxyRamSize = NumbersUtil.parseInt(getConfigValue(conn, "consoleproxy.ram.size"), ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE);
int domrRamSize = NumbersUtil.parseInt(getConfigValue(conn, "router.ram.size"), VirtualNetworkApplianceManager.DEFAULT_ROUTER_VM_RAMSIZE);
int ssvmRamSize = NumbersUtil.parseInt(getConfigValue(conn, "secstorage.vm.ram.size"), SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE);
pstmt = conn
.prepareStatement("select h.id, count(v.id) from host h, vm_instance v where h.type='Routing' and v.state='Running' and v.`type`='ConsoleProxy' and v.host_id=h.id group by h.id");
rs = pstmt.executeQuery();
while (rs.next()) {
if (hostUsedMemoryInfo.get(rs.getLong(1)) != null) {
Long usedMem = hostUsedMemoryInfo.get(rs.getLong(1));
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2) * proxyRamSize + usedMem);
} else {
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2) * proxyRamSize);
}
}
rs.close();
pstmt.close();
pstmt = conn
.prepareStatement("select h.id, count(v.id) from host h, vm_instance v where h.type='Routing' and v.state='Running' and v.`type`='DomainRouter' and v.host_id=h.id group by h.id");
rs = pstmt.executeQuery();
while (rs.next()) {
if (hostUsedMemoryInfo.get(rs.getLong(1)) != null) {
Long usedMem = hostUsedMemoryInfo.get(rs.getLong(1));
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2) * domrRamSize + usedMem);
} else {
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2) * domrRamSize);
}
}
rs.close();
pstmt.close();
pstmt = conn
.prepareStatement("select h.id, count(v.id) from host h, vm_instance v where h.type='Routing' and v.state='Running' and v.`type`='SecondaryStorageVm' and v.host_id=h.id group by h.id");
rs = pstmt.executeQuery();
while (rs.next()) {
if (hostUsedMemoryInfo.get(rs.getLong(1)) != null) {
Long usedMem = hostUsedMemoryInfo.get(rs.getLong(1));
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2) * ssvmRamSize + usedMem);
} else {
hostUsedMemoryInfo.put(rs.getLong(1), rs.getLong(2) * ssvmRamSize);
}
}
rs.close();
pstmt.close();
for (Map.Entry<Long, Long> entry : hostUsedMemoryInfo.entrySet()) {
pstmt = conn.prepareStatement("update op_host_capacity set used_capacity=? where host_id=? and capacity_type=0");
pstmt.setLong(1, entry.getValue() * 1024 * 1024);
pstmt.setLong(2, entry.getKey());
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Can't upgrade host capacity info ", e);
}
}
private void upgradeHostCpuCapacityInfo(Connection conn) {
try {
// count user_vm memory info (M Bytes)
PreparedStatement pstmt = conn
.prepareStatement("select h.id, sum(s.speed*s.cpu) from host h, vm_instance v, service_offering s where h.type='Routing' and v.state='Running' and v.`type`='User' and v.host_id=h.id and v.service_offering_id = s.id group by h.id");
ResultSet rs = pstmt.executeQuery();
Map<Long, Long> hostUsedCpuInfo = new HashMap<Long, Long>();
while (rs.next()) {
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2));
}
rs.close();
pstmt.close();
int proxyCpuMhz = NumbersUtil.parseInt(getConfigValue(conn, "consoleproxy.cpu.mhz"), ConsoleProxyManager.DEFAULT_PROXY_VM_CPUMHZ);
int domrCpuMhz = NumbersUtil.parseInt(getConfigValue(conn, "router.cpu.mhz"), VirtualNetworkApplianceManager.DEFAULT_ROUTER_CPU_MHZ);
int ssvmCpuMhz = NumbersUtil.parseInt(getConfigValue(conn, "secstorage.vm.cpu.mhz"), SecondaryStorageVmManager.DEFAULT_SS_VM_CPUMHZ);
pstmt = conn
.prepareStatement("select h.id, count(v.id) from host h, vm_instance v where h.type='Routing' and v.state='Running' and v.`type`='ConsoleProxy' and v.host_id=h.id group by h.id");
rs = pstmt.executeQuery();
while (rs.next()) {
if (hostUsedCpuInfo.get(rs.getLong(1)) != null) {
Long usedCpuMhz = hostUsedCpuInfo.get(rs.getLong(1));
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2) * proxyCpuMhz + usedCpuMhz);
} else {
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2) * proxyCpuMhz);
}
}
rs.close();
pstmt.close();
pstmt = conn
.prepareStatement("select h.id, count(v.id) from host h, vm_instance v where h.type='Routing' and v.state='Running' and v.`type`='DomainRouter' and v.host_id=h.id group by h.id");
rs = pstmt.executeQuery();
while (rs.next()) {
if (hostUsedCpuInfo.get(rs.getLong(1)) != null) {
Long usedCpuMhz = hostUsedCpuInfo.get(rs.getLong(1));
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2) * domrCpuMhz + usedCpuMhz);
} else {
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2) * domrCpuMhz);
}
}
rs.close();
pstmt.close();
pstmt = conn
.prepareStatement("select h.id, count(v.id) from host h, vm_instance v where h.type='Routing' and v.state='Running' and v.`type`='SecondaryStorageVm' and v.host_id=h.id group by h.id");
rs = pstmt.executeQuery();
while (rs.next()) {
if (hostUsedCpuInfo.get(rs.getLong(1)) != null) {
Long usedCpuMhz = hostUsedCpuInfo.get(rs.getLong(1));
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2) * ssvmCpuMhz + usedCpuMhz);
} else {
hostUsedCpuInfo.put(rs.getLong(1), rs.getLong(2) * ssvmCpuMhz);
}
}
rs.close();
pstmt.close();
for (Map.Entry<Long, Long> entry : hostUsedCpuInfo.entrySet()) {
pstmt = conn.prepareStatement("update op_host_capacity set used_capacity=? where host_id=? and capacity_type=1");
pstmt.setLong(1, entry.getValue());
pstmt.setLong(2, entry.getKey());
pstmt.executeUpdate();
}
} catch (SQLException e) {
throw new CloudRuntimeException("Can't upgrade host capacity info ", e);
}
}
private String getConfigValue(Connection conn, String name) {
try {
// count user_vm memory info (M Bytes)
PreparedStatement pstmt = conn.prepareStatement("select value from configuration where name=?");
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();
String val = null;
if (rs.next()) {
val = rs.getString(1);
}
rs.close();
pstmt.close();
return val;
} catch (SQLException e) {
throw new CloudRuntimeException("Can't upgrade host capacity info ", e);
}
}
private void migrateEvents(Connection conn) {
try {
PreparedStatement pstmt1 = conn.prepareStatement("SHOW DATABASES LIKE 'cloud_usage'");
@ -1733,6 +1904,8 @@ public class Upgrade218to22 implements DbUpgrade {
upgradeInstanceGroups(conn);
upgradePortForwardingRules(conn);
upgradeLoadBalancingRules(conn);
upgradeHostMemoryCapacityInfo(conn);
upgradeHostCpuCapacityInfo(conn);
migrateEvents(conn);
// Update hypervisor type for user vm to be consistent with original 2.2.4
pstmt = conn.prepareStatement("UPDATE vm_instance SET hypervisor_type='XenServer' WHERE hypervisor_type='xenserver'");

View File

@ -0,0 +1,94 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.upgrade;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import com.cloud.upgrade.dao.VersionDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DbTestUtils;
import com.cloud.utils.db.Transaction;
public class Sanity220To224UpgradeTest extends TestCase {
private static final Logger s_logger = Logger.getLogger(Sanity220To224UpgradeTest.class);
@Override
@Before
public void setUp() throws Exception {
DbTestUtils.executeScript("PreviousDatabaseSchema/clean-db.sql", false, true);
}
@Override
@After
public void tearDown() throws Exception {
}
public void test217to22Upgrade() throws SQLException {
s_logger.debug("Finding sample data from 2.2.1");
DbTestUtils.executeScript("/home/alena/Downloads/before/cloud_report_dump_220_April_26th_1521hrs.sql", false, true);
Connection conn;
PreparedStatement pstmt;
ResultSet rs;
VersionDaoImpl dao = ComponentLocator.inject(VersionDaoImpl.class);
DatabaseUpgradeChecker checker = ComponentLocator.inject(DatabaseUpgradeChecker.class);
String version = dao.getCurrentVersion();
if (!version.equals("2.2.1")) {
s_logger.error("Version returned is not 2.2.1 but " + version);
} else {
s_logger.debug("Sanity 2.2.1 to 2.2.4 test version is " + version);
}
checker.upgrade("2.2.1", "2.2.4");
conn = Transaction.getStandaloneConnection();
try {
s_logger.debug("Starting tesing upgrade from 2.2.1 to 2.2.4...");
// Version check
pstmt = conn.prepareStatement("SELECT version FROM version");
rs = pstmt.executeQuery();
if (!rs.next()) {
s_logger.error("ERROR: No version selected");
} else if (!rs.getString(1).equals("2.2.4")) {
s_logger.error("ERROR: VERSION stored is not 2.2.4: " + rs.getString(1));
}
rs.close();
pstmt.close();
s_logger.debug("Sanity 2.2.1 to 2.2.4 DB upgrade test passed");
} finally {
conn.close();
}
}
}

View File

@ -130,6 +130,9 @@ UPDATE `cloud`.`service_offering` s, `cloud`.`disk_offering` d SET s.ha_enabled=
UPDATE `cloud`.`data_center` SET is_security_group_enabled=1 WHERE networktype='Basic';
UPDATE `cloud`.`host` SET resource='com.cloud.hypervisor.xen.resource.XenServer56FP1Resource' WHERE resource='com.cloud.hypervisor.xen.resource.XenServer56FP1PremiumResource';
UPDATE `cloud`.`nics` SET ip_type='Ip4';
UPDATE `cloud`.`nics` SET broadcast_uri='vlan://untagged', isolation_uri='ec2://untagged', strategy='Create' where reserver_name='DirectPodBasedNetworkGuru';