diff --git a/lib/nerves_hub/accounts/remove_account.ex b/lib/nerves_hub/accounts/remove_account.ex index 9ff14578b..09c790960 100644 --- a/lib/nerves_hub/accounts/remove_account.ex +++ b/lib/nerves_hub/accounts/remove_account.ex @@ -5,7 +5,7 @@ defmodule NervesHub.Accounts.RemoveAccount do alias NervesHub.{ Accounts, Firmwares, - Deployments.DeploymentGroup, + ManagedDeployments.DeploymentGroup, Products, Repo, OrgKey, @@ -25,7 +25,7 @@ defmodule NervesHub.Accounts.RemoveAccount do |> Multi.delete_all(:invites, &query_by_org_id(Invite, &1)) |> Multi.delete_all(:device_certificates, &query_by_org_id(DeviceCertificate, &1)) |> Multi.delete_all(:ca_certificates, &query_by_org_id(CACertificate, &1)) - |> Multi.delete_all(:deployments, &query_by_org_id(DeploymentGroup, &1)) + |> Multi.delete_all(:deployment_groups, &query_by_org_id(DeploymentGroup, &1)) |> Multi.delete_all(:firmware_deltas, &query_firmware_deltas/1) |> Multi.delete_all(:firmware_transfers, &query_by_org_id(FirmwareTransfer, &1)) |> Multi.merge(&delete_firmwares/1) diff --git a/lib/nerves_hub/application.ex b/lib/nerves_hub/application.ex index 088bea481..02b5856ce 100644 --- a/lib/nerves_hub/application.ex +++ b/lib/nerves_hub/application.ex @@ -76,7 +76,7 @@ defmodule NervesHub.Application do defp deployments_supervisor("test"), do: [] defp deployments_supervisor(_) do - [NervesHub.Deployments.Supervisor] + [NervesHub.ManagedDeployments.Supervisor] end defp endpoints("test") do diff --git a/lib/nerves_hub/audit_logs.ex b/lib/nerves_hub/audit_logs.ex index 8ed321bd8..3a3deeb61 100644 --- a/lib/nerves_hub/audit_logs.ex +++ b/lib/nerves_hub/audit_logs.ex @@ -2,7 +2,7 @@ defmodule NervesHub.AuditLogs do import Ecto.Query alias NervesHub.AuditLogs.AuditLog - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Repo alias NimbleCSV.RFC4180, as: CSV diff --git a/lib/nerves_hub/audit_logs/templates.ex b/lib/nerves_hub/audit_logs/templates.ex index a89515089..11381ad7a 100644 --- a/lib/nerves_hub/audit_logs/templates.ex +++ b/lib/nerves_hub/audit_logs/templates.ex @@ -4,7 +4,7 @@ defmodule NervesHub.AuditLogs.Templates do def audit_resolve_changed_deployment(device, reference_id) do description = if device.deployment_id do - "device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment.name}" + "device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment_group.name}" else "device #{device.identifier} reloaded deployment and is no longer attached to a deployment" end @@ -13,18 +13,18 @@ defmodule NervesHub.AuditLogs.Templates do end def audit_device_deployment_update_triggered(device, reference_id) do - deployment = device.deployment - firmware = deployment.firmware + deployment_group = device.deployment_group + firmware = deployment_group.firmware description = - "deployment #{deployment.name} update triggered device #{device.identifier} to update firmware #{firmware.uuid}" + "deployment #{deployment_group.name} update triggered device #{device.identifier} to update firmware #{firmware.uuid}" - AuditLogs.audit_with_ref!(deployment, device, description, reference_id) + AuditLogs.audit_with_ref!(deployment_group, device, description, reference_id) end def audit_device_assigned(device, reference_id) do description = - "device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment.name}" + "device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment_group.name}" AuditLogs.audit_with_ref!(device, device, description, reference_id) end diff --git a/lib/nerves_hub/deployments/inflight_deployment_check.ex b/lib/nerves_hub/deployments/inflight_deployment_check.ex deleted file mode 100644 index 4d19a2cf3..000000000 --- a/lib/nerves_hub/deployments/inflight_deployment_check.ex +++ /dev/null @@ -1,15 +0,0 @@ -defmodule NervesHub.Deployments.InflightDeploymentCheck do - use Ecto.Schema - - @timestamps_opts updated_at: false - - alias NervesHub.Deployments.DeploymentGroup - alias NervesHub.Devices.Device - - schema "inflight_deployment_checks" do - belongs_to(:device, Device) - belongs_to(:deployment, DeploymentGroup) - - timestamps() - end -end diff --git a/lib/nerves_hub/deployments/supervisor.ex b/lib/nerves_hub/deployments/supervisor.ex deleted file mode 100644 index 1121b6b9e..000000000 --- a/lib/nerves_hub/deployments/supervisor.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule NervesHub.Deployments.Supervisor do - @moduledoc false - - use Supervisor - - def start_link(_) do - Supervisor.start_link(__MODULE__, [], name: __MODULE__) - end - - def init(_) do - children = [ - {Registry, keys: :unique, name: NervesHub.Deployments}, - NervesHub.Deployments.Monitor, - {DynamicSupervisor, strategy: :one_for_one, name: NervesHub.DeploymentDynamicSupervisor} - ] - - Supervisor.init(children, strategy: :one_for_one) - end -end diff --git a/lib/nerves_hub/devices.ex b/lib/nerves_hub/devices.ex index 5e23ac5b0..29c42c262 100644 --- a/lib/nerves_hub/devices.ex +++ b/lib/nerves_hub/devices.ex @@ -9,8 +9,8 @@ defmodule NervesHub.Devices do alias NervesHub.Accounts.User alias NervesHub.AuditLogs alias NervesHub.Certificate - alias NervesHub.Deployments.DeploymentGroup - alias NervesHub.Deployments.Orchestrator + alias NervesHub.ManagedDeployments.DeploymentGroup + alias NervesHub.ManagedDeployments.Orchestrator alias NervesHub.Devices.CACertificate alias NervesHub.Devices.Alarms alias NervesHub.Devices.Connections @@ -85,12 +85,12 @@ defmodule NervesHub.Devices do |> where([d], d.product_id == ^product_id) |> join(:left, [d], o in assoc(d, :org)) |> join(:left, [d, o], p in assoc(d, :product)) - |> join(:left, [d, o, p], dp in assoc(d, :deployment)) + |> join(:left, [d, o, p], dp in assoc(d, :deployment_group)) |> join(:left, [d, o, p, dp], f in assoc(dp, :firmware)) |> Repo.exclude_deleted() |> order_by(^sort_devices(sorting)) |> filtering(filters) - |> preload([d, o, p, dp, f], org: o, product: p, deployment: {dp, firmware: f}) + |> preload([d, o, p, dp, f], org: o, product: p, deployment_group: {dp, firmware: f}) |> Connections.preload_latest_connection() |> Flop.run(flop) end @@ -313,7 +313,7 @@ defmodule NervesHub.Devices do {:error, :not_found} device -> - {:ok, Repo.preload(device, [:org, :product, deployment: [:firmware]])} + {:ok, Repo.preload(device, [:org, :product, deployment_group: [:firmware]])} end end @@ -340,9 +340,9 @@ defmodule NervesHub.Devices do |> where(identifier: ^identifier) |> where(org_id: ^org_id) |> join(:left, [d], o in assoc(d, :org)) - |> join(:left, [d], dp in assoc(d, :deployment)) + |> join(:left, [d], dp in assoc(d, :deployment_group)) |> join_and_preload(preload_assoc) - |> preload([d, o, dp], org: o, deployment: dp) + |> preload([d, o, dp], org: o, deployment_group: dp) end defp join_and_preload(query, nil), do: query @@ -765,7 +765,7 @@ defmodule NervesHub.Devices do end def resolve_update(device) do - deployment = Repo.preload(device.deployment, [:firmware]) + deployment = Repo.preload(device.deployment_group, [:firmware]) case verify_update_eligibility(device, deployment) do {:ok, _device} -> @@ -776,7 +776,7 @@ defmodule NervesHub.Devices do update_available: true, firmware_url: url, firmware_meta: meta, - deployment: deployment, + deployment_group: deployment, deployment_id: deployment.id } @@ -819,7 +819,7 @@ defmodule NervesHub.Devices do def matches_deployment?(_, _), do: false - @spec update_deployment(Device.t(), Deployment.t()) :: Device.t() + @spec update_deployment(Device.t(), DeploymentGroup.t()) :: Device.t() def update_deployment(device, deployment) do device |> Ecto.Changeset.change() diff --git a/lib/nerves_hub/devices/device.ex b/lib/nerves_hub/devices/device.ex index 0d2b2cdd3..059a71c6a 100644 --- a/lib/nerves_hub/devices/device.ex +++ b/lib/nerves_hub/devices/device.ex @@ -7,7 +7,7 @@ defmodule NervesHub.Devices.Device do alias NervesHub.Devices.DeviceCertificate alias NervesHub.Devices.DeviceConnection alias NervesHub.Extensions.ExtensionsSetting - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Firmwares.FirmwareMetadata alias NervesHub.Products.Product @@ -39,7 +39,7 @@ defmodule NervesHub.Devices.Device do schema "devices" do belongs_to(:org, Org, where: [deleted_at: nil]) belongs_to(:product, Product, where: [deleted_at: nil]) - belongs_to(:deployment, DeploymentGroup) + belongs_to(:deployment_group, DeploymentGroup, foreign_key: :deployment_id) embeds_one(:firmware_metadata, FirmwareMetadata, on_replace: :update) has_many(:device_certificates, DeviceCertificate, on_delete: :delete_all) has_many(:device_connections, DeviceConnection, on_delete: :delete_all) diff --git a/lib/nerves_hub/devices/inflight_update.ex b/lib/nerves_hub/devices/inflight_update.ex index 88367109b..f2546c3bd 100644 --- a/lib/nerves_hub/devices/inflight_update.ex +++ b/lib/nerves_hub/devices/inflight_update.ex @@ -5,14 +5,14 @@ defmodule NervesHub.Devices.InflightUpdate do alias NervesHub.Devices.Device alias NervesHub.Devices.InflightUpdate - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Firmwares.Firmware @required_params [:device_id, :deployment_id, :firmware_id, :firmware_uuid, :expires_at] schema "inflight_updates" do belongs_to(:device, Device) - belongs_to(:deployment, DeploymentGroup) + belongs_to(:deployment_group, DeploymentGroup, foreign_key: :deployment_id) belongs_to(:firmware, Firmware) field(:firmware_uuid, Ecto.UUID) diff --git a/lib/nerves_hub/devices/update_payload.ex b/lib/nerves_hub/devices/update_payload.ex index 564a0a49e..e9bbd750e 100644 --- a/lib/nerves_hub/devices/update_payload.ex +++ b/lib/nerves_hub/devices/update_payload.ex @@ -4,7 +4,7 @@ defmodule NervesHub.Devices.UpdatePayload do """ alias NervesHub.Firmwares.FirmwareMetadata - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup @derive {Jason.Encoder, only: [ @@ -17,7 +17,7 @@ defmodule NervesHub.Devices.UpdatePayload do defstruct update_available: false, firmware_url: nil, firmware_meta: nil, - deployment: nil, + deployment_group: nil, deployment_id: nil @type t :: @@ -25,14 +25,14 @@ defmodule NervesHub.Devices.UpdatePayload do update_available: false, firmware_meta: nil, firmware_url: nil, - deployment: nil, + deployment_group: nil, deployment_id: nil } | %__MODULE__{ update_available: true, firmware_meta: FirmwareMetadata.t(), firmware_url: String.t(), - deployment: DeploymentGroup.t(), + deployment_group: DeploymentGroup.t(), deployment_id: non_neg_integer() } end diff --git a/lib/nerves_hub/firmwares/firmware.ex b/lib/nerves_hub/firmwares/firmware.ex index 34e5cf80d..2706bb15d 100644 --- a/lib/nerves_hub/firmwares/firmware.ex +++ b/lib/nerves_hub/firmwares/firmware.ex @@ -5,7 +5,7 @@ defmodule NervesHub.Firmwares.Firmware do alias NervesHub.Accounts.Org alias NervesHub.Accounts.OrgKey - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Products.Product alias __MODULE__ @@ -46,7 +46,7 @@ defmodule NervesHub.Firmwares.Firmware do belongs_to(:org, Org, where: [deleted_at: nil]) belongs_to(:product, Product, where: [deleted_at: nil]) belongs_to(:org_key, OrgKey) - has_many(:deployments, DeploymentGroup) + has_many(:deployment_groups, DeploymentGroup) field(:architecture, :string) field(:author, :string) @@ -68,7 +68,7 @@ defmodule NervesHub.Firmwares.Firmware do |> cast(params, @required_params ++ @optional_params) |> validate_required(@required_params) |> unique_constraint(:uuid, name: :firmwares_product_id_uuid_index) - |> foreign_key_constraint(:deployments, name: :deployments_firmware_id_fkey) + |> foreign_key_constraint(:deployment_groups, name: :deployment_groups_firmware_id_fkey) end def update_changeset(%Firmware{} = firmware, params) do @@ -76,12 +76,12 @@ defmodule NervesHub.Firmwares.Firmware do |> cast(params, @required_params ++ @optional_params) |> validate_required(@required_params) |> unique_constraint(:uuid, name: :firmwares_product_id_uuid_index) - |> foreign_key_constraint(:deployments, name: :deployments_firmware_id_fkey) + |> foreign_key_constraint(:deployment_groups, name: :deployment_groups_firmware_id_fkey) end def delete_changeset(%Firmware{} = firmware, params) do firmware |> cast(params, @required_params ++ @optional_params) - |> no_assoc_constraint(:deployments, message: "Firmware has associated deployments") + |> no_assoc_constraint(:deployment_groups, message: "Firmware has associated deployments") end end diff --git a/lib/nerves_hub/deployments.ex b/lib/nerves_hub/managed_deployments.ex similarity index 79% rename from lib/nerves_hub/deployments.ex rename to lib/nerves_hub/managed_deployments.ex index 237d88eb6..c97a15a8b 100644 --- a/lib/nerves_hub/deployments.ex +++ b/lib/nerves_hub/managed_deployments.ex @@ -1,11 +1,11 @@ -defmodule NervesHub.Deployments do +defmodule NervesHub.ManagedDeployments do import Ecto.Query require Logger alias NervesHub.AuditLogs - alias NervesHub.Deployments.DeploymentGroup - alias NervesHub.Deployments.InflightDeploymentCheck + alias NervesHub.ManagedDeployments.DeploymentGroup + alias NervesHub.ManagedDeployments.InflightDeploymentCheck alias NervesHub.Devices.Device alias NervesHub.Products.Product alias NervesHub.Repo @@ -120,7 +120,7 @@ defmodule NervesHub.Deployments do {:error, :not_found} {:ok, deployment} -> - _ = broadcast(:monitor, "deployments/delete", %{deployment_id: deployment.id}) + _ = broadcast(:monitor, "deployment_groups/delete", %{deployment_id: deployment.id}) {:ok, deployment} end @@ -164,7 +164,7 @@ defmodule NervesHub.Deployments do case result do {:ok, {deployment, changeset}} -> _ = maybe_trigger_delta_generation(deployment, changeset) - :ok = broadcast(deployment, "deployments/update") + :ok = broadcast(deployment, "deployment_groups/update") {:ok, deployment} @@ -180,15 +180,15 @@ defmodule NervesHub.Deployments do payload = %{archive_id: archive_id} _ = broadcast(deployment, "archives/updated", payload) - description = "deployment #{deployment.name} has a new archive" + description = "deployment group #{deployment.name} has a new archive" AuditLogs.audit!(deployment, deployment, description) {:conditions, _new_conditions} -> - description = "deployment #{deployment.name} conditions changed" + description = "deployment group #{deployment.name} conditions changed" AuditLogs.audit!(deployment, deployment, description) {:is_active, is_active} when is_active != true -> - description = "deployment #{deployment.name} is inactive" + description = "deployment group #{deployment.name} is inactive" AuditLogs.audit!(deployment, deployment, description) _ -> @@ -216,46 +216,6 @@ defmodule NervesHub.Deployments do end @doc """ - <<<<<<< HEAD - ======= - Create any matching inflight deployment checks for devices - - This includes devices that are already part of the deployment and devices - that have no current deployment. They all will be rechecked by `NervesHub.Deployments.Calculator` - - Also clears any previous inflight checks for this deployment. - """ - def schedule_deployment_calculations(deployment_group) do - query = - Device - |> select([d], %{ - worker: "NervesHub.Workers.DeviceCalculateDeployment", - queue: "device_deployment_calculations", - args: - fragment( - "json_build_object('device_id', ?, 'deployment_id', ?::integer)", - d.id, - ^deployment_group.id - ) - }) - |> where([d], d.status == :provisioned) - |> where( - [d], - d.deployment_id == ^deployment_group.id or - (is_nil(d.deployment_id) and d.product_id == ^deployment_group.product_id) - ) - |> where([d], d.firmware_metadata["platform"] == ^deployment_group.firmware.platform) - |> where( - [d], - d.firmware_metadata["architecture"] == ^deployment_group.firmware.architecture - ) - |> where([d], fragment("? <@ ?", ^deployment_group.conditions["tags"], d.tags)) - - Repo.insert_all(Oban.Job, query) - end - - @doc """ - >>>>>>> 0bad5315 (WIP) Delete any matching inflight deployment checks for devices """ @spec delete_inflight_checks(DeploymentGroup.t()) :: :ok @@ -279,7 +239,7 @@ defmodule NervesHub.Deployments do case Repo.insert(changeset) do {:ok, deployment} -> - _ = broadcast(:monitor, "deployments/new", %{deployment_id: deployment.id}) + _ = broadcast(:monitor, "deployment_groups/new", %{deployment_id: deployment.id}) {:ok, deployment} @@ -292,30 +252,30 @@ defmodule NervesHub.Deployments do def broadcast(:none, event, payload) do message = %Phoenix.Socket.Broadcast{ - topic: "deployment:none", + topic: "deployment_group:none", event: event, payload: payload } - Phoenix.PubSub.broadcast(NervesHub.PubSub, "deployment:none", message) + Phoenix.PubSub.broadcast(NervesHub.PubSub, "deployment_group:none", message) end def broadcast(:monitor, event, payload) do Phoenix.PubSub.broadcast( NervesHub.PubSub, - "deployment:monitor", + "deployment_group:monitor", %Phoenix.Socket.Broadcast{event: event, payload: payload} ) end def broadcast(%DeploymentGroup{id: id}, event, payload) do message = %Phoenix.Socket.Broadcast{ - topic: "deployment:#{id}", + topic: "deployment_group:#{id}", event: event, payload: payload } - Phoenix.PubSub.broadcast(NervesHub.PubSub, "deployment:#{id}", message) + Phoenix.PubSub.broadcast(NervesHub.PubSub, "deployment_group:#{id}", message) end @doc """ @@ -349,7 +309,7 @@ defmodule NervesHub.Deployments do @spec verify_deployment_membership(Device.t()) :: Device.t() def verify_deployment_membership(%Device{deployment_id: deployment_id} = device) when not is_nil(deployment_id) do - %{deployment: deployment} = device = Repo.preload(device, deployment: :firmware) + %{deployment_group: deployment} = device = Repo.preload(device, deployment_group: :firmware) bad_architecture = device.firmware_metadata.architecture != deployment.firmware.architecture bad_platform = device.firmware_metadata.platform != deployment.firmware.platform @@ -380,6 +340,6 @@ defmodule NervesHub.Deployments do def verify_deployment_membership(device), do: device def preload_with_firmware_and_archive(device, force \\ false) do - Repo.preload(device, [deployment: [:archive, :firmware]], force: force) + Repo.preload(device, [deployment_group: [:archive, :firmware]], force: force) end end diff --git a/lib/nerves_hub/deployments/deployment_group.ex b/lib/nerves_hub/manged_deployments/deployment_group.ex similarity index 98% rename from lib/nerves_hub/deployments/deployment_group.ex rename to lib/nerves_hub/manged_deployments/deployment_group.ex index c804a0cd0..224839705 100644 --- a/lib/nerves_hub/deployments/deployment_group.ex +++ b/lib/nerves_hub/manged_deployments/deployment_group.ex @@ -1,4 +1,4 @@ -defmodule NervesHub.Deployments.DeploymentGroup do +defmodule NervesHub.ManagedDeployments.DeploymentGroup do use Ecto.Schema import Ecto.Changeset @@ -66,7 +66,7 @@ defmodule NervesHub.Deployments.DeploymentGroup do field(:total_updating_devices, :integer, default: 0) field(:current_updated_devices, :integer, default: 0) field(:inflight_update_expiration_minutes, :integer, default: 60) - # TODO: (nshoes) this column is unused, remove after Managed Deploys is done + # TODO: (nshoes) this column is unused, remove after Managed Deploys is finished field(:recalculation_type, Ecto.Enum, values: [:device, :calculator_queue], default: :device) timestamps() diff --git a/lib/nerves_hub/deployments/deployment_release.ex b/lib/nerves_hub/manged_deployments/deployment_release.ex similarity index 88% rename from lib/nerves_hub/deployments/deployment_release.ex rename to lib/nerves_hub/manged_deployments/deployment_release.ex index ffaac9f8c..991ee1a7c 100644 --- a/lib/nerves_hub/deployments/deployment_release.ex +++ b/lib/nerves_hub/manged_deployments/deployment_release.ex @@ -1,10 +1,10 @@ -defmodule NervesHub.Deployments.DeploymentRelease do +defmodule NervesHub.ManagedDeployments.DeploymentRelease do use Ecto.Schema import Ecto.Changeset alias NervesHub.Archives.Archive - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Firmwares.Firmware alias NervesHub.Accounts.User diff --git a/lib/nerves_hub/manged_deployments/inflight_deployment_check.ex b/lib/nerves_hub/manged_deployments/inflight_deployment_check.ex new file mode 100644 index 000000000..0defe76e5 --- /dev/null +++ b/lib/nerves_hub/manged_deployments/inflight_deployment_check.ex @@ -0,0 +1,15 @@ +defmodule NervesHub.ManagedDeployments.InflightDeploymentCheck do + use Ecto.Schema + + @timestamps_opts updated_at: false + + alias NervesHub.ManagedDeployments.DeploymentGroup + alias NervesHub.Devices.Device + + schema "inflight_deployment_checks" do + belongs_to(:device, Device) + belongs_to(:deployment_group, DeploymentGroup, foreign_key: :deployment_id) + + timestamps() + end +end diff --git a/lib/nerves_hub/deployments/monitor.ex b/lib/nerves_hub/manged_deployments/monitor.ex similarity index 56% rename from lib/nerves_hub/deployments/monitor.ex rename to lib/nerves_hub/manged_deployments/monitor.ex index 116702ce4..251d82437 100644 --- a/lib/nerves_hub/deployments/monitor.ex +++ b/lib/nerves_hub/manged_deployments/monitor.ex @@ -1,4 +1,4 @@ -defmodule NervesHub.Deployments.Monitor do +defmodule NervesHub.ManagedDeployments.Monitor do @moduledoc """ Deployment Monitor starts a deployment orchestrator per deployment @@ -7,9 +7,9 @@ defmodule NervesHub.Deployments.Monitor do use GenServer - alias NervesHub.DeploymentDynamicSupervisor - alias NervesHub.Deployments - alias NervesHub.Deployments.Orchestrator + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeploymentDynamicSupervisor + alias NervesHub.ManagedDeployments.Orchestrator alias Phoenix.PubSub alias Phoenix.Socket.Broadcast @@ -22,18 +22,18 @@ defmodule NervesHub.Deployments.Monitor do end def init(_) do - _ = PubSub.subscribe(NervesHub.PubSub, "deployment:monitor") + _ = PubSub.subscribe(NervesHub.PubSub, "deployment_group:monitor") {:ok, %State{}, {:continue, :boot}} end def handle_continue(:boot, state) do deployments = - Enum.into(Deployments.all(), %{}, fn deployment -> + Enum.into(ManagedDeployments.all(), %{}, fn deployment -> {:ok, orchestrator_pid} = DynamicSupervisor.start_child( - DeploymentDynamicSupervisor, - {Deployments.Orchestrator, deployment} + ManagedDeploymentDynamicSupervisor, + {ManagedDeployments.Orchestrator, deployment} ) {deployment.id, %{orchestrator_pid: orchestrator_pid}} @@ -42,13 +42,13 @@ defmodule NervesHub.Deployments.Monitor do {:noreply, %{state | deployments: deployments}} end - def handle_info(%Broadcast{event: "deployments/new", payload: payload}, state) do - {:ok, deployment} = Deployments.get(payload.deployment_id) + def handle_info(%Broadcast{event: "deployment_groups/new", payload: payload}, state) do + {:ok, deployment} = ManagedDeployments.get(payload.deployment_id) {:ok, orchestrator_pid} = DynamicSupervisor.start_child( - DeploymentDynamicSupervisor, - {Deployments.Orchestrator, deployment} + ManagedDeploymentDynamicSupervisor, + {ManagedDeployments.Orchestrator, deployment} ) deployments = @@ -57,9 +57,9 @@ defmodule NervesHub.Deployments.Monitor do {:noreply, %{state | deployments: deployments}} end - def handle_info(%Broadcast{event: "deployments/delete", payload: payload}, state) do + def handle_info(%Broadcast{event: "deployment_groups/delete", payload: payload}, state) do pid = GenServer.whereis(Orchestrator.name(payload.deployment_id)) - _ = DynamicSupervisor.terminate_child(DeploymentDynamicSupervisor, pid) + _ = DynamicSupervisor.terminate_child(ManagedDeploymentDynamicSupervisor, pid) deployments = Map.delete(state.deployments, payload.deployment_id) {:noreply, %{state | deployments: deployments}} end diff --git a/lib/nerves_hub/deployments/orchestrator.ex b/lib/nerves_hub/manged_deployments/orchestrator.ex similarity index 81% rename from lib/nerves_hub/deployments/orchestrator.ex rename to lib/nerves_hub/manged_deployments/orchestrator.ex index 8e2fddbf6..a1ea8a053 100644 --- a/lib/nerves_hub/deployments/orchestrator.ex +++ b/lib/nerves_hub/manged_deployments/orchestrator.ex @@ -1,4 +1,4 @@ -defmodule NervesHub.Deployments.Orchestrator do +defmodule NervesHub.ManagedDeployments.Orchestrator do @moduledoc """ Orchestration process to handle passing out updates to devices @@ -24,7 +24,7 @@ defmodule NervesHub.Deployments.Orchestrator do end def name(deployment_id) when is_integer(deployment_id) do - {:via, Registry, {NervesHub.Deployments, deployment_id}} + {:via, Registry, {NervesHub.ManagedDeployments, deployment_id}} end def name(deployment), do: name(deployment.id) @@ -49,9 +49,9 @@ defmodule NervesHub.Deployments.Orchestrator do As devices update and reconnect, the new orchestrator is told that the update was successful, and the process is repeated. """ - @decorate with_span("Deployments.Orchestrator.trigger_update") + @decorate with_span("ManagedDeployments.Orchestrator.trigger_update") def trigger_update(deployment) do - :telemetry.execute([:nerves_hub, :deployment, :trigger_update], %{count: 1}) + :telemetry.execute([:nerves_hub, :deployment_group, :trigger_update], %{count: 1}) match_conditions = [ {:and, {:==, {:map_get, :deployment_id, :"$1"}, deployment.id}, @@ -82,7 +82,7 @@ defmodule NervesHub.Deployments.Orchestrator do devices |> Enum.take(count) |> Enum.each(fn %{device_id: device_id, pid: pid} -> - :telemetry.execute([:nerves_hub, :deployment, :trigger_update, :device], %{count: 1}) + :telemetry.execute([:nerves_hub, :deployment_group, :trigger_update, :device], %{count: 1}) device = %Device{id: device_id} @@ -90,7 +90,7 @@ defmodule NervesHub.Deployments.Orchestrator do if Devices.count_inflight_updates_for(deployment) < deployment.concurrent_updates do case Devices.told_to_update(device, deployment) do {:ok, inflight_update} -> - send(pid, {"deployments/update", inflight_update}) + send(pid, {"deployment_groups/update", inflight_update}) :error -> Logger.error( @@ -108,9 +108,9 @@ defmodule NervesHub.Deployments.Orchestrator do {:ok, deployment, {:continue, :boot}} end - @decorate with_span("Deployments.Orchestrator.boot") + @decorate with_span("ManagedDeployments.Orchestrator.boot") def handle_continue(:boot, deployment) do - _ = PubSub.subscribe(NervesHub.PubSub, "deployment:#{deployment.id}") + _ = PubSub.subscribe(NervesHub.PubSub, "deployment_group:#{deployment.id}") # trigger every 10 minutes, plus a jitter between 1 and 5 seconds, as a back up interval = (10 + :rand.uniform(10)) * 60 * 1000 @@ -129,8 +129,8 @@ defmodule NervesHub.Deployments.Orchestrator do {:noreply, deployment} end - @decorate with_span("Deployments.Orchestrator.handle_info:deployments/update") - def handle_info(%Broadcast{event: "deployments/update"}, deployment) do + @decorate with_span("ManagedDeployments.Orchestrator.handle_info:deployment_groups/update") + def handle_info(%Broadcast{event: "deployment_groups/update"}, deployment) do deployment = deployment |> Repo.reload() @@ -142,7 +142,8 @@ defmodule NervesHub.Deployments.Orchestrator do end # Catch all for unknown broadcasts on a deployment - def handle_info(%Broadcast{topic: "deployment:" <> _}, deployment), do: {:noreply, deployment} + def handle_info(%Broadcast{topic: "deployment_group:" <> _}, deployment), + do: {:noreply, deployment} def handle_info(:trigger, deployment) do trigger_update(deployment) diff --git a/lib/nerves_hub/manged_deployments/supervisor.ex b/lib/nerves_hub/manged_deployments/supervisor.ex new file mode 100644 index 000000000..ee94eed48 --- /dev/null +++ b/lib/nerves_hub/manged_deployments/supervisor.ex @@ -0,0 +1,20 @@ +defmodule NervesHub.ManagedDeployments.Supervisor do + @moduledoc false + + use Supervisor + + def start_link(_) do + Supervisor.start_link(__MODULE__, [], name: __MODULE__) + end + + def init(_) do + children = [ + {Registry, keys: :unique, name: NervesHub.ManagedDeployments}, + NervesHub.ManagedDeployments.Monitor, + {DynamicSupervisor, + strategy: :one_for_one, name: NervesHub.ManagedDeploymentDynamicSupervisor} + ] + + Supervisor.init(children, strategy: :one_for_one) + end +end diff --git a/lib/nerves_hub/types.ex b/lib/nerves_hub/types.ex index e42f77b0e..c5eb4ea56 100644 --- a/lib/nerves_hub/types.ex +++ b/lib/nerves_hub/types.ex @@ -73,7 +73,9 @@ defmodule NervesHub.Types do [ "Elixir.NervesHub.Accounts.Org", "Elixir.NervesHub.Accounts.User", - "Elixir.NervesHub.Deployments.DeploymentGroup", + "Elixir.NervesHub.ManagedDeployments.DeploymentGroup", + # TODO: (nshoes) remove after migrating audit_logs actor/resource type + "Elixir.NervesHub.Deployments.Deployment", "Elixir.NervesHub.Devices.Device", "Elixir.NervesHub.Firmwares.Firmware", "Elixir.NervesHub.Products.Product" diff --git a/lib/nerves_hub/workers/firmware_delta_builder.ex b/lib/nerves_hub/workers/firmware_delta_builder.ex index 2331b944c..a37c70d44 100644 --- a/lib/nerves_hub/workers/firmware_delta_builder.ex +++ b/lib/nerves_hub/workers/firmware_delta_builder.ex @@ -7,7 +7,7 @@ defmodule NervesHub.Workers.FirmwareDeltaBuilder do states: [:available, :scheduled, :executing] ] - alias NervesHub.{Deployments, Firmwares} + alias NervesHub.{ManagedDeployments, Firmwares} @impl Oban.Worker def perform(%Oban.Job{args: %{"source_id" => source_id, "target_id" => target_id}}) do @@ -16,8 +16,8 @@ defmodule NervesHub.Workers.FirmwareDeltaBuilder do {:ok, _firmware_delta} = maybe_create_firmware_delta(source, target) - Enum.each(Deployments.get_deployments_by_firmware(target_id), fn deployment -> - Deployments.broadcast(deployment, "deployments/update") + Enum.each(ManagedDeployments.get_deployments_by_firmware(target_id), fn deployment -> + ManagedDeployments.broadcast(deployment, "deployment_groups/update") end) :ok diff --git a/lib/nerves_hub_web/channels/console_channel.ex b/lib/nerves_hub_web/channels/console_channel.ex index 4ae5dd1d7..21e669d0b 100644 --- a/lib/nerves_hub_web/channels/console_channel.ex +++ b/lib/nerves_hub_web/channels/console_channel.ex @@ -73,10 +73,9 @@ defmodule NervesHubWeb.ConsoleChannel do # now that the console is connected, push down the device's elixir, line by line device = socket.assigns.device device = Repo.preload(device, [:deployment]) - deployment = device.deployment - if deployment && deployment.connecting_code do - device.deployment.connecting_code + if device.deployment_group && device.deployment_group.connecting_code do + device.deployment_group.connecting_code |> String.graphemes() |> Enum.each(fn character -> push(socket, "dn", %{"data" => character}) diff --git a/lib/nerves_hub_web/channels/device_channel.ex b/lib/nerves_hub_web/channels/device_channel.ex index e6fe13a8e..0d32554a6 100644 --- a/lib/nerves_hub_web/channels/device_channel.ex +++ b/lib/nerves_hub_web/channels/device_channel.ex @@ -12,7 +12,7 @@ defmodule NervesHubWeb.DeviceChannel do alias NervesHub.Archives alias NervesHub.AuditLogs.Templates - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments alias NervesHub.Devices alias NervesHub.Devices.Device alias NervesHub.Firmwares @@ -36,7 +36,7 @@ defmodule NervesHubWeb.DeviceChannel do def handle_info({:after_join, params}, %{assigns: %{device: device}} = socket) do device = device - |> Deployments.verify_deployment_membership() + |> ManagedDeployments.verify_deployment_membership() maybe_send_public_keys(device, socket, params) @@ -111,12 +111,15 @@ defmodule NervesHubWeb.DeviceChannel do {:noreply, socket} end - def handle_info(%Broadcast{event: "deployments/update"}, socket) do + def handle_info(%Broadcast{event: "deployment_groups/update"}, socket) do {:noreply, socket} end - @decorate with_span("Channels.DeviceChannel.handle_info:deployments/update") - def handle_info({"deployments/update", inflight_update}, %{assigns: %{device: device}} = socket) do + @decorate with_span("Channels.DeviceChannel.handle_info:deployment_groups/update") + def handle_info( + {"deployment_groups/update", inflight_update}, + %{assigns: %{device: device}} = socket + ) do device = deployment_preload(device) payload = Devices.resolve_update(device) @@ -445,14 +448,14 @@ defmodule NervesHubWeb.DeviceChannel do defp deployment_channel(device) do if device.deployment_id do - "deployment:#{device.deployment_id}" + "deployment_group:#{device.deployment_id}" else - "deployment:none" + "deployment_group:none" end end defp deployment_preload(device) do - Repo.preload(device, [deployment: [:archive, :firmware]], force: true) + Repo.preload(device, [deployment_group: [:archive, :firmware]], force: true) end defp maybe_send_archive(socket) do @@ -462,8 +465,8 @@ defmodule NervesHubWeb.DeviceChannel do version_match = Version.match?(socket.assigns.device_api_version, ">= 2.0.0") if updates_enabled && version_match do - if device.deployment && device.deployment.archive do - archive = device.deployment.archive + if device.deployment_group && device.deployment_group.archive do + archive = device.deployment_group.archive push(socket, "archive", %{ size: archive.size, diff --git a/lib/nerves_hub_web/components/navigation.ex b/lib/nerves_hub_web/components/navigation.ex index bf283901b..2af5d69c7 100644 --- a/lib/nerves_hub_web/components/navigation.ex +++ b/lib/nerves_hub_web/components/navigation.ex @@ -237,7 +237,7 @@ defmodule NervesHubWeb.Components.Navigation do %{ title: "Deployments", active: "", - href: ~p"/org/#{assigns.org.name}/#{assigns.product.name}/deployments" + href: ~p"/org/#{assigns.org.name}/#{assigns.product.name}/deployment_groups" }, %{ title: "Scripts", diff --git a/lib/nerves_hub_web/controllers/api/deployment_controller.ex b/lib/nerves_hub_web/controllers/api/deployment_group_controller.ex similarity index 70% rename from lib/nerves_hub_web/controllers/api/deployment_controller.ex rename to lib/nerves_hub_web/controllers/api/deployment_group_controller.ex index dd05cad6f..b88515f3c 100644 --- a/lib/nerves_hub_web/controllers/api/deployment_controller.ex +++ b/lib/nerves_hub_web/controllers/api/deployment_group_controller.ex @@ -1,9 +1,9 @@ -defmodule NervesHubWeb.API.DeploymentController do +defmodule NervesHubWeb.API.DeploymentGroupController do use NervesHubWeb, :api_controller alias NervesHub.AuditLogs - alias NervesHub.Deployments - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Firmwares action_fallback(NervesHubWeb.API.FallbackController) @@ -14,8 +14,8 @@ defmodule NervesHubWeb.API.DeploymentController do @whitelist_fields [:name, :org_id, :firmware_id, :conditions, :is_active] def index(%{assigns: %{product: product}} = conn, _params) do - deployments = Deployments.get_deployments_by_product(product.id) - render(conn, "index.json", deployments: deployments) + deployments = ManagedDeployments.get_deployments_by_product(product.id) + render(conn, "index.json", deployment_groups: deployments) end def create(%{assigns: %{org: org, product: product, user: user}} = conn, params) do @@ -28,7 +28,7 @@ defmodule NervesHubWeb.API.DeploymentController do params <- Map.put(params, "firmware_id", firmware.id), params <- Map.put(params, "org_id", org.id), params <- whitelist(params, @whitelist_fields), - {:ok, deployment} <- Deployments.create_deployment(params) do + {:ok, deployment} <- ManagedDeployments.create_deployment(params) do AuditLogs.audit!( user, deployment, @@ -39,16 +39,16 @@ defmodule NervesHubWeb.API.DeploymentController do |> put_status(:created) |> put_resp_header( "location", - Routes.api_deployment_path(conn, :show, org.name, product.name, deployment.name) + Routes.api_deployment_group_path(conn, :show, org.name, product.name, deployment.name) ) - |> render("show.json", deployment: %{deployment | firmware: firmware}) + |> render("show.json", deployment_group: %{deployment | firmware: firmware}) end end end def show(%{assigns: %{org: _org, product: product}} = conn, %{"name" => name}) do - with {:ok, deployment} <- Deployments.get_deployment_by_name(product, name) do - render(conn, "show.json", deployment: deployment) + with {:ok, deployment} <- ManagedDeployments.get_deployment_by_name(product, name) do + render(conn, "show.json", deployment_group: deployment) end end @@ -56,24 +56,24 @@ defmodule NervesHubWeb.API.DeploymentController do "name" => name, "deployment" => deployment_params }) do - with {:ok, deployment} <- Deployments.get_deployment_by_name(product, name), + with {:ok, deployment} <- ManagedDeployments.get_deployment_by_name(product, name), {:ok, deployment_params} <- update_params(product, deployment_params), deployment_params <- whitelist(deployment_params, @whitelist_fields), {:ok, %DeploymentGroup{} = updated_deployment} <- - Deployments.update_deployment(deployment, deployment_params) do + ManagedDeployments.update_deployment(deployment, deployment_params) do AuditLogs.audit!( user, deployment, "#{user.name} updated deployment #{deployment.name}" ) - render(conn, "show.json", deployment: updated_deployment) + render(conn, "show.json", deployment_group: updated_deployment) end end def delete(%{assigns: %{product: product}} = conn, %{"name" => name}) do - with {:ok, deployment} <- Deployments.get_deployment_by_name(product, name), - {:ok, _deployment} <- Deployments.delete_deployment(deployment) do + with {:ok, deployment} <- ManagedDeployments.get_deployment_by_name(product, name), + {:ok, _deployment} <- ManagedDeployments.delete_deployment(deployment) do send_resp(conn, :no_content, "") end end diff --git a/lib/nerves_hub_web/controllers/api/device_controller.ex b/lib/nerves_hub_web/controllers/api/device_controller.ex index e2c25845d..e5946ee9a 100644 --- a/lib/nerves_hub_web/controllers/api/device_controller.ex +++ b/lib/nerves_hub_web/controllers/api/device_controller.ex @@ -40,7 +40,7 @@ defmodule NervesHubWeb.API.DeviceController do |> Map.put("product_id", product.id) with {:ok, device} <- Devices.create_device(params) do - device = Repo.preload(device, [:org, :product, deployment: [:firmware]]) + device = Repo.preload(device, [:org, :product, deployment_group: [:firmware]]) conn |> put_status(:created) @@ -85,7 +85,8 @@ defmodule NervesHubWeb.API.DeviceController do def update(%{assigns: %{org: org}} = conn, %{"identifier" => identifier} = params) do with {:ok, device} <- Devices.get_device_by_identifier(org, identifier), {:ok, updated_device} <- Devices.update_device(device, params) do - updated_device = Repo.preload(updated_device, [:org, :product, deployment: [:firmware]]) + updated_device = + Repo.preload(updated_device, [:org, :product, deployment_group: [:firmware]]) conn |> put_status(201) @@ -99,7 +100,7 @@ defmodule NervesHubWeb.API.DeviceController do {:ok, %DeviceCertificate{device_id: device_id}} <- Devices.get_device_certificate_by_x509(cert), {:ok, device} <- Devices.get_device_by_org(org, device_id) do - device = Repo.preload(device, [:org, :product, deployment: [:firmware]]) + device = Repo.preload(device, [:org, :product, deployment_group: [:firmware]]) conn |> put_status(200) @@ -219,7 +220,7 @@ defmodule NervesHubWeb.API.DeviceController do _ = NervesHubWeb.Endpoint.broadcast( "device:#{device.id}", - "deployments/update", + "deployment_groups/update", payload ) diff --git a/lib/nerves_hub_web/controllers/api/fallback_controller.ex b/lib/nerves_hub_web/controllers/api/fallback_controller.ex index e3caa123f..a6945f4e0 100644 --- a/lib/nerves_hub_web/controllers/api/fallback_controller.ex +++ b/lib/nerves_hub_web/controllers/api/fallback_controller.ex @@ -51,6 +51,6 @@ defmodule NervesHubWeb.API.FallbackController do end defp conflict_error?(error) do - error in [:deployments, :firmwares, :devices] + error in [:deployment_groups, :firmwares, :devices] end end diff --git a/lib/nerves_hub_web/controllers/deployment_controller.ex b/lib/nerves_hub_web/controllers/deployment_controller.ex index 22a166637..b2ea20330 100644 --- a/lib/nerves_hub_web/controllers/deployment_controller.ex +++ b/lib/nerves_hub_web/controllers/deployment_controller.ex @@ -2,7 +2,7 @@ defmodule NervesHubWeb.DeploymentController do use NervesHubWeb, :controller alias NervesHub.AuditLogs - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments plug(:validate_role, org: :view) @@ -10,13 +10,13 @@ defmodule NervesHubWeb.DeploymentController do %{assigns: %{org: org, product: product}} = conn, %{"name" => deployment_name} ) do - {:ok, deployment} = Deployments.get_deployment_by_name(product, deployment_name) + {:ok, deployment} = ManagedDeployments.get_deployment_by_name(product, deployment_name) case AuditLogs.logs_for(deployment) do [] -> conn |> put_flash(:error, "No audit logs exist for this deployment.") - |> redirect(to: ~p"/org/#{org.name}/#{product.name}/deployments") + |> redirect(to: ~p"/org/#{org.name}/#{product.name}/deployment_groups") audit_logs -> audit_logs = AuditLogs.format_for_csv(audit_logs) diff --git a/lib/nerves_hub_web/helpers/authorization.ex b/lib/nerves_hub_web/helpers/authorization.ex index c7ebabfd8..12a1fb532 100644 --- a/lib/nerves_hub_web/helpers/authorization.ex +++ b/lib/nerves_hub_web/helpers/authorization.ex @@ -50,10 +50,10 @@ defmodule NervesHub.Helpers.Authorization do def authorized?(:"archive:upload", %OrgUser{role: role}), do: role_check(:manage, role) def authorized?(:"archive:delete", %OrgUser{role: role}), do: role_check(:manage, role) - def authorized?(:"deployment:create", %OrgUser{role: role}), do: role_check(:manage, role) - def authorized?(:"deployment:update", %OrgUser{role: role}), do: role_check(:manage, role) - def authorized?(:"deployment:toggle", %OrgUser{role: role}), do: role_check(:manage, role) - def authorized?(:"deployment:delete", %OrgUser{role: role}), do: role_check(:manage, role) + def authorized?(:"deployment_group:create", %OrgUser{role: role}), do: role_check(:manage, role) + def authorized?(:"deployment_group:update", %OrgUser{role: role}), do: role_check(:manage, role) + def authorized?(:"deployment_group:toggle", %OrgUser{role: role}), do: role_check(:manage, role) + def authorized?(:"deployment_group:delete", %OrgUser{role: role}), do: role_check(:manage, role) def authorized?(:"support_script:create", %OrgUser{role: role}), do: role_check(:manage, role) def authorized?(:"support_script:update", %OrgUser{role: role}), do: role_check(:manage, role) diff --git a/lib/nerves_hub_web/live/dashboard/index.ex b/lib/nerves_hub_web/live/dashboard/index.ex index a53dfd0f9..2839760c2 100644 --- a/lib/nerves_hub_web/live/dashboard/index.ex +++ b/lib/nerves_hub_web/live/dashboard/index.ex @@ -3,7 +3,7 @@ defmodule NervesHubWeb.Live.Dashboard.Index do alias NervesHub.Devices alias NervesHub.Devices.Device - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments alias Phoenix.Socket.Broadcast @@ -89,7 +89,7 @@ defmodule NervesHubWeb.Live.Dashboard.Index do Devices.get_minimal_device_location_by_org_id_and_product_id(org.id, product.id) latest_firmwares = - Deployments.get_deployments_by_product(product.id) + ManagedDeployments.get_deployments_by_product(product.id) |> Enum.reduce(%{}, fn deployment, acc -> Map.put(acc, deployment.firmware.uuid, deployment.firmware.platform) end) diff --git a/lib/nerves_hub_web/live/deployments/edit.ex b/lib/nerves_hub_web/live/deployment_groups/edit.ex similarity index 85% rename from lib/nerves_hub_web/live/deployments/edit.ex rename to lib/nerves_hub_web/live/deployment_groups/edit.ex index 5a655df6e..9cc2b39f9 100644 --- a/lib/nerves_hub_web/live/deployments/edit.ex +++ b/lib/nerves_hub_web/live/deployment_groups/edit.ex @@ -1,10 +1,10 @@ -defmodule NervesHubWeb.Live.Deployments.Edit do +defmodule NervesHubWeb.Live.DeploymentGroup.Edit do use NervesHubWeb, :updated_live_view alias NervesHub.Archives alias NervesHub.AuditLogs - alias NervesHub.Deployments - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Firmwares alias NervesHub.Firmwares.Firmware @@ -14,9 +14,10 @@ defmodule NervesHubWeb.Live.Deployments.Edit do %{product: product} = socket.assigns deployment = - Deployments.get_by_product_and_name!(product, name) |> NervesHub.Repo.preload(:firmware) + ManagedDeployments.get_by_product_and_name!(product, name) + |> NervesHub.Repo.preload(:firmware) - current_device_count = Deployments.get_deployment_device_count(deployment.id) + current_device_count = ManagedDeployments.get_deployment_device_count(deployment.id) archives = Archives.all_by_product(deployment.product) firmwares = Firmwares.get_firmwares_for_deployment(deployment) @@ -25,7 +26,7 @@ defmodule NervesHubWeb.Live.Deployments.Edit do socket |> assign(:archives, archives) - |> assign(:deployment, deployment) + |> assign(:deployment_group, deployment) |> assign(:current_device_count, current_device_count) |> assign(:firmware, deployment.firmware) |> assign(:firmwares, firmwares) @@ -35,14 +36,14 @@ defmodule NervesHubWeb.Live.Deployments.Edit do @impl Phoenix.LiveView def handle_event("update-deployment", %{"deployment_group" => params}, socket) do - %{org_user: org_user, org: org, product: product, user: user, deployment: deployment} = + %{org_user: org_user, org: org, product: product, user: user, deployment_group: deployment} = socket.assigns - authorized!(:"deployment:update", org_user) + authorized!(:"deployment_group:update", org_user) params = inject_conditions_map(params) - case Deployments.update_deployment(deployment, params) do + case ManagedDeployments.update_deployment(deployment, params) do {:ok, updated} -> # Use original deployment so changes will get # marked in audit log @@ -54,7 +55,9 @@ defmodule NervesHubWeb.Live.Deployments.Edit do socket |> put_flash(:info, "Deployment updated") - |> push_navigate(to: ~p"/org/#{org.name}/#{product.name}/deployments/#{updated.name}") + |> push_navigate( + to: ~p"/org/#{org.name}/#{product.name}/deployment_groups/#{updated.name}" + ) |> noreply() {:error, changeset} -> @@ -101,8 +104,8 @@ defmodule NervesHubWeb.Live.Deployments.Edit do |> Enum.map(&[value: &1.id, key: firmware_display_name(&1)]) end - def archive_dropdown_options(acrhives) do - acrhives + def archive_dropdown_options(archives) do + archives |> Enum.sort_by( fn archive -> case Version.parse(archive.version) do diff --git a/lib/nerves_hub_web/live/deployments/edit.html.heex b/lib/nerves_hub_web/live/deployment_groups/edit.html.heex similarity index 99% rename from lib/nerves_hub_web/live/deployments/edit.html.heex rename to lib/nerves_hub_web/live/deployment_groups/edit.html.heex index 8a7857066..caf2deef7 100644 --- a/lib/nerves_hub_web/live/deployments/edit.html.heex +++ b/lib/nerves_hub_web/live/deployment_groups/edit.html.heex @@ -1,4 +1,4 @@ -<.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/#{@deployment.name}"} class="back-link"> +<.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/#{@deployment_group.name}"} class="back-link"> Back to Deployment

