From 57f6b16cdb94ce2b5bfff657b32552c9bf22fae4 Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 23 Feb 2011 19:35:22 -0800 Subject: [PATCH] bug 8719: fixed NPE happening during HA process - get control nic infrormation in finalizeCommandsOnStart() method instead of setting it in caller methods status 8719: resolved fixed --- .../consoleproxy/ConsoleProxyManagerImpl.java | 33 ++++++++--------- .../VirtualNetworkApplianceManagerImpl.java | 20 ++++++++--- .../SecondaryStorageManagerImpl.java | 32 ++++++++--------- .../cloud/vm/VirtualMachineManagerImpl.java | 35 +++++++++++-------- 4 files changed, 69 insertions(+), 51 deletions(-) diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 499f66c6701..d45c1bea35b 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1388,8 +1388,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx externalDhcp = true; } - NicProfile controlNic = null; - NicProfile managementNic = null; for (NicProfile nic : profile.getNics()) { int deviceId = nic.getDeviceId(); if(nic.getIp4Address() == null) { @@ -1410,12 +1408,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); - managementNic = nic; - } else if (nic.getTrafficType() == TrafficType.Control) { - if(nic.getIp4Address() != null) { - controlNic = nic; - } - } + } } /*External DHCP mode*/ @@ -1423,18 +1416,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx buf.append(" bootproto=dhcp"); } - if(controlNic == null) { - assert(managementNic != null); - controlNic = managementNic; - } - String bootArgs = buf.toString(); if (s_logger.isDebugEnabled()) { s_logger.debug("Boot Args for " + profile + ": " + bootArgs); } - profile.setParameter(VirtualMachineProfile.Param.ControlNic, controlNic); - return true; } @@ -1462,7 +1448,22 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - NicProfile controlNic = (NicProfile)profile.getParameter(VirtualMachineProfile.Param.ControlNic); + + NicProfile managementNic = null; + NicProfile controlNic = null; + for (NicProfile nic : profile.getNics()) { + if (nic.getTrafficType() == TrafficType.Management) { + managementNic = nic; + } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { + controlNic = nic; + } + } + + if (controlNic == null) { + assert (managementNic != null); + controlNic = managementNic; + } + CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); cmds.addCommand("checkSsh", check); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index d85f27f853e..cad6914b161 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -934,8 +934,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new CloudRuntimeException("Didn't start a control port"); } - profile.setParameter(VirtualMachineProfile.Param.ControlNic, controlNic); - return true; } @@ -964,9 +962,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - DomainRouterVO router = profile.getVirtualMachine(); - NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic); - cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20)); + DomainRouterVO router = profile.getVirtualMachine(); + + NicProfile controlNic = null; + for (NicProfile nic : profile.getNics()) { + if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { + controlNic = nic; + } + } + + if (controlNic == null) { + s_logger.error("Control network doesn't exist for the router " + router); + return false; + } + + cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20)); //restart network if restartNetwork = false is not specified in profile parameters boolean restartNetwork = true; diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 284d34c3c95..8e5eaf17f22 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -984,9 +984,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V buf.append(" instance=SecStorage"); buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy)); - NicProfile controlNic = null; - NicProfile managementNic = null; - boolean externalDhcp = false; String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled"); if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) { @@ -1009,12 +1006,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } if (nic.getTrafficType() == TrafficType.Management) { buf.append(" localgw=").append(dest.getPod().getGateway()); - managementNic = nic; buf.append(" private.network.device=").append("eth").append(deviceId); - } else if (nic.getTrafficType() == TrafficType.Control) { - if (nic.getIp4Address() != null) { - controlNic = nic; - } } else if (nic.getTrafficType() == TrafficType.Public) { buf.append(" public.network.device=").append("eth").append(deviceId); } @@ -1025,11 +1017,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V buf.append(" bootproto=dhcp"); } - if (controlNic == null) { - assert (managementNic != null); - controlNic = managementNic; - } - DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId()); buf.append(" dns1=").append(dc.getInternalDns1()); if (dc.getInternalDns2() != null) { @@ -1041,8 +1028,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V s_logger.debug("Boot Args for " + profile + ": " + bootArgs); } - profile.setParameter(VirtualMachineProfile.Param.ControlNic, controlNic); - return true; } @@ -1072,7 +1057,22 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V @Override public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic); + + NicProfile managementNic = null; + NicProfile controlNic = null; + for (NicProfile nic : profile.getNics()) { + if (nic.getTrafficType() == TrafficType.Management) { + managementNic = nic; + } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { + controlNic = nic; + } + } + + if (controlNic == null) { + assert (managementNic != null); + controlNic = managementNic; + } + CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); cmds.addCommand("checkSsh", check); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 06f3274d8d7..d544eb01673 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1331,26 +1331,33 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Commands cmds = new Commands(OnError.Revert); s_logger.debug("Finalizing commands that need to be send to complete Start process for the vm " + vm); - vmGuru.finalizeCommandsOnStart(cmds, profile); - if (cmds.size() != 0) { - try { - _agentMgr.send(vm.getHostId(), cmds); - } catch (OperationTimedoutException e){ - s_logger.error("Exception during update for running vm: " + vm, e); - return null; - } catch (ResourceUnavailableException e) { - s_logger.error("Exception during update for running vm: " + vm, e); + + if (vmGuru.finalizeCommandsOnStart(cmds, profile)) { + if (cmds.size() != 0) { + try { + _agentMgr.send(vm.getHostId(), cmds); + } catch (OperationTimedoutException e){ + s_logger.error("Exception during update for running vm: " + vm, e); + return null; + } catch (ResourceUnavailableException e) { + s_logger.error("Exception during update for running vm: " + vm, e); + return null; + } + } + + if (vmGuru.finalizeStart(profile, vm.getHostId(), cmds, null)) { + stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId()); + } else { + s_logger.error("Exception during update for running vm: " + vm); return null; } - } - - if (vmGuru.finalizeStart(profile, vm.getHostId(), cmds, null)) { - stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId()); } else { - s_logger.error("Exception during update for running vm: " + vm); + s_logger.error("Unable to finalize commands on start for vm: " + vm); return null; } + + } } else if (serverState == State.Stopping) { s_logger.debug("Scheduling a stop command for " + vm);