Refactor common Yarn scheduler backend logic

As of this commit the mechanism is accessible from cluster mode
in addition to just client mode.