Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Paused] Remove code associated with the old orchestrator #1925

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{"lib/x509/certificate.ex", "Unknown type: X509.ASN1.record/1."},
{"lib/x509/certificate/extension.ex", "Unknown type: X509.ASN1.record/1."},
{"lib/nerves_hub/deployments/orchestrator.ex", :unmatched_return, 1},
{"lib/nerves_hub_web/channels/device_channel.ex", :unmatched_return, 1},
{"lib/nerves_hub_web/channels/device_socket.ex", :unmatched_return, 1}
]
4 changes: 1 addition & 3 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ config :nerves_hub,
System.get_env("FEATURES_HEALTH_UI_POLLING_SECONDS", "60") |> String.to_integer()
]
],
new_ui: System.get_env("NEW_UI_ENABLED", "true") == "true",
display_deployment_orchestrator_strategy:
System.get_env("DISPLAY_DEPLOYMENT_ORCHESTRATOR_STRATEGY", "false") == "true"
new_ui: System.get_env("NEW_UI_ENABLED", "true") == "true"

config :nerves_hub, :device_socket_drainer,
batch_size: String.to_integer(System.get_env("DEVICE_SOCKET_DRAINER_BATCH_SIZE", "1000")),
Expand Down
7 changes: 2 additions & 5 deletions lib/nerves_hub/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ defmodule NervesHub.Application do
{Ecto.Migrator,
repos: Application.fetch_env!(:nerves_hub, :ecto_repos),
skip: Application.get_env(:nerves_hub, :database_auto_migrator) != true},
{Registry, keys: :unique, name: NervesHub.Devices.Registry},
{Finch, name: Swoosh.Finch}
] ++
NervesHub.StatsdMetricsReporter.config() ++
Expand Down Expand Up @@ -75,13 +74,11 @@ defmodule NervesHub.Application do

defp deployments_orchestrator("test"), do: []

# When running in the default `multi` mode, start a deployments orchestrator supervisor
# on every node. But when running in `clustered` mode, run the `ProcessHub` supervisor
# on the `web` or `all` nodes only.
# Only run the `ProcessHub` supervisor on the `web` or `all` nodes.
defp deployments_orchestrator(_) do
case Application.get_env(:nerves_hub, :app) do
["device"] ->
[NervesHub.Deployments.Supervisor]
[]

