Refactored master and slave switch code out of HAMS, so that it is mainly deciding and coordinating
Fixed a critical bug where an instance could be shut down and then switch to slave. This mainly impacts automated tests and causes "flaky HA tests".
Added test for when a new master becomes available during a slave switch.
Merge pull request #2295 from rickardoberg/hams-refactoring

HighAvailabilityModeSwitcher refactoring and fixes