balancerd.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.service import (
  10. Service,
  11. ServiceConfig,
  12. ServiceDependency,
  13. )
  14. class Balancerd(Service):
  15. def __init__(
  16. self,
  17. name: str = "balancerd",
  18. mzbuild: str = "balancerd",
  19. command: list[str] | None = None,
  20. volumes: list[str] = [],
  21. depends_on: list[str] = [],
  22. https_resolver_template: str | None = None,
  23. frontegg_resolver_template: str | None = None,
  24. static_resolver_addr: str | None = None,
  25. ) -> None:
  26. if command is None:
  27. command = [
  28. "service",
  29. "--pgwire-listen-addr=0.0.0.0:6875",
  30. "--https-listen-addr=0.0.0.0:6876",
  31. "--internal-http-listen-addr=0.0.0.0:6878",
  32. f"--static-resolver-addr={static_resolver_addr or 'materialized:6875'}",
  33. f"--https-resolver-template={https_resolver_template or 'materialized:6876'}",
  34. ]
  35. else:
  36. if static_resolver_addr is not None:
  37. command.append(f"--static-resolver-addr={static_resolver_addr}")
  38. if https_resolver_template is not None:
  39. command.append(f"--https-resolver-template={https_resolver_template}")
  40. if frontegg_resolver_template is not None:
  41. command.append(
  42. f"--frontegg-reesolver-template={frontegg_resolver_template}"
  43. )
  44. depends_graph: dict[str, ServiceDependency] = {
  45. s: {"condition": "service_started"} for s in depends_on
  46. }
  47. config: ServiceConfig = {
  48. "mzbuild": mzbuild,
  49. "command": command,
  50. "ports": [6875, 6876, 6877, 6878],
  51. "volumes": volumes,
  52. "depends_on": depends_graph,
  53. }
  54. super().__init__(
  55. name=name,
  56. config=config,
  57. )