_ ->
[
Expand Down
69 changes: 17 additions & 52 deletions lib/nerves_hub/deployments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
Repo.all(Deployment)
end

@spec should_run_in_distributed_orchestrator() :: [Deployment.t()]
def should_run_in_distributed_orchestrator() do
@spec should_run_orchestrator() :: [Deployment.t()]
def should_run_orchestrator() do
Deployment
|> where(is_active: true)
|> where(orchestrator_strategy: :distributed)
|> Repo.all()
end

Expand Down Expand Up @@ -293,14 +292,6 @@
end
end

if Map.has_key?(changeset.changes, :orchestrator_strategy) do
if deployment.orchestrator_strategy == :distributed do
start_deployments_distributed_orchestrator_event(deployment)
else
shutdown_deployments_distributed_orchestrator_event(deployment)
end
end

{:ok, deployment}

{:error, changeset} ->
Expand Down Expand Up @@ -389,7 +380,7 @@
def broadcast(deployment, event, payload \\ %{})

def broadcast(:none, event, payload) do
Phoenix.Channel.Server.broadcast(

Check warning on line 383 in lib/nerves_hub/deployments.ex

View workflow job for this annotation

GitHub Actions / compile-and-test

Nested modules could be aliased at the top of the invoking module.
NervesHub.PubSub,
"deployment:none",
event,
Expand All @@ -397,17 +388,8 @@
)
end

def broadcast(:monitor, event, payload) do
Phoenix.Channel.Server.broadcast(
NervesHub.PubSub,
"deployment:monitor",
event,
payload
)
end

def broadcast(%Deployment{id: id}, event, payload) do
Phoenix.Channel.Server.broadcast(

Check warning on line 392 in lib/nerves_hub/deployments.ex

View workflow job for this annotation

GitHub Actions / compile-and-test

Nested modules could be aliased at the top of the invoking module.
NervesHub.PubSub,
"deployment:#{id}",
event,
Expand Down Expand Up @@ -603,56 +585,39 @@
end

def deployment_created_event(deployment) do
# the old orchestrator
_ = broadcast(:monitor, "deployments/new", %{deployment_id: deployment.id})

# the new orchestrator
_ = DistributedOrchestrator.start_orchestrator(deployment)

:ok
end

def start_deployments_distributed_orchestrator_event(deployment) do
DistributedOrchestrator.start_orchestrator(deployment)

:ok
end

def shutdown_deployments_distributed_orchestrator_event(deployment) do
Phoenix.Channel.Server.broadcast(
NervesHub.PubSub,
"orchestrator:deployment:#{deployment.id}",
"deactivated",
%{}
)

:ok
end

def deployment_activated_event(deployment) do
DistributedOrchestrator.start_orchestrator(deployment)

:ok
end

def deployment_deactivated_event(deployment) do
Phoenix.Channel.Server.broadcast(
NervesHub.PubSub,
"orchestrator:deployment:#{deployment.id}",
"deactivated",
%{}
)
:ok =
Phoenix.Channel.Server.broadcast(
NervesHub.PubSub,
"orchestrator:deployment:#{deployment.id}",
"deactivated",
%{}
)

:ok
end

def deployment_deleted_event(deployment) do
_ =
if deployment.orchestrator_strategy == :distributed do
broadcast(deployment, "deleted")
end
:ok =
Phoenix.Channel.Server.broadcast(
NervesHub.PubSub,
"orchestrator:deployment:#{deployment.id}",
"deactivated",
%{}
)

broadcast(:monitor, "deployments/delete", %{deployment_id: deployment.id})
:ok = broadcast(deployment, "deleted")

:ok
end
Expand Down
6 changes: 1 addition & 5 deletions lib/nerves_hub/deployments/deployment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ defmodule NervesHub.Deployments.Deployment do
:penalty_timeout_minutes,
:connecting_code,
:total_updating_devices,
:current_updated_devices,
:orchestrator_strategy
:current_updated_devices
]

schema "deployments" do
Expand Down Expand Up @@ -74,9 +73,6 @@ defmodule NervesHub.Deployments.Deployment do

field(:device_count, :integer, virtual: true)

# temporary addition while we feature test a new deployment management strategy
field(:orchestrator_strategy, Ecto.Enum, values: [:multi, :distributed], default: :multi)

timestamps()
end

Expand Down
18 changes: 8 additions & 10 deletions lib/nerves_hub/deployments/distributed/orchestrator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,7 @@ defmodule NervesHub.Deployments.Distributed.Orchestrator do
) do
{:ok, deployment} = Deployments.get_deployment(state.deployment)

# shutdown the orchestrator if the deployment is updated to use the old `:multi` strategy
if deployment.orchestrator_strategy == :distributed do
maybe_trigger_update(%{state | deployment: deployment})
else
{:stop, :normal, state}
end
maybe_trigger_update(%{state | deployment: deployment})
end

def handle_info(%Broadcast{topic: "deployment:" <> _, event: "deleted"}, state) do
Expand All @@ -276,10 +271,13 @@ defmodule NervesHub.Deployments.Distributed.Orchestrator do
maybe_trigger_update(state)
end

def start_orchestrator(
%Deployment{is_active: true, orchestrator_strategy: :distributed} = deployment
) do
ProcessHub.start_child(:deployment_orchestrators, child_spec(deployment))
def start_orchestrator(%Deployment{is_active: true} = deployment) do
_ =
if Application.get_env(:nerves_hub, :deploy_env) != "test" do
ProcessHub.start_child(:deployment_orchestrators, child_spec(deployment))
end

:ok
end

def start_orchestrator(_) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule NervesHub.Deployments.Distributed.OrchestratorRegistration do
@impl GenServer
def handle_info(:start_orchestrators, _) do
_ =
Deployments.should_run_in_distributed_orchestrator()
Deployments.should_run_orchestrator()
|> Enum.map(fn deployment ->
Orchestrator.child_spec(deployment)
end)
Expand Down
66 changes: 0 additions & 66 deletions lib/nerves_hub/deployments/monitor.ex

This file was deleted.

Loading
Loading