|
244 | 244 | import com.cloud.vm.dao.UserVmDao; |
245 | 245 | import com.cloud.vm.dao.UserVmDetailsDao; |
246 | 246 | import com.cloud.vm.dao.VMInstanceDao; |
| 247 | + |
247 | 248 | import org.apache.cloudstack.alert.AlertService; |
248 | 249 | import org.apache.cloudstack.alert.AlertService.AlertType; |
249 | 250 | import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd; |
|
266 | 267 | import javax.ejb.Local; |
267 | 268 | import javax.inject.Inject; |
268 | 269 | import javax.naming.ConfigurationException; |
| 270 | + |
269 | 271 | import java.text.ParseException; |
270 | 272 | import java.text.SimpleDateFormat; |
271 | 273 | import java.util.ArrayList; |
@@ -4459,10 +4461,22 @@ public boolean preStateTransitionEvent(State oldState, VirtualMachine.Event even |
4459 | 4461 |
|
4460 | 4462 | @Override |
4461 | 4463 | public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) { |
4462 | | - if (oldState == State.Stopped && event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == State.Running) { |
| 4464 | + if (event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == State.Running) { |
4463 | 4465 | if (vo.getType() == VirtualMachine.Type.DomainRouter) { |
4464 | | - 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"); |
4465 | | - _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); |
| 4466 | + if (opaque != null && opaque instanceof Pair<?, ?>) { |
| 4467 | + Pair<?, ?> pair = (Pair<?, ?>)opaque; |
| 4468 | + Object first = pair.first(); |
| 4469 | + Object second = pair.second(); |
| 4470 | + if (first != null && second != null && first instanceof Long && second instanceof Long) { |
| 4471 | + Long hostId = (Long)first; |
| 4472 | + Long powerHostId = (Long)second; |
| 4473 | + // If VM host known to CS is different from 'PowerOn' report host, then it is out-of-band movement |
| 4474 | + if (hostId.longValue() != powerHostId.longValue()) { |
| 4475 | + 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"); |
| 4476 | + _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); |
| 4477 | + } |
| 4478 | + } |
| 4479 | + } |
4466 | 4480 | } |
4467 | 4481 | } |
4468 | 4482 | return true; |
|
0 commit comments