diff --git a/apps/lenra/lib/lenra/services/openfaas_services.ex b/apps/lenra/lib/lenra/services/openfaas_services.ex index 18ad9e593..0075e2e35 100644 --- a/apps/lenra/lib/lenra/services/openfaas_services.ex +++ b/apps/lenra/lib/lenra/services/openfaas_services.ex @@ -51,10 +51,11 @@ defmodule Lenra.OpenfaasServices do ) Finch.build(:post, url, headers, body) - |> Finch.request(FaasHttp) + |> Finch.request(FaasHttp, receive_timeout: 1000) |> response(:decode) |> case do {:ok, %{"data" => data}} -> {:ok, data} + {:error, :ressource_not_found} -> {:error, :listener_not_found} err -> err end end @@ -77,10 +78,11 @@ defmodule Lenra.OpenfaasServices do body = Jason.encode!(%{widget: widget_name, data: data, props: props}) Finch.build(:post, url, headers, body) - |> Finch.request(FaasHttp) + |> Finch.request(FaasHttp, receive_timeout: 1000) |> response(:decode) |> case do {:ok, %{"widget" => widget}} -> {:ok, widget} + {:error, :ressource_not_found} -> {:error, :widget_not_found} err -> err end end @@ -99,13 +101,16 @@ defmodule Lenra.OpenfaasServices do headers = [{"Content-Type", "application/json"} | base_headers] Finch.build(:post, url, headers) - |> Finch.request(FaasHttp) + |> Finch.request(FaasHttp, receive_timeout: 1000) |> response(:decode) |> case do {:ok, %{"manifest" => manifest}} -> Logger.debug("Got manifest : #{inspect(manifest)}") {:ok, manifest} + {:error, :ressource_not_found} -> + {:error, :manifest_not_found} + err -> Logger.error("Error while getting manifest : #{inspect(err)}") err @@ -153,7 +158,7 @@ defmodule Lenra.OpenfaasServices do headers, body ) - |> Finch.request(FaasHttp) + |> Finch.request(FaasHttp, receive_timeout: 1000) |> response(:deploy_app) end @@ -172,7 +177,7 @@ defmodule Lenra.OpenfaasServices do "functionName" => get_function_name(service_name, build_number) }) ) - |> Finch.request(FaasHttp) + |> Finch.request(FaasHttp, receive_timeout: 1000) |> response(:delete_app) end diff --git a/apps/lenra/test/lenra/services/openfaas_services_test.exs b/apps/lenra/test/lenra/services/openfaas_services_test.exs index cf1abcf1a..2ea40507e 100644 --- a/apps/lenra/test/lenra/services/openfaas_services_test.exs +++ b/apps/lenra/test/lenra/services/openfaas_services_test.exs @@ -54,7 +54,7 @@ defmodule Lenra.OpenfaasServicesTest do test "Openfaas correctly handle 404 not found", %{app: app} do FaasStub.stub_action_once(app, "InitData", {:error, 404, "Not Found"}) - assert {:error, :ressource_not_found} == + assert {:error, :listener_not_found} == OpenfaasServices.run_listener( @john_doe_application, @john_doe_environment, diff --git a/apps/lenra_web/lib/lenra_web/application_runner_adapter.ex b/apps/lenra_web/lib/lenra_web/application_runner_adapter.ex index f9209807d..d17537837 100644 --- a/apps/lenra_web/lib/lenra_web/application_runner_adapter.ex +++ b/apps/lenra_web/lib/lenra_web/application_runner_adapter.ex @@ -23,6 +23,7 @@ defmodule LenraWeb.ApplicationRunnerAdapter do event ) do Logger.info("Run listener for action #{action}") + OpenfaasServices.run_listener(application, environment, action, data, props, event) end @@ -98,4 +99,8 @@ defmodule LenraWeb.ApplicationRunnerAdapter do ) do send(socket_pid, {:send, atom, ui_or_patches}) end + + def on_ui_changed(session_state, message) do + raise "Error, not maching on_ui_changed/2 #{inspect(session_state)}, #{inspect(message)}" + end end diff --git a/apps/lenra_web/lib/lenra_web/channels/app_channel.ex b/apps/lenra_web/lib/lenra_web/channels/app_channel.ex index 6a8c7ccac..b7eac483a 100644 --- a/apps/lenra_web/lib/lenra_web/channels/app_channel.ex +++ b/apps/lenra_web/lib/lenra_web/channels/app_channel.ex @@ -96,15 +96,31 @@ defmodule LenraWeb.AppChannel do {:noreply, socket} end - def handle_info({:send, :error, reason}, socket) do - Logger.debug("send error #{inspect(%{error: reason})}") + def handle_info({:send, :error, {:error, reason}}, socket) when is_atom(reason) do + Logger.error("Send error #{inspect(reason)}") - case is_atom(reason) do - true -> push(socket, "error", %{"errors" => ErrorHelpers.translate_error(reason)}) - # Application error - false -> push(socket, "error", %{"errors" => [%{code: -1, message: reason}]}) - end + push(socket, "error", %{"errors" => ErrorHelpers.translate_error(reason)}) + {:noreply, socket} + end + + def handle_info({:send, :error, {:error, :invalid_ui, errors}}, socket) when is_list(errors) do + formatted_errors = + errors + |> Enum.map(fn {message, path} -> %{code: 0, message: "#{message} at path #{path}"} end) + + push(socket, "error", %{"errors" => formatted_errors}) + {:noreply, socket} + end + + def handle_info({:send, :error, reason}, socket) when is_atom(reason) do + Logger.error("Send error atom #{inspect(reason)}") + push(socket, "error", %{"errors" => ErrorHelpers.translate_error(reason)}) + {:noreply, socket} + end + def handle_info({:send, :error, malformated_error}, socket) do + Logger.error("Malformatted error #{inspect(malformated_error)}") + push(socket, "error", %{"errors" => ErrorHelpers.translate_error(:unknow_error)}) {:noreply, socket} end diff --git a/apps/lenra_web/lib/lenra_web/views/error_helpers.ex b/apps/lenra_web/lib/lenra_web/views/error_helpers.ex index 7016c5aeb..a51e465cd 100644 --- a/apps/lenra_web/lib/lenra_web/views/error_helpers.ex +++ b/apps/lenra_web/lib/lenra_web/views/error_helpers.ex @@ -23,15 +23,16 @@ defmodule LenraWeb.ErrorHelpers do invalid_uuid: %{code: 13, message: "The code is not a valid UUID"}, invalid_code: %{code: 14, message: "The code is invalid"}, invalid_build_status: %{code: 15, message: "The build status should be success or failure."}, - openfass_not_recheable: %{code: 16, message: "Openfaas could not be reached. This should not happen."}, - application_not_found: %{code: 17, message: "The application was not found in Openfaas. This should not happen."}, - listener_not_found: %{code: 18, message: "No listener found in app manifest. This should not happen."}, - openfaas_delete_error: %{code: 19, message: "Openfaas could not delete the application. This should not happen."}, - timeout: %{code: 20, message: "Openfaas timeout. This should not happen."}, + openfass_not_recheable: %{code: 16, message: "Openfaas could not be reached."}, + application_not_found: %{code: 17, message: "The application was not found in Openfaas."}, + listener_not_found: %{code: 18, message: "No listener found in app manifest."}, + openfaas_delete_error: %{code: 19, message: "Openfaas could not delete the application."}, + timeout: %{code: 20, message: "Openfaas timeout."}, no_app_found: %{code: 21, message: "No application found for the current link."}, environement_not_build: %{code: 22, message: "This application was not yet build."}, - widget_not_found: %{code: 23, message: "No Widget found in app manifest. This should not happen."}, + widget_not_found: %{code: 23, message: "No Widget found in app manifest."}, no_app_authorization: %{code: 24, message: "You are not authorized to join this app."}, + invalid_ui: %{code: 25, message: "Invalid UI"}, bad_request: %{code: 400, message: "Server cannot understand or process the request due to a client-side error."}, error_404: %{code: 404, message: "Not Found."}, error_500: %{code: 500, message: "Internal server error."}, diff --git a/apps/lenra_web/mix.exs b/apps/lenra_web/mix.exs index 97b2dc0b9..d3a944c79 100644 --- a/apps/lenra_web/mix.exs +++ b/apps/lenra_web/mix.exs @@ -44,13 +44,14 @@ defmodule LenraWeb.MixProject do {:lenra, in_umbrella: true}, {:cors_plug, "~> 3.0", only: :dev, runtime: false}, {:bouncer, git: "https://github.com/lenra-io/bouncer.git", tag: "v1.0.0"}, - private_git( - name: :application_runner, - host: "github.com", - project: "lenra-io/application-runner.git", - tag: "v1.0.0-beta.22", - credentials: "shiipou:#{System.get_env("GH_PERSONNAL_TOKEN")}" - ) + {:application_runner, path: "../../../application-runner"} + # private_git( + # name: :application_runner, + # host: "github.com", + # project: "lenra-io/application-runner.git", + # tag: "v1.0.0-beta.22", + # credentials: "shiipou:#{System.get_env("GH_PERSONNAL_TOKEN")}" + # ) ] end