bug 10222: fixed issue with associate ip introduced more than one nic. The problem is that associate ip automatically creates a nic but doesn't have sufficient information to properly creates so it uses what it knows for sure is the naming pattern to do it. However, we changed the naming pattern and it broke. I fixed it by passing all of the information in the ipaddressTO object.

This commit is contained in:
Alex Huang 2011-06-11 13:45:00 -07:00
parent 2971fb32fb
commit 44d15d38b0
7 changed files with 156 additions and 232 deletions

View File

@ -18,6 +18,10 @@
package com.cloud.agent.api.to;
import java.util.List;
import com.cloud.network.Networks.TrafficType;
public class IpAddressTO {
@ -32,7 +36,8 @@ public class IpAddressTO {
private String vifMacAddress;
private String guestIp;
private Integer networkRate;
private TrafficType trafficType;
private String[] networkTags;
public IpAddressTO(String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate) {
this.publicIp = ipAddress;
@ -57,6 +62,27 @@ public class IpAddressTO {
public String getPublicIp() {
return publicIp;
}
public TrafficType getTrafficType() {
return trafficType;
}
public void setNetworkTags(List<String> tagsList) {
if (tagsList == null || tagsList.size() == 0) {
networkTags = null;
} else {
networkTags = tagsList.toArray(new String[tagsList.size()]);
}
}
public String[] getNetworkTags() {
return networkTags;
}
public void setTrafficType(TrafficType trafficType) {
this.trafficType = trafficType;
}
public boolean isAdd() {
return add;

View File

@ -507,10 +507,8 @@ public class Request {
@Override
public JsonElement serialize(List<PortConfig> src, Type typeOfSrc, JsonSerializationContext context) {
if (src.size() == 0) {
s_logger.info("Returning JsonNull");
return new JsonNull();
}
s_logger.debug("Returning gson tree");
JsonArray array = new JsonArray();
for (PortConfig pc : src) {
array.add(s_gson.toJsonTree(pc));

View File

@ -159,7 +159,6 @@ import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.dc.Vlan;
import com.cloud.exception.InternalErrorException;
import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@ -222,6 +221,8 @@ import com.xensource.xenapi.VM;
import com.xensource.xenapi.VMGuestMetrics;
import com.xensource.xenapi.XenAPIObject;
import edu.emory.mathcs.backport.java.util.Arrays;
/**
* CitrixResourceBase encapsulates the calls to the XenServer Xapi process
* to perform the required functionalities for CloudStack.
@ -374,119 +375,120 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
@Override
public Answer executeRequest(Command cmd) {
if (cmd instanceof CreateCommand) {
Class<? extends Command> clazz = cmd.getClass();
if (clazz == CreateCommand.class) {
return execute((CreateCommand) cmd);
} else if (cmd instanceof SetPortForwardingRulesCommand) {
} else if (clazz == SetPortForwardingRulesCommand.class) {
return execute((SetPortForwardingRulesCommand) cmd);
} else if (cmd instanceof SetStaticNatRulesCommand) {
} else if (clazz == SetStaticNatRulesCommand.class) {
return execute((SetStaticNatRulesCommand) cmd);
} else if (cmd instanceof LoadBalancerConfigCommand) {
} else if (clazz == LoadBalancerConfigCommand.class) {
return execute((LoadBalancerConfigCommand) cmd);
} else if (cmd instanceof IPAssocCommand) {
} else if (clazz == IPAssocCommand.class) {
return execute((IPAssocCommand) cmd);
} else if (cmd instanceof CheckConsoleProxyLoadCommand) {
} else if (clazz == CheckConsoleProxyLoadCommand.class) {
return execute((CheckConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
} else if (clazz == WatchConsoleProxyLoadCommand.class) {
return execute((WatchConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof SavePasswordCommand) {
} else if (clazz == SavePasswordCommand.class) {
return execute((SavePasswordCommand) cmd);
} else if (cmd instanceof DhcpEntryCommand) {
} else if (clazz == DhcpEntryCommand.class) {
return execute((DhcpEntryCommand) cmd);
} else if (cmd instanceof VmDataCommand) {
} else if (clazz == VmDataCommand.class) {
return execute((VmDataCommand) cmd);
} else if (cmd instanceof ReadyCommand) {
} else if (clazz == ReadyCommand.class) {
return execute((ReadyCommand) cmd);
} else if (cmd instanceof GetHostStatsCommand) {
} else if (clazz == GetHostStatsCommand.class) {
return execute((GetHostStatsCommand) cmd);
} else if (cmd instanceof GetVmStatsCommand) {
} else if (clazz == GetVmStatsCommand.class) {
return execute((GetVmStatsCommand) cmd);
} else if (cmd instanceof CheckHealthCommand) {
} else if (clazz == CheckHealthCommand.class) {
return execute((CheckHealthCommand) cmd);
} else if (cmd instanceof StopCommand) {
} else if (clazz == StopCommand.class) {
return execute((StopCommand) cmd);
} else if (cmd instanceof RebootRouterCommand) {
} else if (clazz == RebootRouterCommand.class) {
return execute((RebootRouterCommand) cmd);
} else if (cmd instanceof RebootCommand) {
} else if (clazz == RebootCommand.class) {
return execute((RebootCommand) cmd);
} else if (cmd instanceof CheckVirtualMachineCommand) {
} else if (clazz == CheckVirtualMachineCommand.class) {
return execute((CheckVirtualMachineCommand) cmd);
} else if (cmd instanceof PrepareForMigrationCommand) {
} else if (clazz == PrepareForMigrationCommand.class) {
return execute((PrepareForMigrationCommand) cmd);
} else if (cmd instanceof MigrateCommand) {
} else if (clazz == MigrateCommand.class) {
return execute((MigrateCommand) cmd);
} else if (cmd instanceof DestroyCommand) {
} else if (clazz == DestroyCommand.class) {
return execute((DestroyCommand) cmd);
} else if (cmd instanceof CreateStoragePoolCommand) {
} else if (clazz == CreateStoragePoolCommand.class) {
return execute((CreateStoragePoolCommand) cmd);
} else if (cmd instanceof ModifyStoragePoolCommand) {
} else if (clazz == ModifyStoragePoolCommand.class) {
return execute((ModifyStoragePoolCommand) cmd);
} else if (cmd instanceof DeleteStoragePoolCommand) {
} else if (clazz == DeleteStoragePoolCommand.class) {
return execute((DeleteStoragePoolCommand) cmd);
} else if (cmd instanceof CopyVolumeCommand) {
} else if (clazz == CopyVolumeCommand.class) {
return execute((CopyVolumeCommand) cmd);
} else if (cmd instanceof AttachVolumeCommand) {
} else if (clazz == AttachVolumeCommand.class) {
return execute((AttachVolumeCommand) cmd);
} else if (cmd instanceof AttachIsoCommand) {
} else if (clazz == AttachIsoCommand.class) {
return execute((AttachIsoCommand) cmd);
} else if (cmd instanceof ManageSnapshotCommand) {
} else if (clazz == ManageSnapshotCommand.class) {
return execute((ManageSnapshotCommand) cmd);
} else if (cmd instanceof BackupSnapshotCommand) {
} else if (clazz == BackupSnapshotCommand.class) {
return execute((BackupSnapshotCommand) cmd);
} else if (cmd instanceof DeleteSnapshotBackupCommand) {
} else if (clazz == DeleteSnapshotBackupCommand.class) {
return execute((DeleteSnapshotBackupCommand) cmd);
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
} else if (clazz == CreateVolumeFromSnapshotCommand.class) {
return execute((CreateVolumeFromSnapshotCommand) cmd);
} else if (cmd instanceof DeleteSnapshotsDirCommand) {
} else if (clazz == DeleteSnapshotsDirCommand.class) {
return execute((DeleteSnapshotsDirCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
} else if (clazz == CreatePrivateTemplateFromVolumeCommand.class) {
return execute((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
} else if (clazz == CreatePrivateTemplateFromSnapshotCommand.class) {
return execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (cmd instanceof UpgradeSnapshotCommand) {
} else if (clazz == UpgradeSnapshotCommand.class) {
return execute((UpgradeSnapshotCommand) cmd);
} else if (cmd instanceof GetStorageStatsCommand) {
} else if (clazz == GetStorageStatsCommand.class) {
return execute((GetStorageStatsCommand) cmd);
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
} else if (clazz == PrimaryStorageDownloadCommand.class) {
return execute((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof GetVncPortCommand) {
} else if (clazz == GetVncPortCommand.class) {
return execute((GetVncPortCommand) cmd);
} else if (cmd instanceof SetupCommand) {
} else if (clazz == SetupCommand.class) {
return execute((SetupCommand) cmd);
} else if (cmd instanceof MaintainCommand) {
} else if (clazz == MaintainCommand.class) {
return execute((MaintainCommand) cmd);
} else if (cmd instanceof PingTestCommand) {
} else if (clazz == PingTestCommand.class) {
return execute((PingTestCommand) cmd);
} else if (cmd instanceof CheckOnHostCommand) {
} else if (clazz == CheckOnHostCommand.class) {
return execute((CheckOnHostCommand) cmd);
} else if (cmd instanceof ModifySshKeysCommand) {
} else if (clazz == ModifySshKeysCommand.class) {
return execute((ModifySshKeysCommand) cmd);
} else if (cmd instanceof PoolEjectCommand) {
} else if (clazz == PoolEjectCommand.class) {
return execute((PoolEjectCommand) cmd);
} else if (cmd instanceof StartCommand) {
} else if (clazz == StartCommand.class) {
return execute((StartCommand)cmd);
} else if (cmd instanceof RemoteAccessVpnCfgCommand) {
} else if (clazz == RemoteAccessVpnCfgCommand.class) {
return execute((RemoteAccessVpnCfgCommand)cmd);
} else if (cmd instanceof VpnUsersCfgCommand) {
} else if (clazz == VpnUsersCfgCommand.class) {
return execute((VpnUsersCfgCommand)cmd);
} else if (cmd instanceof CheckSshCommand) {
} else if (clazz == CheckSshCommand.class) {
return execute((CheckSshCommand)cmd);
} else if (cmd instanceof SecurityIngressRulesCmd) {
} else if (clazz == SecurityIngressRulesCmd.class) {
return execute((SecurityIngressRulesCmd) cmd);
} else if (cmd instanceof OvsCreateGreTunnelCommand) {
} else if (clazz == OvsCreateGreTunnelCommand.class) {
return execute((OvsCreateGreTunnelCommand)cmd);
} else if (cmd instanceof OvsSetTagAndFlowCommand) {
} else if (clazz == OvsSetTagAndFlowCommand.class) {
return execute((OvsSetTagAndFlowCommand)cmd);
} else if (cmd instanceof OvsDeleteFlowCommand) {
} else if (clazz == OvsDeleteFlowCommand.class) {
return execute((OvsDeleteFlowCommand)cmd);
} else if (cmd instanceof CleanupNetworkRulesCmd){
} else if (clazz == CleanupNetworkRulesCmd.class){
return execute((CleanupNetworkRulesCmd)cmd);
} else if (cmd instanceof NetworkRulesSystemVmCommand) {
} else if (clazz == NetworkRulesSystemVmCommand.class) {
return execute((NetworkRulesSystemVmCommand)cmd);
} else if (cmd instanceof OvsCreateTunnelCommand) {
} else if (clazz == OvsCreateTunnelCommand.class) {
return execute((OvsCreateTunnelCommand)cmd);
} else if (cmd instanceof OvsDestroyTunnelCommand) {
} else if (clazz == OvsDestroyTunnelCommand.class) {
return execute((OvsDestroyTunnelCommand)cmd);
} else if (cmd instanceof UpdateHostPasswordCommand) {
} else if (clazz == UpdateHostPasswordCommand.class) {
return execute((UpdateHostPasswordCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
@ -1420,15 +1422,33 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return new Answer(cmd);
}
protected void assignPublicIpAddress(Connection conn, final String vmName, final String privateIpAddress, final String publicIpAddress, final boolean add, final boolean firstIP,
final boolean sourceNat, final String vlanId, final String vlanGateway, final String vlanNetmask, final String vifMacAddress, String guestIp, Integer networkRate) throws InternalErrorException {
protected void assignPublicIpAddress(Connection conn, String vmName, String privateIpAddress, String publicIpAddress, boolean add, boolean firstIP,
boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate, TrafficType trafficType, String[] tags) throws InternalErrorException {
try {
String tag = tags != null && tags.length > 0 ? tags[0] : null;
VM router = getVM(conn, vmName);
NicTO nic = new NicTO();
nic.setMac(vifMacAddress);
nic.setType(trafficType);
if (vlanId == null) {
nic.setBroadcastType(BroadcastDomainType.Native);
} else {
nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
}
nic.setDeviceId(0);
nic.setNetworkRateMbps(networkRate);
if (tags != null) {
nic.setTags(Arrays.asList(tags));
}
Network network = getNetwork(conn, nic);
// Determine the correct VIF on DomR to associate/disassociate the
// IP address with
VIF correctVif = getCorrectVif(conn, router, vlanId);
VIF correctVif = getCorrectVif(conn, router, network);
// If we are associating an IP address and DomR doesn't have a VIF
// for the specified vlan ID, we need to add a VIF
@ -1450,17 +1470,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
throw new InternalErrorException("There were no more available slots for a new VIF on router: " + router.getNameLabel(conn));
}
NicTO nic = new NicTO();
nic.setMac(vifMacAddress);
nic.setType(TrafficType.Public);
if (vlanId == null) {
nic.setBroadcastType(BroadcastDomainType.Native);
} else {
nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
}
nic.setDeviceId(Integer.parseInt(vifDeviceNum));
nic.setNetworkRateMbps(networkRate);
correctVif = createVif(conn, vmName, router, nic);
correctVif.plug(conn);
@ -1503,7 +1513,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
if (removeVif) {
Network network = correctVif.getNetwork(conn);
network = correctVif.getNetwork(conn);
// Mark this vif to be removed from network usage
networkUsage(conn, privateIpAddress, "deleteVif", "eth" + correctVif.getDevice(conn));
@ -1546,7 +1556,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
for (IpAddressTO ip : ips) {
assignPublicIpAddress(conn, routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getVlanId(),
ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getGuestIp(), ip.getNetworkRate());
ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getGuestIp(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkTags());
results[i++] = ip.getPublicIp() + " - success";
}
} catch (InternalErrorException e) {
@ -3310,27 +3320,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
protected VIF getCorrectVif(Connection conn, VM router, String vlanId) {
try {
Set<VIF> routerVIFs = router.getVIFs(conn);
for (VIF vif : routerVIFs) {
Network vifNetwork = vif.getNetwork(conn);
if (vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
if (vifNetwork.getUuid(conn).equals(_host.publicNetwork)) {
return vif;
}
} else {
if (vifNetwork.getNameLabel(conn).equals("VLAN" + vlanId)) {
return vif;
}
}
protected VIF getCorrectVif(Connection conn, VM router, Network network) throws XmlRpcException, XenAPIException {
Set<VIF> routerVIFs = router.getVIFs(conn);
for (VIF vif : routerVIFs) {
Network vifNetwork = vif.getNetwork(conn);
if (vifNetwork.getUuid(conn).equals(network.getUuid(conn))) {
return vif;
}
} catch (XmlRpcException e) {
String msg = "Caught XmlRpcException: " + e.getMessage();
s_logger.warn(msg, e);
} catch (XenAPIException e) {
String msg = "Caught XenAPIException: " + e.toString();
s_logger.warn(msg, e);
}
return null;
@ -5040,7 +5036,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
Set<VDI> snapshots = vdi.getSnapshots(conn);
for( VDI snapshot: snapshots ) {
snapshot.destroy(conn);
}
}
vdi.destroy(conn);
} catch (Exception e) {
String msg = "VDI destroy for " + volumeUUID + " failed due to " + e.toString();

View File

@ -82,7 +82,7 @@ public class XenServer56Resource extends CitrixResourceBase {
@Override
protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
vm.setMemoryLimits(conn, memsize, memsize, memsize, memsize);
}
}
@Override
@ -108,33 +108,37 @@ public class XenServer56Resource extends CitrixResourceBase {
@Override
protected void disableVlanNetwork(Connection conn, Network network) {
try {
if (!network.getNameLabel(conn).startsWith("VLAN")) {
Network.Record networkr = network.getRecord(conn);
if (!networkr.nameLabel.startsWith("VLAN")) {
return;
}
String bridge = network.getBridge(conn).trim();
for (PIF pif : network.getPIFs(conn)) {
if (pif.getHost(conn).getUuid(conn).equalsIgnoreCase(_host.uuid)) {
VLAN vlan = pif.getVLANMasterOf(conn);
if (vlan != null) {
String vlannum = pif.getVLAN(conn).toString();
String device = pif.getDevice(conn).trim();
if (vlannum.equals("-1")) {
return;
}
try {
vlan.destroy(conn);
Host host = Host.getByUuid(conn, _host.uuid);
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
} catch (XenAPIException e) {
s_logger.debug("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.uuid
+ " due to " + e.toString());
}
}
break;
String bridge = networkr.bridge.trim();
for (PIF pif : networkr.PIFs) {
PIF.Record pifr = pif.getRecord(conn);
if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.uuid)) {
continue;
}
VLAN vlan = pifr.VLANMasterOf;
if (vlan != null) {
String vlannum = pifr.VLAN.toString();
String device = pifr.device.trim();
if (vlannum.equals("-1")) {
return;
}
try {
vlan.destroy(conn);
Host host = Host.getByUuid(conn, _host.uuid);
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
} catch (XenAPIException e) {
s_logger.info("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.uuid
+ " due to " + e.toString());
}
}
return;
}
} catch (XenAPIException e) {
String msg = "Unable to disable VLAN network due to " + e.toString();
@ -418,7 +422,7 @@ public class XenServer56Resource extends CitrixResourceBase {
public StartupCommand[] initialize() {
pingXenServer();
StartupCommand[] cmds = super.initialize();
Connection conn = getConnection();
Connection conn = getConnection();
if (!setIptables(conn)) {
s_logger.warn("set xenserver Iptable failed");
return null;

View File

@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cloud.agent.manager.AgentManagerImpl;
import com.cloud.agent.manager.ClusteredAgentManagerImpl;
import com.cloud.alert.AlertManagerImpl;
import com.cloud.alert.dao.AlertDaoImpl;
@ -290,7 +289,6 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
protected void populateManagers() {
addManager("StackMaidManager", CheckPointManagerImpl.class);
addManager("agent manager", AgentManagerImpl.class);
addManager("account manager", AccountManagerImpl.class);
addManager("configuration manager", ConfigurationManagerImpl.class);
addManager("network manager", NetworkManagerImpl.class);
@ -322,14 +320,13 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
addManager("OvsTunnelManager", OvsTunnelManagerImpl.class);
addManager("Capacity Manager", CapacityManagerImpl.class);
addManager("Cluster Manager", ClusterManagerImpl.class);
addManager("ClusteredAgentManager", ClusteredAgentManagerImpl.class);
addManager("VirtualMachineManager", ClusteredVirtualMachineManagerImpl.class);
addManager("HypervisorGuruManager", HypervisorGuruManagerImpl.class);
addManager("ClusterFenceManager", ClusterFenceManagerImpl.class);
addManager("ResourceManager", ResourceManagerImpl.class);
ComponentInfo<? extends Manager> info = addManager("ConsoleProxyManager", ConsoleProxyManagerImpl.class);
info.addParameter("consoleproxy.sslEnabled", "true");
addManager("ClusteredAgentManager", ClusteredAgentManagerImpl.class);
}
@Override

View File

@ -24,10 +24,8 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
@ -36,7 +34,6 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils;
@Local(value={HostPodDao.class})
public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements HostPodDao {
@ -102,103 +99,6 @@ public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements H
return currentPodCidrSubnets;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
Transaction txn = Transaction.currentTxn();
try {
txn.start();
ArrayList<Long> podIds = new ArrayList<Long>();
PreparedStatement pstmt = txn.prepareAutoCloseStatement("SELECT id FROM host_pod_ref FOR UPDATE");
ResultSet rs = pstmt.executeQuery();
int i = 1;
while (rs.next()) {
podIds.add(rs.getLong(1));
}
PreparedStatement alter = txn.prepareAutoCloseStatement("ALTER TABLE host_pod_ref ADD COLUMN cidr_address VARCHAR(15) NOT NULL");
try {
int result = alter.executeUpdate();
if (result == 0) {
txn.rollback();
return true;
}
} catch (SQLException e) {
txn.rollback();
if (e.getMessage().contains("Duplicate column name")) {
s_logger.info("host_pod_ref table is already up to date");
return true;
}
// assume this is because it's already been updated.
s_logger.debug("Got this while updating", e);
throw new ConfigurationException("Unable to update the host_pod_ref table ");
}
alter = txn.prepareStatement("ALTER TABLE host_pod_ref ADD COLUMN cidr_size bigint NOT NULL");
try {
int result = alter.executeUpdate();
if (result == 0) {
txn.rollback();
throw new ConfigurationException("How can the first ALTER work but this doesn't?");
}
} catch (SQLException e) {
s_logger.warn("Couldn't alter the table: ", e);
txn.rollback();
throw new ConfigurationException("How can the first ALTER work but this doesn't? " + e.getMessage());
}
PreparedStatement netmask = txn.prepareAutoCloseStatement("SELECT value FROM configuration WHERE name='private.net.mask'");
String privateNetmask;
try {
rs = netmask.executeQuery();
if (!rs.next()) {
txn.rollback();
throw new ConfigurationException("There's no private.netmask?");
}
privateNetmask = rs.getString(1);
} catch (SQLException e) {
s_logger.warn("Couldn't get private.netmask due to ", e);
txn.rollback();
throw new ConfigurationException("Unable to find the private.netmask");
}
for (Long podId : podIds) {
PreparedStatement ip = txn.prepareAutoCloseStatement("SELECT ip_address from op_dc_ip_address_alloc where pod_id=? LIMIT 0,1");
ip.setLong(1, podId);
String addr = "192.168.1.1";
try {
rs = ip.executeQuery();
if (rs.next()) {
addr = rs.getString(1);
} else {
s_logger.debug("Default pod " + podId + " to 192.168.1.1 because it has no ip addresses allocated to it");
}
} catch(SQLException e) {
s_logger.warn("Didn't work for " + podId + " due to " + e.getMessage(), e);
}
PreparedStatement update = txn.prepareAutoCloseStatement("UPDATE host_pod_ref set cidr_address=?, cidr_size=? WHERE id=?");
update.setString(1, addr);
update.setLong(2, NetUtils.getCidrSize(privateNetmask));
update.setLong(3, podId);
try {
update.executeUpdate();
} catch (SQLException e) {
s_logger.debug("Unable to update host_pod_ref table due to " + e.getMessage(), e);
}
}
txn.commit();
} catch (SQLException e) {
s_logger.error("Unable to upgrade the db due to " + e);
txn.rollback();
throw new ConfigurationException("Unable to upgrade the db due to " + e);
}
return true;
}
@Override
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();

View File

@ -354,7 +354,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
// check if it is a system service offering, if yes return with error as it cannot be used for user vms
if (!newServiceOffering.getSystemUse()) {
throw new InvalidParameterValueException("Cannot upgrade router vm to a non system service offering " + serviceOfferingId);
}
}
// Check that the router is stopped
if (!router.getState().equals(State.Stopped)) {
@ -366,7 +366,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
// Check that the service offering being upgraded to has the same storage pool preference as the VM's current service
// offering
// offering
if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) {
throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newServiceOffering.getUseLocalStorage() + " is different from "
+ "curruent local storage status: " + currentServiceOffering.getUseLocalStorage());
@ -1469,6 +1469,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
});
// Get network rate - required for IpAssoc
Integer networkRate = _networkMgr.getNetworkRate(ipAddrList.get(0).getNetworkId(), router.getId());
Network network = _networkMgr.getNetwork(ipAddrList.get(0).getNetworkId());
IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
int i = 0;
boolean firstIP = true;
@ -1483,10 +1487,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String vmGuestAddress = null;
// Get network rate - required for IpAssoc
Integer networkRate = _networkMgr.getNetworkRate(ipAddr.getNetworkId(), router.getId());
IpAddressTO ip = new IpAddressTO(ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate);
ip.setTrafficType(network.getTrafficType());
ip.setNetworkTags(network.getTags());
ipsToSend[i++] = ip;
firstIP = false;
}