Edit Deployment

diff --git a/lib/nerves_hub_web/live/deployments/index.ex b/lib/nerves_hub_web/live/deployment_groups/index.ex similarity index 68% rename from lib/nerves_hub_web/live/deployments/index.ex rename to lib/nerves_hub_web/live/deployment_groups/index.ex index dc3f9121c..54b7b8d27 100644 --- a/lib/nerves_hub_web/live/deployments/index.ex +++ b/lib/nerves_hub_web/live/deployment_groups/index.ex @@ -1,14 +1,14 @@ -defmodule NervesHubWeb.Live.Deployments.Index do +defmodule NervesHubWeb.Live.DeploymentGroup.Index do use NervesHubWeb, :updated_live_view - alias NervesHub.Deployments - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Firmwares.Firmware @impl Phoenix.LiveView def mount(_params, _session, %{assigns: %{product: product}} = socket) do - deployments = Deployments.get_deployments_by_product(product.id) - counts = Deployments.get_deployment_device_counts_by_product(product.id) + deployments = ManagedDeployments.get_deployments_by_product(product.id) + counts = ManagedDeployments.get_deployment_device_counts_by_product(product.id) deployments = deployments @@ -19,7 +19,7 @@ defmodule NervesHubWeb.Live.Deployments.Index do socket |> page_title("Deployments - #{product.name}") - |> assign(:deployments, deployments) + |> assign(:deployment_groups, deployments) |> assign(:counts, counts) |> ok() end diff --git a/lib/nerves_hub_web/live/deployments/index.html.heex b/lib/nerves_hub_web/live/deployment_groups/index.html.heex similarity index 89% rename from lib/nerves_hub_web/live/deployments/index.html.heex rename to lib/nerves_hub_web/live/deployment_groups/index.html.heex index 97a7ce632..4f0e6f2a7 100644 --- a/lib/nerves_hub_web/live/deployments/index.html.heex +++ b/lib/nerves_hub_web/live/deployment_groups/index.html.heex @@ -1,9 +1,9 @@ -<%= if Enum.empty?(@deployments) do %> +<%= if Enum.empty?(@deployment_groups) do %>
No deployments

<%= @product.name %> doesn’t have any deployments configured

- <.link class="btn btn-outline-light btn-action" aria-label="Setup a deployment" navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/new"}> + <.link class="btn btn-outline-light btn-action" aria-label="Setup a deployment" navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/new"}>
Setup your first Deployment @@ -12,13 +12,13 @@ <% else %>

Deployments

- <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/new"} class="btn btn-outline-light btn-action" aria-label="Create deployment"> + <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/new"} class="btn btn-outline-light btn-action" aria-label="Create deployment"> Create Deployment
- <%= for {platform, deployments} <- @deployments do %> + <%= for {platform, deployments} <- @deployment_groups do %>

<%= platform %>

@@ -36,7 +36,7 @@
Name
- <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/#{deployment.name}"}><%= deployment.name %> + <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/#{deployment.name}"}><%= deployment.name %>
@@ -87,7 +87,7 @@ options
- <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployments"} class="btn btn-secondary"> + <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups"} class="btn btn-secondary"> Cancel
@@ -67,7 +67,7 @@
- <.link class="btn btn-secondary" navigate={~p"/org/#{@org.name}/#{@product.name}/deployments"}>Back + <.link class="btn btn-secondary" navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups"}>Back <%= submit("Create Deployment", class: "btn btn-primary") %>
diff --git a/lib/nerves_hub_web/live/deployments/show.ex b/lib/nerves_hub_web/live/deployment_groups/show.ex similarity index 83% rename from lib/nerves_hub_web/live/deployments/show.ex rename to lib/nerves_hub_web/live/deployment_groups/show.ex index 1f28a8f92..02b1de0db 100644 --- a/lib/nerves_hub_web/live/deployments/show.ex +++ b/lib/nerves_hub_web/live/deployment_groups/show.ex @@ -1,9 +1,9 @@ -defmodule NervesHubWeb.Live.Deployments.Show do +defmodule NervesHubWeb.Live.DeploymentGroup.Show do use NervesHubWeb, :updated_live_view alias NervesHub.AuditLogs - alias NervesHub.Deployments - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Devices alias NervesHub.Firmwares.Firmware alias NervesHub.Repo @@ -13,7 +13,7 @@ defmodule NervesHubWeb.Live.Deployments.Show do %{"name" => name} = params %{product: product} = socket.assigns - deployment = Deployments.get_by_product_and_name!(product, name) + deployment = ManagedDeployments.get_by_product_and_name!(product, name) {logs, audit_pager} = AuditLogs.logs_for_feed(deployment, %{ @@ -29,11 +29,11 @@ defmodule NervesHubWeb.Live.Deployments.Show do |> Map.put(:anchor, "latest-activity") inflight_updates = Devices.inflight_updates_for(deployment) - current_device_count = Deployments.get_deployment_device_count(deployment.id) + current_device_count = ManagedDeployments.get_deployment_device_count(deployment.id) socket |> page_title("Deployment - #{deployment.name} - #{product.name}") - |> assign(:deployment, deployment) + |> assign(:deployment_group, deployment) |> assign(:audit_logs, logs) |> assign(:audit_pager, audit_pager) |> assign(:inflight_updates, inflight_updates) @@ -54,12 +54,12 @@ defmodule NervesHubWeb.Live.Deployments.Show do @impl Phoenix.LiveView def handle_event("toggle", _params, socket) do - authorized!(:"deployment:toggle", socket.assigns.org_user) + authorized!(:"deployment_group:toggle", socket.assigns.org_user) - %{deployment: deployment, user: user} = socket.assigns + %{deployment_group: deployment, user: user} = socket.assigns value = !deployment.is_active - {:ok, deployment} = Deployments.update_deployment(deployment, %{is_active: value}) + {:ok, deployment} = ManagedDeployments.update_deployment(deployment, %{is_active: value}) active_str = if value, do: "active", else: "inactive" description = "#{user.name} marked deployment #{deployment.name} #{active_str}" @@ -67,24 +67,24 @@ defmodule NervesHubWeb.Live.Deployments.Show do socket |> put_flash(:info, "Deployment set #{active_str}") - |> assign(:deployment, deployment) + |> assign(:deployment_group, deployment) |> noreply() end def handle_event("delete", _params, socket) do - authorized!(:"deployment:delete", socket.assigns.org_user) + authorized!(:"deployment_group:delete", socket.assigns.org_user) - %{deployment: deployment, org: org, product: product, user: user} = socket.assigns + %{deployment_group: deployment, org: org, product: product, user: user} = socket.assigns description = "#{user.name} deleted deployment #{deployment.name}" AuditLogs.audit!(user, deployment, description) - {:ok, _} = Deployments.delete_deployment(deployment) + {:ok, _} = ManagedDeployments.delete_deployment(deployment) socket |> put_flash(:info, "Deployment successfully deleted") - |> push_navigate(to: ~p"/org/#{org.name}/#{product.name}/deployments") + |> push_navigate(to: ~p"/org/#{org.name}/#{product.name}/deployment_groups") |> noreply() end diff --git a/lib/nerves_hub_web/live/deployments/show.html.heex b/lib/nerves_hub_web/live/deployment_groups/show.html.heex similarity index 77% rename from lib/nerves_hub_web/live/deployments/show.html.heex rename to lib/nerves_hub_web/live/deployment_groups/show.html.heex index 7cad02e6d..d8eb527de 100644 --- a/lib/nerves_hub_web/live/deployments/show.html.heex +++ b/lib/nerves_hub_web/live/deployment_groups/show.html.heex @@ -1,14 +1,14 @@
- <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployments"} class="back-link"> + <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups"} class="back-link"> All Deployments
- <.link phx-click="toggle" class="btn btn-outline-light btn-action" aria-label={"Turn #{opposite_status(@deployment)} deployment"}> + <.link phx-click="toggle" class="btn btn-outline-light btn-action" aria-label={"Turn #{opposite_status(@deployment_group)} deployment"}> - Turn <%= opposite_status(@deployment) %> + Turn <%= opposite_status(@deployment_group) %> - <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/#{@deployment.name}/edit"} class="btn btn-outline-light btn-action" aria-label="Edit"> + <.link navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/#{@deployment_group.name}/edit"} class="btn btn-outline-light btn-action" aria-label="Edit"> Edit @@ -18,20 +18,25 @@ Delete - <.link href={~p"/org/#{@org.name}/#{@product.name}/deployments/#{@deployment.name}/audit_logs/download"} class="btn btn-outline-light btn-action" aria-label="Download Audit Logs" download> + <.link + href={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/#{@deployment_group.name}/audit_logs/download"} + class="btn btn-outline-light btn-action" + aria-label="Download Audit Logs" + download + >
Download Audit Logs
-

<%= @deployment.name %>

+

<%= @deployment_group.name %>

State
-

- <%= if @deployment.is_active, do: "On", else: "Off" %> +

+ <%= if @deployment_group.is_active, do: "On", else: "Off" %>

@@ -44,8 +49,8 @@
Distributed to
- <%= if Enum.count(tags(@deployment)) > 0 do %> - <%= for tag <- tags(@deployment) do %> + <%= if Enum.count(tags(@deployment_group)) > 0 do %> + <%= for tag <- tags(@deployment_group) do %> <%= tag %> @@ -63,7 +68,7 @@
Version requirement
-

<%= version(@deployment) %>

+

<%= version(@deployment_group) %>

Current device count
@@ -76,7 +81,7 @@ The number of devices that will update at any given time. This is a soft limit and concurrent updates may be slightly above this number.
-

<%= @deployment.concurrent_updates %>

+

<%= @deployment_group.concurrent_updates %>

@@ -84,7 +89,7 @@ The number of minutes before an inflight update expires to clear the queue
-

<%= @deployment.inflight_update_expiration_minutes %>

+

<%= @deployment_group.inflight_update_expiration_minutes %>

@@ -95,7 +100,7 @@ <%= help_message_for(:failure_rate) %>
-

<%= @deployment.failure_rate_amount %> devices per <%= @deployment.failure_rate_seconds %> seconds

+

<%= @deployment_group.failure_rate_amount %> devices per <%= @deployment_group.failure_rate_seconds %> seconds

@@ -105,7 +110,7 @@ <%= help_message_for(:failure_threshold) %>
-

<%= @deployment.failure_threshold %>

+

<%= @deployment_group.failure_threshold %>

@@ -117,7 +122,7 @@ <%= help_message_for(:device_failure_rate) %> -

<%= @deployment.device_failure_rate_amount %> failures per <%= @deployment.device_failure_rate_seconds %> seconds

+

<%= @deployment_group.device_failure_rate_amount %> failures per <%= @deployment_group.device_failure_rate_seconds %> seconds

@@ -127,7 +132,7 @@ <%= help_message_for(:device_failure_threshold) %>
-

<%= @deployment.device_failure_threshold %>

+

<%= @deployment_group.device_failure_threshold %>

@@ -139,14 +144,14 @@ <%= help_message_for(:penalty_timeout_minutes) %> -

<%= @deployment.penalty_timeout_minutes %> minutes

+

<%= @deployment_group.penalty_timeout_minutes %> minutes

Code sent on Device Connect
- <%= if @deployment.connecting_code do %> -
<%= @deployment.connecting_code %>
+ <%= if @deployment_group.connecting_code do %> +
<%= @deployment_group.connecting_code %>
<% else %>

-

<% end %> @@ -161,8 +166,8 @@
Progress
-
- <%= deployment_percentage(@deployment) %>% +
+ <%= deployment_percentage(@deployment_group) %>%
diff --git a/lib/nerves_hub_web/live/devices/show.ex b/lib/nerves_hub_web/live/devices/show.ex index a52bb3494..9d66d89dd 100644 --- a/lib/nerves_hub_web/live/devices/show.ex +++ b/lib/nerves_hub_web/live/devices/show.ex @@ -36,7 +36,7 @@ defmodule NervesHubWeb.Live.Devices.Show do |> assign(:device, device) |> assign(:device_connection, device_connection(device)) |> assign(:console_active?, Tracker.console_active?(device)) - |> assign(:deployment, device.deployment) + |> assign(:deployment_group, device.deployment_group) |> assign(:update_information, Devices.resolve_update(device)) |> assign(:firmwares, Firmwares.get_firmware_for_device(device)) |> assign(:latest_metrics, Devices.Metrics.get_latest_metric_set_for_device(device.id)) @@ -279,7 +279,7 @@ defmodule NervesHubWeb.Live.Devices.Show do def handle_event("push-available-update", _, socket) do authorized!(:"device:push-update", socket.assigns.org_user) - %{device: device, deployment: deployment, user: user} = socket.assigns + %{device: device, deployment_group: deployment, user: user} = socket.assigns deployment = NervesHub.Repo.preload(deployment, :firmware) @@ -293,7 +293,7 @@ defmodule NervesHubWeb.Live.Devices.Show do _ = NervesHubWeb.Endpoint.broadcast( "device:#{device.id}", - "deployments/update", + "deployment_groups/update", inflight_update ) @@ -360,9 +360,9 @@ defmodule NervesHubWeb.Live.Devices.Show do end defp connecting_code(device) do - if device.deployment && device.deployment.connecting_code do + if device.deployment_group && device.deployment_group.connecting_code do """ - #{device.deployment.connecting_code} + #{device.deployment_group.connecting_code} #{device.connecting_code} """ else diff --git a/lib/nerves_hub_web/live/devices/show.html.heex b/lib/nerves_hub_web/live/devices/show.html.heex index e63139dab..2a972a157 100644 --- a/lib/nerves_hub_web/live/devices/show.html.heex +++ b/lib/nerves_hub_web/live/devices/show.html.heex @@ -201,10 +201,10 @@
Assigned Deployment
- <.link :if={@deployment} navigate={~p"/org/#{@org.name}/#{@product.name}/deployments/#{@deployment.name}"} class="badge"> -
<%= @deployment.name %>
+ <.link :if={@deployment_group} navigate={~p"/org/#{@org.name}/#{@product.name}/deployment_groups/#{@deployment_group.name}"} class="badge"> +
<%= @deployment_group.name %>
- No Assigned Deployment + No Assigned Deployment
diff --git a/lib/nerves_hub_web/router.ex b/lib/nerves_hub_web/router.ex index 3635ec62b..d55b1d5d2 100644 --- a/lib/nerves_hub_web/router.ex +++ b/lib/nerves_hub_web/router.ex @@ -153,12 +153,12 @@ defmodule NervesHubWeb.Router do delete("/:uuid", FirmwareController, :delete) end - scope "/deployments" do - get("/", DeploymentController, :index) - post("/", DeploymentController, :create) - get("/:name", DeploymentController, :show) - put("/:name", DeploymentController, :update) - delete("/:name", DeploymentController, :delete) + scope "/deployment_groups" do + get("/", DeploymentGroupController, :index) + post("/", DeploymentGroupController, :create) + get("/:name", DeploymentGroupController, :show) + put("/:name", DeploymentGroupController, :update) + delete("/:name", DeploymentGroupController, :delete) end end end @@ -202,7 +202,7 @@ defmodule NervesHubWeb.Router do get("/archives/:uuid/download", DownloadController, :archive) get("/firmware/:uuid/download", DownloadController, :firmware) - get("/deployments/:name/audit_logs/download", DeploymentController, :export_audit_logs) + get("/deployment_groups/:name/audit_logs/download", DeploymentController, :export_audit_logs) end scope "/", NervesHubWeb do @@ -280,10 +280,14 @@ defmodule NervesHubWeb.Router do live("/org/:org_name/:product_name/archives/upload", Live.Archives, :upload) live("/org/:org_name/:product_name/archives/:archive_uuid", Live.Archives, :show) - live("/org/:org_name/:product_name/deployments", Live.Deployments.Index) - live("/org/:org_name/:product_name/deployments/new", Live.Deployments.New) - live("/org/:org_name/:product_name/deployments/:name", Live.Deployments.Show) - live("/org/:org_name/:product_name/deployments/:name/edit", Live.Deployments.Edit) + live("/org/:org_name/:product_name/deployment_groups", Live.DeploymentGroup.Index) + live("/org/:org_name/:product_name/deployment_groups/new", Live.DeploymentGroup.New) + live("/org/:org_name/:product_name/deployment_groups/:name", Live.DeploymentGroup.Show) + + live( + "/org/:org_name/:product_name/deployment_groups/:name/edit", + Live.DeploymentGroup.Edit + ) live("/org/:org_name/:product_name/scripts", Live.SupportScripts.Index) live("/org/:org_name/:product_name/scripts/new", Live.SupportScripts.New) diff --git a/lib/nerves_hub_web/views/api/deployment_group_view.ex b/lib/nerves_hub_web/views/api/deployment_group_view.ex new file mode 100644 index 000000000..cbcfb1905 --- /dev/null +++ b/lib/nerves_hub_web/views/api/deployment_group_view.ex @@ -0,0 +1,23 @@ +defmodule NervesHubWeb.API.DeploymentGroupView do + use NervesHubWeb, :api_view + + alias NervesHubWeb.API.DeploymentGroupView + + def render("index.json", %{deployment_groups: deployment_groups}) do + %{data: render_many(deployment_groups, DeploymentGroupView, "deployment_group.json")} + end + + def render("show.json", %{deployment_group: deployment_group}) do + %{data: render_one(deployment_group, DeploymentGroupView, "deployment_group.json")} + end + + def render("deployment_group.json", %{deployment_group: deployment_group}) do + %{ + name: deployment_group.name, + is_active: deployment_group.is_active, + state: if(deployment_group.is_active, do: "on", else: "off"), + firmware_uuid: deployment_group.firmware.uuid, + conditions: deployment_group.conditions + } + end +end diff --git a/lib/nerves_hub_web/views/api/deployment_view.ex b/lib/nerves_hub_web/views/api/deployment_view.ex deleted file mode 100644 index f5c07a13b..000000000 --- a/lib/nerves_hub_web/views/api/deployment_view.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule NervesHubWeb.API.DeploymentView do - use NervesHubWeb, :api_view - - alias NervesHubWeb.API.DeploymentView - - def render("index.json", %{deployments: deployments}) do - %{data: render_many(deployments, DeploymentView, "deployment.json")} - end - - def render("show.json", %{deployment: deployment}) do - %{data: render_one(deployment, DeploymentView, "deployment.json")} - end - - def render("deployment.json", %{deployment: deployment}) do - %{ - name: deployment.name, - is_active: deployment.is_active, - state: if(deployment.is_active, do: "on", else: "off"), - firmware_uuid: deployment.firmware.uuid, - conditions: deployment.conditions - } - end -end diff --git a/lib/nerves_hub_web/views/api/device_view.ex b/lib/nerves_hub_web/views/api/device_view.ex index ea483bf5f..a5b32f8ef 100644 --- a/lib/nerves_hub_web/views/api/device_view.ex +++ b/lib/nerves_hub_web/views/api/device_view.ex @@ -28,7 +28,10 @@ defmodule NervesHubWeb.API.DeviceView do last_communication: connection_last_seen_at(device), description: device.description, firmware_metadata: device.firmware_metadata, - deployment: render_one(device.deployment, __MODULE__, "deployment.json", as: :deployment), + deployment_group: + render_one(device.deployment_group, __MODULE__, "deployment_group.json", + as: :deployment_group + ), updates_enabled: device.updates_enabled, updates_blocked_until: device.updates_blocked_until, org_name: device.org.name, @@ -36,12 +39,12 @@ defmodule NervesHubWeb.API.DeviceView do } end - def render("deployment.json", %{deployment: deployment}) do + def render("deployment_group.json", %{deployment_group: deployment_group}) do %{ - firmware_uuid: deployment.firmware.uuid, - firmware_version: deployment.firmware.version, - is_active: deployment.is_active, - name: deployment.name + firmware_uuid: deployment_group.firmware.uuid, + firmware_version: deployment_group.firmware.version, + is_active: deployment_group.is_active, + name: deployment_group.name } end diff --git a/lib/nerves_hub_web/views/layout_view.ex b/lib/nerves_hub_web/views/layout_view.ex index 3984c4087..b34ac4375 100644 --- a/lib/nerves_hub_web/views/layout_view.ex +++ b/lib/nerves_hub_web/views/layout_view.ex @@ -193,7 +193,7 @@ defmodule NervesHubWeb.LayoutView do %{ title: "Deployments", active: "", - href: ~p"/org/#{conn.assigns.org.name}/#{conn.assigns.product.name}/deployments" + href: ~p"/org/#{conn.assigns.org.name}/#{conn.assigns.product.name}/deployment_groups" }, %{ title: "Scripts", diff --git a/priv/repo/add_org_id.exs b/priv/repo/add_org_id.exs index e6ffe92d4..1780aac38 100644 --- a/priv/repo/add_org_id.exs +++ b/priv/repo/add_org_id.exs @@ -1,7 +1,7 @@ alias NervesHub.Repo alias NervesHub.Firmwares.Firmware alias NervesHub.Devices.DeviceCertificate -alias NervesHub.Deployments.DeploymentGroup +alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.AuditLogs.AuditLog import Ecto.Query diff --git a/test/nerves_hub/devices_test.exs b/test/nerves_hub/devices_test.exs index 61a3682fb..5d62ff14a 100644 --- a/test/nerves_hub/devices_test.exs +++ b/test/nerves_hub/devices_test.exs @@ -2,7 +2,7 @@ defmodule NervesHub.DevicesTest do use NervesHub.DataCase, async: false alias NervesHub.AuditLogs - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments alias NervesHub.Devices alias NervesHub.Devices.CACertificate alias NervesHub.Devices.DeviceCertificate @@ -385,13 +385,13 @@ defmodule NervesHub.DevicesTest do } {:ok, deployment} = - Deployments.create_deployment(params) + ManagedDeployments.create_deployment(params) |> elem(1) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) {:ok, device_with_firmware} = Devices.get_device_by_org(org, device.id) - [%Deployments.DeploymentGroup{id: dep_id} | _] = + [%ManagedDeployments.DeploymentGroup{id: dep_id} | _] = Devices.get_eligible_deployments(device_with_firmware) assert dep_id == deployment.id @@ -426,9 +426,9 @@ defmodule NervesHub.DevicesTest do } {:ok, _deployment} = - Deployments.create_deployment(params) + ManagedDeployments.create_deployment(params) |> elem(1) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) {:ok, device_with_firmware} = Devices.get_device_by_org(org, device.id) @@ -451,7 +451,10 @@ defmodule NervesHub.DevicesTest do firmware1 = Fixtures.firmware_fixture(org_key, product, %{version: "2.0.0"}) - Deployments.update_deployment(old_deployment, %{firmware_id: firmware1.id, is_active: true}) + ManagedDeployments.update_deployment(old_deployment, %{ + firmware_id: firmware1.id, + is_active: true + }) device = Fixtures.device_fixture(org, product, firmware, %{ @@ -474,9 +477,9 @@ defmodule NervesHub.DevicesTest do } {:ok, _deployment2} = - Deployments.create_deployment(params) + ManagedDeployments.create_deployment(params) |> elem(1) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) {:ok, device_with_firmware} = Devices.get_device_by_org(org, device.id) diff --git a/test/nerves_hub/deployments_test.exs b/test/nerves_hub/managed_deployments_test.exs similarity index 81% rename from test/nerves_hub/deployments_test.exs rename to test/nerves_hub/managed_deployments_test.exs index 7c2fb474c..3eea81578 100644 --- a/test/nerves_hub/deployments_test.exs +++ b/test/nerves_hub/managed_deployments_test.exs @@ -1,8 +1,8 @@ -defmodule NervesHub.DeploymentsTest do +defmodule NervesHub.ManagedDeploymentsTest do use NervesHub.DataCase, async: false import Phoenix.ChannelTest - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments alias NervesHub.Fixtures alias Ecto.Changeset @@ -52,7 +52,8 @@ defmodule NervesHub.DeploymentsTest do is_active: false } - {:ok, %Deployments.DeploymentGroup{} = deployment} = Deployments.create_deployment(params) + {:ok, %ManagedDeployments.DeploymentGroup{} = deployment} = + ManagedDeployments.create_deployment(params) for key <- Map.keys(params) do assert Map.get(deployment, key) == Map.get(params, key) @@ -76,7 +77,7 @@ defmodule NervesHub.DeploymentsTest do } assert {:error, %Ecto.Changeset{errors: [name: {"has already been taken", _}]}} = - Deployments.create_deployment(params) + ManagedDeployments.create_deployment(params) end test "create_deployment with invalid parameters" do @@ -89,7 +90,7 @@ defmodule NervesHub.DeploymentsTest do is_active: true } - assert {:error, %Changeset{}} = Deployments.create_deployment(params) + assert {:error, %Changeset{}} = ManagedDeployments.create_deployment(params) end end @@ -115,13 +116,13 @@ defmodule NervesHub.DeploymentsTest do is_active: false } - {:ok, deployment} = Deployments.create_deployment(params) + {:ok, deployment} = ManagedDeployments.create_deployment(params) - Phoenix.PubSub.subscribe(NervesHub.PubSub, "deployment:#{deployment.id}") + Phoenix.PubSub.subscribe(NervesHub.PubSub, "deployment_group:#{deployment.id}") - {:ok, _deployment} = Deployments.update_deployment(deployment, %{is_active: true}) + {:ok, _deployment} = ManagedDeployments.update_deployment(deployment, %{is_active: true}) - assert_broadcast("deployments/update", %{}, 500) + assert_broadcast("deployment_groups/update", %{}, 500) end end end diff --git a/test/nerves_hub_web/channels/websocket_test.exs b/test/nerves_hub_web/channels/websocket_test.exs index 59a9f059d..d7ee8e519 100644 --- a/test/nerves_hub_web/channels/websocket_test.exs +++ b/test/nerves_hub_web/channels/websocket_test.exs @@ -6,8 +6,8 @@ defmodule NervesHubWeb.WebsocketTest do import TrackerHelper alias NervesHub.Fixtures - alias NervesHub.Deployments - alias NervesHub.Deployments.Orchestrator + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeployments.Orchestrator alias NervesHub.Devices alias NervesHub.Devices.Connections alias NervesHub.Devices.Device @@ -660,7 +660,7 @@ defmodule NervesHubWeb.WebsocketTest do "tags" => ["beta"] } }) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) device = Fixtures.device_fixture( @@ -682,7 +682,7 @@ defmodule NervesHubWeb.WebsocketTest do Fixtures.firmware_fixture(org_key, firmware.product, %{version: "0.0.2", dir: tmp_dir}) {:ok, deployment} = - Deployments.update_deployment(deployment, %{ + ManagedDeployments.update_deployment(deployment, %{ firmware_id: new_firmware.id }) @@ -757,7 +757,7 @@ defmodule NervesHubWeb.WebsocketTest do "tags" => ["beta", "beta-edge"] } }) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) device = Fixtures.device_fixture( @@ -819,7 +819,7 @@ defmodule NervesHubWeb.WebsocketTest do "tags" => ["beta", "beta-edge"] } }) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) device = Fixtures.device_fixture( @@ -850,23 +850,6 @@ defmodule NervesHubWeb.WebsocketTest do device = Repo.reload(device) assert device.deployment_id - - Fixtures.device_certificate_fixture(device) - - {:ok, socket} = SocketClient.start_link(@socket_config) - - SocketClient.join_and_wait(socket, %{ - "nerves_fw_architecture" => device.firmware_metadata.architecture, - "nerves_fw_platform" => device.firmware_metadata.platform, - "nerves_fw_version" => "0.0.1" - }) - - Process.sleep(100) - - device = Repo.reload(device) - assert device.deployment_id - - SocketClient.clean_close(socket) end end @@ -919,7 +902,7 @@ defmodule NervesHubWeb.WebsocketTest do SocketClient.clean_close(socket) end - test "vaild certificate expired signer can connect", %{user: user, tmp_dir: tmp_dir} do + test "valid certificate expired signer can connect", %{user: user, tmp_dir: tmp_dir} do org = Fixtures.org_fixture(user, %{name: "custom_ca_test"}) {device, _firmware} = device_fixture(tmp_dir, user, %{identifier: @valid_serial}, org) @@ -1054,7 +1037,7 @@ defmodule NervesHubWeb.WebsocketTest do }, archive_id: archive.id }) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) device = Fixtures.device_fixture( @@ -1102,7 +1085,7 @@ defmodule NervesHubWeb.WebsocketTest do }, archive_id: archive.id }) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) device = Fixtures.device_fixture( @@ -1153,7 +1136,7 @@ defmodule NervesHubWeb.WebsocketTest do "tags" => ["beta"] } }) - |> Deployments.update_deployment(%{is_active: true}) + |> ManagedDeployments.update_deployment(%{is_active: true}) device = Fixtures.device_fixture( @@ -1174,7 +1157,8 @@ defmodule NervesHubWeb.WebsocketTest do assert_connection_change() - {:ok, _deployment} = Deployments.update_deployment(deployment, %{archive_id: archive.id}) + {:ok, _deployment} = + ManagedDeployments.update_deployment(deployment, %{archive_id: archive.id}) archive = SocketClient.wait_archive(socket) assert %{"url" => _, "version" => _} = archive diff --git a/test/nerves_hub_web/controllers/api/deployment_controller_test.exs b/test/nerves_hub_web/controllers/api/deployment_controller_test.exs index 33e0d3042..da9346be1 100644 --- a/test/nerves_hub_web/controllers/api/deployment_controller_test.exs +++ b/test/nerves_hub_web/controllers/api/deployment_controller_test.exs @@ -1,11 +1,11 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do use NervesHubWeb.APIConnCase, async: true - alias NervesHub.{AuditLogs, Deployments.DeploymentGroup, Fixtures} + alias NervesHub.{AuditLogs, ManagedDeployments.DeploymentGroup, Fixtures} describe "index" do test "lists all deployments", %{conn: conn, org: org, product: product} do - conn = get(conn, Routes.api_deployment_path(conn, :index, org.name, product.name)) + conn = get(conn, Routes.api_deployment_group_path(conn, :index, org.name, product.name)) assert json_response(conn, 200)["data"] == [] end end @@ -36,11 +36,20 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do params: params, product: product } do - conn = post(conn, Routes.api_deployment_path(conn, :create, org.name, product.name), params) + conn = + post( + conn, + Routes.api_deployment_group_path(conn, :create, org.name, product.name), + params + ) + assert json_response(conn, 201)["data"] conn = - get(conn, Routes.api_deployment_path(conn, :show, org.name, product.name, params.name)) + get( + conn, + Routes.api_deployment_group_path(conn, :show, org.name, product.name, params.name) + ) assert json_response(conn, 200)["data"]["name"] == params.name end @@ -52,7 +61,13 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do product: product, user: user } do - conn = post(conn, Routes.api_deployment_path(conn, :create, org.name, product.name), params) + conn = + post( + conn, + Routes.api_deployment_group_path(conn, :create, org.name, product.name), + params + ) + assert json_response(conn, 201)["data"] [audit_log] = AuditLogs.logs_by(user) @@ -60,7 +75,7 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do end test "renders errors when data is invalid", %{conn: conn, org: org, product: product} do - conn = post(conn, Routes.api_deployment_path(conn, :create, org.name, product.name)) + conn = post(conn, Routes.api_deployment_group_path(conn, :create, org.name, product.name)) assert json_response(conn, 500)["errors"] != %{} end end @@ -74,11 +89,15 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do org: org, product: product } do - path = Routes.api_deployment_path(conn, :update, org.name, product.name, deployment.name) + path = + Routes.api_deployment_group_path(conn, :update, org.name, product.name, deployment.name) + conn = put(conn, path, deployment: %{"is_active" => true}) assert %{"is_active" => true} = json_response(conn, 200)["data"] - path = Routes.api_deployment_path(conn, :show, org.name, product.name, deployment.name) + path = + Routes.api_deployment_group_path(conn, :show, org.name, product.name, deployment.name) + conn = get(conn, path) assert json_response(conn, 200)["data"]["is_active"] end @@ -89,19 +108,25 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do org: org, product: product } do - path = Routes.api_deployment_path(conn, :update, org.name, product.name, deployment.name) + path = + Routes.api_deployment_group_path(conn, :update, org.name, product.name, deployment.name) + refute deployment.is_active conn = put(conn, path, deployment: %{"state" => "on"}) assert %{"is_active" => true, "state" => "on"} = json_response(conn, 200)["data"] - path = Routes.api_deployment_path(conn, :show, org.name, product.name, deployment.name) + path = + Routes.api_deployment_group_path(conn, :show, org.name, product.name, deployment.name) + conn = get(conn, path) assert json_response(conn, 200)["data"]["is_active"] assert json_response(conn, 200)["data"]["state"] == "on" end test "audits on success", %{conn: conn, deployment: deployment, org: org, product: product} do - path = Routes.api_deployment_path(conn, :update, org.name, product.name, deployment.name) + path = + Routes.api_deployment_group_path(conn, :update, org.name, product.name, deployment.name) + conn = put(conn, path, deployment: %{"is_active" => true}) assert json_response(conn, 200)["data"] @@ -115,7 +140,9 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do org: org, product: product } do - path = Routes.api_deployment_path(conn, :update, org.name, product.name, deployment.name) + path = + Routes.api_deployment_group_path(conn, :update, org.name, product.name, deployment.name) + conn = put(conn, path, deployment: %{is_active: "1234"}) assert json_response(conn, 422)["errors"] != %{} end @@ -133,7 +160,7 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do conn = delete( conn, - Routes.api_deployment_path(conn, :delete, org.name, product.name, deployment.name) + Routes.api_deployment_group_path(conn, :delete, org.name, product.name, deployment.name) ) assert response(conn, 204) @@ -141,7 +168,7 @@ defmodule NervesHubWeb.API.DeploymentControllerTest do conn = get( conn, - Routes.api_deployment_path(conn, :show, org.name, product.name, deployment.name) + Routes.api_deployment_group_path(conn, :show, org.name, product.name, deployment.name) ) assert response(conn, 404) diff --git a/test/nerves_hub_web/controllers/api/device_controller_test.exs b/test/nerves_hub_web/controllers/api/device_controller_test.exs index b218f0a74..775d8dde5 100644 --- a/test/nerves_hub_web/controllers/api/device_controller_test.exs +++ b/test/nerves_hub_web/controllers/api/device_controller_test.exs @@ -147,7 +147,7 @@ defmodule NervesHubWeb.API.DeviceControllerTest do conn = post(conn, url, %{"uuid" => firmware_two.uuid}) assert response(conn, 204) - assert_broadcast("deployments/update", %{}) + assert_broadcast("deployment_groups/update", %{}) end end diff --git a/test/nerves_hub_web/live/devices/show_test.exs b/test/nerves_hub_web/live/devices/show_test.exs index 315d3f316..10ad45403 100644 --- a/test/nerves_hub_web/live/devices/show_test.exs +++ b/test/nerves_hub_web/live/devices/show_test.exs @@ -388,7 +388,7 @@ defmodule NervesHubWeb.Live.Devices.ShowTest do assert Repo.aggregate(NervesHub.Devices.InflightUpdate, :count) == 1 - assert_receive %Phoenix.Socket.Broadcast{event: "deployments/update"} + assert_receive %Phoenix.Socket.Broadcast{event: "deployment_groups/update"} end end diff --git a/test/nerves_hub_web/live/deployments/edit_test.exs b/test/nerves_hub_web/live/managed_deployments/edit_test.exs similarity index 76% rename from test/nerves_hub_web/live/deployments/edit_test.exs rename to test/nerves_hub_web/live/managed_deployments/edit_test.exs index 6da7182c8..b367564a6 100644 --- a/test/nerves_hub_web/live/deployments/edit_test.exs +++ b/test/nerves_hub_web/live/managed_deployments/edit_test.exs @@ -1,9 +1,9 @@ -defmodule NervesHubWeb.Live.Deployments.EditTest do +defmodule NervesHubWeb.Live.ManagedDeployments.EditTest do use NervesHubWeb.ConnCase.Browser, async: true alias NervesHub.AuditLogs - alias NervesHub.Deployments - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Fixtures test "update the chosen resource, and adds an audit log", %{ @@ -19,7 +19,7 @@ defmodule NervesHubWeb.Live.Deployments.EditTest do conn = conn - |> visit("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}/edit") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}/edit") |> assert_has("h1", text: "Edit Deployment") |> assert_has("a", text: product.name) |> fill_in("Deployment name", with: "Moussaka") @@ -28,11 +28,11 @@ defmodule NervesHubWeb.Live.Deployments.EditTest do |> fill_in("Firmware version", with: firmware.id) |> click_button("Save Change") - {:ok, reloaded_deployment} = Deployments.get_deployment(product, deployment.id) + {:ok, reloaded_deployment} = ManagedDeployments.get_deployment(product, deployment.id) conn |> assert_path( - URI.encode("/org/#{org.name}/#{product.name}/deployments/#{reloaded_deployment.name}") + URI.encode("/org/#{org.name}/#{product.name}/deployment_groups/#{reloaded_deployment.name}") ) |> assert_has("div", text: "Deployment updated") @@ -58,13 +58,13 @@ defmodule NervesHubWeb.Live.Deployments.EditTest do deployment = Fixtures.deployment_fixture(org, firmware) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}/edit") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}/edit") |> assert_has("h1", text: "Edit Deployment") |> assert_has("a", text: product.name) |> fill_in("Tag(s) distributed to", with: "") |> fill_in("Version requirement", with: "") |> click_button("Save Change") - |> assert_path("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}/edit") + |> assert_path("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}/edit") |> assert_has("div", text: "should have at least 1 item(s)") end end diff --git a/test/nerves_hub_web/live/deployments/index_test.exs b/test/nerves_hub_web/live/managed_deployments/index_test.exs similarity index 73% rename from test/nerves_hub_web/live/deployments/index_test.exs rename to test/nerves_hub_web/live/managed_deployments/index_test.exs index 0c1782b17..5bb128a31 100644 --- a/test/nerves_hub_web/live/deployments/index_test.exs +++ b/test/nerves_hub_web/live/managed_deployments/index_test.exs @@ -1,4 +1,4 @@ -defmodule NervesHubWeb.Live.Deployments.IndexTest do +defmodule NervesHubWeb.Live.ManagedDeployments.IndexTest do use NervesHubWeb.ConnCase.Browser, async: true alias NervesHub.Fixtures @@ -7,13 +7,13 @@ defmodule NervesHubWeb.Live.Deployments.IndexTest do product = Fixtures.product_fixture(user, org, %{name: "Spaghetti"}) conn - |> visit("/org/#{org.name}/#{product.name}/deployments") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups") |> assert_has("h3", text: "#{product.name} doesn’t have any deployments configured") end test "has deployments", %{conn: conn, org: org, product: product, deployment: deployment} do conn - |> visit("/org/#{org.name}/#{product.name}/deployments") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups") |> assert_has("h1", text: "Deployments") |> assert_has("a", text: deployment.name) end diff --git a/test/nerves_hub_web/live/deployments/new_test.exs b/test/nerves_hub_web/live/managed_deployments/new_test.exs similarity index 81% rename from test/nerves_hub_web/live/deployments/new_test.exs rename to test/nerves_hub_web/live/managed_deployments/new_test.exs index 7694acbc6..c76d89a85 100644 --- a/test/nerves_hub_web/live/deployments/new_test.exs +++ b/test/nerves_hub_web/live/managed_deployments/new_test.exs @@ -1,8 +1,8 @@ -defmodule NervesHubWeb.Live.Deployments.NewTest do +defmodule NervesHubWeb.Live.ManagedDeployments.NewTest do use NervesHubWeb.ConnCase.Browser, async: true alias NervesHub.AuditLogs - alias NervesHub.Deployments.DeploymentGroup + alias NervesHub.ManagedDeployments.DeploymentGroup alias NervesHub.Fixtures describe "new deployment" do @@ -19,7 +19,7 @@ defmodule NervesHubWeb.Live.Deployments.NewTest do Fixtures.firmware_fixture(org_key, product, %{dir: tmp_dir, platform: "taramasalata"}) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/new") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/new") |> assert_has("h1", text: "Create Deployment") |> assert_has("option", text: "Choose a platform") |> select(firmware.platform, from: "Platform") @@ -27,9 +27,9 @@ defmodule NervesHubWeb.Live.Deployments.NewTest do |> fill_in("Tag(s) distributed to", with: "josh, lars") |> fill_in("Firmware version", with: firmware.id) |> click_button("Create Deployment") - |> assert_path(URI.encode("/org/#{org.name}/#{product.name}/deployments")) + |> assert_path(URI.encode("/org/#{org.name}/#{product.name}/deployment_groups")) |> assert_has("h1", text: "Deployments") - |> assert_has("div", text: "Deployment created") + |> assert_has("div", text: "Deployment Group created") |> assert_has("a", text: "Moussaka") [%{resource_type: DeploymentGroup}] = AuditLogs.logs_by(user) @@ -48,14 +48,14 @@ defmodule NervesHubWeb.Live.Deployments.NewTest do Fixtures.firmware_fixture(org_key, product, %{dir: tmp_dir, platform: "taramasalata"}) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/new") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/new") |> select(firmware.platform, from: "Platform") |> unwrap(fn view -> view |> element("form") - |> render_submit(%{deployment: %{"firmware_id" => -1}}) + |> render_submit(%{deployment_group: %{"firmware_id" => -1}}) end) - |> assert_path("/org/#{org.name}/#{product.name}/deployments/new") + |> assert_path("/org/#{org.name}/#{product.name}/deployment_groups/new") |> assert_has("div", text: "Invalid firmware selected") end @@ -70,11 +70,11 @@ defmodule NervesHubWeb.Live.Deployments.NewTest do |> init_test_session(%{"auth_user_id" => user.id}) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/new") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/new") |> assert_path(URI.encode("/org/#{org.name}/#{product.name}/firmware/upload")) |> assert_has("h1", text: "Add Firmware") |> assert_has("div", - text: "You must upload a firmware version before creating a deployment" + text: "You must upload a firmware version before creating a Deployment Group" ) end end diff --git a/test/nerves_hub_web/live/deployments/show_test.exs b/test/nerves_hub_web/live/managed_deployments/show_test.exs similarity index 75% rename from test/nerves_hub_web/live/deployments/show_test.exs rename to test/nerves_hub_web/live/managed_deployments/show_test.exs index 2e24e6ea7..a66985128 100644 --- a/test/nerves_hub_web/live/deployments/show_test.exs +++ b/test/nerves_hub_web/live/managed_deployments/show_test.exs @@ -1,8 +1,8 @@ -defmodule NervesHubWeb.Live.Deployments.ShowTest do +defmodule NervesHubWeb.Live.ManagedDeployments.ShowTest do use NervesHubWeb.ConnCase.Browser, async: true alias NervesHub.AuditLogs - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments alias NervesHub.Fixtures test "shows the deployment", %{ @@ -17,7 +17,7 @@ defmodule NervesHubWeb.Live.Deployments.ShowTest do deployment = Fixtures.deployment_fixture(org, firmware) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}") |> assert_has("h1", text: deployment.name) |> assert_has("p.deployment-state", text: "Off") |> then(fn conn -> @@ -41,13 +41,13 @@ defmodule NervesHubWeb.Live.Deployments.ShowTest do deployment = Fixtures.deployment_fixture(org, firmware) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}") |> assert_has("h1", text: deployment.name) |> click_link("Delete") - |> assert_path(URI.encode("/org/#{org.name}/#{product.name}/deployments")) + |> assert_path(URI.encode("/org/#{org.name}/#{product.name}/deployment_groups")) |> assert_has("div", text: "Deployment successfully deleted") - assert Deployments.get_deployment(product, deployment.id) == {:error, :not_found} + assert ManagedDeployments.get_deployment(product, deployment.id) == {:error, :not_found} logs = AuditLogs.logs_for(deployment) @@ -66,12 +66,12 @@ defmodule NervesHubWeb.Live.Deployments.ShowTest do deployment = Fixtures.deployment_fixture(org, firmware) conn - |> visit("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}") + |> visit("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}") |> assert_has("h1", text: deployment.name) |> click_link("Turn On") - |> assert_path("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}") + |> assert_path("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}") |> then(fn conn -> - {:ok, reloaded_deployment} = Deployments.get_deployment(product, deployment.id) + {:ok, reloaded_deployment} = ManagedDeployments.get_deployment(product, deployment.id) assert reloaded_deployment.is_active assert_has(conn, "span", text: "Turn Off") @@ -82,9 +82,9 @@ defmodule NervesHubWeb.Live.Deployments.ShowTest do conn end) |> click_link("Turn Off") - |> assert_path("/org/#{org.name}/#{product.name}/deployments/#{deployment.name}") + |> assert_path("/org/#{org.name}/#{product.name}/deployment_groups/#{deployment.name}") |> then(fn conn -> - {:ok, reloaded_deployment} = Deployments.get_deployment(product, deployment.id) + {:ok, reloaded_deployment} = ManagedDeployments.get_deployment(product, deployment.id) refute reloaded_deployment.is_active assert_has(conn, "span", text: "Turn On") diff --git a/test/support/fixtures.ex b/test/support/fixtures.ex index 534609216..65538069d 100644 --- a/test/support/fixtures.ex +++ b/test/support/fixtures.ex @@ -7,7 +7,7 @@ defmodule NervesHub.Fixtures do alias NervesHub.Certificate alias NervesHub.Devices alias NervesHub.Devices.InflightUpdate - alias NervesHub.Deployments + alias NervesHub.ManagedDeployments alias NervesHub.Firmwares alias NervesHub.Products alias NervesHub.Products.Product @@ -217,7 +217,7 @@ defmodule NervesHub.Fixtures do %{org_id: org.id, firmware_id: firmware.id} |> Enum.into(params) |> Enum.into(@deployment_params) - |> Deployments.create_deployment() + |> ManagedDeployments.create_deployment() deployment end