-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
98 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
defmodule Spawn.Cluster.ClusterSupervisor do | ||
@moduledoc false | ||
use Supervisor | ||
require Logger | ||
|
||
alias Actors.Config.PersistentTermConfig, as: Config | ||
|
||
def start_link(opts) do | ||
Supervisor.start_link(__MODULE__, opts, | ||
name: String.to_atom("#{String.capitalize(Config.get(:app_name))}.Cluster") | ||
) | ||
end | ||
|
||
@impl true | ||
def init(opts) do | ||
children = [ | ||
cluster_supervisor(opts) | ||
] | ||
|
||
Supervisor.init(children, strategy: :one_for_one) | ||
end | ||
|
||
defp cluster_supervisor(opts) do | ||
cluster_strategy = Config.get(:proxy_cluster_strategy) | ||
|
||
topologies = | ||
case cluster_strategy do | ||
"epmd" -> | ||
get_epmd_strategy(opts) | ||
|
||
"gossip" -> | ||
get_gossip_strategy(opts) | ||
|
||
"kubernetes-dns" -> | ||
get_k8s_dns_strategy(opts) | ||
|
||
_ -> | ||
Logger.warning("Invalid Topology") | ||
end | ||
|
||
if topologies && Code.ensure_compiled(Cluster.Supervisor) do | ||
Logger.debug("Cluster topology #{inspect(topologies)}") | ||
|
||
{Cluster.Supervisor, | ||
[ | ||
topologies, | ||
[name: String.to_atom("#{String.capitalize(Config.get(:app_name))}.${__MODULE__}")] | ||
]} | ||
end | ||
end | ||
|
||
defp get_epmd_strategy(_opts) do | ||
[ | ||
proxy: [ | ||
strategy: Cluster.Strategy.Epmd, | ||
config: [ | ||
hosts: [ | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]" | ||
] | ||
] | ||
] | ||
] | ||
end | ||
|
||
defp get_gossip_strategy(_opts) do | ||
[ | ||
proxy: [ | ||
strategy: Cluster.Strategy.Gossip, | ||
config: [ | ||
reuseaddr: Config.get(:proxy_cluster_gossip_reuseaddr_address), | ||
multicast_addr: Config.get(:proxy_cluster_gossip_multicast_address), | ||
broadcast_only: Config.get(:proxy_cluster_gossip_broadcast_only) | ||
] | ||
] | ||
] | ||
end | ||
|
||
defp get_k8s_dns_strategy(_opts), | ||
do: [ | ||
proxy: [ | ||
strategy: Elixir.Cluster.Strategy.Kubernetes.DNS, | ||
config: [ | ||
service: Config.get(:proxy_headless_service), | ||
application_name: "spawn", | ||
polling_interval: Config.get(:proxy_cluster_polling_interval) | ||
] | ||
] | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,16 +9,14 @@ defmodule Spawn.Supervisor do | |
|
||
def start_link(opts) do | ||
Supervisor.start_link(__MODULE__, opts, | ||
name: String.to_atom("#{String.capitalize(Config.get(:app_name))}.Cluster"), | ||
name: __MODULE__, | ||
shutdown: @shutdown_timeout_ms | ||
) | ||
end | ||
|
||
def child_spec(opts) do | ||
id = String.to_atom("#{String.capitalize(Config.get(:app_name))}.Cluster") | ||
|
||
%{ | ||
id: id, | ||
id: __MODULE__, | ||
start: {__MODULE__, :start_link, [opts]} | ||
} | ||
end | ||
|
@@ -27,7 +25,7 @@ defmodule Spawn.Supervisor do | |
def init(opts) do | ||
children = | ||
[ | ||
cluster_supervisor(opts), | ||
{Spawn.Cluster.ClusterSupervisor, []}, | ||
{Spawn.Cache.LookupCache, []}, | ||
Spawn.Cluster.StateHandoff.ManagerSupervisor.child_spec(opts), | ||
Spawn.Cluster.Node.Registry.child_spec() | ||
|
@@ -53,77 +51,4 @@ defmodule Spawn.Supervisor do | |
|> List.flatten() | ||
end | ||
end | ||
|
||
defp cluster_supervisor(opts) do | ||
cluster_strategy = Config.get(:proxy_cluster_strategy) | ||
|
||
topologies = | ||
case cluster_strategy do | ||
"epmd" -> | ||
get_epmd_strategy(opts) | ||
|
||
"gossip" -> | ||
get_gossip_strategy(opts) | ||
|
||
"kubernetes-dns" -> | ||
get_k8s_dns_strategy(opts) | ||
|
||
_ -> | ||
Logger.warning("Invalid Topology") | ||
end | ||
|
||
if topologies && Code.ensure_compiled(Cluster.Supervisor) do | ||
Logger.debug("Cluster topology #{inspect(topologies)}") | ||
|
||
{Cluster.Supervisor, | ||
[ | ||
topologies, | ||
[name: String.to_atom("#{String.capitalize(Config.get(:app_name))}.${__MODULE__}")] | ||
]} | ||
end | ||
end | ||
|
||
defp get_epmd_strategy(_opts) do | ||
[ | ||
proxy: [ | ||
strategy: Cluster.Strategy.Epmd, | ||
config: [ | ||
hosts: [ | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]", | ||
:"[email protected]" | ||
] | ||
] | ||
] | ||
] | ||
end | ||
|
||
defp get_gossip_strategy(_opts) do | ||
[ | ||
proxy: [ | ||
strategy: Cluster.Strategy.Gossip, | ||
config: [ | ||
reuseaddr: Config.get(:proxy_cluster_gossip_reuseaddr_address), | ||
multicast_addr: Config.get(:proxy_cluster_gossip_multicast_address), | ||
broadcast_only: Config.get(:proxy_cluster_gossip_broadcast_only) | ||
] | ||
] | ||
] | ||
end | ||
|
||
defp get_k8s_dns_strategy(_opts), | ||
do: [ | ||
proxy: [ | ||
strategy: Elixir.Cluster.Strategy.Kubernetes.DNS, | ||
config: [ | ||
service: Config.get(:proxy_headless_service), | ||
application_name: "spawn", | ||
polling_interval: Config.get(:proxy_cluster_polling_interval) | ||
] | ||
] | ||
] | ||
end |