Skip to content

Commit b9dd67c

Browse files
committed
CLOUDSTACK-8545 port of the fix to not reboot routers on out of band migration persé
1 parent 931cb95 commit b9dd67c

2 files changed

Lines changed: 47 additions & 24 deletions

File tree

server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
4444
static final String RouterTemplateOvm3CK = "router.template.ovm3";
4545
static final String SetServiceMonitorCK = "network.router.EnableServiceMonitoring";
4646
static final String RouterAlertsCheckIntervalCK = "router.alerts.check.interval";
47+
static final String RouterReprovisionOnOutOfBandMigrationCK = "router.reboot.when.outofband.migrated";
4748

4849
static final ConfigKey<String> RouterTemplateXen = new ConfigKey<String>(String.class, RouterTemplateXenCK, "Advanced", "SystemVM Template (XenServer)",
4950
"Name of the default router template on Xenserver.", true, ConfigKey.Scope.Zone, null);
@@ -63,6 +64,12 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
6364

6465
static final ConfigKey<Integer> RouterAlertsCheckInterval = new ConfigKey<Integer>(Integer.class, RouterAlertsCheckIntervalCK, "Advanced", "1800",
6566
"Interval (in seconds) to check for alerts in Virtual Router.", false, ConfigKey.Scope.Global, null);
67+
static final ConfigKey<Boolean> routerVersionCheckEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "router.version.check", "true",
68+
"If true, router minimum required version is checked before sending command", false);
69+
static final ConfigKey<Boolean> UseExternalDnsServers = new ConfigKey<Boolean>(Boolean.class, "use.external.dns", "Advanced", "false",
70+
"Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null);
71+
static final ConfigKey<Boolean> RouterReprovisionOnOutOfBandMigration = new ConfigKey<Boolean>(Boolean.class, RouterReprovisionOnOutOfBandMigrationCK, "Advanced", "false",
72+
"Reboot routers when they are migrated out of band in order to reprovision", true, ConfigKey.Scope.Zone, null);
6673

6774
public static final int DEFAULT_ROUTER_VM_RAMSIZE = 256; // 256M
6875
public static final int DEFAULT_ROUTER_CPU_MHZ = 500; // 500 MHz

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)