@@ -2604,7 +2604,7 @@ public String getConfigComponentName() {
26042604
26052605 @ Override
26062606 public ConfigKey <?>[] getConfigKeys () {
2607- return new ConfigKey <?>[] { UseExternalDnsServers , routerVersionCheckEnabled , SetServiceMonitor , RouterAlertsCheckInterval };
2607+ return new ConfigKey <?>[] { UseExternalDnsServers , routerVersionCheckEnabled , SetServiceMonitor , RouterAlertsCheckInterval , RouterReprovisionOnOutOfBandMigration };
26082608 }
26092609
26102610 @ Override
@@ -2615,36 +2615,52 @@ public boolean preStateTransitionEvent(final State oldState, final VirtualMachin
26152615
26162616 @ Override
26172617 public boolean postStateTransitionEvent (final StateMachine2 .Transition <State , VirtualMachine .Event > transition , final VirtualMachine vo , final boolean status , final Object opaque ) {
2618+ final State oldState = transition .getCurrentState ();
26182619 final State newState = transition .getToState ();
26192620 final VirtualMachine .Event event = transition .getEvent ();
2620- if (event == VirtualMachine .Event .FollowAgentPowerOnReport && newState == State .Running ) {
2621- if (vo .getType () == VirtualMachine .Type .DomainRouter ) {
2622- // opaque -> <hostId, powerHostId>
2623- if (opaque != null && opaque instanceof Pair <?, ?>) {
2624- final Pair <?, ?> pair = (Pair <?, ?>)opaque ;
2625- final Object first = pair .first ();
2626- final Object second = pair .second ();
2627- // powerHostId cannot be null in case of out-of-band VM movement
2628- if (second != null && second instanceof Long ) {
2629- final Long powerHostId = (Long )second ;
2630- Long hostId = null ;
2631- if (first != null && first instanceof Long ) {
2632- hostId = (Long )first ;
2633- }
2634- // The following scenarios are due to out-of-band VM movement
2635- // 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
2636- // 2. If VM is in running state in CS and there is a 'PowerOn' report from new host
2637- if (hostId == null || hostId .longValue () != powerHostId .longValue ()) {
2638- 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" );
2639- _rebootRouterExecutor .execute (new RebootTask (vo .getId ()));
2640- }
2641- }
2642- }
2621+ boolean reprovision_out_of_band = RouterReprovisionOnOutOfBandMigration .value ();
2622+ if (
2623+ (vo .getType () == VirtualMachine .Type .DomainRouter ) &&
2624+ ((oldState == State .Stopped ) || (reprovision_out_of_band && isOutOfBandMigrated (opaque ))) &&
2625+ (event == VirtualMachine .Event .FollowAgentPowerOnReport ) &&
2626+ (newState == State .Running )) {
2627+ s_logger .info ("Schedule a router reboot task as router " + vo .getId () + " is powered-on out-of-band. we need to reboot to refresh network rules" );
2628+ _rebootRouterExecutor .execute (new RebootTask (vo .getId ()));
2629+ } else {
2630+ if (isOutOfBandMigrated (opaque )) {
2631+ final String title = "Router has been migrated out of band: " + vo .getInstanceName ();
2632+ final String context =
2633+ "An out of band migration of router " + vo .getInstanceName () + "(" + vo .getUuid () + ") was detected. No automated action was performed." ;
2634+ _alertMgr .sendAlert (AlertManager .AlertType .ALERT_TYPE_DOMAIN_ROUTER , vo .getDataCenterId (), vo .getPodIdToDeployIn (), title , context );
26432635 }
26442636 }
2637+
26452638 return true ;
26462639 }
26472640
2641+ private boolean isOutOfBandMigrated (final Object opaque ) {
2642+ if (opaque != null && opaque instanceof Pair <?, ?>) {
2643+ final Pair <?, ?> pair = (Pair <?, ?>)opaque ;
2644+ final Object first = pair .first ();
2645+ final Object second = pair .second ();
2646+ // powerHostId cannot be null in case of out-of-band VM movement
2647+ if (second != null && second instanceof Long ) {
2648+ final Long powerHostId = (Long )second ;
2649+ Long hostId = null ;
2650+ if (first != null && first instanceof Long ) {
2651+ hostId = (Long )first ;
2652+ }
2653+ // The following scenarios are due to out-of-band VM movement
2654+ // 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
2655+ // 2. If VM is in running state in CS and there is a 'PowerOn' report from new host
2656+ if (hostId == null || hostId .longValue () != powerHostId .longValue ()) {
2657+ return true ;
2658+ }
2659+ }
2660+ }
2661+ return false ;
2662+ }
2663+
26482664 protected class RebootTask extends ManagedContextRunnable {
26492665
26502666 long _routerId ;
0 commit comments