@@ -2579,15 +2579,22 @@ public boolean postStateTransitionEvent(final StateMachine2.Transition<State, Vi
25792579 final VirtualMachine .Event event = transition .getEvent ();
25802580 if (event == VirtualMachine .Event .FollowAgentPowerOnReport && newState == State .Running ) {
25812581 if (vo .getType () == VirtualMachine .Type .DomainRouter ) {
2582+ // opaque -> <hostId, powerHostId>
25822583 if (opaque != null && opaque instanceof Pair <?, ?>) {
25832584 Pair <?, ?> pair = (Pair <?, ?>)opaque ;
25842585 Object first = pair .first ();
25852586 Object second = pair .second ();
2586- if ( first != null && second != null && first instanceof Long && second instanceof Long ) {
2587- Long hostId = ( Long )first ;
2587+ // powerHostId cannot be null in case of out-of-band VM movement
2588+ if ( second != null && second instanceof Long ) {
25882589 Long powerHostId = (Long )second ;
2589- // If VM host known to CS is different from 'PowerOn' report host, then it is out-of-band movement
2590- if (hostId .longValue () != powerHostId .longValue ()) {
2590+ Long hostId = null ;
2591+ if (first != null && first instanceof Long ) {
2592+ hostId = (Long )first ;
2593+ }
2594+ // The following scenarios are due to out-of-band VM movement
2595+ // 1. If VM is in stopped state in CS due to 'PowerMissing' report from old host (hostId is null) and then there is a 'PowerOn' report from new host
2596+ // 2. If VM is in running state in CS and there is a 'PowerOn' report from new host
2597+ if (hostId == null || (hostId .longValue () != powerHostId .longValue ())) {
25912598 s_logger .info ("Schedule a router reboot task as router " + vo .getId () + " is powered-on out-of-band, need to reboot to refresh network rules" );
25922599 _executor .schedule (new RebootTask (vo .getId ()), 1000 , TimeUnit .MICROSECONDS );
25932600 }
0 commit comments