diff --git a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java index 4487c91189b..c5d91d309f8 100644 --- a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java @@ -315,6 +315,12 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu // TODO Auto-generated method stub return false; } + + @Override + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + // TODO Auto-generated method stub + return false; + } @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index f56369db58c..ad40a424f93 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -116,6 +116,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.ConsoleProxyVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; +import com.cloud.vm.SecondaryStorageVmVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; @@ -1439,9 +1440,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - NicProfile controlNic = (NicProfile)profile.getParameter(VirtualMachineProfile.Param.ControlNic); - CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); - cmds.addCommand("checkSsh", check); + + finalizeCommandsOnStart(cmds, profile); ConsoleProxyVO proxy = profile.getVirtualMachine(); DataCenter dc = dest.getDataCenter(); @@ -1460,6 +1460,15 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return true; } + @Override + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + NicProfile controlNic = (NicProfile)profile.getParameter(VirtualMachineProfile.Param.ControlNic); + CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); + cmds.addCommand("checkSsh", check); + + return true; + } + @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh"); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 32b911e9122..6c3abcf0956 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -964,10 +964,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException{ - NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic); - - cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20)); - DomainRouterVO router = profile.getVirtualMachine(); List nics = profile.getNics(); @@ -985,6 +981,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } _routerDao.update(router.getId(), router); + finalizeCommandsOnStart(cmds, profile); + return true; + } + + @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)); + //restart network if restartNetwork = false is not specified in profile parameters boolean restartNetwork = true; if (profile.getParameter(Param.RestartNetwork) != null && (Boolean)profile.getParameter(Param.RestartNetwork) == false) { diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index d822f848c7b..edd40ee1114 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -1046,9 +1046,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V @Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic); - CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); - cmds.addCommand("checkSsh", check); + + finalizeCommandsOnStart(cmds, profile); SecondaryStorageVmVO secVm = profile.getVirtualMachine(); DataCenter dc = dest.getDataCenter(); @@ -1068,6 +1067,15 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V return true; } + @Override + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic); + CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); + cmds.addCommand("checkSsh", check); + + return true; + } + @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 240f23a588a..c88fbba4b81 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2210,6 +2210,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager _vmDao.update(userVm.getId(), userVm); return true; } + + @Override + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + return true; + } @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index 93ecd3a7870..6799bbe392d 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -58,6 +58,8 @@ public interface VirtualMachineGuru { */ boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context); + boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile); + void finalizeStop(VirtualMachineProfile profile, StopAnswer answer); void finalizeExpunge(T vm); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index c81830fa4db..53ff451d641 100644 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1304,6 +1304,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi final State serverState = vm.getState(); final String serverName = vm.getName(); + VirtualMachineGuru vmGuru = getVmGuru(vm); + Command command = null; if (s_logger.isDebugEnabled()) { @@ -1389,7 +1391,33 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi s_logger.debug("VM state is starting on full sync so updating it to running"); vm = findById(vm.getType(), vm.getId()); stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId()); - //finalizeStart(new VirtualMachineProfileImpl(vm), vm.getHostId(), null, null); + s_logger.debug("VM's " + vm + " state is starting on full sync so updating it to Running"); + vm = vmGuru.findById(vm.getId()); + + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + + 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); + 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; + } } } else if (serverState == State.Stopping) { if (fullSync) {