Skip to content

Commit

Permalink
Cleanup unusued api endpoint and fix callback payload
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosestito committed Mar 31, 2022
1 parent 28dd7c3 commit 5665e29
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ defmodule Trento.Integration.Checks.MockRunner do
"http://localhost:4000/api/runner/callback",
Jason.encode!(%{
"event" => "execution_started",
"cluster_id" => cluster_id,
"execution_id" => execution_id
"execution_id" => execution_id,
"payload" => %{
"cluster_id" => cluster_id
}
}),
[{"Content-type", "application/json"}]
)
Expand Down
4 changes: 3 additions & 1 deletion lib/trento/application/integration/checks/checks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ defmodule Trento.Integration.Checks do
def handle_callback(%{
"event" => "execution_started",
"execution_id" => execution_id,
"cluster_id" => cluster_id
"payload" => %{
"cluster_id" => cluster_id
}
}) do
case StartChecksExecution.new(%{cluster_id: cluster_id}) do
{:ok, command} ->
Expand Down
34 changes: 0 additions & 34 deletions lib/trento_web/controllers/cluster_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,6 @@ defmodule TrentoWeb.ClusterController do
end
end

@spec store_checks_results(Plug.Conn.t(), map) :: Plug.Conn.t()
def store_checks_results(
conn,
%{"cluster_id" => cluster_id, "hosts" => hosts, "checks" => checks}
) do
[host_id] = Map.keys(hosts)

checks_results =
Enum.map(
checks,
fn {check_id, %{"hosts" => %{^host_id => %{"result" => result}}}} ->
%{
check_id: check_id,
result: String.to_atom(result)
}
end
)
|> Enum.reject(fn %{result: result} ->
result == :skipped
end)

case Clusters.store_checks_results(cluster_id, host_id, checks_results) do
:ok ->
conn
|> put_status(:accepted)
|> json(%{})

{:error, reason} ->
conn
|> put_status(:bad_request)
|> json(%{error: reason})
end
end

@spec request_checks_execution(Plug.Conn.t(), map) :: Plug.Conn.t()
def request_checks_execution(conn, %{"cluster_id" => cluster_id}) do
case Clusters.request_checks_execution(cluster_id) do
Expand Down
6 changes: 2 additions & 4 deletions lib/trento_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ defmodule TrentoWeb.Router do
delete "/sap_systems/:id/tags/:value", SapSystemController, :delete_tag
get "/databases", SapSystemController, :list_databases

# TODO: this url is weird because the ansible callback expect so
# let's maybe change it in the future when we will change the agent as well
post "/checks/:cluster_id/results", ClusterController, :store_checks_results
post "/clusters/:cluster_id/checks", ClusterController, :select_checks

post "/runner/callback", ClusterController, :runner_callback


post "/clusters/:cluster_id/checks/request_execution",
ClusterController,
:request_checks_execution

post "/runner/callback", ClusterController, :runner_callback
get "/checks/catalog", CatalogController, :checks_catalog
end

Expand Down

0 comments on commit 5665e29

Please sign in to comment.