balancerd_actions.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from materialize.mzcompose.composition import Composition
  10. from materialize.mzcompose.services.balancerd import Balancerd
  11. from materialize.zippy.balancerd_capabilities import BalancerdIsRunning
  12. from materialize.zippy.framework import Action, Capability, State
  13. from materialize.zippy.mz_capabilities import MzIsRunning
  14. class BalancerdStart(Action):
  15. """Starts balancerd"""
  16. @classmethod
  17. def requires(cls) -> set[type[Capability]]:
  18. return {MzIsRunning}
  19. @classmethod
  20. def incompatible_with(cls) -> set[type[Capability]]:
  21. return {BalancerdIsRunning}
  22. def run(self, c: Composition, state: State) -> None:
  23. with c.override(
  24. Balancerd(
  25. https_resolver_template=f"{state.mz_service}:6876",
  26. static_resolver_addr=f"{state.mz_service}:6875",
  27. )
  28. ):
  29. c.up("balancerd")
  30. def provides(self) -> list[Capability]:
  31. return [BalancerdIsRunning()]
  32. class BalancerdStop(Action):
  33. """Stops balancerd"""
  34. @classmethod
  35. def requires(cls) -> set[type[Capability]]:
  36. # Technically speaking, we do not need Mz to be up in order to kill balancerd
  37. # However, without this protection we frequently end up in a situation where
  38. # both are down and Zippy enters a prolonged period of restarting one or the
  39. # other and no other useful work can be performed in the meantime.
  40. return {BalancerdIsRunning, MzIsRunning}
  41. def run(self, c: Composition, state: State) -> None:
  42. c.kill("balancerd")
  43. def withholds(self) -> set[type[Capability]]:
  44. return {BalancerdIsRunning}
  45. class BalancerdRestart(Action):
  46. """Restarts balancerd"""
  47. @classmethod
  48. def requires(cls) -> set[type[Capability]]:
  49. return {BalancerdIsRunning, MzIsRunning}
  50. def run(self, c: Composition, state: State) -> None:
  51. with c.override(
  52. Balancerd(
  53. https_resolver_template=f"{state.mz_service}:6876",
  54. static_resolver_addr=f"{state.mz_service}:6875",
  55. )
  56. ):
  57. c.kill("balancerd")
  58. c.up("balancerd")