mirror of https://github.com/apache/cloudstack.git
reboot VR if a out-of-band power-on event is detected
This commit is contained in:
parent
fed85813e9
commit
ee2adab7c7
|
|
@ -251,6 +251,7 @@ import com.cloud.utils.db.Transaction;
|
|||
import com.cloud.utils.db.TransactionCallbackNoReturn;
|
||||
import com.cloud.utils.db.TransactionStatus;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.fsm.StateListener;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.MacAddress;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
|
@ -281,9 +282,9 @@ import com.cloud.vm.dao.VMInstanceDao;
|
|||
/**
|
||||
* VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances available in the Cloud Stack.
|
||||
*/
|
||||
@Local(value = {VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class})
|
||||
public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, VirtualMachineGuru,
|
||||
Listener, Configurable {
|
||||
@Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class })
|
||||
public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService,
|
||||
VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.Event, VirtualMachine> {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
|
||||
|
||||
@Inject
|
||||
|
|
@ -675,6 +676,8 @@ Listener, Configurable {
|
|||
_checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor"));
|
||||
_networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater"));
|
||||
|
||||
VirtualMachine.State.getStateMachine().registerListener(this);
|
||||
|
||||
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
|
||||
|
||||
_routerRamSize = NumbersUtil.parseInt(configs.get("router.ram.size"), DEFAULT_ROUTER_VM_RAMSIZE);
|
||||
|
|
@ -3435,7 +3438,6 @@ Listener, Configurable {
|
|||
"vmdata",
|
||||
generateVmDataCommand(router, nic.getIp4Address(), vm.getUserData(), serviceOffering, zoneName, nic.getIp4Address(), vm.getHostName(), vm.getInstanceName(),
|
||||
vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId()));
|
||||
|
||||
}
|
||||
|
||||
private void createVmDataCommandForVMs(final DomainRouterVO router, final Commands cmds, final long guestNetworkId) {
|
||||
|
|
@ -4228,4 +4230,39 @@ Listener, Configurable {
|
|||
public ConfigKey<?>[] getConfigKeys() {
|
||||
return new ConfigKey<?>[] {UseExternalDnsServers, routerVersionCheckEnabled, SetServiceMonitor};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
|
||||
if (oldState == State.Stopped && event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == State.Running) {
|
||||
if (vo.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
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");
|
||||
_executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected class RebootTask extends ManagedContextRunnable {
|
||||
|
||||
long _routerId;
|
||||
|
||||
public RebootTask(long routerId) {
|
||||
_routerId = routerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runInContext() {
|
||||
try {
|
||||
s_logger.info("Reboot router " + _routerId + " to refresh network rules");
|
||||
rebootRouter(_routerId, true);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Error while rebooting the router", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue