-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new demo env that uses faked execution server (#187)
* Add new demo env that uses faked execution server * Randomize results * Build demo image on the CI * Add demo dir to credo and formatter
- Loading branch information
Showing
8 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
/deps/ | ||
/doc/ | ||
/test/ | ||
!/test/support/factory.ex | ||
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Used by "mix format" | ||
[ | ||
import_deps: [:ecto, :phoenix, :open_api_spex], | ||
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test,demo}/**/*.{ex,exs}"], | ||
subdirectories: ["priv/*/migrations"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Config | ||
|
||
config :wanda, Wanda.Policy, execution_server_impl: Wanda.Executions.FakeServer | ||
|
||
config :wanda, WandaWeb.Endpoint, | ||
check_origin: :conn, | ||
cache_static_manifest: "priv/static/cache_manifest.json", | ||
server: true | ||
|
||
config :logger, level: :debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
defmodule Wanda.Executions.FakeServer do | ||
@moduledoc """ | ||
Execution server implementation that does not actually execute anything and just | ||
returns (fake) random results. | ||
""" | ||
@behaviour Wanda.Executions.ServerBehaviour | ||
|
||
import Wanda.Factory | ||
|
||
alias Wanda.{ | ||
Executions, | ||
Messaging | ||
} | ||
|
||
require Logger | ||
|
||
@impl true | ||
def start_execution(execution_id, group_id, targets, _env, _config \\ []) do | ||
create_fake_execution(execution_id, group_id, targets) | ||
Process.sleep(2_000) | ||
complete_fake_execution(execution_id, group_id, targets) | ||
|
||
:ok | ||
end | ||
|
||
@impl true | ||
def receive_facts(_execution_id, _group_id, _agent_id, _facts) do | ||
:ok | ||
end | ||
|
||
defp create_fake_execution(execution_id, group_id, targets) do | ||
insert(:execution, | ||
status: :running, | ||
execution_id: execution_id, | ||
group_id: group_id, | ||
targets: Enum.map(targets, &Map.from_struct/1) | ||
) | ||
|
||
Executions.create_execution!(execution_id, group_id, targets) | ||
execution_started = Messaging.Mapper.to_execution_started(execution_id, group_id, targets) | ||
:ok = Messaging.publish("results", execution_started) | ||
end | ||
|
||
defp complete_fake_execution(execution_id, group_id, targets) do | ||
result = Enum.random([:passing, :warning, :critical]) | ||
check_results = build(:check_results_from_targets, targets: targets, result: result) | ||
|
||
build_result = | ||
build(:result, | ||
check_results: check_results, | ||
execution_id: execution_id, | ||
group_id: group_id, | ||
result: result | ||
) | ||
|
||
Executions.complete_execution!( | ||
execution_id, | ||
build_result | ||
) | ||
|
||
execution_completed = Messaging.Mapper.to_execution_completed(build_result) | ||
:ok = Messaging.publish("results", execution_completed) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters